public LiteNetLibMessageHandler(ushort msgType, TransportHandler peerHandler, long connectionId, NetDataReader reader)
 {
     this.msgType          = msgType;
     this.transportHandler = peerHandler;
     this.connectionId     = connectionId;
     this.reader           = reader;
 }
Example #2
0
 public ResponseHandlerData(uint ackId, TransportHandler transportHandler, long connectionId, NetDataReader reader)
 {
     AckId            = ackId;
     TransportHandler = transportHandler;
     ConnectionId     = connectionId;
     Reader           = reader;
 }
 public MessageHandlerData(ushort messageType, TransportHandler transportHandler, long connectionId, NetDataReader reader)
 {
     MessageType      = messageType;
     TransportHandler = transportHandler;
     ConnectionId     = connectionId;
     Reader           = reader;
 }
 public RequestHandlerData(ushort requestType, uint requestId, TransportHandler transportHandler, long connectionId, NetDataReader reader)
 {
     RequestType      = requestType;
     RequestId        = requestId;
     TransportHandler = transportHandler;
     ConnectionId     = connectionId;
     Reader           = reader;
 }
        internal void SendUpdate(bool isInitial)
        {
            if (!CanSync())
            {
                Logging.LogError(LogTag, "Error while set value, behaviour is empty");
                return;
            }
            LiteNetLibGameManager manager = Manager;
            LiteNetLibServer      server  = manager.Server;
            LiteNetLibClient      client  = manager.Client;

            switch (syncMode)
            {
            case SyncMode.ServerToClients:
                TransportHandler.WritePacket(ServerWriter, isInitial ? GameMsgTypes.InitialSyncField : GameMsgTypes.UpdateSyncField);
                SerializeForSend(ServerWriter);
                foreach (long connectionId in manager.GetConnectionIds())
                {
                    if (Identity.HasSubscriberOrIsOwning(connectionId))
                    {
                        server.SendMessage(connectionId, dataChannel, deliveryMethod, ServerWriter);
                    }
                }
                break;

            case SyncMode.ServerToOwnerClient:
                if (manager.ContainsConnectionId(ConnectionId))
                {
                    TransportHandler.WritePacket(ServerWriter, isInitial ? GameMsgTypes.InitialSyncField : GameMsgTypes.UpdateSyncField);
                    SerializeForSend(ServerWriter);
                    server.SendMessage(ConnectionId, dataChannel, deliveryMethod, ServerWriter);
                }
                break;

            case SyncMode.ClientMulticast:
                if (IsOwnerClient)
                {
                    TransportHandler.WritePacket(ClientWriter, isInitial ? GameMsgTypes.InitialSyncField : GameMsgTypes.UpdateSyncField);
                    SerializeForSend(ClientWriter);
                    // Client send data to server, then server send to other clients, it should be reliable-ordered
                    client.SendMessage(clientDataChannel, clientDeliveryMethod, ClientWriter);
                }
                else if (IsServer)
                {
                    TransportHandler.WritePacket(ServerWriter, isInitial ? GameMsgTypes.InitialSyncField : GameMsgTypes.UpdateSyncField);
                    SerializeForSend(ServerWriter);
                    foreach (long connectionId in manager.GetConnectionIds())
                    {
                        if (Identity.HasSubscriberOrIsOwning(connectionId))
                        {
                            server.SendMessage(connectionId, dataChannel, deliveryMethod, ServerWriter);
                        }
                    }
                }
                break;
            }
        }
Example #6
0
 public LiteNetLibRequestCallback(
     uint requestId,
     TransportHandler transportHandler,
     LiteNetLibResponseHandler responseHandler,
     ResponseDelegate <INetSerializable> responseDelegate)
 {
     RequestId        = requestId;
     TransportHandler = transportHandler;
     ResponseHandler  = responseHandler;
     ResponseDelegate = responseDelegate;
 }
Example #7
0
 public LiteNetLibRequestCallback(
     uint ackId,
     long duration,
     TransportHandler transportHandler,
     LiteNetLibResponseHandler responseHandler,
     ResponseDelegate responseDelegate)
 {
     AckId            = ackId;
     RequestTime      = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
     Duration         = duration;
     TransportHandler = transportHandler;
     ResponseHandler  = responseHandler;
     ResponseDelegate = responseDelegate;
 }
        internal void SendUpdate(bool isInitial, long connectionId)
        {
            if (!CanSync() || !IsServer)
            {
                return;
            }
            LiteNetLibGameManager manager = Manager;
            LiteNetLibServer      server  = manager.Server;

            TransportHandler.WritePacket(ServerWriter, isInitial ? GameMsgTypes.InitialSyncField : GameMsgTypes.UpdateSyncField);
            SerializeForSend(ServerWriter);
            if (manager.ContainsConnectionId(connectionId))
            {
                server.SendMessage(connectionId, dataChannel, deliveryMethod, ServerWriter);
            }
        }
        protected void SendCall(byte dataChannel, DeliveryMethod deliveryMethod, FunctionReceivers receivers, long targetConnectionId)
        {
            LiteNetLibGameManager manager = Manager;
            LiteNetLibServer      server  = manager.Server;
            LiteNetLibClient      client  = manager.Client;

            if (manager.IsServer)
            {
                switch (receivers)
                {
                case FunctionReceivers.Target:
                    if (Identity.HasSubscriberOrIsOwning(targetConnectionId) && manager.ContainsConnectionId(targetConnectionId))
                    {
                        // Prepare packet
                        TransportHandler.WritePacket(ServerWriter, GameMsgTypes.CallFunction);
                        SerializeForSend(ServerWriter);
                        // Send function call message from server to target client by target connection Id
                        server.SendMessage(targetConnectionId, dataChannel, deliveryMethod, ServerWriter);
                    }
                    break;

                case FunctionReceivers.All:
                    // Send to all connections
                    foreach (long connectionId in manager.GetConnectionIds())
                    {
                        if (manager.ClientConnectionId == connectionId)
                        {
                            // This is host's networking oject, so hook callback immediately
                            // Don't have to send message to the client, because it is currently run as both server and client
                            HookCallback();
                        }
                        else if (Identity.HasSubscriberOrIsOwning(connectionId))
                        {
                            // Prepare packet
                            TransportHandler.WritePacket(ServerWriter, GameMsgTypes.CallFunction);
                            SerializeForSend(ServerWriter);
                            // Send message to subscribing clients
                            server.SendMessage(connectionId, dataChannel, deliveryMethod, ServerWriter);
                        }
                    }
                    if (!manager.IsClientConnected)
                    {
                        // It's not a host(client+host), it's just a server
                        // So hook callback immediately to do the function at server
                        HookCallback();
                    }
                    break;

                case FunctionReceivers.Server:
                    // Call server function at server
                    // So hook callback immediately to do the function at server
                    HookCallback();
                    break;
                }
            }
            else if (manager.IsClientConnected)
            {
                // Prepare packet
                TransportHandler.WritePacket(ClientWriter, GameMsgTypes.CallFunction);
                SerializeForClientSend(ClientWriter, receivers, targetConnectionId);
                // Client send net function call to server
                // Then the server will hook callback or forward message to other clients
                client.SendMessage(dataChannel, deliveryMethod, ClientWriter);
            }
        }