Skip to content

Commit

Permalink
Unload mod only after connect command validation
Browse files Browse the repository at this point in the history
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 7fc2950
Showing 1 changed file with 45 additions and 44 deletions.
89 changes: 45 additions & 44 deletions Client/core/CCommandFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down

0 comments on commit 7fc2950

Please sign in to comment.