private void UpdateMapUser(UpdateUserCharacterMessage.UpdateType updateType, UserCharacterData userData, long exceptConnectionId)
        {
            foreach (long mapServerConnectionId in mapServerConnectionIds)
            {
                if (mapServerConnectionId == exceptConnectionId)
                {
                    continue;
                }

                UpdateMapUser(mapServerConnectionId, updateType, userData);
            }
        }
        private void UpdateMapUser(TransportHandler transportHandler, UpdateUserCharacterMessage.UpdateType updateType, UserCharacterData userData)
        {
            var updateMapUserMessage = new UpdateUserCharacterMessage();

            updateMapUserMessage.type = updateType;
            updateMapUserMessage.data = userData;
            transportHandler.ClientSendPacket(SendOptions.ReliableOrdered, MMOMessageTypes.UpdateMapUser, updateMapUserMessage.Serialize);
        }
        private IEnumerator SetPlayerReadyRoutine(long connectionId, string userId, string accessToken, string selectCharacterId)
        {
            // Validate access token
            var validateAccessTokenJob = new ValidateAccessTokenJob(Database, userId, accessToken);

            validateAccessTokenJob.Start();
            yield return(StartCoroutine(validateAccessTokenJob.WaitFor()));

            if (!validateAccessTokenJob.result)
            {
                if (LogError)
                {
                    Debug.LogError("[Map Server] Invalid access token for user: "******"[Map Server] Cannot find select character: " + selectCharacterId + " for user: "******"[Map Server] Cannot find player character with entity Id: " + playerCharacterData.EntityId);
                        }
                        transport.ServerDisconnect(connectionId);
                    }
                    else
                    {
                        // Spawn character entity and set its data
                        var identity = Assets.NetworkSpawn(entityPrefab.Identity.HashAssetId, playerCharacterData.CurrentPosition, Quaternion.identity, 0, connectionId);
                        var playerCharacterEntity = identity.GetComponent <BasePlayerCharacterEntity>();
                        playerCharacterData.CloneTo(playerCharacterEntity);

                        // Notify clients that this character is spawn or dead
                        if (!playerCharacterEntity.IsDead())
                        {
                            playerCharacterEntity.RequestOnRespawn();
                        }
                        else
                        {
                            playerCharacterEntity.RequestOnDead();
                        }
                        RegisterPlayerCharacter(connectionId, playerCharacterEntity);

                        // Load party data, if this map-server does not have party data
                        if (playerCharacterEntity.PartyId > 0)
                        {
                            if (!parties.ContainsKey(playerCharacterEntity.PartyId))
                            {
                                yield return(StartCoroutine(LoadPartyRoutine(playerCharacterEntity.PartyId)));
                            }
                            if (parties.ContainsKey(playerCharacterEntity.PartyId))
                            {
                                var party = parties[playerCharacterEntity.PartyId];
                                SendCreatePartyToClient(playerCharacterEntity.ConnectionId, party);
                                SendAddPartyMembersToClient(playerCharacterEntity.ConnectionId, party);
                            }
                            else
                            {
                                playerCharacterEntity.ClearParty();
                            }
                        }

                        // Load guild data, if this map-server does not have guild data
                        if (playerCharacterEntity.GuildId > 0)
                        {
                            if (!guilds.ContainsKey(playerCharacterEntity.GuildId))
                            {
                                yield return(StartCoroutine(LoadGuildRoutine(playerCharacterEntity.GuildId)));
                            }
                            if (guilds.ContainsKey(playerCharacterEntity.GuildId))
                            {
                                var guild = guilds[playerCharacterEntity.GuildId];
                                playerCharacterEntity.GuildRole = guild.GetMemberRole(playerCharacterEntity.Id);
                                SendCreateGuildToClient(playerCharacterEntity.ConnectionId, guild);
                                SendAddGuildMembersToClient(playerCharacterEntity.ConnectionId, guild);
                                SendSetGuildMessageToClient(playerCharacterEntity.ConnectionId, guild);
                                SendSetGuildRolesToClient(playerCharacterEntity.ConnectionId, guild);
                                SendSetGuildMemberRolesToClient(playerCharacterEntity.ConnectionId, guild);
                                SendSetGuildSkillLevelsToClient(playerCharacterEntity.ConnectionId, guild);
                                SendGuildLevelExpSkillPointToClient(playerCharacterEntity.ConnectionId, guild);
                            }
                            else
                            {
                                playerCharacterEntity.ClearGuild();
                            }
                        }

                        // Set user data to map server
                        var userData = new UserCharacterData();
                        userData.userId        = userId;
                        userData.id            = playerCharacterEntity.Id;
                        userData.characterName = playerCharacterEntity.CharacterName;
                        userData.dataId        = playerCharacterEntity.DataId;
                        userData.level         = playerCharacterEntity.Level;
                        userData.currentHp     = playerCharacterEntity.CurrentHp;
                        userData.maxHp         = playerCharacterEntity.CacheMaxHp;
                        userData.currentMp     = playerCharacterEntity.CurrentMp;
                        userData.maxMp         = playerCharacterEntity.CacheMaxMp;
                        usersById[userData.id] = userData;

                        // Add map user to central server and chat server
                        UpdateMapUser(CentralAppServerRegister, UpdateUserCharacterMessage.UpdateType.Add, userData);
                        if (ChatNetworkManager.IsClientConnected)
                        {
                            UpdateMapUser(ChatNetworkManager.Client, UpdateUserCharacterMessage.UpdateType.Add, userData);
                        }

                        var player = Players[connectionId];
                        foreach (var spawnedObject in Assets.SpawnedObjects)
                        {
                            if (spawnedObject.Value.ConnectionId == player.ConnectionId)
                            {
                                continue;
                            }

                            if (spawnedObject.Value.ShouldAddSubscriber(player))
                            {
                                spawnedObject.Value.AddSubscriber(player);
                            }
                        }
                    }
                }
            }
        }
        private void UpdateMapUser(long connectionId, UpdateUserCharacterMessage.UpdateType updateType, UserCharacterData userData)
        {
            UpdateUserCharacterMessage updateMapUserMessage = new UpdateUserCharacterMessage();

            updateMapUserMessage.type = updateType;
            updateMapUserMessage.data = userData;
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.UpdateMapUser, updateMapUserMessage);
        }