public OperationResponse HandleFindFriends(OperationRequest operationRequest, SendParameters sendParameters) { // validate the operation request OperationResponse response; var operation = new FindFriendsRequest(this.Protocol, operationRequest); if (OperationHelper.ValidateOperation(operation, log, out response) == false) { return(response); } // check if player online cache is available for the application var playerCache = this.Application.PlayerOnlineCache; if (playerCache == null) { return(new OperationResponse((byte)OperationCode.FindFriends) { ReturnCode = (short)ErrorCode.InternalServerError, DebugMessage = "PlayerOnlineCache is not set!" }); } playerCache.FiendFriends(this, operation, sendParameters); return(null); }
public virtual OperationResponse HandleJoinRandomGame(OperationRequest operationRequest, SendParameters sendParameters) { var response = this.CheckJoinActivity(operationRequest); if (response != null) { return(response); } var joinRandomGameRequest = new JoinRandomGameRequest(this.Protocol, operationRequest); if (OperationHelper.ValidateOperation(joinRandomGameRequest, log, out response) == false) { return(response); } AppLobby lobby; response = this.TryGetLobby(joinRandomGameRequest.LobbyName, joinRandomGameRequest.LobbyType, operationRequest.OperationCode, out lobby); if (response != null) { return(response); } this.IncConcurrentJoinRequest(1); lobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); }
public OperationResponse HandleCreateGame(OperationRequest operationRequest, SendParameters sendParameters) { var createGameRequest = new CreateGameRequest(this.Protocol, operationRequest); OperationResponse response; if (OperationHelper.ValidateOperation(createGameRequest, log, out response) == false) { return(response); } if (createGameRequest.LobbyType > 3) { return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (short)ErrorCode.OperationInvalid, DebugMessage = "Invalid lobby type " + createGameRequest.LobbyType }); } AppLobby lobby; response = this.TryGetLobby(createGameRequest.LobbyName, createGameRequest.LobbyType, operationRequest.OperationCode, out lobby); if (response != null) { return(response); } lobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); }
public OperationResponse HandleJoinRandomGame(OperationRequest operationRequest, SendParameters sendParameters) { var joinRandomGameRequest = new JoinRandomGameRequest(this.Protocol, operationRequest); OperationResponse response; if (OperationHelper.ValidateOperation(joinRandomGameRequest, log, out response) == false) { return(response); } if (string.IsNullOrEmpty(joinRandomGameRequest.LobbyName) && this.AppLobby != null) { this.AppLobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); } AppLobby lobby; if (!this.Application.LobbyFactory.GetOrCreateAppLobby(joinRandomGameRequest.LobbyName, (AppLobbyType)joinRandomGameRequest.LobbyType, out lobby)) { return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (int)ErrorCode.OperationDenied, DebugMessage = "Lobby does not exist" }); } lobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); }
private OperationResponse HandleAuthenticate(OperationRequest operationRequest) { OperationResponse response; var request = new AuthenticateRequest(this.Protocol, operationRequest); if (!OperationHelper.ValidateOperation(request, log, out response)) { return(response); } this.UserId = request.UserId; // add the peer to the application player online cache if available var playerCache = this.Application.PlayerOnlineCache; if (playerCache != null) { playerCache.OnConnectedToMaster(this.UserId); } // publish operation response var responseObject = new AuthenticateResponse { QueuePosition = 0 }; return(new OperationResponse(operationRequest.OperationCode, responseObject)); }
public OperationResponse HandleJoinLobby(OperationRequest operationRequest, SendParameters sendParameters) { var joinLobbyRequest = new JoinLobbyRequest(this.Protocol, operationRequest); OperationResponse response; if (OperationHelper.ValidateOperation(joinLobbyRequest, log, out response) == false) { return(response); } if (joinLobbyRequest.LobbyType > 3) { return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (short)ErrorCode.OperationInvalid, DebugMessage = "Invalid lobby type " + joinLobbyRequest.LobbyType }); } // remove peer from the currently joined lobby if (this.AppLobby != null) { this.AppLobby.RemovePeer(this); this.AppLobby = null; } AppLobby lobby; if (!this.Application.LobbyFactory.GetOrCreateAppLobby(joinLobbyRequest.LobbyName, (AppLobbyType)joinLobbyRequest.LobbyType, out lobby)) { // getting here should never happen if (log.IsWarnEnabled) { log.WarnFormat("Could not get or create lobby: name={0}, type={1}", joinLobbyRequest.LobbyName, (AppLobbyType)joinLobbyRequest.LobbyType); } return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (short)ErrorCode.InternalServerError, DebugMessage = LBErrorMessages.CanNotCreateLobby, }); } this.AppLobby = lobby; this.AppLobby.JoinLobby(this, joinLobbyRequest, sendParameters); if (log.IsDebugEnabled) { log.DebugFormat("Joined lobby: {0}, {1}, u:'{2}'", joinLobbyRequest.LobbyName, joinLobbyRequest.LobbyType, this.UserId); } return(null); }
public OperationResponse HandleLobbyStatsRequest(OperationRequest operationRequest, SendParameters sendParameters) { OperationResponse response; var getStatsRequest = new GetLobbyStatsRequest(this.Protocol, operationRequest); if (OperationHelper.ValidateOperation(getStatsRequest, log, out response) == false) { return(response); } this.Application.LobbyStatsPublisher.EnqueueGetStatsRequest(this, getStatsRequest, sendParameters); return(null); }
public virtual OperationResponse HandleJoinGame(OperationRequest operationRequest, SendParameters sendParameters) { var response = this.CheckJoinActivity(operationRequest); if (response != null) { return(response); } var joinGameRequest = new JoinGameRequest(this.Protocol, operationRequest, this.UserId); if (OperationHelper.ValidateOperation(joinGameRequest, log, out response) == false) { return(response); } GameState gameState; if (this.Application.TryGetGame(joinGameRequest.GameId, out gameState)) { this.IncConcurrentJoinRequest(1); gameState.Lobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); } if (joinGameRequest.JoinMode == JoinModes.JoinOnly && !this.Application.PluginTraits.AllowAsyncJoin) { return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (short)ErrorCode.GameIdNotExists, DebugMessage = HiveErrorMessages.GameIdDoesNotExist }); } AppLobby lobby; response = this.TryGetLobby(joinGameRequest.LobbyName, joinGameRequest.LobbyType, operationRequest.OperationCode, out lobby); if (response != null) { return(response); } this.IncConcurrentJoinRequest(1); lobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); }
public virtual OperationResponse HandleLobbyStatsRequest(OperationRequest operationRequest, SendParameters sendParameters) { if (log.IsDebugEnabled) { log.Debug($"Peer got lobby stats request. peer:{this}"); } var getStatsRequest = new GetLobbyStatsRequest(this.Protocol, operationRequest); if (OperationHelper.ValidateOperation(getStatsRequest, log, out OperationResponse response) == false) { return(response); } this.Application.LobbyStatsPublisher.EnqueueGetStatsRequest(this, getStatsRequest, sendParameters); return(null); }
public virtual OperationResponse HandleGetGameList(OperationRequest operationRequest, SendParameters sendParameters) { var getGameListRequest = new GetGameListRequest(this.Protocol, operationRequest); OperationResponse response; if (OperationHelper.ValidateOperation(getGameListRequest, log, out response) == false) { return(response); } //only supported for SqlListLobby if (getGameListRequest.LobbyType != (byte)AppLobbyType.SqlLobby) { return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (short)ErrorCode.OperationInvalid, DebugMessage = "Invalid lobby type " + getGameListRequest.LobbyType }); } //don't allow empty lobby name, this will cause that the default lobby is used (which does not support this operation) if (string.IsNullOrEmpty(getGameListRequest.LobbyName)) { return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (short)ErrorCode.OperationInvalid, DebugMessage = string.Format("Invalid lobby name: '{0}'", getGameListRequest.LobbyName) }); } AppLobby lobby; response = this.TryGetLobby(getGameListRequest.LobbyName, getGameListRequest.LobbyType, operationRequest.OperationCode, out lobby); if (response != null) { return(response); } lobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); }
private OperationResponse HandleAuthenticate(OperationRequest operationRequest) { OperationResponse response; var request = new AuthenticateRequest(this.Protocol, operationRequest); if (!OperationHelper.ValidateOperation(request, log, out response)) { return(response); } this.UserId = request.UserId; // publish operation response var responseObject = new AuthenticateResponse { QueuePosition = 0 }; return(new OperationResponse(operationRequest.OperationCode, responseObject)); }
public OperationResponse HandleJoinLobby(OperationRequest operationRequest, SendParameters sendParameters) { var joinLobbyRequest = new JoinLobbyRequest(this.Protocol, operationRequest); OperationResponse response; if (OperationHelper.ValidateOperation(joinLobbyRequest, log, out response) == false) { return(response); } // remove peer from the currently joined lobby if (this.AppLobby != null) { this.AppLobby.RemovePeer(this); this.AppLobby = null; } AppLobby lobby; if (!this.Application.LobbyFactory.GetOrCreateAppLobby(joinLobbyRequest.LobbyName, (AppLobbyType)joinLobbyRequest.LobbyType, out lobby)) { return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (short)ErrorCode.OperationDenied, DebugMessage = "Cannot create lobby" }); } this.AppLobby = lobby; this.AppLobby.JoinLobby(this, joinLobbyRequest, sendParameters); if (log.IsDebugEnabled) { log.DebugFormat("Joined lobby: {0}, {1}", joinLobbyRequest.LobbyName, joinLobbyRequest.LobbyType); } return(null); }
public OperationResponse HandleJoinGame(OperationRequest operationRequest, SendParameters sendParameters) { var joinGameRequest = new JoinGameRequest(this.Protocol, operationRequest); OperationResponse response; if (OperationHelper.ValidateOperation(joinGameRequest, log, out response) == false) { return(response); } GameState gameState; if (this.Application.TryGetGame(joinGameRequest.GameId, out gameState)) { gameState.Lobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); } if (joinGameRequest.CreateIfNotExists == false) { return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (int)ErrorCode.GameIdNotExists, DebugMessage = "Game does not exist" }); } AppLobby lobby; if (!this.Application.LobbyFactory.GetOrCreateAppLobby(joinGameRequest.LobbyName, (AppLobbyType)joinGameRequest.LobbyType, out lobby)) { return(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (int)ErrorCode.OperationDenied, DebugMessage = "Lobby does not exist" }); } lobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); }
public OperationResponse HandleJoinRandomGame(OperationRequest operationRequest, SendParameters sendParameters) { var joinRandomGameRequest = new JoinRandomGameRequest(this.Protocol, operationRequest); OperationResponse response; if (OperationHelper.ValidateOperation(joinRandomGameRequest, log, out response) == false) { return(response); } AppLobby lobby; response = this.TryGetLobby(joinRandomGameRequest.LobbyName, joinRandomGameRequest.LobbyType, operationRequest.OperationCode, out lobby); if (response != null) { return(response); } lobby.EnqueueOperation(this, operationRequest, sendParameters); return(null); }