void LogonCommHandler::Connect(LogonServer * server)
{
	server->RetryTime = (uint32)UNIXTIME + 10;
	server->Registered = false;
	LogonCommClientSocket * conn = ConnectToLogon(server->Address, server->Port);
	logons[server] = conn;
	if(conn == 0)
	{
		Log.Notice("LogonCommClient", "Connection failed. Will try again in 10 seconds.");
		return;
	}
	Log.Notice("LogonCommClient", "Authenticating...");
	uint32 tt = (uint32)UNIXTIME + 10;
	conn->SendChallenge();
	while(!conn->authenticated)
	{
		if((uint32)UNIXTIME >= tt)
		{
			Log.Notice("LogonCommClient", "Authentication timed out.");
			conn->Disconnect();
			logons[server]=NULL;
			return;
		}

		Sleep(50);
	}

	if(conn->authenticated != 1)
	{
		Log.Notice("LogonCommClient","Authentication failed.");
		logons[server] = 0;
		conn->Disconnect();
		return;
	}

	Log.Notice("LogonCommClient","Authentication OK.");
  Log.Notice("LogonCommClient", "Logonserver was connected on [%s:%u].", server->Address.c_str(), server->Port );

	// Send the initial ping
	conn->SendPing();

	Log.Notice("LogonCommClient", "Registering Realms...");
	conn->_id = server->ID;

	RequestAddition(conn);

	uint32 st = (uint32)UNIXTIME + 10;

	// Wait for register ACK
	while(server->Registered == false)
	{
		// Don't wait more than.. like 10 seconds for a registration
		if((uint32)UNIXTIME >= st)
		{
			Log.Notice("LogonCommClient", "Realm registration timed out.");
			logons[server] = 0;
			conn->Disconnect();
			break;
		}
		Sleep(50);
	}

	if(!server->Registered)
		return;

	// Wait for all realms to register
	Sleep(200);

	Log.Notice("LogonCommClient", "Logonserver latency is %ums.", conn->latency);
}
Esempio n. 2
0
void LogonCommHandler::Connect(LogonServer * server)
{
	sLog.outColor(TNORMAL, "	>> connecting to `%s` on `%s:%u`...", server->Name.c_str(), server->Address.c_str(), server->Port);
	server->RetryTime = uint32(time(NULL) + 10);
	server->Registered = false;
	LogonCommClientSocket * conn = ConnectToLogon(server->Address, server->Port);
	logons[server] = conn;
	if(conn == 0)
	{
		sLog.outColor(TRED, " fail!\n	   server connection failed. I will try again later.");
		sLog.outColor(TNORMAL, "\n");
		return;
	}
	sLog.outColor(TGREEN, " ok!\n");
	sLog.outColor(TNORMAL, "        >> authenticating...\n");
	sLog.outColor(TNORMAL, "        >> ");
	uint32 tt = uint32(time(NULL) + 10);
	conn->SendChallenge();
	sLog.outColor(TNORMAL, "        >> result:");
	while(!conn->authenticated)
	{
		if((uint32)time(NULL) >= tt)
		{
			sLog.outColor(TYELLOW, " timeout.\n");
			return;
		}

		Sleep(50);
	}

	if(conn->authenticated != 1)
	{
		sLog.outColor(TRED, " failure.\n");
		logons[server] = 0;
		conn->Disconnect();
		return;
	}
	else
		sLog.outColor(TGREEN, " ok!\n");

	// Send the initial ping
	conn->SendPing();

	sLog.outColor(TNORMAL, "        >> registering realms... ");
	conn->_id = server->ID;

	RequestAddition(conn);

	uint32 st = uint32(time(NULL) + 10);

	// Wait for register ACK
	while(server->Registered == false)
	{
		// Don't wait more than.. like 10 seconds for a registration
		if((uint32)time(NULL) >= st)
		{
			sLog.outColor(TYELLOW, "timeout.");
			logons[server] = 0;
			conn->Disconnect();
			break;
		}
		Sleep(50);
	}

	if(!server->Registered)
		return;

	// Wait for all realms to register
	Sleep(200);

	sLog.outColor(TNORMAL, "\n        >> ping test: ");
	sLog.outColor(TYELLOW, "%ums", conn->latency);
	sLog.outColor(TNORMAL, "\n");
}