Permalink
Browse files

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.
  • Loading branch information...
qaisjp committed Jul 24, 2018
1 parent aad3a51 commit 7fc295007ac01508b2290ae6443226aa05b74484
Showing with 45 additions and 44 deletions.
  1. +45 −44 Client/core/CCommandFuncs.cpp
@@ -234,62 +234,63 @@ void CCommandFuncs::Unload(const char* szParameters)
void CCommandFuncs::Connect(const char* szParameters)
{
CModManager::GetSingleton().Unload();
// Parse the arguments (host port nick pass)
char szBuffer[256] = "";
if (szParameters)
STRNCPY(szBuffer, szParameters, NUMELMS(szBuffer));
// Any mod loaded?
if (!CModManager::GetSingleton().GetCurrentMod())
if (!strncmp(szBuffer, "mtasa://", 8))
{
// Parse the arguments (host port nick pass)
char szBuffer[256] = "";
if (szParameters)
STRNCPY(szBuffer, szParameters, NUMELMS(szBuffer));
// Using a mtasa:// URI to connect
SString strArguments = g_pCore->GetConnectCommandFromURI(szBuffer);
if (!strncmp(szBuffer, "mtasa://", 8))
if (strArguments.length() > 0 && g_pCore->GetCommands()->Execute(strArguments))
{
// Using a mtasa:// URI to connect
SString strArguments = g_pCore->GetConnectCommandFromURI(szBuffer);
if (strArguments.length() > 0 && g_pCore->GetCommands()->Execute(strArguments))
{
return;
}
return;
}
}
char* szHost = strtok(szBuffer, " ");
char* szPort = strtok(NULL, " ");
char* szNick = strtok(NULL, " ");
char* szPass = strtok(NULL, " ");
char* szHost = strtok(szBuffer, " ");
char* szPort = strtok(NULL, " ");
char* szNick = strtok(NULL, " ");
char* szPass = strtok(NULL, " ");
std::string strNick;
if (!szNick)
CVARS_GET("nick", strNick);
else
strNick = szNick;
std::string strNick;
if (!szNick)
CVARS_GET("nick", strNick);
else
strNick = szNick;
// Got all required arguments?
if (!szHost || strNick.empty())
{
CCore::GetSingleton().GetConsole()->Print(_("connect: Syntax is 'connect <host> [<port> <nick> <pass>]'"));
return;
}
// Got all required arguments?
if (!szHost || strNick.empty())
{
CCore::GetSingleton().GetConsole()->Print(_("connect: Syntax is 'connect <host> [<port> <nick> <pass>]'"));
return;
}
// Verify and convert the port number
int iPort = szPort ? atoi(szPort) : 22003;
if (iPort <= 0 || iPort > 0xFFFF)
{
CCore::GetSingleton().GetConsole()->Print(_("connect: Bad port number"));
return;
}
// Verify and convert the port number
int iPort = szPort ? atoi(szPort) : 22003;
if (iPort <= 0 || iPort > 0xFFFF)
{
CCore::GetSingleton().GetConsole()->Print(_("connect: Bad port number"));
return;
}
unsigned short usPort = static_cast<unsigned short>(iPort);
unsigned short usPort = static_cast<unsigned short>(iPort);
// Got a password?
char emptyPass = 0;
if (!szPass)
{
szPass = &emptyPass;
}
// Got a password?
char emptyPass = 0;
if (!szPass)
{
szPass = &emptyPass;
}
// Unload any mod before connecting to a server
CModManager::GetSingleton().Unload();
// Only connect if there is no mod loaded
if (!CModManager::GetSingleton().GetCurrentMod())
{
// Start the connect
if (CCore::GetSingleton().GetConnectManager()->Connect(szHost, usPort, strNick.c_str(), szPass))
{

0 comments on commit 7fc2950

Please sign in to comment.