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
parent 8d2de4b8c2
commit 40329b7d2e
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_CommandInfoGroupStart", "sv-commandinfo-group-start@netmsg.ddnet.org", []),
NetMessageEx("Sv_CommandInfoGroupEnd", "sv-commandinfo-group-end@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

@ -273,9 +273,9 @@ void CMenus::SetNeedSendInfo()
void CMenus::RenderSettingsPlayer(CUIRect MainView) void CMenus::RenderSettingsPlayer(CUIRect MainView)
{ {
CUIRect TabBar, PlayerTab, DummyTab, QuickSearch, QuickSearchClearButton; CUIRect TabBar, PlayerTab, DummyTab, ChangeInfo, QuickSearch, QuickSearchClearButton;
MainView.HSplitTop(20.0f, &TabBar, &MainView); MainView.HSplitTop(20.0f, &TabBar, &MainView);
TabBar.VSplitMid(&TabBar, nullptr); TabBar.VSplitMid(&TabBar, &ChangeInfo, 20.f);
TabBar.VSplitMid(&PlayerTab, &DummyTab); TabBar.VSplitMid(&PlayerTab, &DummyTab);
MainView.HSplitTop(10.0f, nullptr, &MainView); MainView.HSplitTop(10.0f, nullptr, &MainView);
@ -291,6 +291,14 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView)
m_Dummy = true; 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_NameInput;
static CLineInput s_ClanInput; static CLineInput s_ClanInput;
@ -520,9 +528,9 @@ void CMenus::OnConfigSave(IConfigManager *pConfigManager)
void CMenus::RenderSettingsTee(CUIRect MainView) void CMenus::RenderSettingsTee(CUIRect MainView)
{ {
CUIRect TabBar, PlayerTab, DummyTab; CUIRect TabBar, PlayerTab, DummyTab, ChangeInfo;
MainView.HSplitTop(20.0f, &TabBar, &MainView); MainView.HSplitTop(20.0f, &TabBar, &MainView);
TabBar.VSplitMid(&TabBar, nullptr); TabBar.VSplitMid(&TabBar, &ChangeInfo, 20.f);
TabBar.VSplitMid(&PlayerTab, &DummyTab); TabBar.VSplitMid(&PlayerTab, &DummyTab);
MainView.HSplitTop(10.0f, nullptr, &MainView); MainView.HSplitTop(10.0f, nullptr, &MainView);
@ -538,6 +546,14 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
m_Dummy = true; 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; char *pSkinName;
size_t SkinNameSize; size_t SkinNameSize;
int *pUseCustomColor; int *pUseCustomColor;

View file

@ -574,6 +574,8 @@ void CGameClient::OnReset()
m_LastFlagCarrierBlue = -4; m_LastFlagCarrierBlue = -4;
m_aTuning[g_Config.m_ClDummy] = CTuningParams(); m_aTuning[g_Config.m_ClDummy] = CTuningParams();
m_NextChangeInfo = 0;
m_Teams.Reset(); m_Teams.Reset();
m_aDDRaceMsgSent[0] = false; m_aDDRaceMsgSent[0] = false;
m_aDDRaceMsgSent[1] = 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); 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) void CGameClient::OnStateChange(int NewState, int OldState)

View file

@ -517,6 +517,8 @@ public:
void SendDummyInfo(bool Start) override; void SendDummyInfo(bool Start) override;
void SendKill(int ClientID) const; void SendKill(int ClientID) const;
int m_NextChangeInfo;
// DDRace // DDRace
int m_aLocalIDs[NUM_DUMMIES]; 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->m_LastChangeInfo = Server()->Tick();
pPlayer->UpdatePlaytime(); 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 // set infos
if(Server()->WouldClientNameChange(ClientID, pMsg->m_pName) && !ProcessSpamProtection(ClientID)) if(Server()->WouldClientNameChange(ClientID, pMsg->m_pName) && !ProcessSpamProtection(ClientID))
{ {