protected async UniTaskVoid HandleRequestSelectCharacter( RequestHandlerData requestHandler, RequestSelectCharacterMessage request, RequestProceedResultDelegate <ResponseSelectCharacterMessage> result) { long connectionId = requestHandler.ConnectionId; ResponseSelectCharacterMessage.Error error = ResponseSelectCharacterMessage.Error.None; CentralServerPeerInfo mapServerPeerInfo = default; CentralUserPeerInfo userPeerInfo; if (!userPeers.TryGetValue(connectionId, out userPeerInfo)) { error = ResponseSelectCharacterMessage.Error.NotLoggedin; } else { CharacterResp characterResp = await DbServiceClient.ReadCharacterAsync(new ReadCharacterReq() { UserId = userPeerInfo.userId, CharacterId = request.characterId }); PlayerCharacterData character = characterResp.CharacterData.FromByteString <PlayerCharacterData>(); if (character == null) { error = ResponseSelectCharacterMessage.Error.InvalidCharacterData; } else if (!mapServerPeersBySceneName.TryGetValue(character.CurrentMapName, out mapServerPeerInfo)) { error = ResponseSelectCharacterMessage.Error.MapNotReady; } } AckResponseCode responseCode = error == ResponseSelectCharacterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error; ResponseSelectCharacterMessage response = new ResponseSelectCharacterMessage(); response.error = error; if (error != ResponseSelectCharacterMessage.Error.MapNotReady) { response.sceneName = mapServerPeerInfo.extra; response.networkAddress = mapServerPeerInfo.networkAddress; response.networkPort = mapServerPeerInfo.networkPort; } // Response result.Invoke(responseCode, response); }
private async UniTaskVoid HandleRequestSelectCharacterRoutine(LiteNetLibMessageHandler messageHandler) { long connectionId = messageHandler.connectionId; RequestSelectCharacterMessage message = messageHandler.ReadMessage <RequestSelectCharacterMessage>(); ResponseSelectCharacterMessage.Error error = ResponseSelectCharacterMessage.Error.None; CentralServerPeerInfo mapServerPeerInfo = default(CentralServerPeerInfo); CentralUserPeerInfo userPeerInfo; if (!userPeers.TryGetValue(connectionId, out userPeerInfo)) { error = ResponseSelectCharacterMessage.Error.NotLoggedin; } else { CharacterResp characterResp = await DbServiceClient.ReadCharacterAsync(new ReadCharacterReq() { UserId = userPeerInfo.userId, CharacterId = message.characterId }); PlayerCharacterData character = characterResp.CharacterData.FromByteString <PlayerCharacterData>(); 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 (error != ResponseSelectCharacterMessage.Error.MapNotReady) { responseMessage.sceneName = mapServerPeerInfo.extra; responseMessage.networkAddress = mapServerPeerInfo.networkAddress; responseMessage.networkPort = mapServerPeerInfo.networkPort; } ServerSendResponse(connectionId, MMOMessageTypes.ResponseSelectCharacter, responseMessage); }
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); }