serverQuery.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SERVERQUERY_H_
  23. #define _SERVERQUERY_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef _EVENT_H_
  28. #include "platform/event.h"
  29. #endif
  30. #ifndef _BITSET_H_
  31. #include "collection/bitSet.h"
  32. #endif
  33. #include "network/netConnection.h"
  34. #include "network/netInterface.h"
  35. //-----------------------------------------------------------------------------
  36. // Master server information
  37. class DemoNetInterface : public NetInterface
  38. {
  39. public:
  40. void handleInfoPacket(const NetAddress *address, U8 packetType, BitStream *stream);
  41. };
  42. struct MasterInfo
  43. {
  44. NetAddress address;
  45. U32 region;
  46. };
  47. //-----------------------------------------------------------------------------
  48. // Game Server Information
  49. struct ServerInfo
  50. {
  51. enum StatusFlags
  52. {
  53. // Info flags (0-7):
  54. Status_Dedicated = BIT(0),
  55. Status_Passworded = BIT(1),
  56. Status_Linux = BIT(2),
  57. // Status flags:
  58. Status_New = 0,
  59. Status_Querying = BIT(28),
  60. Status_Updating = BIT(29),
  61. Status_Responded = BIT(30),
  62. Status_TimedOut = BIT(31),
  63. };
  64. U8 numPlayers;
  65. U8 maxPlayers;
  66. U8 numBots;
  67. char* name;
  68. char* gameType;
  69. char* missionName;
  70. char* missionType;
  71. char* statusString;
  72. char* infoString;
  73. NetAddress address;
  74. U32 version;
  75. U32 ping;
  76. U32 cpuSpeed;
  77. bool isFavorite;
  78. BitSet32 status;
  79. ServerInfo()
  80. {
  81. numPlayers = 0;
  82. maxPlayers = 0;
  83. numBots = 0;
  84. name = NULL;
  85. gameType = NULL;
  86. missionType = NULL;
  87. missionName = NULL;
  88. statusString = NULL;
  89. infoString = NULL;
  90. version = 0;
  91. ping = 0;
  92. cpuSpeed = 0;
  93. isFavorite = false;
  94. status = Status_New;
  95. }
  96. ~ServerInfo();
  97. bool isNew() { return( status == Status_New ); }
  98. bool isQuerying() { return( status.test( Status_Querying ) ); }
  99. bool isUpdating() { return( status.test( Status_Updating ) ); }
  100. bool hasResponded() { return( status.test( Status_Responded ) ); }
  101. bool isTimedOut() { return( status.test( Status_TimedOut ) ); }
  102. bool isDedicated() { return( status.test( Status_Dedicated ) ); }
  103. bool isPassworded() { return( status.test( Status_Passworded ) ); }
  104. bool isLinux() { return( status.test( Status_Linux ) ); }
  105. };
  106. //-----------------------------------------------------------------------------
  107. extern Vector<ServerInfo> gServerList;
  108. extern bool gServerBrowserDirty;
  109. extern void clearServerList();
  110. extern void queryLanServers(U32 port, U8 flags, const char* gameType, const char* missionType,
  111. U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing, U16 minCPU,
  112. U8 filterFlags);
  113. extern void queryMasterGameTypes();
  114. extern void queryMasterServer(U8 flags, const char* gameType, const char* missionType,
  115. U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing, U16 minCPU,
  116. U8 filterFlags, U8 buddyCount, U32* buddyList );
  117. extern void queryFavoriteServers( U8 flags );
  118. extern void querySingleServer(const NetAddress* addr, U8 flags);
  119. extern void cancelServerQuery();
  120. extern void stopServerQuery();
  121. extern void startHeartbeat();
  122. extern void stopHeartBeat();
  123. extern void sendHeartbeat( U8 flags );
  124. #ifdef TORQUE_DEBUG
  125. extern void addFakeServers( S32 howMany );
  126. #endif // DEBUG
  127. #endif