diff --git a/datasrc/crosscompile.py b/datasrc/crosscompile.py index 6a2ab895f..331618c5c 100644 --- a/datasrc/crosscompile.py +++ b/datasrc/crosscompile.py @@ -10,6 +10,18 @@ def get_msgs_7(): return ["NETMSG_INVALID"] + [m.enum_name for m in network.Messages] +def get_objs(): + from datatypes import NetObject + import network + + return ["NETOBJ_INVALID"] + [m.enum_name for m in network.Objects] + +def get_objs_7(): + from seven.datatypes import NetObject + import seven.network as network + + return ["NETOBJ_INVALID"] + [m.enum_name for m in network.Objects] + def generate_map(a, b): map = [] for i, m in enumerate(a): @@ -31,8 +43,13 @@ def main(): msgs = get_msgs() msgs7 = get_msgs_7() - output_map("SixToSeven", generate_map(msgs, msgs7)) - output_map("SevenToSix", generate_map(msgs7, msgs)) + output_map("Msg_SixToSeven", generate_map(msgs, msgs7)) + output_map("Msg_SevenToSix", generate_map(msgs7, msgs)) + + objs = get_objs() + objs7 = get_objs_7() + output_map("Obj_SixToSeven", generate_map(objs, objs7)) + output_map("Obj_SevenToSix", generate_map(objs7, objs)) if __name__ == "__main__": main() diff --git a/src/engine/shared/snapshot.cpp b/src/engine/shared/snapshot.cpp index 01e87556a..839f2eee5 100644 --- a/src/engine/shared/snapshot.cpp +++ b/src/engine/shared/snapshot.cpp @@ -5,30 +5,7 @@ #include "uuid_manager.h" #include - -static int ObjTypeToSixup(int Type) -{ - int Six; - if(Type >= NETOBJTYPE_PLAYERINPUT && Type <= NETOBJTYPE_FLAG) - Six = Type; - else if(Type >= NETOBJTYPE_CHARACTERCORE && Type <= NETOBJTYPE_PLAYERINFO) - Six = Type + 1; - else if(Type == NETOBJTYPE_SPECTATORINFO) - Six = Type; - else if(Type >= NETEVENTTYPE_COMMON && Type <= NETEVENTTYPE_DEATH) - Six = Type + 3; - else if(Type == NETEVENTTYPE_SOUNDWORLD) - Six = Type + 2; - else if(Type > 24) - Six = Type - 24; - else - { - //dbg_msg("net", "DROP obj %d", Type); - return -1; - } - //dbg_msg("net", "pack obj %d -> %d", Type, Six); - return Six; -} +#include // CSnapshot @@ -651,7 +628,11 @@ void *CSnapshotBuilder::NewItem(int Type, int ID, int Size) if(m_Sixup) { - Type = ObjTypeToSixup(Type); + if(Type >= 0) + Type = Obj_SixToSeven(Type); + else + Type *= -1; + if(Type < 0) return pObj; } diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 95bd35ca1..08b535a6c 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -756,6 +756,13 @@ void CCharacter::Tick() if(m_Paused) return; + // set emote + if(m_EmoteStop < Server()->Tick()) + { + m_EmoteType = m_pPlayer->m_DefEmote; + m_EmoteStop = -1; + } + DDRaceTick(); Antibot()->OnCharacterTick(m_pPlayer->GetCID()); @@ -1043,6 +1050,142 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) return true; } +//TODO: Move the emote stuff to a function +void CCharacter::SnapCharacter(int SnappingClient) +{ + int OwnID = m_pPlayer->GetCID(); + + CCharacterCore *pCore; + int Tick, Emote = m_EmoteType, Weapon = m_Core.m_ActiveWeapon, AmmoCount = 0, + Health = 0, Armor = 0; + if(!m_ReckoningTick || GameServer()->m_World.m_Paused) + { + Tick = 0; + pCore = &m_Core; + } + else + { + Tick = m_ReckoningTick; + pCore = &m_SendCore; + } + + // change eyes and use ninja graphic if player is frozen + if(m_DeepFreeze || m_FreezeTime > 0 || m_FreezeTime == -1) + { + if(Emote == EMOTE_NORMAL) + Emote = m_DeepFreeze ? EMOTE_PAIN : EMOTE_BLINK; + + Weapon = WEAPON_NINJA; + } + + // This could probably happen when m_Jetpack changes instead + // jetpack and ninjajetpack prediction + if(m_pPlayer->GetCID() == SnappingClient) + { + if(m_Jetpack && Weapon != WEAPON_NINJA) + { + if(!(m_NeededFaketuning & FAKETUNE_JETPACK)) + { + m_NeededFaketuning |= FAKETUNE_JETPACK; + GameServer()->SendTuningParams(m_pPlayer->GetCID(), m_TuneZone); + } + } + else + { + if(m_NeededFaketuning & FAKETUNE_JETPACK) + { + m_NeededFaketuning &= ~FAKETUNE_JETPACK; + GameServer()->SendTuningParams(m_pPlayer->GetCID(), m_TuneZone); + } + } + } + + // change eyes, use ninja graphic and set ammo count if player has ninjajetpack + if(m_pPlayer->m_NinjaJetpack && m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN && !m_DeepFreeze && !(m_FreezeTime > 0 || m_FreezeTime == -1)) + { + if(Emote == EMOTE_NORMAL) + Emote = EMOTE_HAPPY; + Weapon = WEAPON_NINJA; + AmmoCount = 10; + } + + if(m_pPlayer->GetCID() == SnappingClient || SnappingClient == -1 || + (!g_Config.m_SvStrictSpectateMode && m_pPlayer->GetCID() == GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID)) + { + Health = m_Health; + Armor = m_Armor; + if(m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo > 0) + AmmoCount = (!m_FreezeTime)?m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo:0; + } + + if(GetPlayer()->m_Afk || GetPlayer()->IsPaused()) + { + if(m_FreezeTime > 0 || m_FreezeTime == -1 || m_DeepFreeze) + Emote = EMOTE_NORMAL; + else + Emote = EMOTE_BLINK; + } + + if(Emote == EMOTE_NORMAL) + { + if(250 - ((Server()->Tick() - m_LastAction)%(250)) < 5) + Emote = EMOTE_BLINK; + } + + if(m_pPlayer->m_Halloween) + { + if(1200 - ((Server()->Tick() - m_LastAction)%(1200)) < 5) + { + GameServer()->SendEmoticon(m_pPlayer->GetCID(), EMOTICON_GHOST); + } + } + + if(!Server()->IsSixup(SnappingClient)) + { + CNetObj_Character *pCharacter = static_cast(Server()->SnapNewItem(NETOBJTYPE_CHARACTER, OwnID, sizeof(CNetObj_Character))); + if(!pCharacter) + return; + + pCore->Write(pCharacter); + + pCharacter->m_Tick = Tick; + pCharacter->m_Emote = Emote; + + if(pCharacter->m_HookedPlayer != -1) + { + if(!Server()->Translate(pCharacter->m_HookedPlayer, SnappingClient)) + pCharacter->m_HookedPlayer = -1; + } + + pCharacter->m_AttackTick = m_AttackTick; + pCharacter->m_Direction = m_Input.m_Direction; + pCharacter->m_Weapon = Weapon; + pCharacter->m_AmmoCount = AmmoCount; + pCharacter->m_Health = Health; + pCharacter->m_Armor = Armor; + pCharacter->m_PlayerFlags = GetPlayer()->m_PlayerFlags; + } + else + { + protocol7::CNetObj_Character *pCharacter = static_cast(Server()->SnapNewItem(NETOBJTYPE_CHARACTER, OwnID, sizeof(protocol7::CNetObj_Character))); + if(!pCharacter) + return; + + //TODO: Avoid this + pCore->Write(reinterpret_cast(pCharacter)); + + pCharacter->m_Tick = Tick; + pCharacter->m_Emote = Emote; + pCharacter->m_AttackTick = m_AttackTick; + pCharacter->m_Direction = m_Input.m_Direction; + pCharacter->m_Weapon = Weapon; + pCharacter->m_AmmoCount = AmmoCount; + pCharacter->m_Health = Health; + pCharacter->m_Armor = Armor; + pCharacter->m_TriggeredEvents = 0; + } +} + void CCharacter::Snap(int SnappingClient) { int id = m_pPlayer->GetCID(); @@ -1074,122 +1217,7 @@ void CCharacter::Snap(int SnappingClient) if (m_Paused) return; - CNetObj_Character *pCharacter = static_cast(Server()->SnapNewItem(NETOBJTYPE_CHARACTER, id, sizeof(CNetObj_Character))); - if(!pCharacter) - return; - - // write down the m_Core - if(!m_ReckoningTick || GameServer()->m_World.m_Paused) - { - // no dead reckoning when paused because the client doesn't know - // how far to perform the reckoning - pCharacter->m_Tick = 0; - m_Core.Write(pCharacter); - } - else - { - pCharacter->m_Tick = m_ReckoningTick; - m_SendCore.Write(pCharacter); - } - - // set emote - if (m_EmoteStop < Server()->Tick()) - { - m_EmoteType = m_pPlayer->m_DefEmote; - m_EmoteStop = -1; - } - pCharacter->m_Emote = m_EmoteType; - - if (pCharacter->m_HookedPlayer != -1) - { - if (!Server()->Translate(pCharacter->m_HookedPlayer, SnappingClient)) - pCharacter->m_HookedPlayer = -1; - } - - pCharacter->m_AttackTick = m_AttackTick; - pCharacter->m_Direction = m_Input.m_Direction; - pCharacter->m_Weapon = m_Core.m_ActiveWeapon; - pCharacter->m_AmmoCount = 0; - pCharacter->m_Health = 0; - pCharacter->m_Armor = 0; - - // change eyes and use ninja graphic if player is freeze - if (m_DeepFreeze) - { - if (pCharacter->m_Emote == EMOTE_NORMAL) - pCharacter->m_Emote = EMOTE_PAIN; - pCharacter->m_Weapon = WEAPON_NINJA; - } - else if (m_FreezeTime > 0 || m_FreezeTime == -1) - { - if (pCharacter->m_Emote == EMOTE_NORMAL) - pCharacter->m_Emote = EMOTE_BLINK; - pCharacter->m_Weapon = WEAPON_NINJA; - } - - // jetpack and ninjajetpack prediction - if (m_pPlayer->GetCID() == SnappingClient) - { - if (m_Jetpack && pCharacter->m_Weapon != WEAPON_NINJA) - { - if (!(m_NeededFaketuning & FAKETUNE_JETPACK)) - { - m_NeededFaketuning |= FAKETUNE_JETPACK; - GameServer()->SendTuningParams(m_pPlayer->GetCID(), m_TuneZone); - } - } - else - { - if (m_NeededFaketuning & FAKETUNE_JETPACK) - { - m_NeededFaketuning &= ~FAKETUNE_JETPACK; - GameServer()->SendTuningParams(m_pPlayer->GetCID(), m_TuneZone); - } - } - } - - // change eyes, use ninja graphic and set ammo count if player has ninjajetpack - if (m_pPlayer->m_NinjaJetpack && m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN && !m_DeepFreeze && !(m_FreezeTime > 0 || m_FreezeTime == -1)) - { - if (pCharacter->m_Emote == EMOTE_NORMAL) - pCharacter->m_Emote = EMOTE_HAPPY; - pCharacter->m_Weapon = WEAPON_NINJA; - pCharacter->m_AmmoCount = 10; - } - - if(m_pPlayer->GetCID() == SnappingClient || SnappingClient == -1 || - (!g_Config.m_SvStrictSpectateMode && m_pPlayer->GetCID() == GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID)) - { - pCharacter->m_Health = m_Health; - pCharacter->m_Armor = m_Armor; - if(m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo > 0) - //pCharacter->m_AmmoCount = m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo; - pCharacter->m_AmmoCount = (!m_FreezeTime)?m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo:0; - } - - if(GetPlayer()->m_Afk || GetPlayer()->IsPaused()) - { - if(m_FreezeTime > 0 || m_FreezeTime == -1 || m_DeepFreeze) - pCharacter->m_Emote = EMOTE_NORMAL; - else - pCharacter->m_Emote = EMOTE_BLINK; - } - - if(pCharacter->m_Emote == EMOTE_NORMAL) - { - if(250 - ((Server()->Tick() - m_LastAction)%(250)) < 5) - pCharacter->m_Emote = EMOTE_BLINK; - } - - if(m_pPlayer->m_Halloween) - { - if(1200 - ((Server()->Tick() - m_LastAction)%(1200)) < 5) - { - GameServer()->SendEmoticon(m_pPlayer->GetCID(), EMOTICON_GHOST); - } - } - - pCharacter->m_PlayerFlags = GetPlayer()->m_PlayerFlags; + SnapCharacter(SnappingClient); CNetObj_DDNetCharacter *pDDNetCharacter = static_cast(Server()->SnapNewItem(NETOBJTYPE_DDNETCHARACTER, id, sizeof(CNetObj_DDNetCharacter))); if(!pDDNetCharacter) @@ -1241,18 +1269,6 @@ void CCharacter::Snap(int SnappingClient) pDDNetCharacter->m_Jumps = m_Core.m_Jumps; pDDNetCharacter->m_TeleCheckpoint = m_TeleCheckpoint; pDDNetCharacter->m_StrongWeakID = m_StrongWeakID; - - if(Server()->IsSixup(SnappingClient)) - { - int Offset = sizeof(CNetObj_CharacterCore) / 4; - ((int*)pCharacter)[Offset+0] = pCharacter->m_Health; - ((int*)pCharacter)[Offset+1] = pCharacter->m_Armor; - ((int*)pCharacter)[Offset+2] = pCharacter->m_AmmoCount; - ((int*)pCharacter)[Offset+3] = pCharacter->m_Weapon; - ((int*)pCharacter)[Offset+4] = pCharacter->m_Emote; - ((int*)pCharacter)[Offset+5] = pCharacter->m_AttackTick; - ((int*)pCharacter)[Offset+6] = 0; // m_TriggeredEvents - } } int CCharacter::NetworkClipped(int SnappingClient) diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index 75b053c29..68a2b4fec 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -166,6 +166,7 @@ private: // DDRace + void SnapCharacter(int SnappingClient); static bool IsSwitchActiveCb(int Number, void *pUser); void HandleTiles(int Index); float m_Time; diff --git a/src/game/server/eventhandler.cpp b/src/game/server/eventhandler.cpp index c49ea8cbc..e1f6f582e 100644 --- a/src/game/server/eventhandler.cpp +++ b/src/game/server/eventhandler.cpp @@ -70,7 +70,7 @@ void CEventHandler::EventToSixup(int *Type, int *Size, const char **pData) { const CNetEvent_DamageInd *pEvent = (const CNetEvent_DamageInd *)(*pData); protocol7::CNetEvent_Damage *pEvent7 = (protocol7::CNetEvent_Damage *)s_aEventStore; - *Type = protocol7::NETEVENTTYPE_DAMAGE + 24; + *Type = -protocol7::NETEVENTTYPE_DAMAGE; *Size = sizeof(*pEvent7); pEvent7->m_X = pEvent->m_X; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 6b3a85199..72ee62b6a 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -384,8 +384,11 @@ void CGameContext::SendChat(int ChatterClientID, int Team, const char *pText, in // send to the clients for(int i = 0; i < MAX_CLIENTS; i++) { - if(m_apPlayers[i] != 0 && !m_apPlayers[i]->m_DND && Server()->IsSixup(i) == !!(Flags & CHAT_SIXUP)) - Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, i); + bool Send = (Server()->IsSixup(i) && (Flags & CHAT_SIXUP)) || + (!Server()->IsSixup(i) && (Flags & CHAT_SIX)); + + if(m_apPlayers[i] != 0 && !m_apPlayers[i]->m_DND && Send) + Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, i); } } else @@ -1375,7 +1378,7 @@ void *CGameContext::PreProcessMsg(int *MsgID, CUnpacker *pUnpacker, int ClientID return 0; } - *MsgID = SevenToSix(*MsgID); + *MsgID = Msg_SevenToSix(*MsgID); return s_aRawMsg; } diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index c7b1567e9..ab6f1aece 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -561,13 +561,13 @@ void IGameController::Snap(int SnappingClient) if(Server()->IsSixup(SnappingClient)) { - int *pGameData = (int*)Server()->SnapNewItem(6 + 24, 0, 3*4); // NETOBJTYPE_GAMEDATA + protocol7::CNetObj_GameData *pGameData = static_cast(Server()->SnapNewItem(-protocol7::NETOBJTYPE_GAMEDATA, 0, sizeof(protocol7::CNetObj_GameData))); if(!pGameData) return; - pGameData[0] = m_RoundStartTick; - pGameData[1] = 0; // m_GameStateFlags - pGameData[2] = 0; // m_GameStateEndTick + pGameData->m_GameStartTick = m_RoundStartTick; + pGameData->m_GameStateFlags = 0; + pGameData->m_GameStateEndTick = 0; } } diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index ba5702ac7..5f1b89ed8 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -302,10 +302,10 @@ void CPlayer::Snap(int SnappingClient) return; int id = m_ClientID; - if (SnappingClient > -1 && !Server()->Translate(id, SnappingClient)) return; + if(SnappingClient > -1 && !Server()->Translate(id, SnappingClient)) + return; CNetObj_ClientInfo *pClientInfo = static_cast(Server()->SnapNewItem(NETOBJTYPE_CLIENTINFO, id, sizeof(CNetObj_ClientInfo))); - if(!pClientInfo) return; @@ -317,11 +317,6 @@ void CPlayer::Snap(int SnappingClient) pClientInfo->m_ColorBody = m_TeeInfos.m_ColorBody; pClientInfo->m_ColorFeet = m_TeeInfos.m_ColorFeet; - int Size = Server()->IsSixup(SnappingClient) ? 3*4 : sizeof(CNetObj_PlayerInfo); - CNetObj_PlayerInfo *pPlayerInfo = static_cast(Server()->SnapNewItem(NETOBJTYPE_PLAYERINFO, id, Size)); - if(!pPlayerInfo) - return; - int ClientVersion = GetClientVersion(); int Latency = SnappingClient == -1 ? m_Latency.m_Min : GameServer()->m_apPlayers[SnappingClient]->m_aActLatency[m_ClientID]; int Score = abs(m_Score) * -1; @@ -334,6 +329,10 @@ void CPlayer::Snap(int SnappingClient) if(!Server()->IsSixup(SnappingClient)) { + CNetObj_PlayerInfo *pPlayerInfo = static_cast(Server()->SnapNewItem(NETOBJTYPE_PLAYERINFO, id, sizeof(CNetObj_PlayerInfo))); + if(!pPlayerInfo) + return; + pPlayerInfo->m_Latency = Latency; pPlayerInfo->m_Score = Score; pPlayerInfo->m_Local = (int)(m_ClientID == SnappingClient && (m_Paused != PAUSE_PAUSED || ClientVersion >= VERSION_DDNET_OLD)); @@ -345,9 +344,13 @@ void CPlayer::Snap(int SnappingClient) } else { - ((int*)pPlayerInfo)[0] = 0; // m_PlayerFlags - ((int*)pPlayerInfo)[1] = Score; - ((int*)pPlayerInfo)[2] = Latency; + protocol7::CNetObj_PlayerInfo *pPlayerInfo = static_cast(Server()->SnapNewItem(NETOBJTYPE_PLAYERINFO, id, sizeof(protocol7::CNetObj_PlayerInfo))); + if(!pPlayerInfo) + return; + + pPlayerInfo->m_PlayerFlags = 0; //TODO: Check if this needs translation + pPlayerInfo->m_Score = Score; + pPlayerInfo->m_Latency = Latency; } if(m_ClientID == SnappingClient && (m_Team == TEAM_SPECTATORS || m_Paused))