private void ReponseMapSpawn(uint ackId, ResponseSpawnMapMessage.Error error)
        {
            ResponseSpawnMapMessage responseMessage = new ResponseSpawnMapMessage();

            responseMessage.ackId        = ackId;
            responseMessage.responseCode = error == ResponseSpawnMapMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            CentralAppServerRegister.ClientSendPacket(DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseSpawnMap, responseMessage.Serialize);
        }
Пример #2
0
 public override void OnStopServer()
 {
     if (!IsServer)
     {
         Clean();
     }
     CentralAppServerRegister.OnStopServer();
     base.OnStopServer();
 }
Пример #3
0
 public override void OnStopServer()
 {
     base.OnStopServer();
     CentralAppServerRegister.OnStopServer();
     if (ChatNetworkManager.IsClientConnected)
     {
         ChatNetworkManager.StopClient();
     }
 }
Пример #4
0
        private void CustomFromClientToCentralServer_RegisterServerMessages()
        {
            // In map-server there is client which connect to central-server, the field is `CentralAppServerRegister`
            // So developer may register `CentralAppServerRegister` messages here
            CentralAppServerRegister.RegisterMessage(10001, SampleHandleMsgFromCentralServer);

            // Server will receive this message from clients, then send it to central server by `CentralAppServerRegister`
            RegisterServerMessage(10001, SampleHandleMsgFromClient);
        }
        protected override void Awake()
        {
            if (useWebSocket)
            {
                if (centralTransportFactory == null || !centralTransportFactory.CanUseWithWebGL)
                {
                    centralTransportFactory = gameObject.AddComponent <WebSocketTransportFactory>();
                }
            }
            else
            {
                if (centralTransportFactory == null)
                {
                    centralTransportFactory = gameObject.AddComponent <LiteNetLibTransportFactory>();
                }
            }
#if UNITY_STANDALONE && !CLIENT_BUILD
            CentralAppServerRegister = new CentralAppServerRegister(CentralTransportFactory.Build(), this);
            CentralAppServerRegister.onAppServerRegistered = OnAppServerRegistered;
            CentralAppServerRegister.RegisterMessageHandler(MMOMessageTypes.AppServerAddress, HandleResponseAppServerAddress);
            CentralAppServerRegister.RegisterResponseHandler <RequestSpawnMapMessage, ResponseSpawnMapMessage>(MMORequestTypes.RequestSpawnMap);
            this.InvokeInstanceDevExtMethods("OnInitCentralAppServerRegister");
            ChatNetworkManager = gameObject.AddComponent <ChatNetworkManager>();
#endif
            // Server Handlers
            ServerUserHandlers        = gameObject.GetOrAddComponent <IServerUserHandlers, DefaultServerUserHandlers>();
            ServerBuildingHandlers    = gameObject.GetOrAddComponent <IServerBuildingHandlers, DefaultServerBuildingHandlers>();
            ServerCharacterHandlers   = gameObject.GetOrAddComponent <IServerCharacterHandlers, DefaultServerCharacterHandlers>();
            ServerGameMessageHandlers = gameObject.GetOrAddComponent <IServerGameMessageHandlers, DefaultServerGameMessageHandlers>();
            ServerStorageHandlers     = gameObject.GetOrAddComponent <IServerStorageHandlers, MMOServerStorageHandlers>();
            ServerPartyHandlers       = gameObject.GetOrAddComponent <IServerPartyHandlers, DefaultServerPartyHandlers>();
            ServerGuildHandlers       = gameObject.GetOrAddComponent <IServerGuildHandlers, MMOServerGuildHandlers>();
            // Server Message Handlers
            ServerCashShopMessageHandlers  = gameObject.GetOrAddComponent <IServerCashShopMessageHandlers, MMOServerCashShopMessageHandlers>();
            ServerMailMessageHandlers      = gameObject.GetOrAddComponent <IServerMailMessageHandlers, MMOServerMailMessageHandlers>();
            ServerStorageMessageHandlers   = gameObject.GetOrAddComponent <IServerStorageMessageHandlers, MMOServerStorageMessageHandlers>();
            ServerCharacterMessageHandlers = gameObject.GetOrAddComponent <IServerCharacterMessageHandlers, DefaultServerCharacterMessageHandlers>();
            ServerInventoryMessageHandlers = gameObject.GetOrAddComponent <IServerInventoryMessageHandlers, DefaultServerInventoryMessageHandlers>();
            ServerPartyMessageHandlers     = gameObject.GetOrAddComponent <IServerPartyMessageHandlers, MMOServerPartyMessageHandlers>();
            ServerGuildMessageHandlers     = gameObject.GetOrAddComponent <IServerGuildMessageHandlers, MMOServerGuildMessageHandlers>();
            ServerFriendMessageHandlers    = gameObject.GetOrAddComponent <IServerFriendMessageHandlers, MMOServerFriendMessageHandlers>();
            ServerBankMessageHandlers      = gameObject.GetOrAddComponent <IServerBankMessageHandlers, MMOServerBankMessageHandlers>();
            // Client handlers
            ClientCashShopHandlers        = gameObject.GetOrAddComponent <IClientCashShopHandlers, DefaultClientCashShopHandlers>();
            ClientMailHandlers            = gameObject.GetOrAddComponent <IClientMailHandlers, DefaultClientMailHandlers>();
            ClientStorageHandlers         = gameObject.GetOrAddComponent <IClientStorageHandlers, DefaultClientStorageHandlers>();
            ClientCharacterHandlers       = gameObject.GetOrAddComponent <IClientCharacterHandlers, DefaultClientCharacterHandlers>();
            ClientInventoryHandlers       = gameObject.GetOrAddComponent <IClientInventoryHandlers, DefaultClientInventoryHandlers>();
            ClientPartyHandlers           = gameObject.GetOrAddComponent <IClientPartyHandlers, DefaultClientPartyHandlers>();
            ClientGuildHandlers           = gameObject.GetOrAddComponent <IClientGuildHandlers, DefaultClientGuildHandlers>();
            ClientFriendHandlers          = gameObject.GetOrAddComponent <IClientFriendHandlers, DefaultClientFriendHandlers>();
            ClientBankHandlers            = gameObject.GetOrAddComponent <IClientBankHandlers, DefaultClientBankHandlers>();
            ClientOnlineCharacterHandlers = gameObject.GetOrAddComponent <IClientOnlineCharacterHandlers, DefaultClientOnlineCharacterHandlers>();
            ClientGameMessageHandlers     = gameObject.GetOrAddComponent <IClientGameMessageHandlers, DefaultClientGameMessageHandlers>();
            base.Awake();
        }
 public override void OnStopServer()
 {
     base.OnStopServer();
     CentralAppServerRegister.OnStopServer();
     if (ChatNetworkManager.IsClientConnected)
     {
         ChatNetworkManager.StopClient();
     }
     mapServerConnectionIdsBySceneName.Clear();
 }
        protected override void FixedUpdate()
        {
            base.FixedUpdate();
#if UNITY_STANDALONE && !CLIENT_BUILD
            float tempTime = Time.fixedTime;
            if (IsServer)
            {
                CentralAppServerRegister.Update();
                if (tempTime - lastSaveTime > autoSaveDuration)
                {
                    lastSaveTime = tempTime;
                    SaveCharactersRoutine().Forget();
                    if (!IsInstanceMap())
                    {
                        // Don't save building if it's instance map
                        SaveBuildingsRoutine().Forget();
                    }
                }
                if (IsInstanceMap())
                {
                    // Quitting application when no players
                    if (Players.Count > 0)
                    {
                        terminatingTime = tempTime;
                    }
                    else if (tempTime - terminatingTime >= TERMINATE_INSTANCE_DELAY)
                    {
                        Application.Quit();
                    }
                }

                if (pendingSpawnPlayerCharacters.Count > 0 && IsReadyToInstantiateObjects())
                {
                    // Spawn pending player characters
                    LiteNetLibPlayer player;
                    foreach (PendingSpawnPlayerCharacter spawnPlayerCharacter in pendingSpawnPlayerCharacters)
                    {
                        if (!Players.TryGetValue(spawnPlayerCharacter.connectionId, out player))
                        {
                            continue;
                        }
                        player.IsReady = true;
                        SetPlayerReadyRoutine(spawnPlayerCharacter.connectionId, spawnPlayerCharacter.userId, spawnPlayerCharacter.selectCharacterId).Forget();
                    }
                    pendingSpawnPlayerCharacters.Clear();
                }
            }
#endif
        }
