serverQuery.h 4.2 KB

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