show countdown in player/tee settings for sv_info_change_delay

This commit is contained in:
dobrykafe 2024-02-20 21:41:20 +01:00 committed by Dennis Felsing
parent b544c3e839
commit 1ced40d95b
5 changed files with 40 additions and 4 deletions

View file

@ -578,4 +578,8 @@ Messages = [
NetMessageEx("Sv_CommandInfoGroupStart", "sv-commandinfo-group-start@netmsg.ddnet.org", []),
NetMessageEx("Sv_CommandInfoGroupEnd", "sv-commandinfo-group-end@netmsg.ddnet.org", []),
NetMessageEx("Sv_ChangeInfoCooldown", "change-info-cooldown@netmsg.ddnet.org", [
NetTick("m_WaitUntil")
]),
]

View file

@ -263,9 +263,9 @@ void CMenus::SetNeedSendInfo()
void CMenus::RenderSettingsPlayer(CUIRect MainView)
{
CUIRect TabBar, PlayerTab, DummyTab, QuickSearch, QuickSearchClearButton;
CUIRect TabBar, PlayerTab, DummyTab, ChangeInfo, QuickSearch, QuickSearchClearButton;
MainView.HSplitTop(20.0f, &TabBar, &MainView);
TabBar.VSplitMid(&TabBar, nullptr);
TabBar.VSplitMid(&TabBar, &ChangeInfo, 20.f);
TabBar.VSplitMid(&PlayerTab, &DummyTab);
MainView.HSplitTop(10.0f, nullptr, &MainView);
@ -281,6 +281,14 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView)
m_Dummy = true;
}
if(Client()->State() == IClient::STATE_ONLINE && m_pClient->m_NextChangeInfo && m_pClient->m_NextChangeInfo > Client()->GameTick(g_Config.m_ClDummy))
{
char aChangeInfo[128], aTimeLeft[32];
str_format(aTimeLeft, sizeof(aTimeLeft), Localize("%ds left"), (m_pClient->m_NextChangeInfo - Client()->GameTick(g_Config.m_ClDummy) + Client()->GameTickSpeed() - 1) / Client()->GameTickSpeed());
str_format(aChangeInfo, sizeof(aChangeInfo), "%s: %s", Localize("Player info change cooldown"), aTimeLeft);
UI()->DoLabel(&ChangeInfo, aChangeInfo, 10.f, TEXTALIGN_ML);
}
static CLineInput s_NameInput;
static CLineInput s_ClanInput;
@ -510,9 +518,9 @@ void CMenus::OnConfigSave(IConfigManager *pConfigManager)
void CMenus::RenderSettingsTee(CUIRect MainView)
{
CUIRect TabBar, PlayerTab, DummyTab;
CUIRect TabBar, PlayerTab, DummyTab, ChangeInfo;
MainView.HSplitTop(20.0f, &TabBar, &MainView);
TabBar.VSplitMid(&TabBar, nullptr);
TabBar.VSplitMid(&TabBar, &ChangeInfo, 20.f);
TabBar.VSplitMid(&PlayerTab, &DummyTab);
MainView.HSplitTop(10.0f, nullptr, &MainView);
@ -528,6 +536,14 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
m_Dummy = true;
}
if(Client()->State() == IClient::STATE_ONLINE && m_pClient->m_NextChangeInfo && m_pClient->m_NextChangeInfo > Client()->GameTick(g_Config.m_ClDummy))
{
char aChangeInfo[128], aTimeLeft[32];
str_format(aTimeLeft, sizeof(aTimeLeft), Localize("%ds left"), (m_pClient->m_NextChangeInfo - Client()->GameTick(g_Config.m_ClDummy) + Client()->GameTickSpeed() - 1) / Client()->GameTickSpeed());
str_format(aChangeInfo, sizeof(aChangeInfo), "%s: %s", Localize("Player info change cooldown"), aTimeLeft);
UI()->DoLabel(&ChangeInfo, aChangeInfo, 10.f, TEXTALIGN_ML);
}
char *pSkinName;
size_t SkinNameSize;
int *pUseCustomColor;

View file

@ -574,6 +574,8 @@ void CGameClient::OnReset()
m_LastFlagCarrierBlue = -4;
m_aTuning[g_Config.m_ClDummy] = CTuningParams();
m_NextChangeInfo = 0;
m_Teams.Reset();
m_aDDRaceMsgSent[0] = false;
m_aDDRaceMsgSent[1] = false;
@ -964,6 +966,11 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Conn, bool Dumm
m_CharOrder.GiveWeak(ID.first);
}
}
else if(MsgId == NETMSGTYPE_SV_CHANGEINFOCOOLDOWN)
{
CNetMsg_Sv_ChangeInfoCooldown *pMsg = (CNetMsg_Sv_ChangeInfoCooldown *)pRawMsg;
m_NextChangeInfo = pMsg->m_WaitUntil;
}
}
void CGameClient::OnStateChange(int NewState, int OldState)

View file

@ -517,6 +517,8 @@ public:
void SendDummyInfo(bool Start) override;
void SendKill(int ClientID) const;
int m_NextChangeInfo;
// DDRace
int m_aLocalIDs[NUM_DUMMIES];

View file

@ -2554,6 +2554,13 @@ void CGameContext::OnChangeInfoNetMessage(const CNetMsg_Cl_ChangeInfo *pMsg, int
pPlayer->m_LastChangeInfo = Server()->Tick();
pPlayer->UpdatePlaytime();
if(g_Config.m_SvSpamprotection)
{
CNetMsg_Sv_ChangeInfoCooldown ChangeInfoCooldownMsg;
ChangeInfoCooldownMsg.m_WaitUntil = Server()->Tick() + Server()->TickSpeed() * g_Config.m_SvInfoChangeDelay;
Server()->SendPackMsg(&ChangeInfoCooldownMsg, MSGFLAG_VITAL | MSGFLAG_NORECORD, ClientID);
}
// set infos
if(Server()->WouldClientNameChange(ClientID, pMsg->m_pName) && !ProcessSpamProtection(ClientID))
{