Пример #8
0
        // Server message handlers
        private void SampleHandleMsgFromClient(LiteNetLibMessageHandler messageHandler)
        {
            // Receive message from client at map-server
            // Then keep transport handler at server to use later to send message to client
            string text       = messageHandler.reader.GetString();
            long   clientTime = messageHandler.reader.GetLong();

            Debug.Log("[CustomFromClientToCentralServer] map-server receive from client: " + text + " " + clientTime + " then send this to central-server");
            CentralAppServerRegister.SendPacket(LiteNetLib.DeliveryMethod.ReliableOrdered, 10001, (writer) =>
            {
                writer.Put(sampleMessageToCentralServer);
                writer.Put(ServerUnixTime);
                writer.Put(messageHandler.connectionId);
            });
        }
Пример #9
0
        protected override void WarpCharacterToInstance(BasePlayerCharacterEntity playerCharacterEntity, string mapName, Vector3 position)
        {
            if (!CanWarpCharacter(playerCharacterEntity))
            {
                return;
            }
            // Generate instance id
            string instanceId = GenericUtils.GetUniqueId();
            RequestSpawnMapMessage requestSpawnMapMessage = new RequestSpawnMapMessage();

            requestSpawnMapMessage.mapId      = mapName;
            requestSpawnMapMessage.instanceId = instanceId;
            // Prepare data for warp character later when instance map server registered to this map server
            HashSet <uint> instanceMapWarpingCharacters = new HashSet <uint>();
            PartyData      party;

            if (parties.TryGetValue(playerCharacterEntity.PartyId, out party))
            {
                // If character is party member, will bring party member to join instance
                if (party.IsLeader(playerCharacterEntity))
                {
                    List <BasePlayerCharacterEntity> aliveAllies = playerCharacterEntity.FindAliveCharacters <BasePlayerCharacterEntity>(gameInstance.joinInstanceMapDistance, true, false, false);
                    foreach (BasePlayerCharacterEntity aliveAlly in aliveAllies)
                    {
                        if (!party.IsMember(aliveAlly))
                        {
                            continue;
                        }
                        instanceMapWarpingCharacters.Add(aliveAlly.ObjectId);
                        aliveAlly.IsWarping = true;
                    }
                    instanceMapWarpingCharacters.Add(playerCharacterEntity.ObjectId);
                    playerCharacterEntity.IsWarping = true;
                }
            }
            else
            {
                // If no party enter instance alone
                instanceMapWarpingCharacters.Add(playerCharacterEntity.ObjectId);
                playerCharacterEntity.IsWarping = true;
            }
            instanceMapWarpingCharactersByInstanceId.Add(instanceId, instanceMapWarpingCharacters);
            instanceMapWarpingLocations.Add(instanceId, new KeyValuePair <string, Vector3>(mapName, position));
            CentralAppServerRegister.ClientSendAckPacket(DeliveryMethod.ReliableOrdered, MMOMessageTypes.RequestSpawnMap, requestSpawnMapMessage, OnRequestSpawnMap);
        }
        protected override void Update()
        {
            base.Update();
            var tempUnscaledTime = Time.unscaledTime;

            if (IsServer)
            {
                CentralAppServerRegister.Update();
                if (tempUnscaledTime - lastSaveCharacterTime > autoSaveDuration)
                {
                    StartCoroutine(SaveCharactersRoutine());
                    lastSaveCharacterTime = tempUnscaledTime;
                }
                if (tempUnscaledTime - lastSaveBuildingTime > autoSaveDuration)
                {
                    StartCoroutine(SaveBuildingsRoutine());
                    lastSaveBuildingTime = tempUnscaledTime;
                }
            }
        }
