| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- $#include "Network.h"
- /// %Network subsystem. Manages client-server communications using the UDP protocol.
- class Network
- {
- public:
- /// Connect to a server using UDP protocol. Return true if connection process successfully started.
- bool Connect(const String& address, unsigned short port, Scene* scene);
- bool Connect(const String& address, unsigned short port, Scene* scene, const VariantMap& identity = Variant::emptyVariantMap);
- /// Disconnect the connection to the server. If wait time is non-zero, will block while waiting for disconnect to finish.
- void Disconnect(int waitMSec = 0);
- /// Start a server on a port using UDP protocol. Return true if successful.
- bool StartServer(unsigned short port);
- /// Stop the server.
- void StopServer();
- /// Broadcast a message with content ID to all client connections.
- void BroadcastMessage(int msgID, bool reliable, bool inOrder, const VectorBuffer& msg, unsigned contentID = 0);
- /// Broadcast a message with content ID to all client connections.
- void BroadcastMessage(int msgID, bool reliable, bool inOrder, const unsigned char* data, unsigned numBytes, unsigned contentID = 0);
- /// Broadcast a remote event to all client connections.
- void BroadcastRemoteEvent(StringHash eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
- /// Broadcast a remote event to all client connections in a specific scene.
- void BroadcastRemoteEvent(Scene* scene, StringHash eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
- /// Broadcast a remote event with the specified node as a sender. Is sent to all client connections in the node's scene.
- void BroadcastRemoteEvent(Node* node, StringHash eventType, bool inOrder, const VariantMap& eventData = Variant::emptyVariantMap);
- /// Set network update FPS.
- void SetUpdateFps(int fps);
- /// Register a remote event as allowed to be sent and received. If no events are registered, all are allowed.
- // void RegisterRemoteEvent(StringHash eventType);
- tolua_outside void NetworkRegisterRemoteEvent @ RegisterRemoteEvent(const char* eventType);
- /// Unregister a remote event as allowed to be sent and received.
- // void UnregisterRemoteEvent(StringHash eventType);
- tolua_outside void NetworkUnregisterRemoteEvent @ UnregisterRemoteEvent(const char* eventType);
- /// Unregister all remote events. This results in all being allowed.
- void UnregisterAllRemoteEvents();
- /// Set the package download cache directory.
- void SetPackageCacheDir(const String& path);
-
- /// Return network update FPS.
- int GetUpdateFps() const { return updateFps_; }
- /// Return the connection to the server. Null if not connected.
- Connection* GetServerConnection() const;
- /// Return whether the server is running.
- bool IsServerRunning() const;
- /// Return whether a remote event is allowed to be sent and received. If no events are registered, all are allowed.
- bool CheckRemoteEvent(StringHash eventType) const;
- /// Return the package download cache directory.
- const String& GetPackageCacheDir() const { return packageCacheDir_; }
- };
- ${
- static void NetworkRegisterRemoteEvent(Network* network, const char* eventType)
- {
- network->RegisterRemoteEvent(StringHash(eventType));
- }
- static void NetworkUnregisterRemoteEvent(Network* network, const char* eventType)
- {
- network->UnregisterRemoteEvent(StringHash(eventType));
- }
- $}
|