public virtual GetGameListResponses GetGameList(out int outCount, GetGameListRequest list)
        {
            var items = _gameListManager.GetGames(out outCount, list, CultureCode);

            return(new GetGameListResponses
            {
                Code = ResponseCode.Success,
                GameList = items
            });
        }
        private static bool IsValid(GetGameListRequest request, out string message)
        {
            if (string.IsNullOrEmpty(request.UserId))
            {
                message = "Missing UserId.";
                return false;
            }

            message = "";
            return true;
        }
        private static bool IsValid(GetGameListRequest request, out string message)
        {
            if (string.IsNullOrEmpty(request.UserId))
            {
                message = "Missing UserId.";
                return(false);
            }

            message = "";
            return(true);
        }
        public IActionResult Index([FromBody] GetGameListRequest request, string appId)
        {
            string message;

            if (!IsValid(request, out message))
            {
                var errorResponse = new ErrorResponse {
                    Message = message
                };
                _logger.LogError($"{Request.GetUri()} - {JsonConvert.SerializeObject(errorResponse)}");
                return(BadRequest(errorResponse));
            }

            var list = new Dictionary <string, object>();

            foreach (var pair in _dataAccess.GameGetAll(appId, request.UserId))
            {
                // exists - save result in list
                //if (DataSources.DataAccess.StateExists(appId, pair.Key))
                var stateJson = _dataAccess.StateGet(appId, pair.Key);
                if (stateJson != null)
                {
                    dynamic customProperties = null;
                    if (stateJson != string.Empty)
                    {
                        var state = JsonConvert.DeserializeObject <dynamic>(stateJson);
                        customProperties = state.CustomProperties;
                    }

                    var gameListItem = new GameListItem()
                    {
                        ActorNr = int.Parse(pair.Value), Properties = customProperties
                    };

                    list.Add(pair.Key, gameListItem);
                }
                // not exists - delete
                else
                {
                    _dataAccess.GameDelete(appId, request.UserId, pair.Key);
                }
            }

            var getGameListResponse = new GetGameListResponse {
                Data = list
            };

            _logger.LogInformation($"{Request.GetUri()} - {JsonConvert.SerializeObject(getGameListResponse)}");
            return(Ok(getGameListResponse));
        }
        private static bool IsValid(GetGameListRequest request, out string message)
        {
            if (request == null)
            {
                message = "Received request does not contain expected JSON data.";
                return(false);
            }

            if (string.IsNullOrWhiteSpace(request.UserId))
            {
                message = "Missing \"UserId\" parameter.";
                return(false);
            }

            message = string.Empty;
            return(true);
        }
        public dynamic Post(GetGameListRequest request, string appId)
        {
            if (log.IsDebugEnabled) log.DebugFormat("{0} - {1}", Request.RequestUri, JsonConvert.SerializeObject(request));

            string message;
            if (!IsValid(request, out message))
            {
                var errorResponse = new ErrorResponse { Message = message };
                if (log.IsDebugEnabled) log.Debug(JsonConvert.SerializeObject(errorResponse));
                return errorResponse;
            }

            var list = new Dictionary<string, object>();

            foreach (var pair in WebApiApplication.DataAccess.GameGetAll(appId, request.UserId))
            {
                // exists - save result in list
                //if (WebApiApplication.DataAccess.StateExists(appId, pair.Key))
                var stateJson = WebApiApplication.DataAccess.StateGet(appId, pair.Key);
                if (stateJson != null)
                {
                    dynamic customProperties = null;
                    if (stateJson != string.Empty)
                    {
                        var state = JsonConvert.DeserializeObject<dynamic>(stateJson);
                        customProperties = state.CustomProperties;
                    }

                    var gameListItem = new GameListItem(){ ActorNr = int.Parse(pair.Value), Properties = customProperties };

                    list.Add(pair.Key, gameListItem);
                }
                // not exists - delete
                else
                {
                    WebApiApplication.DataAccess.GameDelete(appId, request.UserId, pair.Key);
                }
            }

            var getGameListResponse = new GetGameListResponse { Data = list };
            if (log.IsDebugEnabled) log.Debug(JsonConvert.SerializeObject(getGameListResponse));
            return getGameListResponse;
        }
Example #7
0
        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);
        }
Example #8
0
        protected virtual OperationResponse HandleGetGameList(MasterClientPeer peer, OperationRequest operationRequest)
        {
            var operation = new GetGameListRequest(peer.Protocol, operationRequest);
            OperationResponse response;

            if (OperationHelper.ValidateOperation(operation, log, out response) == false)
            {
                return(response);
            }

            //check is already done in MasterClientPeer
            if (this.LobbyType != AppLobbyType.SqlLobby)
            {
                return(new OperationResponse
                {
                    OperationCode = operationRequest.OperationCode,
                    ReturnCode = (short)ErrorCode.OperationInvalid,
                    DebugMessage = string.Format("Invalid lobby type: {0}", this.LobbyType)
                });
            }

            var gameList = (SqlGameList)GameList;

            ErrorCode errorCode;
            string    message;

            var games = gameList.GetGameList(operation.QueryData, out errorCode, out message);

            if (errorCode != ErrorCode.Ok)
            {
                return(new OperationResponse
                {
                    OperationCode = operationRequest.OperationCode,
                    ReturnCode = (short)errorCode,
                    DebugMessage = message
                });
            }

            var getGameListResponse = this.GetGetGameListResponse(peer, games);

            return(new OperationResponse(operationRequest.OperationCode, getGameListResponse));
        }
        public dynamic Post(GetGameListRequest request, string appId)
        {
            appId = appId.ToLowerInvariant();

            string message;

            if (!IsValid(request, out message))
            {
                var errorResponse = new ErrorResponse {
                    Message = message
                };
                if (log.IsDebugEnabled)
                {
                    log.Debug(JsonConvert.SerializeObject(errorResponse));
                }
                return(errorResponse);
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("{0} - {1}", Request.RequestUri, JsonConvert.SerializeObject(request));
            }

            var list = new Dictionary <string, object>();

            foreach (var pair in WebApiApplication.DataAccess.GameGetAll(appId, request.UserId))
            {
                // exists - save result in list
                //if (WebApiApplication.DataAccess.StateExists(appId, pair.Key))
                var stateJson = WebApiApplication.DataAccess.StateGet(appId, pair.Key);
                if (stateJson != null)
                {
                    dynamic customProperties = null;
                    if (stateJson != string.Empty)
                    {
                        var state = JsonConvert.DeserializeObject <dynamic>(stateJson);
                        customProperties = state.CustomProperties;
                    }

                    var gameListItem = new GameListItem()
                    {
                        ActorNr = int.Parse(pair.Value), Properties = customProperties
                    };

                    list.Add(pair.Key, gameListItem);
                }
                // not exists - delete
                else
                {
                    WebApiApplication.DataAccess.GameDelete(appId, request.UserId, pair.Key);
                }
            }

            var getGameListResponse = new GetGameListResponse {
                Data = list
            };

            if (log.IsDebugEnabled)
            {
                log.Debug(JsonConvert.SerializeObject(getGameListResponse));
            }
            return(getGameListResponse);
        }