Connection.pkg 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /// Send a remote event with the specified node as sender.
  25. void SendRemoteEvent(Node* node, StringHash eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
  26. /// Assign scene. On the server, this will cause the client to load it.
  27. void SetScene(Scene* newScene);
  28. /// Assign identity. Called by Network.
  29. void SetIdentity(const VariantMap& identity);
  30. /// Set new controls.
  31. void SetControls(const Controls& newControls);
  32. /// Set the observer position for interest management.
  33. void SetPosition(const Vector3& position);
  34. /// Set the connection pending status. Called by Network.
  35. void SetConnectPending(bool connectPending);
  36. /// Set whether to log data in/out statistics.
  37. void SetLogStatistics(bool enable);
  38. /// Disconnect. If wait time is non-zero, will block while waiting for disconnect to finish.
  39. void Disconnect(int waitMSec = 0);
  40. /// Send scene update messages. Called by Network.
  41. void SendServerUpdate();
  42. /// Send latest controls from the client. Called by Network.
  43. void SendClientUpdate();
  44. /// Send queued remote events. Called by Network.
  45. void SendRemoteEvents();
  46. /// Send package files to client. Called by network.
  47. void SendPackages();
  48. /// Process pending latest data for nodes and components.
  49. void ProcessPendingLatestData();
  50. /// Process a message from the server or client. Called by Network.
  51. bool ProcessMessage(int msgID, MemoryBuffer& msg);
  52. /// Return client identity.
  53. const VariantMap& GetIdentity() const;
  54. /// Return the scene used by this connection.
  55. Scene* GetScene() const;
  56. /// Return the client controls of this connection.
  57. const Controls& GetControls() const;
  58. /// Return the observer position for interest management.
  59. const Vector3& GetPosition() const;
  60. /// Return whether is a client connection.
  61. bool IsClient() const;
  62. /// Return whether is fully connected.
  63. bool IsConnected() const;
  64. /// Return whether connection is pending.
  65. bool IsConnectPending() const;
  66. /// Return whether the scene is loaded and ready to receive server updates.
  67. bool IsSceneLoaded() const;
  68. /// Return whether to log data in/out statistics.
  69. bool GetLogStatistics() const;
  70. /// Return remote address.
  71. String GetAddress() const;
  72. /// Return remote port.
  73. unsigned short GetPort() const;
  74. /// Return an address:port string.
  75. String ToString() const;
  76. /// Return number of package downloads remaining.
  77. unsigned GetNumDownloads() const;
  78. /// Return name of current package download, or empty if no downloads.
  79. const String& GetDownloadName() const;
  80. /// Return progress of current package download, or 1.0 if no downloads.
  81. float GetDownloadProgress() const;
  82. };