/* HawkNLU cross platform network library Copyright (C) 2000-2002 Phil Frisbie, Jr. (phil@hawksoft.com) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Or go to http://www.gnu.org/copyleft/lgpl.html */ #ifndef PROTOCOL_H #define PROTOCOL_H #include "nl.h" #ifdef __cplusplus extern "C" { #endif /* The internal protocol is a binary protocol for small packet size. A packet is composed of the following: NLubyte magic number for protocol, 0xf1 NLushort packet sequence number NLubyte[] data The data is composed of one or more messages. Each message begins with an NLubyte which specifies the type of message, followed by the required data: NLU_SERVER_INFO- Sent from server to player in response to NLU_GET_SERVER_INFO (most of this info is from nlu_server_t) NLlong nluVersion (16.16 format) NLlong serverType NLlong maxPlayers NLlong currentPlayers NLbyte *gameName NLlong gameVersion NLbyte *serverName NLlong user1 NLlong user2 NLlong user3 NLlong user4 NLU_PLAYER_INFO- Sent from server to player in response to NLU_GET_PLAYER_INFO (most of this info is from client_t) NLubyte[14] address- from NLaddress->sa_data, we need the address and port for peer/peer messages NLlong playerID NLbyte *playerName NLlong user1 NLlong user2 NLlong user3 NLlong user4 ... info for all players in one packet NLU_GET_SERVER_INFO- Sent from player to server to get NLU_SERVER_INFO (none) NLU_GET_PLAYER_INFO- Sent from player to server to get NLU_PLAYER_INFO for all players (none) NLU_CONNECT- Sent from player to server to connect to game (most of this info is from client_t) NLlong nluVersion (16.16 format) NLbyte *gameName NLlong gameVersion NLlong playerID 0 for new connect, or assigned number if reconnecting NLbyte *playerName NLbyte *password NLlong user1 NLlong user2 NLlong user3 NLlong user4 NLU_ACCEPT- Sent from server to player in response to NLU_CONNECT NLlong playerID- Assigned by server NLU_REJECT- Sent from server to player in response to NLU_CONNECT NLubyte reason NLU_ACK- Sent in response to a packet with NLU_REQ_ACK type mask NLushort packetnumber NLU_GAME_DATA- This is a normal game data packet, it will NEVER have another message after it NLvoid *data NLU_GAME_DATA_LOW- This is a low priority game data packet, it may have another message after it NLushort datalength NLvoid *data NLU_DISCONNECT- Sent from player to server to ask for a disconnect NLlong playerID NLU_BYE- Sent from server to player to inform the player he has been disconnected and why NLubyte reason NLU_PLAYER_JOIN- Sent from server to all players, a new player has joined the game NLlong playerID NLbyte *playerName NLlong user1 NLlong user2 NLlong user3 NLlong user4 NLU_PLAYER_LEFT- Sent from server to all players, a player has left the game NLlong playerID */ #define NLU_PROTOCOL 0xf1 #define NLU_BAD_MESSAGE 0x00 /* bad message */ /* client/server message types */ #define NLU_SERVER_INFO 0x01 /* from server to client */ #define NLU_PLAYER_INFO 0x02 /* from client to/from server */ #define NLU_GET_SERVER_INFO 0x03 /* get server info */ #define NLU_GET_PLAYER_INFO 0x04 /* get the player info for all players */ #define NLU_CONNECT 0x05 /* connect to server */ #define NLU_ACCEPT 0x06 /* client accepted by server */ #define NLU_REJECT 0x07 /* client rejected by server */ #define NLU_ACK 0x08 /* acknowledgement of receipt */ #define NLU_GAME_DATA 0x09 /* a game data message */ #define NLU_GAME_DATA_LOW 0x0a /* low priority game data message */ #define NLU_DISCONNECT 0x0b /* disconnect from the server */ #define NLU_BYE 0x0c /* server is disconnecting the player */ #define NLU_PLAYER_JOIN 0x0d /* A new player has entered the game */ #define NLU_PLAYER_LEFT 0x0e /* A player has left the game */ /* message type modifiers */ #define NLU_REQ_ACK 0x80 /* request acknowledgement for this message */ #define NLU_ENCRYPTED 0x40 /* packet is encrypted */ /* NLU_REJECT reasons */ #define NLU_SERVER_FULL 0x00 /* server is full */ #define NLU_VERSION 0x01 /* wrong game or NLU version */ #define NLU_PASSWORD 0x02 /* wrong or missing password */ #define NLU_PLAYER_ID 0x03 /* reconnecting with a player ID already in use */ #define NLU_BANNED 0x04 /* the address is banned from the server */ /*NLU_BYE reasons */ #define NLU_REQUESTED 0x10 /* requested by player */ #define NLU_SHUTDOWN 0x11 /* server is shutting down */ #define NLU_TIMEOUT 0x12 /* too much time has elasped since last packet */ #define NLU_BOOTED 0x13 /* player was booted off system */ /* default server ports */ #define NLU_PORT 1258 /* our assigned port! */ #ifdef __cplusplus } /* extern "C" */ #endif #endif /* PROTOCOL_H */