/* 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 NLU_H #define NLU_H #include "nl.h" #ifdef __cplusplus extern "C" { #endif #define NLU_MAJOR_VERSION 0 #define NLU_MINOR_VERSION 7 #define NLU_VERSION_STRING "HawkNLU 0.7 alpha" #define NLU_MAX_NAME_LEN 32 /* max string length (including NULL) for server, game, and player names */ typedef struct { NLlong serverType; /* Type of server */ NLlong maxPlayers; /* Max number of players allowed in this game */ NLlong currentPlayers; /* Current number of players in this game */ NLchar *gameName; /* Name of this game/app */ NLlong gameVersion; /* Version number of game */ NLchar *serverName; /* Name of this server */ NLushort port; /* port number to use, or 0 for default port */ NLchar *password; /* Password for game */ NLlong user1; /* For application use */ NLlong user2; NLlong user3; NLlong user4; } nlu_server_t; typedef struct { NLchar *gameName; /* Name of this game/app */ NLlong gameVersion; /* Version number of game */ NLlong playerID; /* Player ID number, provided by the server */ NLchar *playerName; /* Name of client */ NLchar *password; /* Password for game */ NLlong user1; /* For application use */ NLlong user2; NLlong user3; NLlong user4; } nlu_player_t; /* the player object */ typedef NLlong NLUplayer; /* callback functions */ /* returns NL_TRUE if successfull, else NL_FALSE */ typedef NLboolean (NL_CALLBACK *NLUcryptCB)(NLint mode, NLbyte *in, NLint insize, NLbyte *out, NLint outsize); /* returns NL_TRUE for more, or NL_FALSE to stop enumerating */ typedef NLboolean (NL_CALLBACK *NLUenumServersCB)(NLbyte *description, NLint serverType, NLint maxPlayers, NLint currentPlayers, NLaddress address); typedef NLboolean (NL_CALLBACK *NLUenumPlayersCB)(NLUplayer playerID, NLchar *name); /* returns a code relevant to the event processed */ typedef NLint (NL_CALLBACK *NLUeventCB)(NLint event, void *data); #define NLU_ALL 0xffff /* send to all clients */ #define NLU_SERVER 0 /* send to server */ /* NLUcryptCB modes */ #define NLU_ENCRYPT_BUFFER 0 #define NLU_DECRYPT_BUFFER 1 /* nluEnable, nluDisable */ #define NLU_ENCRYPT 0x1001 /* encrypt/decrypt packets using provided routine, default disabled */ /* Server types */ #define NLU_PEER_TO_PEER 0x1010 /* The server only provides the addresses of all players */ /* so that each player can send to the others directly */ #define NLU_CLIENT_SERVER 0x1011 /* Players only send to the server */ /* nluSend options */ #define NLU_RELIABLE 0x0001 /* Packet is resent until an acknowledgment is received */ #define NLU_LOW_PRIORITY 0x0002 /* Packet can be briefly buffered before sending to reduce the number of sends; other messages can be piggy-backed */ /* Server type modifiers */ #define NLU_DEDICATED 0x80000000 /* The server is a dedicated server */ /* NLU events */ #define NLU_NEW_PLAYER 0x1200 /* A new player has joined the game, sends nlu_player_t */ #define NLU_DEL_PLAYER 0x1201 /* The player has left the game, sends playerID */ #define NLU_PACKET 0x1202 /* A game packet has arrived, sends playerID */ /* Connection stats, per connection */ #define NLU_PACKETS_DROPPED 0x1210 /* Dropped packets since connected */ #define NLU_AVE_BYTES_SENT 0x1211 /* Average bytes sent per second */ #define NLU_AVE_BYTES_REC 0x1212 /* Average bytes received per second */ #define NLU_HIGH_BYTES_SENT 0x1213 /* Highest bytes sent per second */ #define NLU_HIGH_BYTES_REC 0x1214 /* Highest bytes received per second */ /* Common API */ NL_EXP NLboolean NL_APIENTRY nluInit(NLUeventCB func, NLenum network); NL_EXP void NL_APIENTRY nluShutdown(void); NL_EXP void NL_APIENTRY nluGetMessages(void); NL_EXP void NL_APIENTRY nluEnable(NLenum name); NL_EXP void NL_APIENTRY nluDisable(NLenum name); NL_EXP NLboolean NL_APIENTRY nluGetBoolean(NLenum name); NL_EXP NLlong NL_APIENTRY nluGetConnectionStats(NLUplayer player, NLenum name); NL_EXP void NL_APIENTRY nluBanAddress(NLaddress *address); NL_EXP NLint NL_APIENTRY nluSend(NLUplayer player, NLubyte *data, NLint length, NLenum options); /* player or group */ NL_EXP NLint NL_APIENTRY nluReceive(NLUplayer player, NLubyte *data, NLint length); NL_EXP void NL_APIENTRY nluCryptFunc(NLUcryptCB func); /* Group management API */ NL_EXP NLint NL_APIENTRY nluGroupCreate(void); NL_EXP void NL_APIENTRY nluGroupDestroy(NLint group); NL_EXP NLboolean NL_APIENTRY nluGroupAddPlayer(NLint group, NLUplayer player); NL_EXP void NL_APIENTRY nluGroupGetPlayers(NLint group, NLUplayer *players, NLint *number); NL_EXP void NL_APIENTRY nluGroupDeletePlayer(NLint group, NLUplayer player); /* Server API */ NL_EXP NLboolean NL_APIENTRY nluServerCreate(nlu_server_t *server); NL_EXP void NL_APIENTRY nluServerDestroy(void); NL_EXP void NL_APIENTRY nluServerDisconnectPlayer(NLUplayer player); /* Client API */ NL_EXP NLUplayer NL_APIENTRY nluPlayerCreate(nlu_player_t *player); NL_EXP NLboolean NL_APIENTRY nluPlayerConnect(NLUplayer player, NLaddress *address); NL_EXP void NL_APIENTRY nluEnumerateServers(NLUplayer player, NLUenumServersCB func, NLint timeout); NL_EXP void NL_APIENTRY nluEnumeratePlayers(NLUplayer player, NLUenumPlayersCB func, NLint timeout); NL_EXP void NL_APIENTRY nluPlayerDisconnect(NLUplayer player); NL_EXP void NL_APIENTRY nluPlayerDestroy(NLUplayer player); #ifdef __cplusplus } /* extern "C" */ #endif #endif /* NLU_H */