server_interface.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // This file defines the server interface.
  2. #ifndef __SERVER_INTERFACE_H__
  3. #define __SERVER_INTERFACE_H__
  4. #include "ltbasedefs.h"
  5. #define SI_VERSION 2
  6. // Update flags for the server.
  7. // Non-active (ie: the server should just eat up time but not update anything).
  8. #define UPDATEFLAG_NONACTIVE 1
  9. // Create status.
  10. #define SI_CREATESTATUS int
  11. #define SI_OK 0 // Create a server successfully.
  12. #define SI_ALREADYINSTANCED 1 // A server has already been instanced.
  13. #define SI_INVALIDVERSION 2 // Different server version.
  14. #define SI_ERRORINITTING 3 // Error initializing.
  15. #define SI_CANTLOADRESOURCEMODULE 4 // Couldn't load de_msg.dll.
  16. // Client info structure.
  17. #define MAX_CLIENTINFO_NAME 64
  18. struct ClientInfo
  19. {
  20. char m_sName[MAX_CLIENTINFO_NAME];
  21. uint32 m_ClientID;
  22. float m_Ping;
  23. };
  24. // You should derive from this class and pass a pointer to it to
  25. // ServerInterface::SetHandler so it can talk back to you.
  26. class ServerAppHandler
  27. {
  28. public:
  29. // This message comes from ServerDE::SendToServerApp. Format stuff
  30. // going back and forth into strings to reduce incompatibilities.
  31. virtual LTRESULT ShellMessageFn(char *pInfo, uint32 nLen) {return LT_OK;}
  32. // All console output goes into here.
  33. virtual LTRESULT ConsoleOutputFn(char *pszMsg) {return LT_OK;}
  34. // Called when the server has run out of memory. A message should
  35. // be displayed and exit() should be called immediately.. if you don't,
  36. // LT exits() right after calling OutOfMemory().
  37. virtual LTRESULT OutOfMemory() {return LT_OK;}
  38. // The engine calls this for packets it doesn't understand (used for Gamespy).
  39. virtual LTRESULT ProcessPacket(char *pData, uint32 dataLen, uint8 senderAddr[4], uint16 senderPort) {return LT_OK;}
  40. };
  41. class ServerInterface
  42. {
  43. public:
  44. // Set this on startup.. this is how the engine and game talk to you.
  45. virtual LTRESULT SetAppHandler(ServerAppHandler *pHandler)=0;
  46. // Run a string in the console.
  47. virtual LTRESULT RunConsoleString(char *pStr)=0;
  48. // Get access to console variables. hVar is filled in. If a variable with the given
  49. // name doesn't exist and pDefaultVal is set, it'll set the value to pDefaultVal
  50. // and return LT_FINISHED. If it already existed, it returns LT_OK.
  51. virtual LTRESULT GetConsoleVar(char *pName, HCONSOLEVAR *hVar, char *pDefaultVal)=0;
  52. virtual LTRESULT GetVarValueFloat(HCONSOLEVAR hVar, float *val)=0;
  53. virtual LTRESULT GetVarValueString(HCONSOLEVAR hVar, char *pStr, uint32 maxLen)=0;
  54. // Load/save config files into the server's console state.
  55. virtual LTRESULT LoadConfigFile(char *pFilename)=0;
  56. virtual LTRESULT SaveConfigFile(char *pFilename)=0;
  57. // Calls ServerShellDE::ServerAppMessageFn (the equivalent of the game
  58. // calling ServerDE::SendToServerApp but in the opposite direction).
  59. // Returns LT_NOTFOUND if the server shell hasn't been created (it gets
  60. // created in AddResources).
  61. virtual LTRESULT SendToServerShell(char *pInfo, int nLen)=0;
  62. // Add resources for the server to use.
  63. virtual LTBOOL AddResources(char **pResources, uint32 nResources)=0;
  64. // Load the object.lto file.
  65. virtual LTBOOL LoadBinaries( )=0;
  66. // Look thru the available worlds.
  67. virtual FileEntry* GetFileList(char *pDirName)=0;
  68. virtual void FreeFileList(FileEntry *pList)=0;
  69. // Open a file up. Pass in the relative filename.
  70. // Free the file by calling DStream::Release().
  71. virtual LTRESULT OpenFile(char *pFilename, ILTStream **pStream) = 0;
  72. // Copies a file. This function is useful for copying files out of the
  73. // rez file to a temporary file, so you can do special operations on it like
  74. // LoadLibrary.
  75. virtual LTRESULT CopyFile( const char *pszSourceFile, const char *pszDestFile ) = 0;
  76. // Sets game info. Call this before LoadBinaries.
  77. virtual LTBOOL SetGameInfo( void *pGameInfo, uint32 nGameInfoLen ) = 0;
  78. // Look at the clients.
  79. virtual int GetNumClients()=0;
  80. virtual LTBOOL GetClientName(int index, char *pName, int maxChars)=0;
  81. virtual LTBOOL GetClientInfo(int index, ClientInfo* pInfo)=0;
  82. virtual LTBOOL BootClient(uint32 dwClientID)=0;
  83. virtual LTRESULT GetClientPing( uint32 nClientId, float &ping )=0;
  84. // When an error occurs, you can get the error code and error string.
  85. virtual int GetErrorCode()=0;
  86. virtual void GetErrorString(char *pString, int maxLen)=0;
  87. // Update as often as possible.
  88. virtual LTBOOL Update(long flags)=0;
  89. // Call this function, with the app's LTGUID, before calling any other
  90. // network functions. pDriver can be LTNULL to use the default net driver.
  91. // No flags are currently supported.
  92. virtual LTBOOL InitNetworking(char *pDriver, uint32 dwFlags)=0;
  93. // Gets a list (and count) of enumerated services.
  94. virtual LTBOOL GetServiceList(NetService *&pListHead)=0;
  95. // Call this function when you are finished using the list returned by
  96. // GetServiceList().
  97. virtual LTBOOL FreeServiceList(NetService *pListHead)=0;
  98. // Selects the given service as the one to use.
  99. virtual LTBOOL SelectService(HNETSERVICE hNetService)=0;
  100. // Updates the sessions's name (only the host can do this).
  101. virtual LTBOOL UpdateSessionName(const char* sName)=0;
  102. // Hosts the game session.
  103. virtual LTBOOL HostGame( NetHost &hostInfo )=0;
  104. // Gets the tcp/ip address of the main driver if available.
  105. virtual LTBOOL GetTcpIpAddress(char* sAddress, uint32 dwBufferSize, unsigned short &hostPort)=0;
  106. // Send a packet thru tcp/ip if we're using tcp/ip.
  107. virtual LTRESULT SendTo(const void *pData, uint32 len, const char *sAddr, uint32 port)=0;
  108. };
  109. #ifdef __cplusplus
  110. extern "C"
  111. {
  112. #endif
  113. #ifdef __SERVERAPI_EXPORT__
  114. #define SERVERAPI __declspec( dllexport )
  115. #else
  116. #define SERVERAPI __declspec( dllimport )
  117. #endif
  118. // The server DLL implements these functions to create and delete a
  119. // server. You can only have one server at a time. Pass in SI_VERSION to CreateServer.
  120. SERVERAPI SI_CREATESTATUS CreateServer(int version, LTGUID &appGuid, ServerInterface **ppServer);
  121. SERVERAPI void DeleteServer();
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif // __SERVER_INTERFACE_H__