My Community
August 30, 2014, 01:10:24 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: 6/29/2011 RakNet 4.022 released.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Disconnect reason  (Read 2573 times)
vandeer
Not-a-newbie
*

Karma: 0
Posts: 15


View Profile
« on: September 08, 2011, 11:43:27 PM »

It would be great to have an ability to set disconection reason in ID_DISCONNECTION_NOTIFICATION message.

For example, on server side call function:

void RakPeer::CloseConnection( const AddressOrGUID target, bool sendDisconnectionNotification, int disconnetReason=0, unsigned char orderingChannel=0, PacketPriority disconnectionNotificationPriority=LOW_PRIORITY )

where disconnetReason is userData, like
Code:
enum DisconnectReason
{
DR_UNSPECIFIED = 0,
DR_BAD_PROTO_VERSION, // client has incompatible protocol version
DR_BAD_GAME_VERSION, // client has incompatible game version
DR_TOO_MANY_PLAYERS, // all server slots are taken
DR_BANNED, // client is banned
DR_KICK, // client was manually kicked
DR_QUIT, // gentle quit
};

on client side
Code:
RakNet::Packet* packet = m_host->Receive();
switch( packet->data[ 0 ] )
{
//...
case ID_DISCONNECTION_NOTIFICATION:
{
int reason = (int)(packet->data[ 1 ])
switch( reason )
{
case DR_UNSPECIFIED:
case DR_BAD_PROTO_VERSION:
case DR_BAD_GAME_VERSION:
// show appropriate UI message
}
}
break;

case ID_CONNECTION_LOST:
// show UI message about unknown network problem
break;
}
« Last Edit: September 08, 2011, 11:45:59 PM by vandeer » Report to moderator   Logged
Rak'kar
Administrator
Hero Member
*****

Karma: 295
Posts: 6895



View Profile WWW
« Reply #1 on: September 09, 2011, 09:07:01 AM »

Just send a packet right before calling CloseConnection(). Provided that you set true to send the disconnection notification, the connection is not actually closed until all pending messages have been delivered.
Report to moderator   Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.17 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!