Esempio n. 1
0
        protected void HandleResponseAppServerRegister(LiteNetLibMessageHandler messageHandler)
        {
            TransportHandler transportHandler        = messageHandler.transportHandler;
            ResponseAppServerRegisterMessage message = messageHandler.ReadMessage <ResponseAppServerRegisterMessage>();

            transportHandler.TriggerAck(message.ackId, message.responseCode, message);
        }
Esempio n. 2
0
        private void HandleResponseAppServerRegister(LiteNetLibMessageHandler messageHandler)
        {
            TransportHandler transportHandler        = messageHandler.transportHandler;
            ResponseAppServerRegisterMessage message = messageHandler.ReadMessage <ResponseAppServerRegisterMessage>();

            transportHandler.ReadResponse(message.ackId, message.responseCode, message);
        }
Esempio n. 3
0
        private void HandleResponseAppServerRegister(LiteNetLibMessageHandler messageHandler)
        {
            TransportHandler peerHandler             = messageHandler.transportHandler;
            ResponseAppServerRegisterMessage message = messageHandler.ReadMessage <ResponseAppServerRegisterMessage>();
            uint ackId = message.ackId;

            peerHandler.TriggerAck(ackId, message.responseCode, message);
        }
Esempio n. 4
0
 public void OnAppServerRegistered(
     ResponseHandlerData responseHandler,
     AckResponseCode responseCode,
     ResponseAppServerRegisterMessage response)
 {
     if (responseCode == AckResponseCode.Success)
     {
         IsRegisteredToCentralServer = true;
     }
     if (onAppServerRegistered != null)
     {
         onAppServerRegistered.Invoke(responseCode);
     }
 }
Esempio n. 5
0
 private void HandleResponseAppServerRegister(
     ResponseHandlerData responseHandler,
     AckResponseCode responseCode,
     ResponseAppServerRegisterMessage response)
 {
     if (responseCode == AckResponseCode.Success)
     {
         Logging.Log(LogTag, "App Registered successfully");
         IsAppRegistered = true;
     }
     if (onResponseAppServerRegister != null)
     {
         onResponseAppServerRegister.Invoke(responseCode);
     }
 }
