Jump to content
  • Advertisement
Sign in to follow this  
SelethD

raknet getdata help?

This topic is 4859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to understand how I get the staticdata from a client that connects to the server. when you get the packet , what do you do to get the client information? thanks

Share this post


Link to post
Share on other sites
Advertisement
Although I've never used RakNet, you could easily just send the client data through packets to the server and have the server read in the packets.

Share this post


Link to post
Share on other sites
I suggest you read RakNET tutorial which comes with it, it's really good and explains all the basics very carefully.

I'm using RakNet for the current game I'm working on, I tried to use static data but the data received by the server somehow was strange, like sometimes I tried to send the username of the player trying to connect, and I arrived in the server like " (strangechar)username ", and when I tried to send both user and password through static data, it just didnt arrive at all, so I decided to send a normal packet instead.

I think you want something like this:


void HandleSystemInfo(Packet *packet){

packetIdentifier = GetPacketIdentifier(packet);

switch (packetIdentifier)
{
case ID_INVENTORY:
cout << "Main char inventory information received.\n";
DoMyPacketHandler(packet,"inventory");
break;
case ID_WORLD_SAVE:
cout << "World is saving...\n";
WorldSave("begin");
break;
case ID_WORLD_SAVE_OK:
cout << "World save finished.\n";
WorldSave("end");
break;
case ID_PLAYER_NEW_SWORD:
DoMyPacketHandler(packet,"newsword");
break;
case ID_CHAT_MSG:
DoMyPacketHandler(packet,"chatmsg");
break;
case ID_PLAYER_DISCONNECTION:
DoMyPacketHandler(packet,"disconnection");
break;
case ID_REMOTE_EXISTING_CONNECTION:
//cout << "The server has more than one player connected.\n";
break;
case ID_REMOTE_PORT_REFUSED:
shutdown();
if(connected == true) MessageBox(NULL, " CONNECTION LOST", "Phoenix Online", MB_OK);
else MessageBox(NULL, "Server is currently offline. Please try again later.", "Phoenix Online", MB_OK);
cout << "Can\'t connect to the server. Try again later.\n";
cout << "Can\'t connect to the server. Try again later.\n";
cout << "Can\'t connect to the server. Try again later.\n";
cout << "Can\'t connect to the server. Try again later.\n";
system("pause");
exit(0);
break;
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
printf("A player has disconnected.\n");
cout << "processing disconnection info\n";
break;
case ID_REMOTE_CONNECTION_LOST:
printf("A player has lost the connection.\n");
cout << "processing disconnection info\n";
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
printf("Another player has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
printf("Connection to the server accepted.\n");
cout << "Logging in...\n";

break;
case ID_RECEIVED_STATIC_DATA:
//printf("Received server data.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
printf("The server is full.\n");
break;
case ID_DISCONNECTION_NOTIFICATION:
printf("We have been disconnected.\n");
break;
case ID_CONNECTION_LOST:
shutdown();
MessageBox(NULL, " CONNECTION LOST", "Phoenix Online", MB_OK);
cout << "Can\'t connect to the server. Try again later.\n";
cout << "Can\'t connect to the server. Try again later.\n";
cout << "Can\'t connect to the server. Try again later.\n";
cout << "Can\'t connect to the server. Try again later.\n";
system("pause");
exit(0);
break;
case ID_LOGIN_OK:
loginsuccess = true;
break;
case ID_LOGIN_WRONG:
loginsuccess = false;
cout << endl;
cout << "REJECTED BY SERVER: Username or password incorrect.\n\n";
system("pause");
shutdown();
exit(0);
break;
case ID_MAINCHAR_INFO:
cout << "Received player information from the server.\n";
cout << "Loading player information.\n";
DoMyPacketHandler(packet,"mainchar");
break;
case ID_MOVE_UPDATE:
//cout << "Received other player movement update.\n";
DoMyPacketHandler(packet,"normalmove");
break;
case ID_MOVE_MAPCHANGE:
//cout << "Received other player map change.\n";
DoMyPacketHandler(packet,"mapchange");
break;
case ID_PLAYERS_INFO:
cout << "Received other players information from the server.\n";
DoMyPacketHandler(packet,"allplayers");
break;
case ID_STATUS:
cout << "Received player status update.\n";
DoMyPacketHandler(packet,"status");
break;
case ID_ANIMATION:
cout << "Received player animation.\n";
DoMyPacketHandler(packet,"animation");
break;
case ID_GENDER_M:
DoMyPacketHandler(packet,"genderM");
break;
case ID_GENDER_F:
DoMyPacketHandler(packet,"genderF");
break;
default:
printf("Message with identifier %i has arrived.\n", packet->data[0]);
break;
}

client->DeallocatePacket(packet);



}



In every frame of the game, it runs this function which receives the packets and decides what to do with them, like displaying a message or actually reading the packet information which for that it calls DoMyPacketHandler.

Below, is a PART of my DoMyPacketHandler function:


void DoMyPacketHandler(Packet *packet,string type)
{
if(type == "inventory")
{
InventoryPacket *s = (InventoryPacket *) packet->data;

minv = s->inv;

cout << "Loaded inventory information.\n";
}
if(type == "newsword")
{
NewSwordPacket *s = (NewSwordPacket *) packet->data;

for(pITR = players.begin();pITR != players.end();pITR++)
{
if(comparePID(packet->playerId,pITR->playerId) == 0)
{
configweapon(s->sword,*pITR);

return;
}
}
}

else if(type == "mapchange")
{
MapChangePacket *s = (MapChangePacket *) packet->data;

for(pITR = players.begin();pITR != players.end();pITR++)
{
if(strcmp(s->name,pITR->name) == 0)
{

int pos = s->pos;
int X = s->X;
int Y = s->Y;
int frame = s->frame;

pITR->pos = pos;
pITR->X = X;
pITR->Y = Y;
pITR->frame = frame;
strcpy(pITR->level,s->level);

return;
}

}

return;
}

else if(type == "normalmove")
{
MovementPacket *s = (MovementPacket *) packet->data;

for(pITR = players.begin();pITR != players.end();pITR++)
{
if(strcmp(s->name,pITR->name) == 0)
{

int pos = s->pos;
int X = s->X;
int Y = s->Y;
int frame = s->frame;

pITR->pos = pos;
pITR->X = X;
pITR->Y = Y;
pITR->frame = frame;

return;
}

}
}


...




Again, I strongly recommend that you read RakNet beginner's tutorial and all of this will make sense to you, if you can't understand it.

Good luck and feel free to ask me for further help.



Share this post


Link to post
Share on other sites
The spurious character..

I don't know if its related, but is it to do with the first bytes in the Static bitstream being and ID? If you look at the Static data methods..

So if you're intercepting the bitstream, you would get the ID_RECEIVED_STATIC_DATA as the first element.

void RakPeer::SendStaticDataInternal( PlayerID target, bool performImmediate )
{
RakNet::BitStream reply( sizeof( unsigned char ) + localStaticData.GetNumberOfBytesUsed() );
reply.Write( ( unsigned char ) ID_RECEIVED_STATIC_DATA );
reply.Write( ( char* ) localStaticData.GetData(), localStaticData.GetNumberOfBytesUsed() );

...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!