Network.pkg 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. $#include "Network.h"
  2. /// %Network subsystem. Manages client-server communications using the UDP protocol.
  3. class Network
  4. {
  5. public:
  6. /// Connect to a server using UDP protocol. Return true if connection process successfully started.
  7. bool Connect(const String& address, unsigned short port, Scene* scene, const VariantMap& identity = Variant::emptyVariantMap);
  8. /// Disconnect the connection to the server. If wait time is non-zero, will block while waiting for disconnect to finish.
  9. void Disconnect(int waitMSec = 0);
  10. /// Start a server on a port using UDP protocol. Return true if successful.
  11. bool StartServer(unsigned short port);
  12. /// Stop the server.
  13. void StopServer();
  14. /// Broadcast a message with content ID to all client connections.
  15. void BroadcastMessage(int msgID, bool reliable, bool inOrder, const VectorBuffer& msg, unsigned contentID = 0);
  16. /// Broadcast a message with content ID to all client connections.
  17. void BroadcastMessage(int msgID, bool reliable, bool inOrder, const unsigned char* data, unsigned numBytes, unsigned contentID = 0);
  18. /// Broadcast a remote event to all client connections.
  19. void BroadcastRemoteEvent(StringHash eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
  20. /// Broadcast a remote event to all client connections in a specific scene.
  21. void BroadcastRemoteEvent(Scene* scene, StringHash eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
  22. /// Broadcast a remote event with the specified node as a sender. Is sent to all client connections in the node's scene.
  23. void BroadcastRemoteEvent(Node* node, StringHash eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
  24. /// Set network update FPS.
  25. void SetUpdateFps(int fps);
  26. /// Register a remote event as allowed to be sent and received. If no events are registered, all are allowed.
  27. void RegisterRemoteEvent(StringHash eventType);
  28. /// Unregister a remote event as allowed to be sent and received.
  29. void UnregisterRemoteEvent(StringHash eventType);
  30. /// Unregister all remote events. This results in all being allowed.
  31. void UnregisterAllRemoteEvents();
  32. /// Set the package download cache directory.
  33. void SetPackageCacheDir(const String& path);
  34. /// Return network update FPS.
  35. int GetUpdateFps() const;
  36. /// Return the connection to the server. Null if not connected.
  37. Connection* GetServerConnection() const;
  38. /// Return whether the server is running.
  39. bool IsServerRunning() const;
  40. /// Return whether a remote event is allowed to be sent and received. If no events are registered, all are allowed.
  41. bool CheckRemoteEvent(StringHash eventType) const;
  42. /// Return the package download cache directory.
  43. const String& GetPackageCacheDir() const;
  44. };
  45. Network* GetNetwork();