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

Method OnSetTeamNetMessage

src/game/server/gamecontext.cpp:2677–2724  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2675}
2676
2677void CGameContext::OnSetTeamNetMessage(const CNetMsg_Cl_SetTeam *pMsg, int ClientId)
2678{
2679 if(m_pController->IsGamePaused())
2680 return;
2681
2682 CPlayer *pPlayer = m_apPlayers[ClientId];
2683
2684 if(pPlayer->GetTeam() == pMsg->m_Team)
2685 return;
2686 if(g_Config.m_SvSpamprotection && pPlayer->m_LastSetTeam && pPlayer->m_LastSetTeam + Server()->TickSpeed() * g_Config.m_SvTeamChangeDelay > Server()->Tick())
2687 return;
2688
2689 // Kill Protection
2690 CCharacter *pChr = pPlayer->GetCharacter();
2691 if(pChr)
2692 {
2693 int CurrTime = (Server()->Tick() - pChr->m_StartTime) / Server()->TickSpeed();
2694 if(g_Config.m_SvKillProtection != 0 && CurrTime >= (60 * g_Config.m_SvKillProtection) && pChr->m_DDRaceState == ERaceState::STARTED)
2695 {
2696 SendChatTarget(ClientId, "Kill Protection enabled. If you really want to join the spectators, first type /kill");
2697 return;
2698 }
2699 }
2700
2701 if(pPlayer->m_TeamChangeTick > Server()->Tick())
2702 {
2703 pPlayer->m_LastSetTeam = Server()->Tick();
2704 int TimeLeft = (pPlayer->m_TeamChangeTick - Server()->Tick()) / Server()->TickSpeed();
2705 char aTime[32];
2706 str_time((int64_t)TimeLeft * 100, TIME_HOURS, aTime, sizeof(aTime));
2707 char aBuf[128];
2708 str_format(aBuf, sizeof(aBuf), "Time to wait before changing team: %s", aTime);
2709 SendBroadcast(aBuf, ClientId);
2710 return;
2711 }
2712
2713 // Switch team on given client and kill/respawn them
2714 char aTeamJoinError[512];
2715 if(m_pController->CanJoinTeam(pMsg->m_Team, ClientId, aTeamJoinError, sizeof(aTeamJoinError)))
2716 {
2717 if(pPlayer->GetTeam() == TEAM_SPECTATORS || pMsg->m_Team == TEAM_SPECTATORS)
2718 m_VoteUpdate = true;
2719 m_pController->DoTeamChange(pPlayer, pMsg->m_Team);
2720 pPlayer->m_TeamChangeTick = Server()->Tick();
2721 }
2722 else
2723 SendBroadcast(aTeamJoinError, ClientId);
2724}
2725
2726void CGameContext::OnIsDDNetLegacyNetMessage(const CNetMsg_Cl_IsDDNetLegacy *pMsg, int ClientId, CUnpacker *pUnpacker)
2727{

Callers

nothing calls this directly

Calls 10

str_timeFunction · 0.85
str_formatFunction · 0.85
IsGamePausedMethod · 0.80
GetTeamMethod · 0.80
TickSpeedMethod · 0.80
GetCharacterMethod · 0.80
ServerClass · 0.50
TickMethod · 0.45
CanJoinTeamMethod · 0.45
DoTeamChangeMethod · 0.45

Tested by

no test coverage detected