CloudServerHelper.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifndef __CLOUD_SERVER_HELPER_H
  11. #define __CLOUD_SERVER_HELPER_H
  12. #include "CloudServer.h"
  13. namespace RakNet
  14. {
  15. class DynDNS;
  16. class CloudClient;
  17. class TwoWayAuthentication;
  18. class FullyConnectedMesh2;
  19. class ConnectionGraph2;
  20. class CloudServerHelperFilter : public CloudServerQueryFilter
  21. {
  22. public:
  23. virtual bool OnPostRequest(RakNetGUID clientGuid, SystemAddress clientAddress, CloudKey key, uint32_t dataLength, const char *data);
  24. virtual bool OnReleaseRequest(RakNetGUID clientGuid, SystemAddress clientAddress, DataStructures::List<CloudKey> &cloudKeys);
  25. virtual bool OnGetRequest(RakNetGUID clientGuid, SystemAddress clientAddress, CloudQuery &query, DataStructures::List<RakNetGUID> &specificSystems);
  26. virtual bool OnUnsubscribeRequest(RakNetGUID clientGuid, SystemAddress clientAddress, DataStructures::List<CloudKey> &cloudKeys, DataStructures::List<RakNetGUID> &specificSystems);
  27. RakNetGUID serverGuid;
  28. };
  29. // To use this class without DynDNS, you only need the CloudServer class. and CloudServerHelperFilter
  30. // The only function you need is CloudServerHelper::OnPacket() for CloudServerHelper::OnConnectionCountChange
  31. // For setup, call cloudServer->AddQueryFilter(sampleFilter);
  32. struct CloudServerHelper
  33. {
  34. char *serverToServerPassword;
  35. unsigned short rakPeerPort;
  36. unsigned short allowedIncomingConnections;
  37. unsigned short allowedOutgoingConnections;
  38. virtual void OnPacket(Packet *packet, RakPeerInterface *rakPeer, CloudClient *cloudClient, RakNet::CloudServer *cloudServer, RakNet::FullyConnectedMesh2 *fullyConnectedMesh2, TwoWayAuthentication *twoWayAuthentication, ConnectionGraph2 *connectionGraph2);
  39. virtual bool Update(void);
  40. virtual bool ParseCommandLineParameters(int argc, char **argv);
  41. virtual void PrintHelp(void);
  42. bool StartRakPeer(RakNet::RakPeerInterface *rakPeer);
  43. Packet *ConnectToRakPeer(const char *host, unsigned short port, RakPeerInterface *rakPeer);
  44. MessageID AuthenticateRemoteServerBlocking(RakPeerInterface *rakPeer, TwoWayAuthentication *twoWayAuthentication, RakNetGUID remoteSystem);
  45. void SetupPlugins(
  46. RakNet::CloudServer *cloudServer,
  47. RakNet::CloudServerHelperFilter *sampleFilter,
  48. RakNet::CloudClient *cloudClient,
  49. RakNet::FullyConnectedMesh2 *fullyConnectedMesh2,
  50. RakNet::TwoWayAuthentication *twoWayAuthentication,
  51. RakNet::ConnectionGraph2 *connectionGraph2,
  52. const char *serverToServerPassword
  53. );
  54. int JoinCloud(
  55. RakNet::RakPeerInterface *rakPeer,
  56. RakNet::CloudServer *cloudServer,
  57. RakNet::CloudClient *cloudClient,
  58. RakNet::FullyConnectedMesh2 *fullyConnectedMesh2,
  59. RakNet::TwoWayAuthentication *twoWayAuthentication,
  60. RakNet::ConnectionGraph2 *connectionGraph2,
  61. const char *rakPeerIpOrDomain
  62. );
  63. // Call when the number of client connections change
  64. // Usually internal
  65. virtual void OnConnectionCountChange(RakPeerInterface *rakPeer, CloudClient *cloudClient);
  66. protected:
  67. // Call when you get ID_FCM2_NEW_HOST
  68. virtual void OnFCMNewHost(Packet *packet, RakPeerInterface *rakPeer);
  69. virtual int OnJoinCloudResult(
  70. Packet *packet,
  71. RakNet::RakPeerInterface *rakPeer,
  72. RakNet::CloudServer *cloudServer,
  73. RakNet::CloudClient *cloudClient,
  74. RakNet::FullyConnectedMesh2 *fullyConnectedMesh2,
  75. RakNet::TwoWayAuthentication *twoWayAuthentication,
  76. RakNet::ConnectionGraph2 *connectionGraph2,
  77. const char *rakPeerIpOrDomain,
  78. char myPublicIP[32]
  79. );
  80. };
  81. struct CloudServerHelper_DynDns : public CloudServerHelper
  82. {
  83. public:
  84. CloudServerHelper_DynDns(DynDNS *_dynDns);
  85. // Returns false on DNS update failure
  86. virtual bool Update(void);
  87. virtual bool SetHostDNSToThisSystemBlocking(void);
  88. virtual bool ParseCommandLineParameters(int argc, char **argv);
  89. protected:
  90. DynDNS *dynDNS;
  91. char *dynDNSUsernameAndPassword;
  92. char *dnsHost;
  93. // Call when you get ID_FCM2_NEW_HOST
  94. virtual void OnFCMNewHost(Packet *packet, RakPeerInterface *rakPeer);
  95. virtual int OnJoinCloudResult(
  96. Packet *packet,
  97. RakNet::RakPeerInterface *rakPeer,
  98. RakNet::CloudServer *cloudServer,
  99. RakNet::CloudClient *cloudClient,
  100. RakNet::FullyConnectedMesh2 *fullyConnectedMesh2,
  101. RakNet::TwoWayAuthentication *twoWayAuthentication,
  102. RakNet::ConnectionGraph2 *connectionGraph2,
  103. const char *rakPeerIpOrDomain,
  104. char myPublicIP[32]
  105. );
  106. };
  107. } // namespace RakNet
  108. #endif // __CLOUD_SERVER_HELPER_H
粤ICP备19079148号