fix: switch servers after player confirms

When a player wants to switch servers in-game, but needs to confirm the
action because of cl_confirm_disconnect, the game used to not actually
connect to the new server.

This adds a way to still connect to that server, after the player
confirms.

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2021-06-26 13:39:14 +02:00
parent 0393ac0f88
commit 801ebbd161
No known key found for this signature in database
GPG key ID: C10411294912A422
3 changed files with 40 additions and 2 deletions

View file

@ -1752,6 +1752,12 @@ int CMenus::Render()
pButtonText = m_aMessageButton;
ExtraAlign = -1;
}
else if(m_Popup == POPUP_SWITCH_SERVER)
{
pTitle = Localize("Disconnect");
pExtraText = Localize("Are you sure that you want to disconnect and switch to a different server?");
ExtraAlign = -1;
}
CUIRect Box, Part;
Box = Screen;
@ -2393,6 +2399,29 @@ int CMenus::Render()
SetActive(false);
}
}
else if(m_Popup == POPUP_SWITCH_SERVER)
{
CUIRect Yes, No;
Box.HSplitBottom(20.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
// buttons
Part.VMargin(80.0f, &Part);
Part.VSplitMid(&No, &Yes);
Yes.VMargin(20.0f, &Yes);
No.VMargin(20.0f, &No);
static int s_ButtonAbort = 0;
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
{
m_Popup = POPUP_NONE;
m_aNextServer[0] = '\0';
}
static int s_ButtonTryAgain = 0;
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
Client()->Connect(m_aNextServer);
}
else
{
Box.HSplitBottom(20.f, &Box, &Part);

View file

@ -290,6 +290,8 @@ protected:
vec2 m_MousePos;
bool m_MouseSlow;
char m_aNextServer[256];
int64 m_LastInput;
// images
@ -679,6 +681,7 @@ public:
POPUP_DISCONNECT,
POPUP_DISCONNECT_DUMMY,
POPUP_WARNING,
POPUP_SWITCH_SERVER,
// demo player states
DEMOPLAYER_NONE = 0,

View file

@ -487,7 +487,10 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
if(Input()->MouseDoubleClick() && DoubleClicked)
{
if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
m_Popup = POPUP_DISCONNECT;
{
m_Popup = POPUP_SWITCH_SERVER;
str_copy(m_aNextServer, g_Config.m_UiServerAddress, sizeof(m_aNextServer));
}
else
Client()->Connect(g_Config.m_UiServerAddress);
}
@ -647,7 +650,10 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
m_EnterPressed)
{
if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
m_Popup = POPUP_DISCONNECT;
{
m_Popup = POPUP_SWITCH_SERVER;
str_copy(m_aNextServer, g_Config.m_UiServerAddress, sizeof(m_aNextServer));
}
else
Client()->Connect(g_Config.m_UiServerAddress);
m_EnterPressed = false;