// ReSharper restore FunctionNeverReturns

        public void SendUser(string message, SocketConnection item)
        {
            if (!item.ConnectionSocket.Connected)
            {
                return;
            }
            Logger.Log(Enums.LogType.Msg, message);
            try
            {
                if (item.IsDataMasked)
                {
                    var dr = new DataFrame(message);
                    item.ConnectionSocket.Send(dr.GetBytes());
                }
                else
                {
                    item.ConnectionSocket.Send(firstByte);
                    item.ConnectionSocket.Send(Encoding.UTF8.GetBytes(message));
                    item.ConnectionSocket.Send(lastByte);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(Enums.LogType.Error, ex.Message);
            }
        }
Example #2
0
        public void Plan(JObject jo, SocketConnection sConn)
        {
            var    user = jo["UserName"].ToString();
            string msg;

            if (!userList.Contains(user))
            {
                userList.Add(user);
                msg = string.Format("RevicePlan|True|{0}", user);
                Send(msg);
            }
            else
            {
                msg = string.Format("RevicePlan|False|你要爪子,准备了还点。。");
                var dr = new DataFrame(msg);
                sConn.ConnectionSocket.Send(dr.GetBytes());
            }
        }
Example #3
0
        public void SendTitle(JObject jo, SocketConnection sConn)
        {
            var    userName = jo["UserName"].ToString();
            string msg;

            if (titleList.Count == 0)
            {
                var requestPeople    = jo["People"].ToString();
                var requestGhost     = jo["Ghost"].ToString();
                var requestPeopleNum = Convert.ToInt32(jo["PeopleNum"].ToString());
                var requestGhostNum  = Convert.ToInt32(jo["GhostNum"].ToString());
                var requestXiaoBai   = Convert.ToInt32(jo["XiaoBai"].ToString());

                titleUserName = userName;
                people        = requestPeople;
                ghost         = requestGhost;
                peopleNum     = requestPeopleNum;
                ghostNum      = requestGhostNum;

                for (var i = 0; i < requestPeopleNum; i++)
                {
                    titleList.Add(requestPeople);
                }
                for (var i = 0; i < requestGhostNum; i++)
                {
                    titleList.Add(requestGhost);
                }
                for (var i = 0; i < requestXiaoBai; i++)
                {
                    titleList.Add("你是小白,伤不起");
                }
                type = "_plan";
                msg  = string.Format("ReviceTitle|{0}已出题,请要参加的人员,赶快准备!|{0}", userName);
                Send(msg);
            }
            else
            {
                msg = string.Format("ReviceTitle|出题失败!{0}已出题,请先完成当前题目!!", titleUserName);
                var dr = new DataFrame(msg);
                sConn.ConnectionSocket.Send(dr.GetBytes());
            }
        }
Example #4
0
        public void StartGame(JObject jo, SocketConnection sConn)
        {
            userList.Remove(sConn.Name);
            judge = sConn.Name;

            string msg;

            if (titleList.Count != userList.Count)
            {
                msg = string.Format("ReviceStartGame|False|抱歉,出题要求{0}人参加,但现在只有{1}人,所以游戏启动失败!", titleList.Count, userList.Count);
                Send(msg);
            }
            else
            {
                var num = Rank();
                speak = userList[0];

                var i = 0;
                foreach (var item in connectionSocketList)
                {
                    if (item.Name != sConn.Name)
                    {
                        var title = titleList[num[i] - 1];
                        msg = string.Format("ReviceStartGame|True|游戏开始,{1}开始发言!|{0}|{1}", title, speak);

                        if (!userTitle.ContainsKey(item.Name))
                        {
                            userTitle.Add(item.Name, title);
                        }
                        i++;
                    }
                    else
                    {
                        type = "_game";
                        msg  = string.Format("ReviceStartGame|True|游戏开始,{0}开始发言!|你是法官|{0}", speak);
                    }
                    var dr = new DataFrame(msg);
                    item.ConnectionSocket.Send(dr.GetBytes());
                }
            }
        }
Example #5
0
        public void VoteUser(JObject jo, SocketConnection sConn)
        {
            var userName = jo["UserName"].ToString();
            var voteUser = jo["VoteUser"].ToString();

            if (!voteList.ContainsKey(userName))
            {
                voteList.Add(userName, voteUser);
            }
            else
            {
                const string message = "ReviceVote|Flase|你已经投过票了,请不要重复投票!";
                var          dr      = new DataFrame(message);
                sConn.ConnectionSocket.Send(dr.GetBytes());
                return;
            }

            if (userList.Count != voteList.Count)
            {
                return;
            }


            var result = voteList.GroupBy(d => d.Value).Select(
                n => new
            {
                Count = n.Count(),
                value = n.FirstOrDefault().Value
            }).OrderByDescending(n => n.Count).ToList();

            var voteTxt = voteList.Aggregate("", (current, vote) => current + (":" + vote.Key + ":" + vote.Value));

            string resultVote = null;

            for (var i = 0; i < result.Count - 1; i++)
            {
                if (result[i].Count == result[i + 1].Count)
                {
                    resultVote += "," + result[i + 1].value;
                }
                else
                {
                    break;
                }
            }

            string style;
            string isOver;

            if (resultVote == null)
            {
                userList.Remove(result[0].value);
                resultVote = string.Format("{0}获得了{1}票,所以{0}出局!", result[0].value, result[0].Count);
                isOver     = IsOver(result[0].value, userTitle[result[0].value]);
                style      = "Kill";
            }
            else
            {
                resultVote = string.Format("{0}等人票数相同,都是{1}票,所以进行PK!", result[0].value + resultVote, result[0].Count);
                style      = "Pk";
                isOver     = "continue";
            }

            voteList.Clear();

            var msg = string.Format("ReviceVote|True|{0}|{1}|{2}|{3}|{4}|{5}", voteTxt, style, resultVote,
                                    result[0].value, userList[0], isOver);

            Send(msg);

            speak = userList[0];

            if (isOver == "_over")
            {
                GameOver();
            }
        }
        public void VoteUser(JObject jo, SocketConnection sConn)
        {
            var userName = jo["UserName"].ToString();
            var voteUser = jo["VoteUser"].ToString();

            if (!voteList.ContainsKey(userName))
            {
                voteList.Add(userName, voteUser);
            }
            else
            {
                const string message = "ReviceVote|Flase|你已经投过票了,请不要重复投票!";
                var dr = new DataFrame(message);
                sConn.ConnectionSocket.Send(dr.GetBytes());
                return;
            }

            if (userList.Count != voteList.Count) return;

            var result = voteList.GroupBy(d => d.Value).Select(
                n => new
                {
                    Count = n.Count(),
                    value = n.FirstOrDefault().Value
                }).OrderByDescending(n => n.Count).ToList();

            var voteTxt = voteList.Aggregate("", (current, vote) => current + (":" + vote.Key + ":" + vote.Value));

            string resultVote = null;
            for (var i = 0; i < result.Count - 1; i++)
            {
                if (result[i].Count == result[i + 1].Count)
                {
                    resultVote += "," + result[i + 1].value;
                }
                else
                {
                    break;
                }
            }

            string style;
            string isOver;
            if (resultVote == null)
            {
                userList.Remove(result[0].value);
                resultVote = string.Format("{0}获得了{1}票,所以{0}出局!", result[0].value, result[0].Count);
                isOver = IsOver(result[0].value, userTitle[result[0].value]);
                style = "Kill";
            }
            else
            {
                resultVote = string.Format("{0}等人票数相同,都是{1}票,所以进行PK!", result[0].value + resultVote, result[0].Count);
                style = "Pk";
                isOver = "continue";
            }

            voteList.Clear();

            var msg = string.Format("ReviceVote|True|{0}|{1}|{2}|{3}|{4}|{5}", voteTxt, style, resultVote,
                                    result[0].value, userList[0], isOver);
            Send(msg);

            speak = userList[0];

            if (isOver == "_over")
            {
                GameOver();
            }
        }
        public void StartGame(JObject jo, SocketConnection sConn)
        {
            userList.Remove(sConn.Name);
            judge = sConn.Name;

            string msg;
            if (titleList.Count != userList.Count)
            {
                msg = string.Format("ReviceStartGame|False|抱歉,出题要求{0}人参加,但现在只有{1}人,所以游戏启动失败!", titleList.Count, userList.Count);
                Send(msg);
            }
            else
            {
                var num = Rank();
                speak = userList[0];

                var i = 0;
                foreach (var item in connectionSocketList)
                {
                    if (item.Name != sConn.Name)
                    {
                        var title = titleList[num[i] - 1];
                        msg = string.Format("ReviceStartGame|True|游戏开始,{1}开始发言!|{0}|{1}", title, speak);

                        if (!userTitle.ContainsKey(item.Name))
                            userTitle.Add(item.Name, title);
                        i++;
                    }
                    else
                    {
                        type = "_game";
                        msg = string.Format("ReviceStartGame|True|游戏开始,{0}开始发言!|你是法官|{0}", speak);
                    }
                    var dr = new DataFrame(msg);
                    item.ConnectionSocket.Send(dr.GetBytes());
                }
            }
        }
        public void SendTitle(JObject jo, SocketConnection sConn)
        {
            var userName = jo["UserName"].ToString();
            string msg;
            if (titleList.Count == 0)
            {
                var requestPeople = jo["People"].ToString();
                var requestGhost = jo["Ghost"].ToString();
                var requestPeopleNum = Convert.ToInt32(jo["PeopleNum"].ToString());
                var requestGhostNum = Convert.ToInt32(jo["GhostNum"].ToString());
                var requestXiaoBai = Convert.ToInt32(jo["XiaoBai"].ToString());

                titleUserName = userName;
                people = requestPeople;
                ghost = requestGhost;
                peopleNum = requestPeopleNum;
                ghostNum = requestGhostNum;

                for (var i = 0; i < requestPeopleNum; i++)
                {
                    titleList.Add(requestPeople);
                }
                for (var i = 0; i < requestGhostNum; i++)
                {
                    titleList.Add(requestGhost);
                }
                for (var i = 0; i < requestXiaoBai; i++)
                {
                    titleList.Add("你是小白,伤不起");
                }
                type = "_plan";
                msg = string.Format("ReviceTitle|{0}已出题,请要参加的人员,赶快准备!|{0}", userName);
                Send(msg);
            }
            else
            {
                msg = string.Format("ReviceTitle|出题失败!{0}已出题,请先完成当前题目!!", titleUserName);
                var dr = new DataFrame(msg);
                sConn.ConnectionSocket.Send(dr.GetBytes());
            }
        }
 public void Plan(JObject jo, SocketConnection sConn)
 {
     var user = jo["UserName"].ToString();
     string msg;
     if (!userList.Contains(user))
     {
         userList.Add(user);
         msg = string.Format("RevicePlan|True|{0}", user);
         Send(msg);
     }
     else
     {
         msg = string.Format("RevicePlan|False|你要爪子,准备了还点。。");
         var dr = new DataFrame(msg);
         sConn.ConnectionSocket.Send(dr.GetBytes());
     }
 }
Example #10
0
 // ReSharper restore FunctionNeverReturns
 public void SendUser(string message, SocketConnection item)
 {
     if (!item.ConnectionSocket.Connected) return;
     Logger.Log(Enums.LogType.Msg, message);
     try
     {
         if (item.IsDataMasked)
         {
             var dr = new DataFrame(message);
             item.ConnectionSocket.Send(dr.GetBytes());
         }
         else
         {
             item.ConnectionSocket.Send(firstByte);
             item.ConnectionSocket.Send(Encoding.UTF8.GetBytes(message));
             item.ConnectionSocket.Send(lastByte);
         }
     }
     catch (Exception ex)
     {
         Logger.Log(Enums.LogType.Error, ex.Message);
     }
 }