serverQuery.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 "core/bitSet.h"
  32. #endif
  33. #include "platform/platformNet.h"
  34. //-----------------------------------------------------------------------------
  35. // Game Server Information
  36. struct ServerInfo
  37. {
  38. enum StatusFlags
  39. {
  40. // Info flags (0-7):
  41. Status_Dedicated = BIT(0),
  42. Status_Passworded = BIT(1),
  43. Status_Linux = BIT(2),
  44. Status_Xenon = BIT(6),
  45. // Status flags:
  46. Status_New = 0,
  47. Status_Querying = BIT(28),
  48. Status_Updating = BIT(29),
  49. Status_Responded = BIT(30),
  50. Status_TimedOut = BIT(31),
  51. };
  52. U8 numPlayers;
  53. U8 maxPlayers;
  54. U8 numBots;
  55. char* name;
  56. char* gameType;
  57. char* missionName;
  58. char* missionType;
  59. char* statusString;
  60. char* infoString;
  61. NetAddress address;
  62. U32 version;
  63. U32 ping;
  64. U32 cpuSpeed;
  65. bool isFavorite;
  66. BitSet32 status;
  67. ServerInfo()
  68. {
  69. numPlayers = 0;
  70. maxPlayers = 0;
  71. numBots = 0;
  72. name = NULL;
  73. gameType = NULL;
  74. missionType = NULL;
  75. missionName = NULL;
  76. statusString = NULL;
  77. infoString = NULL;
  78. version = 0;
  79. ping = 0;
  80. cpuSpeed = 0;
  81. isFavorite = false;
  82. status = Status_New;
  83. }
  84. ~ServerInfo();
  85. bool isNew() { return( status == Status_New ); }
  86. bool isQuerying() { return( status.test( Status_Querying ) ); }
  87. bool isUpdating() { return( status.test( Status_Updating ) ); }
  88. bool hasResponded() { return( status.test( Status_Responded ) ); }
  89. bool isTimedOut() { return( status.test( Status_TimedOut ) ); }
  90. bool isDedicated() { return( status.test( Status_Dedicated ) ); }
  91. bool isPassworded() { return( status.test( Status_Passworded ) ); }
  92. bool isLinux() { return( status.test( Status_Linux ) ); }
  93. bool isXenon() { return( status.test( Status_Xenon ) ); }
  94. };
  95. //-----------------------------------------------------------------------------
  96. extern Vector<ServerInfo> gServerList;
  97. extern bool gServerBrowserDirty;
  98. extern void clearServerList();
  99. extern void queryLanServers(U32 port, U8 flags, const char* gameType, const char* missionType,
  100. U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing, U16 minCPU,
  101. U8 filterFlags);
  102. extern void queryMasterGameTypes();
  103. extern void queryMasterServer(U8 flags, const char* gameType, const char* missionType,
  104. U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing, U16 minCPU,
  105. U8 filterFlags, U8 buddyCount, U32* buddyList );
  106. extern void queryFavoriteServers( U8 flags );
  107. extern void querySingleServer(const NetAddress* addr, U8 flags);
  108. extern void startHeartbeat();
  109. extern void sendHeartbeat( U8 flags );
  110. #ifdef TORQUE_DEBUG
  111. extern void addFakeServers( S32 howMany );
  112. #endif // DEBUG
  113. #endif