protected virtual OperationResponse HandleJoinLobby(MasterClientPeer peer, JoinLobbyRequest operation, SendParameters sendParameters) { try { // special handling for game properties send by AS3/Flash (Amf3 protocol) clients if (peer.Protocol.ProtocolType == ProtocolType.Amf3V152 || peer.Protocol.ProtocolType == ProtocolType.Json) { Utilities.ConvertAs3WellKnownPropertyKeys(operation.GameProperties, null); } peer.GameChannelSubscription = null; var subscription = this.GameList.AddSubscription(peer, operation.GameProperties, operation.GameListCount); peer.GameChannelSubscription = subscription; peer.SendOperationResponse(new OperationResponse(operation.OperationRequest.OperationCode), sendParameters); // publish game list to peer after the response has been sent var gameList = subscription.GetGameList(); var e = new GameListEvent { Data = gameList }; var eventData = new EventData((byte)EventCode.GameList, e); peer.SendEvent(eventData, new SendParameters()); return(null); } catch (Exception ex) { log.Error(ex); return(null); } }
protected virtual OperationResponse HandleJoinLobby(MasterClientPeer peer, OperationRequest operationRequest, SendParameters sendParameters) { // validate operation var operation = new JoinLobbyRequest(peer.Protocol, operationRequest); OperationResponse response; if (OperationHelper.ValidateOperation(operation, log, out response) == false) { return(response); } // special handling for game properties send by AS3/Flash (Amf3 protocol) clients if (peer.Protocol.ProtocolType == ProtocolType.Amf3V151 || peer.Protocol.ProtocolType == ProtocolType.Amf3V152) { Utilities.ConvertAs3WellKnownPropertyKeys(operation.GameProperties, null); } peer.GameChannelSubscription = null; var subscription = this.GameList.AddSubscription(peer, operation.GameProperties, operation.GameListCount); peer.GameChannelSubscription = subscription; peer.SendOperationResponse(new OperationResponse(operationRequest.OperationCode), sendParameters); // publish game list to peer after the response has been sent var gameList = subscription.GetGameList(); var e = new GameListEvent { Data = gameList }; var eventData = new EventData((byte)EventCode.GameList, e); peer.SendEvent(eventData, new SendParameters()); return(null); }
protected virtual void ExecuteOperation(MasterClientPeer peer, OperationRequest operationRequest, SendParameters sendParameters) { try { OperationResponse response; switch ((OperationCode)operationRequest.OperationCode) { default: response = new OperationResponse(operationRequest.OperationCode) { ReturnCode = -1, DebugMessage = "Unknown operation code" }; break; case OperationCode.JoinLobby: var joinLobbyRequest = new JoinLobbyRequest(peer.Protocol, operationRequest); if (OperationHelper.ValidateOperation(joinLobbyRequest, log, out response)) { response = this.HandleJoinLobby(peer, joinLobbyRequest, sendParameters); } break; case OperationCode.LeaveLobby: response = this.HandleLeaveLobby(peer, operationRequest); break; case OperationCode.CreateGame: response = this.HandleCreateGame(peer, operationRequest); break; case OperationCode.JoinGame: response = this.HandleJoinGame(peer, operationRequest); break; case OperationCode.JoinRandomGame: response = this.HandleJoinRandomGame(peer, operationRequest); break; case OperationCode.DebugGame: response = this.HandleDebugGame(peer, operationRequest); break; } if (response != null) { peer.SendOperationResponse(response, sendParameters); } } catch (Exception ex) { log.Error(ex); } }
protected virtual OperationResponse HandleJoinLobby(MasterClientPeer peer, JoinLobbyRequest operation, SendParameters sendParameters) { try { peer.GameChannelSubscription = null; if (operation.GameListCount > 0 && this.gameListLimit > 0) { if (operation.GameListCount > this.gameListLimit) { operation.GameListCount = this.gameListLimit; } } var subscription = this.GameList.AddSubscription(peer, operation.GameProperties, operation.GameListCount); peer.GameChannelSubscription = subscription; peer.SendOperationResponse(new OperationResponse(operation.OperationRequest.OperationCode), sendParameters); if (subscription != null) { // publish game list to peer after the response has been sent var gameList = subscription.GetGameList(); if (gameList.Count != 0) { var sb = new StringBuilder(); foreach (var game in gameList.Keys) { sb.AppendFormat("{0};", game); } if (log.IsDebugEnabled) { log.DebugFormat("Game list is: {0}", sb.ToString()); } } var e = new GameListEvent { Data = gameList }; var eventData = new EventData((byte)EventCode.GameList, e); peer.SendEvent(eventData, new SendParameters()); } this.peers.Add(peer); return(null); } catch (Exception ex) { log.Error(ex); return(null); } }
protected virtual void ExecuteOperation(MasterClientPeer peer, OperationRequest operationRequest, SendParameters sendParameters) { OperationResponse response; try { switch ((OperationCode)operationRequest.OperationCode) { default: response = new OperationResponse(operationRequest.OperationCode) { ReturnCode = (short)ErrorCode.OperationInvalid, DebugMessage = LBErrorMessages.UnknownOperationCode }; break; case OperationCode.CreateGame: response = this.HandleCreateGame(peer, operationRequest); break; case OperationCode.JoinGame: response = this.HandleJoinGame(peer, operationRequest); break; case OperationCode.JoinRandomGame: response = this.HandleJoinRandomGame(peer, operationRequest); break; case OperationCode.DebugGame: if (MasterServerSettings.Default.AllowDebugGameOperation) { response = this.HandleDebugGame(peer, operationRequest); } else { response = new OperationResponse(operationRequest.OperationCode) { ReturnCode = (short)ErrorCode.OperationDenied, DebugMessage = LBErrorMessages.NotAuthorized }; } break; case OperationCode.GetGameList: response = this.HandleGetGameList(peer, operationRequest); break; } } catch (Exception ex) { response = new OperationResponse(operationRequest.OperationCode) { ReturnCode = (short)ErrorCode.InternalServerError, DebugMessage = ex.Message }; log.Error(string.Format("Exception in AppLobby:{0}, Exception Msg:{1}", this, ex.Message), ex); } try { if (response != null) { peer.SendOperationResponse(response, sendParameters); switch ((OperationCode)response.OperationCode) { case OperationCode.CreateGame: case OperationCode.JoinGame: case OperationCode.JoinRandomGame: { peer.IncConcurrentJoinRequest(-1); if (response.ReturnCode == (short)ErrorCode.Ok) { peer.IncTotalSuccessfulJoinRequest(); } break; } } } } catch (Exception ex) { log.Error(string.Format("Exception in AppLobby:{0}, Exception Msg:{1}", this, ex.Message), ex); } }
protected virtual OperationResponse HandleJoinLobby(MasterClientPeer peer, JoinLobbyRequest operation, SendParameters sendParameters) { try { // special handling for game properties send by AS3/Flash (Amf3 protocol) clients if (peer.Protocol.ProtocolType == ProtocolType.Amf3V152 || peer.Protocol.ProtocolType == ProtocolType.Json) { Utilities.ConvertAs3WellKnownPropertyKeys(operation.GameProperties, null); } peer.GameChannelSubscription = null; var subscription = this.GameList.AddSubscription(peer, operation.GameProperties, operation.GameListCount); peer.GameChannelSubscription = subscription; peer.SendOperationResponse(new OperationResponse(operation.OperationRequest.OperationCode), sendParameters); // publish game list to peer after the response has been sent var gameList = subscription.GetGameList(); var e = new GameListEvent { Data = gameList }; var eventData = new EventData((byte)EventCode.GameList, e); peer.SendEvent(eventData, new SendParameters()); return null; } catch (Exception ex) { log.Error(ex); return null; } }