コード例 #1
0
ファイル: KingProcesser.cs プロジェクト: xljiulang/KingBrain
        /// <summary>
        /// 从本地和网络查找答案
        /// 并转发给对应的ws客户端
        /// </summary>
        /// <param name="session">会话</param>
        private static void SetResponseWithAnswer(Session session)
        {
            var beginTime   = DateTime.Now;
            var optionIndex = GetOptionIndex(session, out KingQuestion kingQuestion);

            if (kingQuestion == null || kingQuestion.IsValidate() == false)
            {
                return;
            }

            // 推送答案给ws客户端
            const double offsetSecondes = 3.7d;
            var          delay          = (int)beginTime.AddSeconds(offsetSecondes).Subtract(DateTime.Now).TotalMilliseconds;
            var          gameAnswer     = new WsGameAnswer
            {
                Index             = optionIndex,
                Quiz              = kingQuestion.data.quiz,
                Options           = kingQuestion.data.options,
                DelayMilliseconds = delay
            };
            var notifyData = new WsNotifyData <WsGameAnswer>
            {
                Cmd  = WsCmd.GameAnser,
                Data = gameAnswer,
            };

            WsNotifyByClientIP(notifyData, session.clientIP);


            // 改写响应结果
            if (AppConfig.ResponseAnswer == true && optionIndex > -1)
            {
                var json = JsonConvert.SerializeObject(kingQuestion);
                kingQuestion = JsonConvert.DeserializeObject <KingQuestion>(json);
                var quizData = kingQuestion.data;

                quizData.quiz = quizData.quiz + $" 老九提示:[{(char)('A' + optionIndex)}]";
                quizData.options[optionIndex] = quizData.options[optionIndex] + " [√]";

                json = JsonConvert.SerializeObject(kingQuestion);
                session.utilSetResponseBody(json);
            }
        }
コード例 #2
0
 public ActionResult GetHtml([Body] WsGameAnswer model)
 {
     return(this.View("GetHtml", model));
 }