MCPcopy Create free account
hub / github.com/ddnet/ddnet / OnMessage

Method OnMessage

src/game/client/gameclient.cpp:1008–1239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1006}
1007
1008void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Conn, bool Dummy)
1009{
1010 // special messages
1011 static_assert((int)NETMSGTYPE_SV_TUNEPARAMS == (int)protocol7::NETMSGTYPE_SV_TUNEPARAMS, "0.6 and 0.7 tune message id do not match");
1012 if(MsgId == NETMSGTYPE_SV_TUNEPARAMS)
1013 {
1014 // unpack the new tuning
1015 CTuningParams NewTuning;
1016 int *pParams = (int *)&NewTuning;
1017
1018 // No jetpack on DDNet incompatible servers,
1019 // jetpack strength will be received by tune params
1020 NewTuning.m_JetpackStrength = 0;
1021
1022 for(unsigned i = 0; i < sizeof(CTuningParams) / sizeof(int); i++)
1023 {
1024 // 31 is the magic number index of laser_damage
1025 // which was removed in 0.7
1026 // also in 0.6 it is unused so we just set it to 0
1027 const int Value = (Client()->IsSixup() && i == 30) ? 0 : pUnpacker->GetInt();
1028
1029 // check for unpacking errors
1030 if(pUnpacker->Error())
1031 break;
1032
1033 pParams[i] = Value;
1034 }
1035
1036 m_ServerMode = SERVERMODE_PURE;
1037
1038 m_aReceivedTuning[Conn] = true;
1039 // apply new tuning
1040 m_aTuning[Conn] = NewTuning;
1041 return;
1042 }
1043
1044 void *pRawMsg = TranslateGameMsg(&MsgId, pUnpacker, Conn);
1045
1046 if(!pRawMsg)
1047 {
1048 // the 0.7 version of this error message is printed on translation
1049 // in sixup/translate_game.cpp
1050 if(!Client()->IsSixup())
1051 {
1052 char aBuf[256];
1053 str_format(aBuf, sizeof(aBuf), "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgId), MsgId, m_NetObjHandler.FailedMsgOn());
1054 Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf);
1055 }
1056 return;
1057 }
1058
1059 if(MsgId == NETMSGTYPE_SV_CHANGEINFOCOOLDOWN)
1060 {
1061 CNetMsg_Sv_ChangeInfoCooldown *pMsg = (CNetMsg_Sv_ChangeInfoCooldown *)pRawMsg;
1062 m_aNextChangeInfo[Conn] = pMsg->m_WaitUntil;
1063 return;
1064 }
1065

Callers 3

ProcessServerPacketMethod · 0.45
OnDemoPlayerMessageMethod · 0.45
ProcessClientPacketMethod · 0.45

Calls 15

str_formatFunction · 0.85
EnterGameMethod · 0.80
EnqueueMethod · 0.80
GiveWeakMethod · 0.80
GetCharacterByIdMethod · 0.80
ResetPredictionMethod · 0.80
SpectateMethod · 0.80
GetStrongWeakIdMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
ClientFunction · 0.50

Tested by

no test coverage detected