From 9e2434c65dc71fb2adc9c94f841907e5f8eca7ad Mon Sep 17 00:00:00 2001 From: Learath Date: Sun, 14 Jun 2020 20:32:14 +0300 Subject: [PATCH] Better skin colors. Better game message translation --- datasrc/crosscompile.py | 6 ++ datasrc/seven/compile.py | 15 +++++ datasrc/seven/datatypes.py | 1 + src/base/color.h | 14 ++++ src/engine/message.h | 3 +- src/engine/server.h | 4 +- src/engine/server/server.cpp | 18 ++--- src/game/server/gamecontext.cpp | 116 ++++++++++++++++++++++---------- src/game/server/teeinfo.cpp | 12 ++-- 9 files changed, 134 insertions(+), 55 deletions(-) diff --git a/datasrc/crosscompile.py b/datasrc/crosscompile.py index 167523d75..683f6ddeb 100644 --- a/datasrc/crosscompile.py +++ b/datasrc/crosscompile.py @@ -40,6 +40,10 @@ def output_map(name, map): print("inline int {0}(int a) {{ if(a < 0 || a >= {1}) return -1; return gs_{0}[a]; }}".format(name, len(map))) def main(): + guard = "GAME_GENERATED_PROTOCOLGLUE" + print("#ifndef " + guard) + print("#define " + guard) + msgs = get_msgs() msgs7 = get_msgs_7() @@ -51,5 +55,7 @@ def main(): output_map("Obj_SixToSeven", generate_map(objs, objs7)) output_map("Obj_SevenToSix", generate_map(objs7, objs)) + print("#endif //" + guard) + if __name__ == "__main__": main() diff --git a/datasrc/seven/compile.py b/datasrc/seven/compile.py index b613d2a71..b3051c640 100644 --- a/datasrc/seven/compile.py +++ b/datasrc/seven/compile.py @@ -115,6 +115,21 @@ if gen_network_header: for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print(l) print("") + print(""" +template +using void_t = void; + +template +struct is_sixup { + constexpr static bool value = false; +}; + +template +struct is_sixup> { + constexpr static bool value = true; +}; +""") + for item in network.Objects + network.Messages: for line in item.emit_declaration(): print(line) diff --git a/datasrc/seven/datatypes.py b/datasrc/seven/datatypes.py index 4fd88420d..26c8f4dc0 100644 --- a/datasrc/seven/datatypes.py +++ b/datasrc/seven/datatypes.py @@ -268,6 +268,7 @@ class NetMessage(NetObject): return lines def emit_declaration(self): extra = [] + extra += ["\tusing is_sixup = char;"] extra += ["\tint MsgID() const { return %s; }" % self.enum_name] extra += ["\t"] extra += ["\tbool Pack(CMsgPacker *pPacker)"] diff --git a/src/base/color.h b/src/base/color.h index f2ae1c6c0..448f8a2fa 100644 --- a/src/base/color.h +++ b/src/base/color.h @@ -136,6 +136,20 @@ public: else return color4_base::Pack(Alpha); } + + unsigned Pack7() + { + if(m_Lit) + { + float Darkest = 61.0f/255.0f; + ColorHSLA Dark = *this; + Dark.l = (l - Darkest)/(1 - Darkest); + Dark.m_Lit = false; + return Dark.Pack7(); + } + else + return color4_base::Pack(false); + } }; class ColorHSVA : public color4_base diff --git a/src/engine/message.h b/src/engine/message.h index 55d800bf2..533044961 100644 --- a/src/engine/message.h +++ b/src/engine/message.h @@ -11,7 +11,8 @@ class CMsgPacker : public CPacker public: int m_MsgID; bool m_System; - CMsgPacker(int Type, bool System=false) : m_MsgID(Type), m_System(System) + bool m_NoTranslate; + CMsgPacker(int Type, bool System = false, bool NoTranslate = false) : m_MsgID(Type), m_System(System), m_NoTranslate(NoTranslate) { Reset(); } diff --git a/src/engine/server.h b/src/engine/server.h index 947a8bba5..1c8d1396b 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -10,6 +10,7 @@ #include "message.h" #include #include +#include #include struct CAntibotRoundData; @@ -118,7 +119,8 @@ public: template int SendPackMsgOne(T *pMsg, int Flags, int ClientID) { - CMsgPacker Packer(pMsg->MsgID(), false); + CMsgPacker Packer(pMsg->MsgID(), false, protocol7::is_sixup::value); + if(pMsg->Pack(&Packer)) return -1; return SendMsg(&Packer, Flags, ClientID); diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 6af2635cd..ce91b0655 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -652,7 +652,7 @@ static inline bool RepackMsg(const CMsgPacker *pMsg, CPacker &Packer, bool Sixup Packer.Reset(); if(MsgId < OFFSET_UUID) { - if(Sixup) + if(Sixup && !pMsg->m_NoTranslate) { if(pMsg->m_System) { @@ -674,19 +674,11 @@ static inline bool RepackMsg(const CMsgPacker *pMsg, CPacker &Packer, bool Sixup } else { - if(MsgId >= NETMSGTYPE_SV_MOTD && MsgId <= NETMSGTYPE_SV_CHAT) - ; - else if(MsgId == NETMSGTYPE_SV_KILLMSG) - MsgId += 1; - else if(MsgId >= NETMSGTYPE_SV_TUNEPARAMS && MsgId <= NETMSGTYPE_SV_VOTESTATUS) - ; - else if(MsgId < 0) - MsgId *= -1; - else - { - dbg_msg("net", "DROP send game %d", MsgId); + if(MsgId >= 0) + MsgId = Msg_SixToSeven(MsgId); + + if(MsgId < 0) return true; - } } } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 41e95fcd6..22aede673 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1127,56 +1127,68 @@ void CGameContext::OnClientEnter(int ClientID) if(Server()->IsSixup(i)) { // new info for others - CMsgPacker NewClientInfoMsg(-protocol7::NETMSGTYPE_SV_CLIENTINFO); // NETMSGTYPE_SV_CLIENTINFO - NewClientInfoMsg.AddInt(ClientID); - NewClientInfoMsg.AddInt(0); // m_Local - NewClientInfoMsg.AddInt(pNewPlayer->GetTeam()); - NewClientInfoMsg.AddString(Server()->ClientName(ClientID), -1); - NewClientInfoMsg.AddString(Server()->ClientClan(ClientID), -1); - NewClientInfoMsg.AddInt(Server()->ClientCountry(ClientID)); - for(int p = 0; p < 6; p++) NewClientInfoMsg.AddString(pNewPlayer->m_TeeInfos.m_apSkinPartNames[p], -1); - for(int p = 0; p < 6; p++) NewClientInfoMsg.AddInt(pNewPlayer->m_TeeInfos.m_aUseCustomColors[p]); - for(int p = 0; p < 6; p++) NewClientInfoMsg.AddInt(pNewPlayer->m_TeeInfos.m_aSkinPartColors[p]); - NewClientInfoMsg.AddInt(0); // m_Silent + protocol7::CNetMsg_Sv_ClientInfo NewClientInfoMsg; + NewClientInfoMsg.m_ClientID = ClientID; + NewClientInfoMsg.m_Local = 0; + NewClientInfoMsg.m_Team = pNewPlayer->GetTeam(); + NewClientInfoMsg.m_pName = Server()->ClientName(ClientID); + NewClientInfoMsg.m_pClan = Server()->ClientClan(ClientID); + NewClientInfoMsg.m_Country = Server()->ClientCountry(ClientID); + NewClientInfoMsg.m_Silent = false; - Server()->SendMsg(&NewClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, i); + for(int p = 0; p < 6; p++) + { + NewClientInfoMsg.m_apSkinPartNames[p] = pNewPlayer->m_TeeInfos.m_apSkinPartNames[p]; + NewClientInfoMsg.m_aUseCustomColors[p] = pNewPlayer->m_TeeInfos.m_aUseCustomColors[p]; + NewClientInfoMsg.m_aSkinPartColors[p] = pNewPlayer->m_TeeInfos.m_aSkinPartColors[p]; + } + + Server()->SendPackMsgOne(&NewClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, i); } if(Server()->IsSixup(ClientID)) { // existing infos for new player - CMsgPacker ClientInfoMsg(-protocol7::NETMSGTYPE_SV_CLIENTINFO); // NETMSGTYPE_SV_CLIENTINFO - ClientInfoMsg.AddInt(i); - ClientInfoMsg.AddInt(0); // m_Local - ClientInfoMsg.AddInt(pPlayer->GetTeam()); - ClientInfoMsg.AddString(Server()->ClientName(i), -1); - ClientInfoMsg.AddString(Server()->ClientClan(i), -1); - ClientInfoMsg.AddInt(Server()->ClientCountry(i)); - for(int p = 0; p < 6; p++) ClientInfoMsg.AddString(pPlayer->m_TeeInfos.m_apSkinPartNames[p], -1); - for(int p = 0; p < 6; p++) ClientInfoMsg.AddInt(pPlayer->m_TeeInfos.m_aUseCustomColors[p]); - for(int p = 0; p < 6; p++) ClientInfoMsg.AddInt(pPlayer->m_TeeInfos.m_aSkinPartColors[p]); - ClientInfoMsg.AddInt(0); // m_Silent + protocol7::CNetMsg_Sv_ClientInfo ClientInfoMsg; + ClientInfoMsg.m_ClientID = i; + ClientInfoMsg.m_Local = 0; + ClientInfoMsg.m_Team = pPlayer->GetTeam(); + ClientInfoMsg.m_pName = Server()->ClientName(i); + ClientInfoMsg.m_pClan = Server()->ClientClan(i); + ClientInfoMsg.m_Country = Server()->ClientCountry(i); + ClientInfoMsg.m_Silent = 0; - Server()->SendMsg(&ClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID); + for(int p = 0; p < 6; p++) + { + ClientInfoMsg.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p]; + ClientInfoMsg.m_aUseCustomColors[p] = pPlayer->m_TeeInfos.m_aUseCustomColors[p]; + ClientInfoMsg.m_aSkinPartColors[p] = pPlayer->m_TeeInfos.m_aSkinPartColors[p]; + } + + Server()->SendPackMsgOne(&ClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID); } } // local info if(Server()->IsSixup(ClientID)) { - CMsgPacker SelfClientInfoMsg(-protocol7::NETMSGTYPE_SV_CLIENTINFO); // NETMSGTYPE_SV_CLIENTINFO - SelfClientInfoMsg.AddInt(ClientID); - SelfClientInfoMsg.AddInt(1); // m_Local - SelfClientInfoMsg.AddInt(pNewPlayer->GetTeam()); - SelfClientInfoMsg.AddString(Server()->ClientName(ClientID), -1); - SelfClientInfoMsg.AddString(Server()->ClientClan(ClientID), -1); - SelfClientInfoMsg.AddInt(Server()->ClientCountry(ClientID)); - for(int p = 0; p < 6; p++) SelfClientInfoMsg.AddString(pNewPlayer->m_TeeInfos.m_apSkinPartNames[p], -1); - for(int p = 0; p < 6; p++) SelfClientInfoMsg.AddInt(pNewPlayer->m_TeeInfos.m_aUseCustomColors[p]); - for(int p = 0; p < 6; p++) SelfClientInfoMsg.AddInt(pNewPlayer->m_TeeInfos.m_aSkinPartColors[p]); - SelfClientInfoMsg.AddInt(0); // m_Silent + protocol7::CNetMsg_Sv_ClientInfo SelfClientInfoMsg; + SelfClientInfoMsg.m_ClientID = ClientID; + SelfClientInfoMsg.m_Local = 1; + SelfClientInfoMsg.m_Team = pNewPlayer->GetTeam(); + SelfClientInfoMsg.m_pName = Server()->ClientName(ClientID); + SelfClientInfoMsg.m_pClan = Server()->ClientClan(ClientID); + SelfClientInfoMsg.m_Country = Server()->ClientCountry(ClientID); + SelfClientInfoMsg.m_Silent = 0; - Server()->SendMsg(&SelfClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID); + for(int p = 0; p < 6; p++) + { + SelfClientInfoMsg.m_apSkinPartNames[p] = pNewPlayer->m_TeeInfos.m_apSkinPartNames[p]; + SelfClientInfoMsg.m_aUseCustomColors[p] = pNewPlayer->m_TeeInfos.m_aUseCustomColors[p]; + SelfClientInfoMsg.m_aSkinPartColors[p] = pNewPlayer->m_TeeInfos.m_aSkinPartColors[p]; + } + + Server()->SendPackMsgOne(&SelfClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID); } } @@ -1375,6 +1387,19 @@ void *CGameContext::PreProcessMsg(int *MsgID, CUnpacker *pUnpacker, int ClientID Info.FromSixup(); pPlayer->m_TeeInfos = Info; + protocol7::CNetMsg_Sv_SkinChange Msg; + Msg.m_ClientID = ClientID; + for(int p = 0; p < 6; p++) + { + Msg.m_apSkinPartNames[p] = pMsg->m_apSkinPartNames[p]; + Msg.m_aSkinPartColors[p] = pMsg->m_aSkinPartColors[p]; + Msg.m_aUseCustomColors[p] = pMsg->m_aUseCustomColors[p]; + } + + for(int i = 0; i < MAX_CLIENTS; i++) + if(Server()->IsSixup(i)) + Server()->SendPackMsgOne(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, i); + return 0; } else if(*MsgID == protocol7::NETMSGTYPE_CL_SETSPECTATORMODE) @@ -1945,6 +1970,25 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet; pPlayer->m_TeeInfos.ToSixup(); + protocol7::CNetMsg_Sv_SkinChange SkinChangeMsg; + SkinChangeMsg.m_ClientID = ClientID; + for(int p = 0; p < 6; p++) + { + SkinChangeMsg.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p]; + SkinChangeMsg.m_aSkinPartColors[p] = pPlayer->m_TeeInfos.m_aSkinPartColors[p]; + SkinChangeMsg.m_aUseCustomColors[p] = pPlayer->m_TeeInfos.m_aUseCustomColors[p]; + } + + //TODO: Common pattern send-to-sixup could be abstracted out + for(int i = 0; i < MAX_CLIENTS; i++) + { + if(Server()->IsSixup(i)) + { + dbg_msg("debug", "sending to %d", i); + Server()->SendPackMsgOne(&SkinChangeMsg, MSGFLAG_VITAL, i); + } + } + Server()->ExpireServerInfo(); } else if (MsgID == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused) diff --git a/src/game/server/teeinfo.cpp b/src/game/server/teeinfo.cpp index 33ae95d4a..9849d629a 100644 --- a/src/game/server/teeinfo.cpp +++ b/src/game/server/teeinfo.cpp @@ -1,4 +1,5 @@ #include +#include #include "teeinfo.h" @@ -73,16 +74,19 @@ void CTeeInfo::ToSixup() if(m_UseCustomColor) { + int ColorBody = ColorHSLA(m_ColorBody).Lighten().Pack7(); + dbg_msg("color", "o=%d n=%d", m_ColorBody, ColorBody); + int ColorFeet = ColorHSLA(m_ColorFeet).Lighten().Pack7(); m_aUseCustomColors[0] = true; m_aUseCustomColors[1] = true; m_aUseCustomColors[2] = true; m_aUseCustomColors[3] = true; m_aUseCustomColors[4] = true; - m_aSkinPartColors[0] = m_ColorBody; + m_aSkinPartColors[0] = ColorBody; m_aSkinPartColors[1] = 0x22FFFFFF; - m_aSkinPartColors[2] = m_ColorBody; - m_aSkinPartColors[3] = m_ColorBody; - m_aSkinPartColors[4] = m_ColorFeet; + m_aSkinPartColors[2] = ColorBody; + m_aSkinPartColors[3] = ColorBody; + m_aSkinPartColors[4] = ColorFeet; } }