void LogonCommHandler::UpdateSockets()
{
	mapLock.Acquire();

	map<LogonServer*, LogonCommClientSocket*>::iterator itr = logons.begin();
	LogonCommClientSocket * cs;
	uint32 t = (uint32)UNIXTIME;
	for(; itr != logons.end(); ++itr)
	{
		cs = itr->second;
		if(cs != 0)
		{
			if(!pings) continue;

            if(cs->IsDeleted() || !cs->IsConnected())
            {
                cs->_id = 0;
                itr->second = 0;
                continue;
            }

			if(cs->last_pong < t && ((t - cs->last_pong) > 60))
			{
				// no pong for 60 seconds -> remove the socket
				printf(" >> realm id %u connection dropped due to pong timeout.\n", (unsigned int)itr->first->ID);
				cs->_id = 0;
				cs->Disconnect();
				itr->second = 0;
				continue;
			}
            
			if( (t - cs->last_ping) > 15 )
			{
				// send a ping packet.
				cs->SendPing();
			}
		}
		else
		{
			// check retry time
			if(t >= itr->first->RetryTime)
			{
				Connect(itr->first);
			}
		}
	}
	mapLock.Release();
}
Exemplo n.º 2
0
uint32 LogonCommHandler::ClientConnected(string AccountName, WorldSocket * Socket)
{
    uint32 request_id = next_request++;
    size_t i = 0;
    const char * acct = AccountName.c_str();
    sLog.outDebug ( " >> sending request for account information: `%s` (request %u).", AccountName.c_str(), request_id);
    //  sLog.outColor(TNORMAL, "\n");

    // Send request packet to server.
    map<LogonServer*, LogonCommClientSocket*>::iterator itr = logons.begin();
    if(logons.size() == 0)
    {
        // No valid logonserver is connected.
        return (uint32)-1;
    }

    LogonCommClientSocket * s = itr->second;
    if( s == NULL )
        return (uint32)-1;

    pendingLock.Acquire();

    WorldPacket data(RCMSG_REQUEST_SESSION, 100);
    data << request_id;

    // strip the shitty hash from it
    for(; acct[i] != '#' && acct[i] != '\0'; ++i )
        data.append( &acct[i], 1 );

    data.append( "\0", 1 );
    s->SendPacket(&data,false);

    pending_logons[request_id] = Socket;
    pendingLock.Release();

    RefreshRealmPop();
    return request_id;
}
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);
}
Exemplo n.º 4
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");
}