Пример #11
0
 protected override void Awake()
 {
     base.Awake();
     if (useWebSocket)
     {
         if (centralTransportFactory == null || !centralTransportFactory.CanUseWithWebGL)
         {
             centralTransportFactory = gameObject.AddComponent <WebSocketTransportFactory>();
         }
     }
     else
     {
         if (centralTransportFactory == null)
         {
             centralTransportFactory = gameObject.AddComponent <LiteNetLibTransportFactory>();
         }
     }
     CentralAppServerRegister = new CentralAppServerRegister(CentralTransportFactory.Build(), this);
     this.InvokeInstanceDevExtMethods("OnInitCentralAppServerRegister");
 }
Пример #12
0
 protected override void Awake()
 {
     base.Awake();
     if (useWebSocket)
     {
         if (centralTransportFactory == null || !centralTransportFactory.CanUseWithWebGL)
         {
             centralTransportFactory = gameObject.AddComponent <WebSocketTransportFactory>();
         }
     }
     else
     {
         if (centralTransportFactory == null)
         {
             centralTransportFactory = gameObject.AddComponent <LiteNetLibTransportFactory>();
         }
     }
     CentralAppServerRegister = new CentralAppServerRegister(CentralTransportFactory.Build(), this);
     CentralAppServerRegister.onAppServerRegistered = OnAppServerRegistered;
     CentralAppServerRegister.RegisterRequestHandler <RequestSpawnMapMessage, ResponseSpawnMapMessage>(MMORequestTypes.RequestSpawnMap, HandleRequestSpawnMap);
     this.InvokeInstanceDevExtMethods("OnInitCentralAppServerRegister");
 }
Пример #13
0
        protected override void Update()
        {
            base.Update();
            if (IsServer && CentralAppServerRegister.IsRegisteredToCentralServer)
            {
                if (mainThreadActions.Count > 0)
                {
                    lock (mainThreadLock)
                    {
                        foreach (var actions in mainThreadActions)
                        {
                            actions.Invoke();
                        }

                        mainThreadActions.Clear();
                    }
                }
            }
            if (IsServer)
            {
                CentralAppServerRegister.Update();
            }
        }
 public override void OnStartServer()
 {
     base.OnStartServer();
     CentralAppServerRegister.OnStartServer();
 }
Пример #15
0
 public override void OnStopServer()
 {
     CentralAppServerRegister.OnStopServer();
     base.OnStopServer();
 }
Пример #16
0
 protected override void OnDestroy()
 {
     CentralAppServerRegister.StopServer();
     base.OnDestroy();
 }
        protected override async UniTask PostSpawnEntities()
        {
            await UniTask.Yield();

            CentralAppServerRegister.OnStartServer();
        }
 public override void OnStartServer()
 {
     this.InvokeInstanceDevExtMethods("OnStartServer");
     CentralAppServerRegister.OnStartServer();
     base.OnStartServer();
 }