bool MasterClient::OnReceive(RakPeerInterface *peer, Packet *packet) { switch(packet->data[0]) { case ID_NO_FREE_INCOMING_CONNECTIONS: OnMasterServerFull(); return false; // Do not absorb packet case ID_DISCONNECTION_NOTIFICATION: OnLostConnection(); return false; // Do not absorb packet case ID_CONNECTION_LOST: OnLostConnection(); return false; // Do not absorb packet case ID_MODIFIED_PACKET: OnModifiedPacket(); return false; case ID_CONNECTION_ATTEMPT_FAILED: OnConnectionAttemptFailed(); return false; // Do not absorb packet case ID_MASTER_SERVER_UPDATE_SERVER: HandleServerListResponse(packet, false); return true; // Absorb packet case ID_MASTER_SERVER_SET_SERVER: HandleServerListResponse(packet, true); return true; // Absorb packet case ID_PONG: HandlePong(packet); return false; // Absorb packet case ID_RELAYED_CONNECTION_NOTIFICATION: HandleRelayedConnectionNotification(packet); return true; // Absorb packet } return 0; }
void XSocketImpl::OnReceiveMessage(const MessageConstPtr& msg) { byte packetID = msg->GetMessageID(); // If this is a user's packet, forward it to them if (packetID >= ID_USER_PACKET_ENUM) { if (m_listener) { m_listener->OnMessageReceived(this, msg->GetData(), msg->GetSize()); } else { LogError("XSocket received message with no listener"); } } else { // Check to see if this is a packet we should handle (connected, disconnected, etc) switch (packetID) { case ID_CONNECTION_REQUEST_ACCEPTED: OnConnected(); break; case ID_DISCONNECTION_NOTIFICATION: OnLostConnection(); break; case ID_CONNECTION_LOST: OnLostConnection(); break; case ID_CONNECTION_ATTEMPT_FAILED: case ID_ALREADY_CONNECTED: case ID_NO_FREE_INCOMING_CONNECTIONS: OnConnectionAttemptFailed(packetID); break; case ID_IP_RECENTLY_CONNECTED: LogInfo("Connection attempt rejected because it was too soon after the last connection"); break; } } }