1#include <base/dbg.h>
2
3#include <engine/client/client.h>
4
5int CClient::TranslateSysMsg(int *pMsgId, bool System, CUnpacker *pUnpacker, CPacker *pPacker, CNetChunk *pPacket, bool *pIsExMsg)
6{
7 *pIsExMsg = false;
8 if(!System)
9 return -1;
10
11 // ddnet ex
12 if(*pMsgId > NETMSG_WHATIS && *pMsgId < NETMSG_RCON_CMD_GROUP_END)
13 {
14 *pIsExMsg = true;
15 return 0;
16 }
17
18 pPacker->Reset();
19
20 if(*pMsgId == protocol7::NETMSG_MAP_CHANGE)
21 {
22 *pMsgId = NETMSG_MAP_CHANGE;
23 const char *pMapName = pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC | CUnpacker::SKIP_START_WHITESPACES);
24 int MapCrc = pUnpacker->GetInt();
25 int Size = pUnpacker->GetInt();
26 m_TranslationContext.m_MapDownloadChunksPerRequest = pUnpacker->GetInt();
27 int ChunkSize = pUnpacker->GetInt();
28 // void *pSha256 = pUnpacker->GetRaw(); // probably safe to ignore
29 pPacker->AddString(pStr: pMapName, Limit: 0);
30 pPacker->AddInt(i: MapCrc);
31 pPacker->AddInt(i: Size);
32 m_TranslationContext.m_MapdownloadTotalsize = Size;
33 m_TranslationContext.m_MapDownloadChunkSize = ChunkSize;
34 return 0;
35 }
36 else if(*pMsgId == protocol7::NETMSG_SERVERINFO)
37 {
38 // side effect only
39 // this is a 0.7 only message and not handled in 0.6 code
40 *pMsgId = -1;
41 net_addr_str(addr: &pPacket->m_Address, string: m_CurrentServerInfo.m_aAddress, max_length: sizeof(m_CurrentServerInfo.m_aAddress), add_port: true);
42 str_copy(dst&: m_CurrentServerInfo.m_aVersion, src: pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC | CUnpacker::SKIP_START_WHITESPACES));
43 str_copy(dst&: m_CurrentServerInfo.m_aName, src: pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC | CUnpacker::SKIP_START_WHITESPACES));
44 str_clean_whitespaces(str: m_CurrentServerInfo.m_aName);
45 pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC | CUnpacker::SKIP_START_WHITESPACES); // Hostname
46 pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC | CUnpacker::SKIP_START_WHITESPACES); // Map, determined based on filename
47 str_copy(dst&: m_CurrentServerInfo.m_aGameType, src: pUnpacker->GetString(SanitizeType: CUnpacker::SANITIZE_CC | CUnpacker::SKIP_START_WHITESPACES));
48 int Flags = pUnpacker->GetInt();
49 if(Flags & SERVER_FLAG_PASSWORD)
50 m_CurrentServerInfo.m_Flags |= SERVER_FLAG_PASSWORD;
51 // ddnets http master server handles timescore for us already
52 // if(Flags&SERVER_FLAG_TIMESCORE)
53 // m_CurrentServerInfo.m_Flags |= SERVER_FLAG_TIMESCORE;
54 pUnpacker->GetInt(); // Server level
55 m_CurrentServerInfo.m_NumPlayers = pUnpacker->GetInt();
56 m_CurrentServerInfo.m_MaxPlayers = pUnpacker->GetInt();
57 m_CurrentServerInfo.m_NumClients = pUnpacker->GetInt();
58 m_CurrentServerInfo.m_MaxClients = pUnpacker->GetInt();
59 return 0;
60 }
61 else if(*pMsgId == protocol7::NETMSG_RCON_AUTH_ON)
62 {
63 *pMsgId = NETMSG_RCON_AUTH_STATUS;
64 pPacker->AddInt(i: 1); // authed
65 pPacker->AddInt(i: 1); // cmdlist
66 return 0;
67 }
68 else if(*pMsgId == protocol7::NETMSG_RCON_AUTH_OFF)
69 {
70 *pMsgId = NETMSG_RCON_AUTH_STATUS;
71 pPacker->AddInt(i: 0); // authed
72 pPacker->AddInt(i: 0); // cmdlist
73 return 0;
74 }
75 else if(*pMsgId == protocol7::NETMSG_MAP_DATA)
76 {
77 // not binary compatible but translation happens on unpack
78 *pMsgId = NETMSG_MAP_DATA;
79 }
80 else if(*pMsgId >= protocol7::NETMSG_CON_READY && *pMsgId <= protocol7::NETMSG_INPUTTIMING)
81 {
82 *pMsgId = *pMsgId - 1;
83 }
84 else if(*pMsgId == protocol7::NETMSG_RCON_LINE)
85 {
86 *pMsgId = NETMSG_RCON_LINE;
87 }
88 else if(*pMsgId == protocol7::NETMSG_RCON_CMD_ADD)
89 {
90 *pMsgId = NETMSG_RCON_CMD_ADD;
91 }
92 else if(*pMsgId == protocol7::NETMSG_RCON_CMD_REM)
93 {
94 *pMsgId = NETMSG_RCON_CMD_REM;
95 }
96 else if(*pMsgId == protocol7::NETMSG_PING_REPLY)
97 {
98 *pMsgId = NETMSG_PING_REPLY;
99 }
100 else if(*pMsgId == protocol7::NETMSG_MAPLIST_ENTRY_ADD || *pMsgId == protocol7::NETMSG_MAPLIST_ENTRY_REM)
101 {
102 // This is just a nice to have so silently dropping that is fine
103 return -1;
104 }
105 else if(*pMsgId >= NETMSG_INFO && *pMsgId <= NETMSG_MAP_DATA)
106 {
107 return -1; // same in 0.6 and 0.7
108 }
109 else if(*pMsgId < OFFSET_UUID)
110 {
111 dbg_msg(sys: "sixup", fmt: "drop unknown sys msg=%d", *pMsgId);
112 return -1;
113 }
114
115 return -1;
116}
117