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
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
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;
}