protected override AjaxResult ProcessRequestInternal(HttpContext context) { var login = AuthModule.GetAuthLogin(); AntiFlood.CheckFlood($"{context.Request.CurrentExecutionFilePath}:{login}"); var flags = DbStorage.FindFlags(login); if (ElCapitan.GameEnded(flags)) { throw new HttpException(403, "The End"); } var user = DbStorage.FindUserByLogin(login); if (user == null) { throw new HttpException(403, "Access denied"); } if (user.EndTime != DateTime.MinValue && user.EndTime < DateTime.UtcNow) { throw new HttpException(403, "The End"); } var question = context.Request.Form["question"].TrimToNull(); if (question == null) { throw new HttpException(400, "Message is empty"); } if (question.Length > Settings.MaxMsgLength) { throw new HttpException(400, "Message too large"); } Flag flag; File[] files; DateTime timer; var answer = ElCapitan.GetAnswer(question, flags, out flag, out files, out timer); var msg = new Msg { Text = answer, Time = DateTime.UtcNow, Type = MsgType.Answer }; DbStorage.AddDialog(login, new Msg { Text = question, Time = DateTime.UtcNow, Type = MsgType.Question }, new[] { msg }, flag, files); return(new AjaxResult { Messages = new[] { msg }, Files = files, Score = flag != null ? 1 : 0, Timer = timer == DateTime.MinValue ? DateTime.MinValue : (user.EndTime != DateTime.MinValue ? user.EndTime : timer) }); }
protected override AjaxResult ProcessRequestInternal(HttpContext context) { var login = AuthModule.GetAuthLogin(); AntiFlood.CheckFlood($"{context.Request.CurrentExecutionFilePath}:{login}"); /*if(DateTime.UtcNow > Settings.BombTimerEnd) * throw new HttpException(403, "Connection lost...");*/ var user = DbStorage.FindUserByLogin(login); if (user == null) { throw new HttpException(403, "Access denied"); } var revision = DbStorage.FindBroadcast(login); var flags = DbStorage.FindFlags(login); var timer = ElCapitan.HasBombTimer(flags) ? (user.EndTime != DateTime.MinValue ? user.EndTime : Settings.BombTimerEnd) : DateTime.MinValue; var answers = ElCapitan.GetBroadcastMsgs(ref revision); if (answers.Length == 0) { return new AjaxResult { Messages = null, Files = null, Score = 0, Timer = timer } } ; var msgs = answers.Select(msg => new Msg { Text = msg, Time = DateTime.UtcNow, Type = MsgType.Answer }).ToArray(); DbStorage.AddDialog(login, null, msgs, null, null, revision); return(new AjaxResult { Messages = msgs, Files = null, Score = 0, Timer = timer }); } }