MasterClient.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. // TOPOLOGY
  11. // Connect to master server
  12. // Stay connected
  13. // When an information query comes in, parse it and write out to a bitstream.
  14. // When all bitstreams are written, send that back to the master server.
  15. #ifndef __MASTER_CLIENT_H
  16. #define __MASTER_CLIENT_H
  17. #include "MasterCommon.h"
  18. #include "BitStream.h"
  19. /// \ingroup MasterServer
  20. /// \brief implements the master client
  21. class MasterClient : public MasterCommon
  22. {
  23. public:
  24. MasterClient();
  25. ~MasterClient();
  26. // ---------------------------------------------------
  27. // NETWORKING FUNCTIONS
  28. // ---------------------------------------------------
  29. // We must be connected to call any of the following functions.
  30. // Host is the master server IP
  31. // masterServerPort is the master server port
  32. // masterClientPort is the port the master client should use (must be different than gamePort)
  33. // gamePort is the port your game server or game client is using.
  34. bool Connect(char* host, int masterServerPort);
  35. // Disconnect and terminate. Game servers should stay connected to use NAT punch-through. Game clients,
  36. // or game servers that do not need NAT punch-through can disconnect.
  37. void Disconnect(void);
  38. // Returns true if connected
  39. bool IsConnected(void);
  40. // This will tell the master server that we are trying to connect to the indicated game server.
  41. // The indicated server will then also try to connect to us, bypassing most NATs
  42. // and increasing the chance of a successful connection. You should try connecting to the game server
  43. // at the same time you call this function.
  44. void ConnectionAttemptNotification(char *serverIP, unsigned short serverPort);
  45. // ---------------------------------------------------
  46. // SERVER LISTING FUNCTIONS
  47. // ---------------------------------------------------
  48. // List the server.
  49. void ListServer(void);
  50. // Remove our server listing from the master server
  51. void DelistServer(void);
  52. // Add a rule about our server. Can be done before or after listing
  53. void PostRule(char *ruleIdentifier, char *stringData, int intData);
  54. // Remove a rule about our server
  55. void RemoveRule(char *ruleIdentifier);
  56. // ---------------------------------------------------
  57. // SERVER QUERY FUNCTIONS
  58. // ---------------------------------------------------
  59. // Adds a rule to look for when we query. This will update existing servers that contain these rules.
  60. // Do not query for "Ping", "IP", or "Port" as these are automatically returned.
  61. void AddQueryRule(char *ruleIdentifier);
  62. // Clears all rules from our query list. This will return all servers.
  63. void ClearQueryRules(void);
  64. // Query the master server with our rule set. To get all servers, call ClearQueryRules() after
  65. // any prior calls to add AddQueryRule to clear the rule set.
  66. void QueryMasterServer(void);
  67. // Pings all servers on our list.
  68. void PingServers(void);
  69. // ---------------------------------------------------
  70. // SEE MasterCommon.h FOR BROWSER FUNCTIONS
  71. // ---------------------------------------------------
  72. // ---------------------------------------------------
  73. // OVERRIDABLE EVENTS
  74. // ---------------------------------------------------
  75. // Event if we lose the connection to the master server
  76. void OnLostConnection(void);
  77. // Couldn't connect
  78. void OnConnectionAttemptFailed(void);
  79. // Event if the master server is full when we try to connect
  80. void OnMasterServerFull(void);
  81. // Event if a packet was tampered with mid-steram
  82. void OnModifiedPacket(void);
  83. // Event if a server was added to the list
  84. void OnGameServerListAddition(GameServer *newServer);
  85. // Event if a server has its rules updated (only happens if querying with a rule set)
  86. void OnGameServerListRuleUpdate(GameServer *updatedServer);
  87. // Event when we complete a query
  88. void OnGameServerListQueryComplete(void);
  89. // Event when a game client wants to connect to our server
  90. // You should call AdvertiseSystem to the passed IP and port from your game instance
  91. void OnConnectionRequest(const char *clientIP, unsigned short clientPort);
  92. protected:
  93. void Update(RakPeerInterface *peer);
  94. bool OnReceive(RakPeerInterface *peer, Packet *packet);
  95. void HandleServerListResponse(Packet *packet, bool overwriteExisting);
  96. void HandleRelayedConnectionNotification(Packet *packet);
  97. bool listServer, serverListed, localServerModified;
  98. GameServer localServer;
  99. BitStream ruleIdentifierList;
  100. };
  101. #endif
粤ICP备19079148号