/// <summary> /// Handles a <see cref="AcquireServerResponse"/>. /// </summary> private void HandleOperationResponseAcquireServerResponse(IRpcProtocol protocol, OperationResponse operationResponse) { var response = new AcquireServerResponse(protocol, operationResponse); if (!response.IsValid || operationResponse.ReturnCode != (short)ResultCode.Ok) { #if MMO_DEBUG _logger.DebugFormat("Re-acquiring chat server connection info. ResponseValid?={0}. ReturnCode={1}.", response.IsValid, operationResponse.ReturnCode); #endif this.AcquireChatServerConnection(ServerSettings.SERVER_RECONNECT_INTERVAL); return; } Interlocked.CompareExchange(ref listenerState, (int)ListenerState.Connecting, (int)ListenerState.Disconnected); var newListenerState = ListenerState; if (newListenerState != ListenerState.Connecting) { _logger.ErrorFormat("[HandleOperationResponseAcquireServerResponse]: Invalid listener state (State={0})", newListenerState); return; } var ipAddress = IPAddress.Parse(response.Address); var port = response.TcpPort; WorldApplication.Instance.ConnectToExternalServer(new IPEndPoint(ipAddress, port), "Chat", this); }
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 }); }