/// <summary> /// Fired when the player posts a new comment. /// </summary> /// <param name="player"></param> /// <param name="request"></param> /// <returns></returns> private async Task <ActionResult> OnRequestUpdateComment(Player player, GrimRequest request) { if (!request.TryGetParameterByKey("bbs_board_id", out var bbsBoardIdParam) || !int.TryParse(bbsBoardIdParam.Text, out int bbs_board_id)) { _logger.LogWarning($"Got bbs.updateComment request with missing 'bbs_board_id' parameter"); return(BadRequest()); } if (!request.TryGetParameterByKey("comment", out var comment)) { _logger.LogWarning($"Got bbs.updateComment request with missing 'bbs_comment_id' parameter"); return(BadRequest()); } if (comment.Text.Length == 0 || comment.Text.Length > 140) { _logger.LogWarning("Got bbs.updateComment with empty or too long comment? In: {length}, Max: 30", comment.Text.Length); return(BadRequest()); } // Bbs Board ids is just the user number - get the user using it var user = await _userDb.GetByIDAsync(bbs_board_id); if (user is null) { BadRequest(); } var newComment = new BbsDTO(bbs_board_id, player.Data.Id, comment.Text, DateTime.Now); await _bbsDb.AddAsync(newComment); return(Ok(GrimResult.FromBool(true))); }
/// <summary> /// Fired when the player deletes an image, or can also be used for the player /// to sync their local images to the server and removing the ones that the player no longer has. /// </summary> /// <param name="player"></param> /// <param name="gRequest"></param> /// <returns></returns> private async Task <ActionResult> OnRequestDeleteImage(Player player, GrimRequest gRequest) { if (Player is null) { _logger.LogWarning("Could not get current player for host {host}", Request.Host); return(Unauthorized()); } if (!gRequest.TryGetParameterLongByKey("photo_id", out long photo_id)) { _logger.LogWarning($"Got photo.upload request with missing 'photo_id' parameter"); return(BadRequest()); } var photo = await _photoDb.GetByIDAsync(photo_id); if (photo is null) { return(NotFound()); } if (photo.UserId != player.Data.Id) { return(Forbid()); } await _photoDb.RemoveAsync(photo_id); return(Ok(GrimResult.FromBool(true))); }
public async Task <ActionResult> Get() { GrimRequest requestReq = await GrimRequest.Deserialize(Request.Body); if (requestReq is null) { // Handle var badReq = GrimResult.FromInt(-1); return(BadRequest(badReq)); } _logger.LogDebug("<- Got ranking request: {command}", requestReq.Command); switch (requestReq.Command) { case "ranking.calc2": return(OnGetCalc2Ranking(requestReq)); case "ranking.getCount": return(OnGetCount(requestReq)); case "ranking.getListFriends": return(OnGetFriendList(requestReq)); } _logger.LogDebug("<- Got unknown ranking command: {command}", requestReq.Command); var badReqs = GrimResult.FromInt(-1); return(BadRequest(badReqs)); }
public ActionResult OnGetCount(GrimRequest request) { if (!request.TryGetParameterByKey("board_id", out var boardIdParam)) { _logger.LogWarning("Got ranking getCount request without 'board_id'"); return(BadRequest()); } return(Ok(GrimResult.FromInt(1))); }
private ActionResult OnSetLanguage(GrimRequest gRequest) { if (!gRequest.TryGetParameterByKey("language", out GrimRequestParam param)) { _logger.LogWarning("Got missing language parameter for language.set"); return(BadRequest()); } return(Ok(GrimResult.FromString(param.Text.ToLower()))); }
private ActionResult OnGetServerTime(GrimRequest gRequest) { if (_gsOptions.GameType != GameType.GT5) { _logger.LogWarning("Got servertime.get request for non GT5"); return(BadRequest()); } var result = GrimResult.FromDateTimeRfc3339(DateTime.Now); return(Ok(result)); }
public async Task <ActionResult> Post() { var player = Player; if (player is null) { _logger.LogWarning("Could not get current player for host {host}", Request.Host); return(Unauthorized()); } GrimRequest gRequest = await GrimRequest.Deserialize(Request.Body); if (gRequest is null) { // Handle var badReq = GrimResult.FromInt(-1); return(BadRequest(badReq)); } _logger.LogDebug("<- {command}", gRequest.Command); switch (gRequest.Command) { case "profile.update": return(await OnProfileUpdate(player, gRequest)); case "profile.getspecialstatus": return(OnGetSpecialStatus()); case "profile.updatefriendlist": return(await OnUpdateFriendList(gRequest)); case "profile.getsimplefriendlist": return(await OnGetSimpleFriendList(player)); case "profile.updateNickname": return(await OnUpdateNickname(player, gRequest)); case "profile.setpresence": return(SetPresence(gRequest)); case "profile.getSpecialList": return(await OnGetUserSpecialPresentList(player, gRequest)); } _logger.LogDebug("Received unimplemented profile call: {command}", gRequest.Command); var res = GrimResult.FromInt(-1); return(BadRequest(res)); }
/// <summary> /// Fired when the player updates their welcome message (GT5). /// </summary> /// <param name="player"></param> /// <param name="message">New welcome message.</param> /// <returns></returns> private async Task <ActionResult> OnUpdateAutoMessage(Player player, string message) { if (message.Length > 30) { return(BadRequest()); } var data = player.Data; data.WelcomeMessage = message; await _userDB.UpdateWelcomeMessage(data); return(Ok(GrimResult.FromBool(true))); }
// see requestActionLogList in gtmode.ad private async Task <ActionResult> OnActionPutLog(Player player, GrimRequest gRequest) { if (!gRequest.TryGetParameterByKey("action_type", out var actionTypeParam) || !int.TryParse(actionTypeParam.Text, out int action_type)) { _logger.LogWarning($"Got actionlog.putActionLog request with missing 'action_type' parameter"); return(BadRequest()); } if (!gRequest.TryGetParameterByKey("value1", out var value1Param)) { _logger.LogWarning($"Got actionlog.putActionLog request with missing 'value1' parameter"); return(BadRequest()); } if (!gRequest.TryGetParameterByKey("value2", out var value2Param)) { _logger.LogWarning($"Got actionlog.putActionLog request with missing 'value2' parameter"); return(BadRequest()); } if (!gRequest.TryGetParameterByKey("value3", out var value3Param)) { _logger.LogWarning($"Got actionlog.putActionLog request with missing 'value3' parameter"); return(BadRequest()); } if (!gRequest.TryGetParameterByKey("value4", out var value4Param)) { _logger.LogWarning($"Got actionlog.putActionLog request with missing 'value4' parameter"); return(BadRequest()); } if (!gRequest.TryGetParameterByKey("value5", out var value5Param)) { _logger.LogWarning($"Got actionlog.putActionLog request with missing 'value5' parameter"); return(BadRequest()); } if (!ActionLog.Tags.TryGetValue(value1Param.Text, out string def)) { return(Ok()); } // TODO: Some actionlog checks LogAction(player, def, value2Param.Text, value3Param.Text, value4Param.Text, value5Param.Text); var log = new ActionLogDTO(player.Data.Id, DateTime.Now, value1Param.Text, value2Param.Text, value3Param.Text, value4Param.Text, value5Param.Text); await _actionLogDb.AddAsync(log); return(Ok(GrimResult.FromBool(true))); }
/// <summary> /// Fired when the player updates their progression. /// </summary> /// <param name="player"></param> /// <param name="license_level">Current license of the player.</param> /// <param name="achievement">Achievement count.</param> /// <param name="trophy">Trophy count.</param> /// <param name="car_count">Total car count.</param> /// <param name="license_gold">Total golded licenses.</param> /// <param name="odometer">Total distance travelled.</param> /// <returns></returns> private async Task <ActionResult> OnRequestUpdateGameStats(Player player, int license_level, int achievement, int trophy, int car_count, int license_gold, float odometer) { // TODO: Do game stats verification var data = player.Data; data.LicenseLevel = license_level; data.AchievementCount = achievement; data.TrophyCount = trophy; data.CarCount = car_count; data.LicenseGoldCount = license_gold; data.Odometer = odometer; await _userDB.UpdateGameStats(data); return(Ok(GrimResult.FromBool(true))); }
/// <summary> /// Fired when the player updates their menu design (GT5). /// </summary> /// <param name="player"></param> /// <param name="menuColorParam">Menu color index (string).</param> /// <param name="menuMatiereParam">Menu matiere index (string).</param> /// <returns></returns> private async Task <ActionResult> OnUpdateMyHomeDesign(Player player, string menuColorParam, string menuMatiereParam) { if (!int.TryParse(menuColorParam, out int menuColorIndex)) { return(BadRequest()); } if (!int.TryParse(menuMatiereParam, out int menuMatiereIndex)) { return(BadRequest()); } player.Data.MenuColor = menuColorIndex; player.Data.MenuMatiere = menuMatiereIndex; await _userDB.UpdateHomeDesign(player.Data); return(Ok(GrimResult.FromBool(true))); }
/// <summary> /// Fired when the player updates their helmet data. /// </summary> /// <param name="player"></param> /// <param name="helmetParam">Helmet Id (string).</param> /// <param name="helmetColorParam">Helmet Color Index (string).</param> /// <returns></returns> private async Task <ActionResult> OnUpdateHelmet(Player player, string helmetParam, string helmetColorParam) { if (!int.TryParse(helmetParam, out int helmetId)) { return(BadRequest()); } if (!int.TryParse(helmetColorParam, out int helmetColorId)) { return(BadRequest()); } player.Data.HelmetId = helmetId; player.Data.HelmetColorId = helmetColorId; await _userDB.UpdateHelmet(player.Data); return(Ok(GrimResult.FromBool(true))); }
/// <summary> /// Fired when the player updates their suit data. /// </summary> /// <param name="player"></param> /// <param name="wearParam">Wear Id (string).</param> /// <param name="wearColorParam">Wear Color Index (string).</param> /// <returns></returns> private async Task <ActionResult> OnUpdateWear(Player player, string wearParam, string wearColorParam) { if (!int.TryParse(wearParam, out int wearId)) { return(BadRequest()); } if (!int.TryParse(wearColorParam, out int wearColorId)) { return(BadRequest()); } player.Data.WearId = wearId; player.Data.WearColorId = wearColorId; await _userDB.UpdateWear(player.Data); return(Ok(GrimResult.FromBool(true))); }
public async Task <ActionResult> Post() { var player = Player; if (player is null) { _logger.LogWarning("Could not get current player for host {host}", Request.Host); return(Unauthorized()); } if (_gsOptions.GameType != GameType.GT5) { _logger.LogWarning("Got a bbs request on a non GT5 server from host: {host}", Request.Host); return(Unauthorized()); } GrimRequest gRequest = await GrimRequest.Deserialize(Request.Body); if (gRequest is null) { // Handle var badReq = GrimResult.FromInt(-1); return(BadRequest(badReq)); } _logger.LogDebug("<- {command}", gRequest.Command); switch (gRequest.Command) { case "bbs.getCommentList": return(await OnRequestGetCommentList(player, gRequest)); case "bbs.updateComment": return(await OnRequestUpdateComment(player, gRequest)); case "bbs.deleteComment": return(await OnRequestDeleteComment(player, gRequest)); } _logger.LogDebug("Received unimplemented bbs call: {command}", gRequest.Command); var res = GrimResult.FromInt(-1); return(BadRequest(res)); }
/// <summary> /// Fired when the player deletes a comment from their board. /// </summary> /// <param name="player"></param> /// <param name="request"></param> /// <returns></returns> private async Task <ActionResult> OnRequestDeleteComment(Player player, GrimRequest request) { if (!request.TryGetParameterByKey("bbs_comment_id", out var commentIdParam) || !int.TryParse(commentIdParam.Text, out int bbs_comment_id)) { _logger.LogWarning($"Got bbs.deleteComment request with missing 'bbs_comment_id' parameter"); return(BadRequest()); } // Get user's comment var comment = await _bbsDb.GetByIDAsync(bbs_comment_id); if (comment is null || (comment.BbsBoardId != player.Data.Id && comment.AuthorId != player.Data.Id)) { return(Forbid()); } await _bbsDb.RemoveAsync(bbs_comment_id); return(Ok(GrimResult.FromBool(true))); }
public async Task <ActionResult> Post() { var player = Player; if (player is null) { _logger.LogWarning("Could not get current player for host {host}", Request.Host); return(Unauthorized()); } if (_gsOptions.GameType != GameType.GT6) { _logger.LogWarning("Got course getlist request on non GT6"); return(BadRequest()); } GrimRequest requestReq = await GrimRequest.Deserialize(Request.Body); if (requestReq is null) { // Handle var badReq = GrimResult.FromInt(-1); return(BadRequest(badReq)); } _logger.LogDebug("<- Got course request: {command}", requestReq.Command); switch (requestReq.Command) { case "course.getlist": return(await OnGetList(requestReq, player)); case "course.update": return(await OnUpdateCourse(requestReq, player)); } _logger.LogDebug("<- Got unknown course command: {command}", requestReq.Command); var badReqs = GrimResult.FromInt(-1); return(BadRequest(badReqs)); }
public async Task <ActionResult> Post(string server) { var player = Player; if (player is null) { _logger.LogWarning("Could not get current player for host {host}", Request.Host); return(Unauthorized()); } if (_gsOptions.GameType != GameType.GT5) { _logger.LogWarning("Got actionlog request on a non GT5 server from host: {host}", Request.Host); return(Unauthorized()); } GrimRequest gRequest = await GrimRequest.Deserialize(Request.Body); if (gRequest is null) { // Handle var badReq = GrimResult.FromInt(-1); return(BadRequest(badReq)); } _logger.LogDebug("<- {command}", gRequest.Command); switch (gRequest.Command) { case "actionlog.putActionLog": return(await OnActionPutLog(player, gRequest)); } _logger.LogDebug("Got unimplemented actionlog call: {command}", gRequest.Command); return(BadRequest()); }
public async Task <ActionResult> OnRequestUploadImage() { Player player = Player; if (player is null) { _logger.LogWarning("Could not get current player for host {host}", Request.Host); return(Unauthorized()); } var value = Request.Headers["X-gt-xml"]; if (value.Count != 1) { return(BadRequest()); } string xml = value[0]; if (string.IsNullOrEmpty(xml)) { return(BadRequest()); } GrimRequest gRequest = GrimRequest.Deserialize(xml); if (gRequest is null) { return(BadRequest()); } if (gRequest.Command != "photo.upload") { return(BadRequest()); } if (!gRequest.TryGetParameterByKey("place", out var place)) { _logger.LogWarning($"Got photo.upload request with missing 'place' parameter"); return(BadRequest()); } if (!gRequest.TryGetParameterByKey("car_name", out var car_name)) { _logger.LogWarning($"Got photo.upload request with missing 'car_name' parameter"); return(BadRequest()); } if (!gRequest.TryGetParameterByKey("comment", out var comment)) { _logger.LogWarning($"Got photo.upload request with missing 'comment' parameter"); return(BadRequest()); } if (comment.Text.Length > 140) { _logger.LogWarning("Received photo.upload request with too long 'comment' parameter (len {comment.Text.Length} > 140)", comment.Text.Length); return(BadRequest()); } // type 3 is regular photo upload, 1 is avatar if (!gRequest.TryGetParameterIntByKey("type", out int type)) { _logger.LogWarning($"Got photo.upload request with missing 'type' parameter"); return(BadRequest()); } // Make sure they don't already have more photos that we allow, gets big quick if (await _photoDb.GetPhotoCountOfUserAsync(player.Data.Id) >= GTConstants.MaxPhotos) { return(Forbid()); } using var ms = Program.StreamManager.GetStream(); await Request.Body.CopyToAsync(ms); ms.Position = 0; // Check the image itself if (!await VerifyImage(ms, GTConstants.MaxPhotoWidth, GTConstants.MaxPhotoHeight)) { return(BadRequest()); } if (type != 3) { return(BadRequest()); } PhotoDTO photo = new PhotoDTO(Player.Data.Id, DateTime.Now, comment.Text, car_name.Text, place.Text); long newId = await _photoDb.AddAsync(photo); Directory.CreateDirectory($"{_gsOptions.XmlResourcePath}/photo/image"); ms.Position = 0; using (var fs = new FileStream($"{_gsOptions.XmlResourcePath}/photo/image/{newId}_0.jpg", FileMode.Create)) await ms.CopyToAsync(fs); // To let the client aware of the photo's online id var result = GrimResult.FromLong(newId); return(Ok(result)); }
public GrimResult Post() { _logger.LogInformation($"Got session extend request"); return(GrimResult.FromBool(true)); }
/// <summary> /// Fired when the player requests any kind of profile update. /// </summary> /// <param name="player"></param> /// <param name="requestReq"></param> /// <returns></returns> private async Task <ActionResult> OnProfileUpdate(Player player, GrimRequest requestReq) { // requestUpdateGameStats or updateMyHomeProfile? if (requestReq.TryGetParameterByKey("license_level", out var licenseLevelParam) && int.TryParse(licenseLevelParam.Text, out int license_level)) { if (!requestReq.TryGetParameterByKey("achievement", out var achievementParam) || !int.TryParse(achievementParam.Text, out int achievement)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("trophy", out var trophyParam) || !int.TryParse(trophyParam.Text, out int trophy)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("car_count", out var carCountParam) || !int.TryParse(carCountParam.Text, out int car_count)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("license_gold", out var licenseGoldParam) || !int.TryParse(licenseGoldParam.Text, out int license_gold)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("odometer", out var odometerParam) || !float.TryParse(odometerParam.Text, out float odometer)) { return(BadRequest()); } // Can we assume we have don't have more? If so, it's requestUpdateGameStats if (!requestReq.TryGetParameterByKey("win_count", out var winCountParam)) { return(await OnRequestUpdateGameStats(player, license_level, achievement, trophy, car_count, license_gold, odometer)); } // Then we know its a global profile update - UpdateMyHomeProfile if (!int.TryParse(winCountParam.Text, out int win_count)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("credit", out var creditParam) || !int.TryParse(creditParam.Text, out int credit)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("license_silver", out var licenseSilverParam) || !int.TryParse(licenseSilverParam.Text, out int license_silver)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("license_bronze", out var licenseBronzeParam) || !int.TryParse(licenseBronzeParam.Text, out int license_bronze)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("aspec_level", out var aspecLevelParam) || !int.TryParse(aspecLevelParam.Text, out int aspec_level)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("bspec_level", out var bspecLevelParam) || !int.TryParse(bspecLevelParam.Text, out int bspec_level)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("aspec_exp", out var aspecExpParam) || !int.TryParse(aspecExpParam.Text, out int aspec_exp)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("bspec_exp", out var bspecExpParam) || !int.TryParse(bspecExpParam.Text, out int bspec_exp)) { return(BadRequest()); } var data = player.Data; data.WinCount = win_count; data.Credit = credit; data.LicenseSilverCount = license_silver; data.LicenseBronzeCount = license_bronze; data.ASpecLevel = aspec_level; data.ASpecExp = aspec_exp; data.BSpecLevel = bspec_level; data.BSpecExp = bspec_exp; await _userDB.UpdateMyHomeProfile(data); return(Ok(GrimResult.FromBool(true))); } // Can we assume its requestUpdateOnlineProfile? else if (requestReq.TryGetParameterByKey("profile_level", out var profileLevelParam) && requestReq.Params.ParamList.Count == 5) { if (!int.TryParse(profileLevelParam.Text, out int profile_level)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("comment_level", out var commentLevelParam) || !int.TryParse(commentLevelParam.Text, out int comment_level)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("playtime_level", out var playtimeLevelParam) || !int.TryParse(playtimeLevelParam.Text, out int playtime_level)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("playtime", out var playtimeParam)) { return(BadRequest()); } if (!requestReq.TryGetParameterByKey("comment", out var commentParam)) { return(BadRequest()); } return(await OnUpdateOnlineProfile(player, profile_level, comment_level, playtime_level, playtimeParam.Text, commentParam.Text)); } else if (requestReq.TryGetParameterByKey("welcomemessage", out var welcomeMessage) && requestReq.Params.ParamList.Count == 1) { return(await OnUpdateAutoMessage(player, welcomeMessage.Text)); } else if (requestReq.TryGetParameterByKey("helmet", out var helmet) && requestReq.TryGetParameterByKey("helmet_color", out var helmetColor)) { return(await OnUpdateHelmet(player, helmet.Text, helmetColor.Text)); } else if (requestReq.TryGetParameterByKey("wear", out var wear) && requestReq.TryGetParameterByKey("wear_color", out var wear_color)) { return(await OnUpdateWear(player, wear.Text, wear_color.Text)); } else if (requestReq.TryGetParameterByKey("menu_color", out var menu_color) && requestReq.TryGetParameterByKey("menu_matiere", out var menu_matiere)) { return(await OnUpdateMyHomeDesign(player, menu_color.Text, menu_matiere.Text)); } // No parsing is done. return(BadRequest()); }