serverQuery.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. ping = 0;
  76. cpuSpeed = 0;
  77. isFavorite = false;
  78. status = Status_New;
  79. }
  80. ~ServerInfo();
  81. bool isNew() { return( status == Status_New ); }
  82. bool isQuerying() { return( status.test( Status_Querying ) ); }
  83. bool isUpdating() { return( status.test( Status_Updating ) ); }
  84. bool hasResponded() { return( status.test( Status_Responded ) ); }
  85. bool isTimedOut() { return( status.test( Status_TimedOut ) ); }
  86. bool isDedicated() { return( status.test( Status_Dedicated ) ); }
  87. bool isPassworded() { return( status.test( Status_Passworded ) ); }
  88. bool isLinux() { return( status.test( Status_Linux ) ); }
  89. };
  90. //-----------------------------------------------------------------------------
  91. extern Vector<ServerInfo> gServerList;
  92. extern bool gServerBrowserDirty;
  93. extern void clearServerList();
  94. extern void queryLanServers(U32 port, U8 flags, const char* gameType, const char* missionType,
  95. U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing, U16 minCPU,
  96. U8 filterFlags);
  97. extern void queryMasterGameTypes();
  98. extern void queryMasterServer(U8 flags, const char* gameType, const char* missionType,
  99. U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing, U16 minCPU,
  100. U8 filterFlags, U8 buddyCount, U32* buddyList );
  101. extern void queryFavoriteServers( U8 flags );
  102. extern void querySingleServer(const NetAddress* addr, U8 flags);
  103. extern void startHeartbeat();
  104. extern void sendHeartbeat( U8 flags );
  105. #ifdef TORQUE_DEBUG
  106. extern void addFakeServers( S32 howMany );
  107. #endif // DEBUG
  108. #endif