Skip to main content
GameDev.net gamedev.net
🔒 Locked

[RakNet]Abnormal Disconnect?

Started by Mr_Fhqwhgads Jan 19, 2007 at 12:42 AM 0 replies 2.2k views
Original Post
Mr_Fhqwhgads
Mr_Fhqwhgads
I run my server, and the server starts up fine. When the client connects I get this output... Incoming Connection Received static data Found Player Abnormally lost connection Received static Data Found Player Abnormally lost connection and right here the client program crashes. Currently the only thing both the client and the server do in the loop is check for packets. server packet handling

switch(packetId)
		{
		case ID_DISCONNECTION_NOTIFICATION:
		{	// Player Disconnected
			std::cout << "Player Disconnected";
		}
		case ID_NEW_INCOMING_CONNECTION:
		{	// New Connection
			CPlayer player = CPlayer( packet->playerId );
			playerList.push_back( player );
			std::cout << "Incoming Connection - ";
			std::cout << packet->playerId.ToString() << "\n";
		}
		case ID_RECEIVED_STATIC_DATA:
		{	// Received static user data
			
			// Make sure client has current version
			std::cout << "Received static data\n";
			// Search for the correct player
			for(std::list<CPlayer>::iterator plIter = playerList.begin(); plIter != playerList.end(); plIter++)
			{
				// If we found it
				if( plIter->getPlayerID() == packet->playerId )
				{
					std::cout << "Found Player\n";
					
					// Check version
					if( ((SClientData*)(networkManager.getNetworkInterface()->GetStaticClientData(packet->playerId))->GetData())->version
						!= networkManager.serverData.version)
					{
						// Send him a message then kick him.
						const char *msg = "Invalid Version";
						networkManager.getNetworkInterface()->Send( (char*)msg, strlen(msg)+1, HIGH_PRIORITY, RELIABLE, 0, packet->playerId, false); 
						networkManager.getNetworkInterface()->Kick(packet->playerId);
					}
				}
			}
		}
		case ID_MODIFIED_PACKET:
		{
			// Its teh hax!
			
		}
		case ID_CONNECTION_LOST:
			// Abnormally lost connection
			std::cout << "Abnormally lost connection\n";
			break;
		default:
			// Other kind of message
			break;
		};

Client setup and connection

	networkInterface = RakNetworkFactory::GetRakClientInterface();
	networkInterface->InitializeSecurity( 0, 0 );
	networkInterface->SetPassword( PASSWORD );

	clientData.version.append( VERSION );
	clientData.username.append( "Cirdan" );

	networkInterface->SetStaticClientData( UNASSIGNED_PLAYER_ID, (char*)&clientData, sizeof(clientData) );
	networkInterface->AllowConnectionResponseIPMigration( false );

	if( networkInterface->Connect( SERVER_IP, SERVER_PORT, CLIENT_PORT, 0, 30 ) )
	{
		std::cout << "Client connected";
	}
	else
	{
		std::cout << "Connection faild";
	}


[Edited by - Mr_Fhqwhgads on January 20, 2007 8:11:04 PM]
Blupix Games
Mr_Fhqwhgads
Mr_Fhqwhgads
Ok here is an update(twas late when I posted this). I made it so if I type quit on the client it properly disconnects.

I get the following output:

Incoming Connection
Received static data
Abnormally lost connection
Received static data
Abnormally lost connection
Player Disconnected
Incoming Connection
Received static data
Abnormally lost connection

Now what my problem is, if a player disconnects I need to remove it from a list. But if the player isn't really disconnected, what do I do? And why does the server receive the static data so many times? If you need more code, let me know.
Blupix Games

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.