LJHCServer

API

By Andrew Strauss

 

This server was designed to be VERY simple and clean.  Server

settings are read from a file passed in to the Init functions.  These settings include

the server port, number of players allowed, and the max time to wait for players to

connect after the first player has connected.  Here is an example of an ini file:

 

[Server]

port=2507

numOfPlayersAllowed=4

maxTimeToWaitForPlayers=16

 

------------------------------------------------------------------------------------

 

/*****

 *

 * LJHCServer::initLJHCServer

 *

 * Description

 *   Load in info from ini file, initialize

 *   direct play, and start the server

 *

 * Params

 *    char* iniFile

 *      The ini file to read settings from

 *   PFNDPNMESSAGEHANDLER blah

 *      The message handler for the server

 *      Example:

 *        HRESULT WINAPI LJHCServerDirectPlayMessageHandler(

 *                     PVOID pvUserContext, DWORD dwMessageId,

 *                               PVOID pMsgBuffer );

 *

 * Return Value

 *   None

 *

 *****/

void LJHCServer::Init(char* iniFile, PFNDPNMESSAGEHANDLER blah)

 

/*****

 *

 * LJHCServer::Cleanup

 *

 * Description

 *   Stops the server and cleans up direct play

 *

 * Params

 *   None

 *

 * Return Value

 *   None

 *

 *****/

void LJHCServer::Cleanup()

 

/*****

 *

 * LJHCServer::Send

 *

 * Description

 *   Sends a gamemsg to all clients

 *

 * Params

 *   GAMEMSG_GENERIC *msg

 *       This game msg to send to everyone

 *   int size

 *       The size of the game msg

 *

 * Return Value

 *      -E_FAIL - didn't send

 *      -DPNERR_INVALIDFLAGS - the flags passed to send()

 *                          were invalid (shouldn't happen)

 *    -DPNERR_INVALIDPARAM - one or more params to

 *        SendTo were invalid

 *    -DPNERR_INVALIDPLAYER - invalid playerid passed to SendTo

 *    -DPNERR_TIMEDOUT - send timed out

 *      -DPNSUCCESS_PENDING - if send() was processed

 *                                        asynchronously

 *      -S_OK - method was synchronous and succesful

 *

 *****/

HRESULT LJHCServer::Send(GAMEMSG_GENERIC *msg, int size)

{

      DPN_BUFFER_DESC dpnBuffer;

      dpnBuffer.dwBufferSize = size;

      dpnBuffer.pBufferData = (BYTE*)(msg);

 

    DPNHANDLE hAsync;

      if(initCalled)

            return g_pDPServer->SendTo( DPNID_ALL_PLAYERS_GROUP, &dpnBuffer, 1,

                                          0, NULL, &hAsync, DPNSEND_NOLOOPBACK);

      return E_FAIL;

}

 

/*****

 *

 * LJHCServer::SendSync

 *

 * Description

 *   Sends a gamemsg to all clients synchronously

 *

 * Params

 *   GAMEMSG_GENERIC *msg

 *       This game msg to send to everyone

 *   int size

 *       The size of the game msg

 *

 * Return Value

 *      -E_FAIL - didn't send

 *      -DPNERR_INVALIDFLAGS - the flags passed to send()

 *                          were invalid (shouldn't happen)

 *    -DPNERR_INVALIDPARAM - one or more params to

 *        SendTo were invalid

 *    -DPNERR_INVALIDPLAYER - invalid playerid passed to SendTo

 *    -DPNERR_TIMEDOUT - send timed out

 *      -DPNSUCCESS_PENDING - if send() was processed

 *                                        asynchronously

 *      -S_OK - method was synchronous and succesful

 *

 *****/

HRESULT LJHCServer::SendSync(GAMEMSG_GENERIC *msg, int size)

 

/*****

 *

 * LJHCServer::Send

 *

 * Description

 *   Sends a gamemsg to a specific clients

 *

 * Params

 *   GAMEMSG_GENERIC *msg

 *       This game msg to send

 *   int size

 *       The size of the game msg

 *   DPNID id

 *       DPNID of the client to send msg to

 *

 * Return Value

 *      -E_FAIL - didn't send

 *      -DPNERR_INVALIDFLAGS - the flags passed to send()

 *                          were invalid (shouldn't happen)

 *    -DPNERR_INVALIDPARAM - one or more params to

 *        SendTo were invalid

 *    -DPNERR_INVALIDPLAYER - invalid playerid passed to SendTo

 *    -DPNERR_TIMEDOUT - send timed out

 *      -DPNSUCCESS_PENDING - if send() was processed

 *                                        asynchronously

 *      -S_OK - method was synchronous and succesful

 *

 *****/

HRESULT LJHCServer::Send(GAMEMSG_GENERIC *msg, int size, DPNID id)

 

/*****

 *

 * LJHCServer::SendSync

 *

 * Description

 *   Sends a gamemsg to a specific clients synchronously

 *

 * Params

 *   GAMEMSG_GENERIC *msg

 *       This game msg to send

 *   int size

 *       The size of the game msg

 *   DPNID id

 *       DPNID of the client to send msg to

 *

 * Return Value

 *      -E_FAIL - didn't send

 *      -DPNERR_INVALIDFLAGS - the flags passed to send()

 *                          were invalid (shouldn't happen)

 *    -DPNERR_INVALIDPARAM - one or more params to

 *        SendTo were invalid

 *    -DPNERR_INVALIDPLAYER - invalid playerid passed to SendTo

 *    -DPNERR_TIMEDOUT - send timed out

 *      -DPNSUCCESS_PENDING - if send() was processed

 *                                        asynchronously

 *      -S_OK - method was synchronous and succesful

 *

 *****/

HRESULT LJHCServer::SendSync(GAMEMSG_GENERIC *msg, int size, DPNID id)

 

/*****

 *

 * LJHCServer::SendArray

 *

 * Description

 *   Sends an array to all clients

 *

 * Params

 *   void *blah

 *       This array to send to everyone

 *   int size

 *       The size of the game msg

 *

 * Return Value

 *      -E_FAIL - didn't send

 *      -DPNERR_INVALIDFLAGS - the flags passed to send()

 *                          were invalid (shouldn't happen)

 *    -DPNERR_INVALIDPARAM - one or more params to

 *        SendTo were invalid

 *    -DPNERR_INVALIDPLAYER - invalid playerid passed to SendTo

 *    -DPNERR_TIMEDOUT - send timed out

 *      -DPNSUCCESS_PENDING - if send() was processed

 *                                        asynchronously

 *      -S_OK - method was synchronous and succesful

 *

 *****/

HRESULT LJHCServer::SendArray(void *blah, int size)

 

/*****

 *

 * LJHCServer::SendArraySync

 *

 * Description

 *   Sends an array to all clients synchronously

 *

 * Params

 *   void *blah

 *       This array to send to everyone

 *   int size

 *       The size of the game msg

 *

 * Return Value

 *      -E_FAIL - didn't send

 *      -DPNERR_INVALIDFLAGS - the flags passed to send()

 *                          were invalid (shouldn't happen)

 *    -DPNERR_INVALIDPARAM - one or more params to

 *        SendTo were invalid

 *    -DPNERR_INVALIDPLAYER - invalid playerid passed to SendTo

 *    -DPNERR_TIMEDOUT - send timed out

 *      -DPNSUCCESS_PENDING - if send() was processed

 *                                        asynchronously

 *      -S_OK - method was synchronous and succesful

 *

 *****/

HRESULT LJHCServer::SendArraySync(void *blah, int size)