Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef SERVER_CLASS_H
  9. #define SERVER_CLASS_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "tier0/dbg.h"
  14. #include "dt_send.h"
  15. #include "networkstringtabledefs.h"
  16. class ServerClass;
  17. class SendTable;
  18. extern ServerClass *g_pServerClassHead;
  19. class ServerClass
  20. {
  21. public:
  22. ServerClass( char *pNetworkName, SendTable *pTable )
  23. {
  24. m_pNetworkName = pNetworkName;
  25. m_pTable = pTable;
  26. m_InstanceBaselineIndex = INVALID_STRING_INDEX;
  27. // g_pServerClassHead is sorted alphabetically, so find the correct place to insert
  28. if ( !g_pServerClassHead )
  29. {
  30. g_pServerClassHead = this;
  31. m_pNext = NULL;
  32. }
  33. else
  34. {
  35. ServerClass *p1 = g_pServerClassHead;
  36. ServerClass *p2 = p1->m_pNext;
  37. // Comment from Alfred on 7/2/2004 6:43:24 PM in CL 91253, //ValveGames/main/src/public/server_class.h#18:
  38. // ---> use _stricmp because Q_stricmp isn't hooked up properly yet
  39. // [Sergiy, 10/19/2009] hooking up V_stricmp
  40. if ( V_stricmp( p1->GetName(), pNetworkName ) > 0)
  41. {
  42. m_pNext = g_pServerClassHead;
  43. g_pServerClassHead = this;
  44. p1 = NULL;
  45. }
  46. while( p1 )
  47. {
  48. if ( p2 == NULL || V_stricmp( p2->GetName(), pNetworkName ) > 0)
  49. {
  50. m_pNext = p2;
  51. p1->m_pNext = this;
  52. break;
  53. }
  54. p1 = p2;
  55. p2 = p2->m_pNext;
  56. }
  57. }
  58. }
  59. const char* GetName() { return m_pNetworkName; }
  60. public:
  61. char *m_pNetworkName;
  62. SendTable *m_pTable;
  63. ServerClass *m_pNext;
  64. int m_ClassID; // Managed by the engine.
  65. // This is an index into the network string table (sv.GetInstanceBaselineTable()).
  66. int m_InstanceBaselineIndex; // INVALID_STRING_INDEX if not initialized yet.
  67. };
  68. class CBaseNetworkable;
  69. // If you do a DECLARE_SERVERCLASS, you need to do this inside the class definition.
  70. #define DECLARE_SERVERCLASS() \
  71. public: \
  72. virtual ServerClass* GetServerClass(); \
  73. static SendTable *m_pClassSendTable; \
  74. template <typename T> friend int ServerClassInit(T *); \
  75. virtual int YouForgotToImplementOrDeclareServerClass(); \
  76. #define DECLARE_SERVERCLASS_NOBASE() \
  77. public: \
  78. template <typename T> friend int ServerClassInit(T *); \
  79. // Use this macro to expose your class's data across the network.
  80. #define IMPLEMENT_SERVERCLASS( DLLClassName, sendTable ) \
  81. IMPLEMENT_SERVERCLASS_INTERNAL( DLLClassName, sendTable )
  82. // You can use this instead of BEGIN_SEND_TABLE and it will do a DECLARE_SERVERCLASS automatically.
  83. #define IMPLEMENT_SERVERCLASS_ST(DLLClassName, sendTable) \
  84. IMPLEMENT_SERVERCLASS_INTERNAL( DLLClassName, sendTable )\
  85. BEGIN_SEND_TABLE(DLLClassName, sendTable)
  86. #define IMPLEMENT_SERVERCLASS_ST_NOBASE(DLLClassName, sendTable) \
  87. IMPLEMENT_SERVERCLASS_INTERNAL( DLLClassName, sendTable )\
  88. BEGIN_SEND_TABLE_NOBASE( DLLClassName, sendTable )
  89. #ifdef VALIDATE_DECLARE_CLASS
  90. #define CHECK_DECLARE_CLASS( DLLClassName, sendTable ) \
  91. template <typename T> int CheckDeclareClass_Access(T *); \
  92. template <> int CheckDeclareClass_Access<sendTable::ignored>(sendTable::ignored *, const char *pIgnored) \
  93. { \
  94. return DLLClassName::CheckDeclareClass( #DLLClassName ); \
  95. } \
  96. namespace sendTable \
  97. { \
  98. int verifyDeclareClass = CheckDeclareClass_Access( (sendTable::ignored*)0 ); \
  99. }
  100. #else
  101. #define CHECK_DECLARE_CLASS( DLLClassName, sendTable )
  102. #endif
  103. #define IMPLEMENT_SERVERCLASS_INTERNAL( DLLClassName, sendTable ) \
  104. namespace sendTable \
  105. { \
  106. struct ignored; \
  107. extern SendTable g_SendTable; \
  108. } \
  109. CHECK_DECLARE_CLASS( DLLClassName, sendTable ) \
  110. static ServerClass g_##DLLClassName##_ClassReg(\
  111. #DLLClassName, \
  112. &sendTable::g_SendTable\
  113. ); \
  114. \
  115. ServerClass* DLLClassName::GetServerClass() {return &g_##DLLClassName##_ClassReg;} \
  116. SendTable *DLLClassName::m_pClassSendTable = &sendTable::g_SendTable;\
  117. int DLLClassName::YouForgotToImplementOrDeclareServerClass() {return 0;}
  118. #endif