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