private IEnumerator HandleRequestSelectCharacterRoutine(LiteNetLibMessageHandler messageHandler) { long connectionId = messageHandler.connectionId; RequestSelectCharacterMessage message = messageHandler.ReadMessage <RequestSelectCharacterMessage>(); ResponseSelectCharacterMessage.Error error = ResponseSelectCharacterMessage.Error.None; CentralServerPeerInfo mapServerPeerInfo = null; CentralUserPeerInfo userPeerInfo; if (!userPeers.TryGetValue(connectionId, out userPeerInfo)) { error = ResponseSelectCharacterMessage.Error.NotLoggedin; } else { ReadCharacterJob job = new ReadCharacterJob(Database, userPeerInfo.userId, message.characterId, false, false, false, false, false, false, false, false, false); job.Start(); yield return(StartCoroutine(job.WaitFor())); PlayerCharacterData character = job.result; if (character == null) { error = ResponseSelectCharacterMessage.Error.InvalidCharacterData; } else if (!mapServerPeersBySceneName.TryGetValue(character.CurrentMapName, out mapServerPeerInfo)) { error = ResponseSelectCharacterMessage.Error.MapNotReady; } } ResponseSelectCharacterMessage responseMessage = new ResponseSelectCharacterMessage(); responseMessage.ackId = message.ackId; responseMessage.responseCode = error == ResponseSelectCharacterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error; responseMessage.error = error; if (mapServerPeerInfo != null) { responseMessage.sceneName = mapServerPeerInfo.extra; responseMessage.networkAddress = mapServerPeerInfo.networkAddress; responseMessage.networkPort = mapServerPeerInfo.networkPort; responseMessage.connectKey = mapServerPeerInfo.connectKey; } ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseSelectCharacter, responseMessage); }
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); } } } } } }