Skip to content

Commit 7fc2950

Browse files
committed
Unload mod only after connect command validation
Fixes mantis #7047 Previously if there was a syntax error it would disconnect you from the server and show an error. Now it won't do that.
1 parent aad3a51 commit 7fc2950

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

Client/core/CCommandFuncs.cpp

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -234,62 +234,63 @@ void CCommandFuncs::Unload(const char* szParameters)
234234

235235
void CCommandFuncs::Connect(const char* szParameters)
236236
{
237-
CModManager::GetSingleton().Unload();
237+
// Parse the arguments (host port nick pass)
238+
char szBuffer[256] = "";
239+
if (szParameters)
240+
STRNCPY(szBuffer, szParameters, NUMELMS(szBuffer));
238241

239-
// Any mod loaded?
240-
if (!CModManager::GetSingleton().GetCurrentMod())
242+
if (!strncmp(szBuffer, "mtasa://", 8))
241243
{
242-
// Parse the arguments (host port nick pass)
243-
char szBuffer[256] = "";
244-
if (szParameters)
245-
STRNCPY(szBuffer, szParameters, NUMELMS(szBuffer));
244+
// Using a mtasa:// URI to connect
245+
SString strArguments = g_pCore->GetConnectCommandFromURI(szBuffer);
246246

247-
if (!strncmp(szBuffer, "mtasa://", 8))
247+
if (strArguments.length() > 0 && g_pCore->GetCommands()->Execute(strArguments))
248248
{
249-
// Using a mtasa:// URI to connect
250-
SString strArguments = g_pCore->GetConnectCommandFromURI(szBuffer);
251-
252-
if (strArguments.length() > 0 && g_pCore->GetCommands()->Execute(strArguments))
253-
{
254-
return;
255-
}
249+
return;
256250
}
251+
}
257252

258-
char* szHost = strtok(szBuffer, " ");
259-
char* szPort = strtok(NULL, " ");
260-
char* szNick = strtok(NULL, " ");
261-
char* szPass = strtok(NULL, " ");
253+
char* szHost = strtok(szBuffer, " ");
254+
char* szPort = strtok(NULL, " ");
255+
char* szNick = strtok(NULL, " ");
256+
char* szPass = strtok(NULL, " ");
262257

263-
std::string strNick;
264-
if (!szNick)
265-
CVARS_GET("nick", strNick);
266-
else
267-
strNick = szNick;
258+
std::string strNick;
259+
if (!szNick)
260+
CVARS_GET("nick", strNick);
261+
else
262+
strNick = szNick;
268263

269-
// Got all required arguments?
270-
if (!szHost || strNick.empty())
271-
{
272-
CCore::GetSingleton().GetConsole()->Print(_("connect: Syntax is 'connect <host> [<port> <nick> <pass>]'"));
273-
return;
274-
}
264+
// Got all required arguments?
265+
if (!szHost || strNick.empty())
266+
{
267+
CCore::GetSingleton().GetConsole()->Print(_("connect: Syntax is 'connect <host> [<port> <nick> <pass>]'"));
268+
return;
269+
}
275270

276-
// Verify and convert the port number
277-
int iPort = szPort ? atoi(szPort) : 22003;
278-
if (iPort <= 0 || iPort > 0xFFFF)
279-
{
280-
CCore::GetSingleton().GetConsole()->Print(_("connect: Bad port number"));
281-
return;
282-
}
271+
// Verify and convert the port number
272+
int iPort = szPort ? atoi(szPort) : 22003;
273+
if (iPort <= 0 || iPort > 0xFFFF)
274+
{
275+
CCore::GetSingleton().GetConsole()->Print(_("connect: Bad port number"));
276+
return;
277+
}
283278

284-
unsigned short usPort = static_cast<unsigned short>(iPort);
279+
unsigned short usPort = static_cast<unsigned short>(iPort);
285280

286-
// Got a password?
287-
char emptyPass = 0;
288-
if (!szPass)
289-
{
290-
szPass = &emptyPass;
291-
}
281+
// Got a password?
282+
char emptyPass = 0;
283+
if (!szPass)
284+
{
285+
szPass = &emptyPass;
286+
}
292287

288+
// Unload any mod before connecting to a server
289+
CModManager::GetSingleton().Unload();
290+
291+
// Only connect if there is no mod loaded
292+
if (!CModManager::GetSingleton().GetCurrentMod())
293+
{
293294
// Start the connect
294295
if (CCore::GetSingleton().GetConnectManager()->Connect(szHost, usPort, strNick.c_str(), szPass))
295296
{

0 commit comments

Comments
 (0)