public bool HandleMessage(IMessage message, IServerPeer peer) { // Got a response back from the LoginUserPass - might be successful, might not. if (message.Parameters.ContainsKey(_serverConfiguration.PeerIdCode)) { Log.DebugFormat("Looking for Peer Id {0}", new Guid((Byte[])message.Parameters[_serverConfiguration.PeerIdCode])); IClientPeer clientPeer = _connectionCollection.GetPeers <IClientPeer>().FirstOrDefault(p => p.PeerId == new Guid((Byte[])message.Parameters[_serverConfiguration.PeerIdCode])); if (clientPeer != null) { Log.DebugFormat("Found Peer"); var response = message as Response; // copy our response to a return response Response returnResponse = new Response(Code, SubCode, message.Parameters); // remove any unnecessary codes from the returning packet _clientCodeRemover.RemoveCodes(returnResponse); if (response.ReturnCode == (short)ReturnCode.OK) { // Good response, get the client data and look for the userId to set it for the future. clientPeer.ClientData <CharacterData>().UserId = (int)response.Parameters[(byte)MessageParameterCode.UserId]; } // make one call to send the message back - One "exit point" for the message. clientPeer.SendMessage(response); } } return(true); }
public override void DisconnectPeer(IClientPeer peer) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Client Peer {peer.ClientData<UserData>().Id} disconnected from {GetType().Name}"); Console.ResetColor(); ConnectionCollection.Disconnect(peer); peer.Client.MessageReceived -= OnOperationRequest; }