/// <summary> /// Call this when the user logs out. /// Disconnects the client. /// </summary> /// <param name="logoutServerPeer"></param> public void OnUserLogout(IncomingSubServerPeer logoutServerPeer) { var oldState = this.CurrentState; this.CurrentState = ClientPeerState.Disconnecting; this.Disconnect(); #if MMO_DEBUG if (_logger.IsDebugEnabled) { if (logoutServerPeer != null) { _logger.DebugFormat("Client (Id={0}) Disconnected by GameServer (Type={1})", this.ClientId, logoutServerPeer.ServerType); } else { _logger.DebugFormat("Client (Id={0}) Disconnected", this.ClientId); } } #endif if (IsSafelyDisconnected) { return; } // no need to send a(n) UserLoggedOut event // unless the intend is NOT to disconnect the client when the user logs out // our game disconnects the client when the user logs out this.IsSafelyDisconnected = true; this.NotifyDisconnection(oldState, logoutServerPeer != null ? new List <IncomingSubServerPeer> { logoutServerPeer } : null); }
/// <summary> /// Call this when the character logs out. /// Throws <see cref="NotImplementedException"/>. /// </summary> /// <param name="logoutServerPeer"></param> public void OnCharacterLogout(IncomingSubServerPeer logoutServerPeer) { throw new NotImplementedException(); // sending the logged out character message to the client !important! var clientEventData = new EventData((byte)ClientEventCode.CharacterLoggedOut, new Dictionary <byte, object> { { (byte)ParameterCode.CharacterName, loginData.CharacterName } }); this.SendEvent(clientEventData, new SendParameters()); }
protected OperationResponse HandleOperationAcquireServerAddress(OperationRequest operationRequest) { var operation = new AcquireServerAddress(this.Protocol, operationRequest); if (!operation.IsValid) { return(operation.GetResponse((short)ResultCode.InvalidOperationParameter, operation.GetErrorMessage())); } IncomingSubServerPeer peer = null; switch ((ServerType)operation.ServerType) { case Server.ServerType.Chat: { peer = this.application.MasterLobby.SubServers.ChatServer; if (peer == null) { this.application.MasterLobby.SubServers.TryGetSubserverByTypeAny(SubServerType.Chat, out peer); } } break; case Server.ServerType.Social: { peer = this.application.MasterLobby.SubServers.SocialServer; if (peer == null) { this.application.MasterLobby.SubServers.TryGetSubserverByTypeAny(SubServerType.Social, out peer); } } break; } if (peer == null || !peer.Connected) { return(operation.GetResponse((short)ResultCode.ServerNotFound, null)); } var serverInfo = new AcquireServerResponse { ServerType = operation.ServerType, Address = peer.ServerAddress, TcpPort = peer.TcpPort, UdpPort = peer.UdpPort, }; return(new OperationResponse(operationRequest.OperationCode, serverInfo) { ReturnCode = (short)ResultCode.Ok }); }
/// <summary> /// Call this when the player enters world. /// </summary> /// <param name="worldServerPeer"></param> public void OnPlayerTransferWorld(IncomingSubServerPeer worldServerPeer) { // client trying to play without logging? // this cannot happen if (LoginData == null) { _logger.ErrorFormat("[OnCharacterEnterWorld]: LoginData not found for Character"); return; } if (CurrentState == ClientPeerState.WorldEnter) { _logger.ErrorFormat("[OnCharacterEnterWorld]: Character (CharName={0}) is already playing", loginData.CharacterName); return; } // resetting world server in case there is a world shutdown and the transfer was routed to another world if (WorldServer != worldServerPeer) { #if MMO_DEBUG _logger.DebugFormat("[OnCharacterEnterWorld]: Updating the current world (NewId={0}. OldId={1})", worldServerPeer.SubServerId, WorldServer.SubServerId); #endif this.WorldServer = worldServerPeer; this.LoginData.WorldId = WorldServer.SubServerId; } // updating the state world enter so the client can send messages to the world this.CurrentState = ClientPeerState.WorldEnter; // sending the player entered world message to the client this.SendEvent( new EventData((byte)ClientEventCode.PlayerTransferred, new Dictionary <byte, object> { { (byte)ParameterCode.WorldId, WorldServer.SubServerId } }), new SendParameters()); }
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { IncomingSubServerPeer receiver = null; OperationResponse response = null; switch (CurrentState) { case ClientPeerState.Connect: { if (operationRequest.OperationCode == (byte)ClientOperationCode.Login) { receiver = Application.MasterLobby.SubServers.LoginServer; } } break; case ClientPeerState.Login: { if (operationRequest.OperationCode != (byte)ClientOperationCode.Character) { break; } operationRequest.Parameters.Remove((byte)ParameterCode.Username); operationRequest.Parameters.Add((byte)ParameterCode.Username, this.LoginData.Username); receiver = Application.MasterLobby.SubServers.LoginServer; } break; case ClientPeerState.WorldEnter: { switch ((ClientOperationCode)operationRequest.OperationCode) { case ClientOperationCode.Chat: receiver = Application.MasterLobby.SubServers.ChatServer; break; case ClientOperationCode.Group: case ClientOperationCode.Social: receiver = Application.MasterLobby.SubServers.SocialServer; break; case ClientOperationCode.World: receiver = WorldServer; break; } } break; } if (receiver != null) { operationRequest.Parameters.Remove(0); operationRequest.Parameters.Add(0, ClientId); receiver.SendOperationRequest(operationRequest, sendParameters); } else { response = new OperationResponse(operationRequest.OperationCode) { ReturnCode = (short)ResultCode.OperationNotAvailable }; _logger.ErrorFormat("State={0} SessionId={1} OpCode={2}", CurrentState, ClientId, (ClientOperationCode)operationRequest.OperationCode); } if (response != null) { this.SendOperationResponse(response, new SendParameters()); } }
public void OnServerDisconnected(IncomingSubServerPeer peer) { this.subServers.OnDisconnect(peer); }