Connection.pkg 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. $#include "Connection.h"
  2. /// Queued remote event.
  3. struct RemoteEvent
  4. {
  5. /// Remote sender node ID (0 if not a remote node event.)
  6. unsigned senderID_ @ senderID;
  7. /// Event type.
  8. StringHash eventType_ @ eventType;
  9. /// Event data.
  10. VariantMap eventData_ @ eventData;
  11. /// In order flag.
  12. bool inOrder_ @ inOrder;
  13. };
  14. /// %Connection to a remote network host.
  15. class Connection : public Object
  16. {
  17. public:
  18. /// Send a message.
  19. void SendMessage(int msgID, bool reliable, bool inOrder, const VectorBuffer& msg, unsigned contentID = 0);
  20. /// Send a message.
  21. void SendMessage(int msgID, bool reliable, bool inOrder, const unsigned char* data, unsigned numBytes, unsigned contentID = 0);
  22. /// Send a remote event.
  23. // void SendRemoteEvent(StringHash eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
  24. tolua_outside void ConnectionSendRemoteEvent @ SendRemoteEvent(const char* eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
  25. /// Send a remote event with the specified node as sender.
  26. void SendRemoteEvent(Node* node, StringHash eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
  27. tolua_outside void ConnectSendRemoteEvent @ SendRemoteEvent(Node* node, const char* eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
  28. /// Assign scene. On the server, this will cause the client to load it.
  29. void SetScene(Scene* newScene);
  30. /// Assign identity. Called by Network.
  31. void SetIdentity(const VariantMap& identity);
  32. /// Set new controls.
  33. void SetControls(const Controls& newControls);
  34. /// Set the observer position for interest management.
  35. void SetPosition(const Vector3& position);
  36. /// Set the connection pending status. Called by Network.
  37. void SetConnectPending(bool connectPending);
  38. /// Set whether to log data in/out statistics.
  39. void SetLogStatistics(bool enable);
  40. /// Disconnect. If wait time is non-zero, will block while waiting for disconnect to finish.
  41. void Disconnect(int waitMSec = 0);
  42. /// Send scene update messages. Called by Network.
  43. void SendServerUpdate();
  44. /// Send latest controls from the client. Called by Network.
  45. void SendClientUpdate();
  46. /// Send queued remote events. Called by Network.
  47. void SendRemoteEvents();
  48. /// Send package files to client. Called by network.
  49. void SendPackages();
  50. /// Process pending latest data for nodes and components.
  51. void ProcessPendingLatestData();
  52. /// Process a message from the server or client. Called by Network.
  53. bool ProcessMessage(int msgID, MemoryBuffer& msg);
  54. /// Return client identity.
  55. const VariantMap& GetIdentity() const { return identity_; }
  56. /// Return the scene used by this connection.
  57. Scene* GetScene() const;
  58. /// Return the client controls of this connection.
  59. const Controls& GetControls() const { return controls_; }
  60. /// Return the observer position for interest management.
  61. const Vector3& GetPosition() const { return position_; }
  62. /// Return whether is a client connection.
  63. bool IsClient() const { return isClient_; }
  64. /// Return whether is fully connected.
  65. bool IsConnected() const;
  66. /// Return whether connection is pending.
  67. bool IsConnectPending() const { return connectPending_; }
  68. /// Return whether the scene is loaded and ready to receive server updates.
  69. bool IsSceneLoaded() const { return sceneLoaded_; }
  70. /// Return whether to log data in/out statistics.
  71. bool GetLogStatistics() const { return logStatistics_; }
  72. /// Return remote address.
  73. String GetAddress() const;
  74. /// Return remote port.
  75. unsigned short GetPort() const;
  76. /// Return an address:port string.
  77. String ToString() const;
  78. /// Return number of package downloads remaining.
  79. unsigned GetNumDownloads() const;
  80. /// Return name of current package download, or empty if no downloads.
  81. const String& GetDownloadName() const;
  82. /// Return progress of current package download, or 1.0 if no downloads.
  83. float GetDownloadProgress() const;
  84. };
  85. ${
  86. static void ConnectionSendRemoteEvent(Connection* connection, const char* eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap)
  87. {
  88. connection->SendRemoteEvent(StringHash(eventType), inOrder, eventData);
  89. }
  90. static void ConnectSendRemoteEvent(Connection* connection, Node* node, const char* eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap)
  91. {
  92. connection->SendRemoteEvent(node, StringHash(eventType), inOrder, eventData);
  93. }
  94. $}