Esempio n. 6
0
        protected void HandleRequestAppServerRegister(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestAppServerRegisterMessage message = messageHandler.ReadMessage <RequestAppServerRegisterMessage>();

            ResponseAppServerRegisterMessage.Error error = ResponseAppServerRegisterMessage.Error.None;
            if (message.ValidateHash())
            {
                CentralServerPeerInfo peerInfo = message.peerInfo;
                peerInfo.connectionId = connectionId;
                switch (message.peerInfo.peerType)
                {
                case CentralServerPeerType.MapSpawnServer:
                    mapSpawnServerPeers[connectionId] = peerInfo;
                    if (LogInfo)
                    {
                        Debug.Log("[Central] Register Map Spawn Server: [" + connectionId + "]");
                    }
                    break;

                case CentralServerPeerType.MapServer:
                    string sceneName = peerInfo.extra;
                    if (!mapServerPeersBySceneName.ContainsKey(sceneName))
                    {
                        BroadcastAppServers(connectionId, peerInfo);
                        // Collects server data
                        mapServerPeersBySceneName[sceneName] = peerInfo;
                        mapServerPeers[connectionId]         = peerInfo;
                        mapUserIds[connectionId]             = new HashSet <string>();
                        if (LogInfo)
                        {
                            Debug.Log("[Central] Register Map Server: [" + connectionId + "] [" + sceneName + "]");
                        }
                    }
                    else
                    {
                        error = ResponseAppServerRegisterMessage.Error.MapAlreadyExisted;
                        if (LogInfo)
                        {
                            Debug.Log("[Central] Register Map Server Failed: [" + connectionId + "] [" + sceneName + "] [" + error + "]");
                        }
                    }
                    break;

                case CentralServerPeerType.InstanceMapServer:
                    string instanceId = peerInfo.extra;
                    if (!instanceMapServerPeersByInstanceId.ContainsKey(instanceId))
                    {
                        BroadcastAppServers(connectionId, peerInfo);
                        // Collects server data
                        instanceMapServerPeersByInstanceId[instanceId] = peerInfo;
                        instanceMapServerPeers[connectionId]           = peerInfo;
                        mapUserIds[connectionId] = new HashSet <string>();
                        if (LogInfo)
                        {
                            Debug.Log("[Central] Register Instance Map Server: [" + connectionId + "] [" + instanceId + "]");
                        }
                    }
                    else
                    {
                        error = ResponseAppServerRegisterMessage.Error.EventAlreadyExisted;
                        if (LogInfo)
                        {
                            Debug.Log("[Central] Register Instance Map Server Failed: [" + connectionId + "] [" + instanceId + "] [" + error + "]");
                        }
                    }
                    break;

                case CentralServerPeerType.Chat:
                    chatServerPeers[connectionId] = peerInfo;
                    // Send chat peer info to map servers
                    foreach (CentralServerPeerInfo mapServerPeer in mapServerPeers.Values)
                    {
                        ResponseAppServerAddressMessage responseChatAddressMessage = new ResponseAppServerAddressMessage();
                        responseChatAddressMessage.responseCode = AckResponseCode.Success;
                        responseChatAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                        responseChatAddressMessage.peerInfo     = peerInfo;
                        ServerSendPacket(mapServerPeer.connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseChatAddressMessage);
                    }
                    if (LogInfo)
                    {
                        Debug.Log("[Central] Register Chat Server: [" + connectionId + "]");
                    }
                    break;
                }
            }
            else
            {
                error = ResponseAppServerRegisterMessage.Error.InvalidHash;
                if (LogInfo)
                {
                    Debug.Log("[Central] Register Server Failed: [" + connectionId + "] [" + error + "]");
                }
            }

            ResponseAppServerRegisterMessage responseMessage = new ResponseAppServerRegisterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseAppServerRegisterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseAppServerRegister, responseMessage);
        }
        protected void HandleRequestAppServerRegister(LiteNetLibMessageHandler messageHandler)
        {
            var connectionId = messageHandler.connectionId;
            var message      = messageHandler.ReadMessage <RequestAppServerRegisterMessage>();
            var error        = ResponseAppServerRegisterMessage.Error.None;

            if (message.ValidateHash())
            {
                var peerInfo = message.peerInfo;
                peerInfo.connectionId = connectionId;
                switch (message.peerInfo.peerType)
                {
                case CentralServerPeerType.MapSpawnServer:
                    mapSpawnServerPeers[connectionId] = peerInfo;
                    Debug.Log("[Central] Register Map Spawn Server: [" + connectionId + "]");
                    break;

                case CentralServerPeerType.MapServer:
                    var sceneName = peerInfo.extra;
                    if (!mapServerPeersBySceneName.ContainsKey(sceneName))
                    {
                        // Send map peer info to other map server
                        foreach (var mapServerPeer in mapServerPeers.Values)
                        {
                            // Send other info to current peer
                            var responseMapAddressMessage = new ResponseAppServerAddressMessage();
                            responseMapAddressMessage.responseCode = AckResponseCode.Success;
                            responseMapAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                            responseMapAddressMessage.peerInfo     = mapServerPeer;
                            ServerSendPacket(connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseMapAddressMessage);
                            // Send current info to other peer
                            responseMapAddressMessage = new ResponseAppServerAddressMessage();
                            responseMapAddressMessage.responseCode = AckResponseCode.Success;
                            responseMapAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                            responseMapAddressMessage.peerInfo     = peerInfo;
                            ServerSendPacket(mapServerPeer.connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseMapAddressMessage);
                        }
                        // Send chat peer info to new map server
                        if (chatServerPeers.Count > 0)
                        {
                            var chatPeerInfo = chatServerPeers.Values.First();
                            var responseChatAddressMessage = new ResponseAppServerAddressMessage();
                            responseChatAddressMessage.responseCode = AckResponseCode.Success;
                            responseChatAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                            responseChatAddressMessage.peerInfo     = chatPeerInfo;
                            ServerSendPacket(connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseChatAddressMessage);
                        }
                        // Collects server data
                        mapServerPeersBySceneName[sceneName] = peerInfo;
                        mapServerPeers[connectionId]         = peerInfo;
                        mapUserIds[connectionId]             = new HashSet <string>();
                        Debug.Log("[Central] Register Map Server: [" + connectionId + "] [" + sceneName + "]");
                    }
                    else
                    {
                        error = ResponseAppServerRegisterMessage.Error.MapAlreadyExisted;
                        Debug.Log("[Central] Register Map Server Failed: [" + connectionId + "] [" + sceneName + "] [" + error + "]");
                    }
                    break;

                case CentralServerPeerType.Chat:
                    chatServerPeers[connectionId] = peerInfo;
                    // Send chat peer info to map servers
                    foreach (var mapServerPeer in mapServerPeers.Values)
                    {
                        var responseChatAddressMessage = new ResponseAppServerAddressMessage();
                        responseChatAddressMessage.responseCode = AckResponseCode.Success;
                        responseChatAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                        responseChatAddressMessage.peerInfo     = peerInfo;
                        ServerSendPacket(mapServerPeer.connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseChatAddressMessage);
                    }
                    Debug.Log("[Central] Register Chat Server: [" + connectionId + "]");
                    break;
                }
            }
            else
            {
                error = ResponseAppServerRegisterMessage.Error.InvalidHash;
                Debug.Log("[Central] Register Server Failed: [" + connectionId + "] [" + error + "]");
            }

            var responseMessage = new ResponseAppServerRegisterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseAppServerRegisterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            ServerSendPacket(connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerRegister, responseMessage);
        }