From fba3815ddcb892e52c088791ff76a5f6b38f3743 Mon Sep 17 00:00:00 2001 From: def Date: Sat, 15 Jul 2017 17:29:20 +0200 Subject: [PATCH] Only send password on connection when explicitly asked to (fixes #788) --- src/engine/client.h | 2 +- src/engine/client/client.cpp | 12 +++++++++--- src/engine/client/client.h | 3 ++- src/game/client/components/menus.cpp | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/engine/client.h b/src/engine/client.h index d4126f501..271510f38 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -87,7 +87,7 @@ public: inline float LocalTime() const { return m_LocalTime; } // actions - virtual void Connect(const char *pAddress) = 0; + virtual void Connect(const char *pAddress, const char *pPassword = NULL) = 0; virtual void Disconnect() = 0; // dummy diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 76a44f6b1..e6fbfe404 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -299,6 +299,7 @@ CClient::CClient() : m_DemoPlayer(&m_SnapshotDelta) m_RconAuthed[0] = 0; m_RconAuthed[1] = 0; m_RconPassword[0] = '\0'; + m_Password[0] = '\0'; // version-checking m_aVersionStr[0] = '0'; @@ -403,7 +404,7 @@ void CClient::SendInfo() { CMsgPacker Msg(NETMSG_INFO); Msg.AddString(GameClient()->NetVersion(), 128); - Msg.AddString(g_Config.m_Password, 128); + Msg.AddString(m_Password, 128); SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH); } @@ -664,7 +665,7 @@ void CClient::GenerateTimeoutCodes() } } -void CClient::Connect(const char *pAddress) +void CClient::Connect(const char *pAddress, const char *pPassword) { char aBuf[512]; int Port = 8303; @@ -685,6 +686,11 @@ void CClient::Connect(const char *pAddress) net_host_lookup("localhost", &m_ServerAddress, m_NetClient[0].NetType()); } + if(!pPassword) + m_Password[0] = 0; + else + str_copy(m_Password, pPassword, sizeof(m_Password)); + m_RconAuthed[0] = 0; if(m_ServerAddress.port == 0) m_ServerAddress.port = Port; @@ -2791,7 +2797,7 @@ void CClient::Run() // send client info CMsgPacker MsgInfo(NETMSG_INFO); MsgInfo.AddString(GameClient()->NetVersion(), 128); - MsgInfo.AddString(g_Config.m_Password, 128); + MsgInfo.AddString(m_Password, 128); SendMsgExY(&MsgInfo, MSGFLAG_VITAL|MSGFLAG_FLUSH, true, 1); // update netclient diff --git a/src/engine/client/client.h b/src/engine/client/client.h index b8ecea01f..adab03172 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -108,6 +108,7 @@ class CClient : public IClient, public CDemoPlayer::IListener int m_RconAuthed[2]; char m_RconPassword[32]; int m_UseTempRconCommands; + char m_Password[32]; // version-checking char m_aVersionStr[10]; @@ -252,7 +253,7 @@ public: void OnEnterGame(); virtual void EnterGame(); - virtual void Connect(const char *pAddress); + virtual void Connect(const char *pAddress, const char *pPassword = NULL); void DisconnectWithReason(const char *pReason); virtual void Disconnect(); diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index a0399380e..59ba142bc 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1277,7 +1277,7 @@ int CMenus::Render() static int s_ButtonTryAgain = 0; if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || m_EnterPressed) { - Client()->Connect(g_Config.m_UiServerAddress); + Client()->Connect(g_Config.m_UiServerAddress, g_Config.m_Password); } Box.HSplitBottom(60.f, &Box, &Part);