Code:
////////////////////////////////////////////////////////////////////////////////////////////////////
// file: XorRelayServiceCli.h
//
// summary: Declares the XorNet Relay Service Client API.
////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <Windows.h>
#include <vector>
#include <map>
// Callback typedef
typedef bool (*CmdHandler)();
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary> XorNet Relay Service Client API. </summary>
///
/// <remarks> Lethal, 5/31/2012. </remarks>
////////////////////////////////////////////////////////////////////////////////////////////////////
class XorRelayServiceCli
{
public:
XorRelayServiceCli();
virtual ~XorRelayServiceCli();
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Adds a callback.
/// Commands called by Relay Service by default:
/// - "SaveAllExit"(calls this before "stop signal")
/// - "Census"(calls this to request the number of users online this server)
/// </summary>
///
/// <remarks> Lethal, 5/31/2012. </remarks>
///
/// <param name="hCmd"> The command handler. </param>
/// <param name="szCommand"> The command string. </param>
/// <param name="szDescription"> The description string. </param>
////////////////////////////////////////////////////////////////////////////////////////////////////
static void AddCallback(CmdHandler hCmd, const char *szCommand, const char *szDescription);
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary> Sends a response to the Controller node. </summary>
///
/// <remarks> Lethal, 5/31/2012. </remarks>
///
/// <param name="szResponse"> The response format. </param>
////////////////////////////////////////////////////////////////////////////////////////////////////
static void RespondToControl( const char *szResponse, ... );
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Used to retreive the input buffer, which can be used for reading dynamic commands.
/// </summary>
///
/// <remarks> Lethal, 5/31/2012. </remarks>
///
/// <returns>
/// NULL if it fails, else the command 1024 char input buffer. The command code is not
/// included and the buffer will "never" be NULL.
/// </returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
static const char* GetInputBuffer();
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary> Initializes the Relay Service Client. </summary>
///
/// <remarks> Lethal, 5/31/2012. </remarks>
///
/// <param name="szSrvName"> Name of the server app. </param>
/// <param name="szIniFile"> The path of the server app's INI file. </param>
/// <param name="nStartupNumber"> The startup number order(starts at 0). </param>
/// <param name="bCreateThread"> (optional) Create a new thread for processing. </param>
///
/// <returns> true if it succeeds, false if it fails. </returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
static bool Init(const char* szSrvName, const char* szIniFile, int nStartupNumber, bool bCreateThread=false);
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Connects to the Relay Service. Should be called after initial application loading
/// is done. After this is called, the next server will begin startup.
/// </summary>
///
/// <remarks> Lethal, 5/31/2012. </remarks>
///
/// <returns> true if it succeeds, false if it fails. </returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
static bool Start();
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Gracefully disconnects the server app from the Relay Service after the Relay Service
/// signals stop. If this is called before the Relay Service signals, "stop", it will be
/// considered a crash.
/// </summary>
///
/// <remarks> Lethal, 5/31/2012. </remarks>
///
/// <returns> true if it succeeds, false if it fails. </returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
static bool Stop();
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Call this every 1-1000ms(100ms recommended) if the bCreateThread param was passed as
/// FALSE in the initialization call.
/// </summary>
///
/// <remarks> Lethal, 5/31/2012. </remarks>
///
/// <returns> TRUE if the "stop" signal has been received, the application should then exit. </returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
static bool Process();
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary> Retrieves strings from controller client. </summary>
////////////////////////////////////////////////////////////////////////////////////////////////////
static const char* GetIniFile();
static const char* GetServerName();
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary> Response codes </summary>
///
/// <remarks> Lethal, 5/31/2012. </remarks>
/////////////////////////////////////////////////////////////////////////////////////////////////
#define XORRC_RESPONSECODE_SERVER_READY "SERVER READY IDSTR = {6EC9D721-D946-4906-AB79-5AF7B35241CB}\n" // Notifies Relay Service that server app is ready!
#define XORRC_RESPONSECODE_SET_CUSTOM_STATE "Set Custom State {79CC1671-A46D-478a-9497-4933581B5B03},%d,%s\n" // Sets custom state(1st param: state id, 2nd param: state display name)
#define XORRC_RESPONSECODE_SERVER_ERROR "Server Error {FE58BC7B-ECE9-4d9a-85D0-ED6433ACAF6D},%s\n" // Sets Custom Error(1st param: error string to display)
#define XORRC_RESPONSECODE_WORLD_CENSUS "World Census {8B1B5C78-AB81-4c0f-B0EF-A380269E44C5},%d\n" // Sets World Census(1st param: CCU) -- Recommended one per "cluster"
#define XORRC_RESPONSECODE_ZONE_CENSUS "Zone Census {79CC1671-A46D-478a-9497-4933581B5B03},%d\n" // Sets Zone Census(1st param: CCU) -- Recommended one per zone "channel"
#define XORRC_RESPONSECODE_ADD_COMMAND "Add Command {79CC1671-A46D-478a-9497-4933581B5B03},%s,%s\n" // Adds Dynamic Command(1st param: display name, 2nd param: callback cmd name)
#define XORRC_RESPONSECODE_ADD_INPUT_COMMAND "Add Input Command {79CC1671-A46D-478a-9497-4933581B5B03},%s,%s\n" // Adds Dynamic Command(1st param: display name, 2nd param: callback cmd name)
#define XORRC_RESPONSECODE_REMOVE_COMMAND "Remove Command {79CC1671-A46D-478a-9497-4933581B5B03},%s\n" // Removes Dynamic Command(1st param: display name)
#define XORRC_RESPONSECODE_ENABLE_COMMAND "Enable Command {79CC1671-A46D-478a-9497-4933581B5B03},%s\n" // Enables Dynamic Command(1st param: display name)
#define XORRC_RESPONSECODE_DISABLE_COMMAND "Disable Command {79CC1671-A46D-478a-9497-4933581B5B03},%s\n" // Disables Dynamic Command(1st param: display name)
#define XORRC_RESPONSECODE_WORLD_ID "World ID {8E3FD4DA-BF63-4C6C-AA7D-013218CED9CA},%d\n" // Sets World ID(1st param: world id)
#define XORRC_RESPONSECODE_WAIT_COUNT "WaitCount {7E52C067-80A5-42AA-AA4D-6D25469B3C00},W[%d],L[%d]\n" // For Queues(untested)
#define XORRC_RESPONSECODE_AUX_1 "Aux1 {E9E41FAF-A7D0-4762-8446-C8E85CDC5065}\n" // Sets Aux1 status
#define XORRC_RESPONSECODE_AUX_2 "Aux2 {E4D780A7-873B-4888-8133-023DBCD680B4}\n" // Sets Aux2 status