public override void DoCommand()
        {
            byte[]       content    = Decode.DecodeFirstContendBtyes(bytes);
            LoginInfo    myInfo     = DataDo.Json2Object <LoginInfo>(content);
            string       strContent = "SELECT * FROM counter where id=" + myInfo.id + " ;";
            PersonalInfo user       = SqlConn.Select(strContent);

            if (user != null)
            {
                if (user.password == myInfo.passWord)
                {
                    Console.WriteLine("用户登陆成功");
                    Server.AddUser(myInfo.id, conn);
                    conn.ID = myInfo.id;                    //客户端的id作为属性存起来了便于访问

                    user.status = (int)PersonStatus.OnLine; //在线
                    PersonalInfo.ChangeStatusInfo(int.Parse(conn.ID), "", (int)PersonStatus.OnLine);
                    conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(user)));
                }
                else
                {
                    Console.WriteLine("密码错误");
                    //回客户端消息
                }
            }
            else
            {
                Console.WriteLine("账号不存在");
                //回客户端消息
            }
        }
Example #2
0
        public override void DoCommand()
        {
            int         type = BitConverter.ToInt32(bytes, 8);//消息类型:私聊/群聊
            MessageInfo info = DataDo.Json2Object <MessageInfo>(Decode.DecodeSecondContendBtyes(bytes));

            Console.WriteLine("ChatCommad=>msg:" + " MYid:" + info.sendId + " Fridend:" + info.toIds + " Msg:" + info.content);
            if (Server.connMap != null)
            {
                //Console.WriteLine("当前连接数:" + Server.connMap.Count);
                if (type == PrivateChat)
                {
                    Conn receiver_conn;
                    Server.connMap.TryGetValue(info.toIds.ToString(), out receiver_conn);

                    if (receiver_conn != null)        //做一个判断receiver_conn是否为空,就不需要在做遍历了
                    {
                        receiver_conn.SendBts(bytes); //转发给接收方
                        Console.WriteLine("已发送");
                    }
                    else
                    {
                        Console.WriteLine("发送失败,好友不在线");
                    }
                }
                else
                {
                    Console.WriteLine("群发");
                }
            }
        }
        /// <summary>
        /// 发单摸结果
        /// </summary>
        /// <param name="secondCommand"></param>
        /// <param name="roomInfo"></param>
        /// <param name="cardIndex">所摸牌在桌牌中的下标</param>
        /// <param name="card">所摸牌</param>
        void ForeachSendDraw(int secondCommand, RoomInfo roomInfo, int cardIndex, BaseCard card)
        {
            byte[] data_1 = BitConverter.GetBytes(cardIndex);
            byte[] data_3;
            if (card == null)
            {
                data_3 = new byte[0];
            }
            else
            {
                data_3 = DataDo.Object2Json(card);
            }
            byte[] datas = new byte[data_1.Length + data_3.Length];
            Buffer.BlockCopy(data_1, 0, datas, 0, 4);
            Buffer.BlockCopy(data_3, 0, datas, 4, data_3.Length);
            Conn conn;

            Console.WriteLine("----roomInfo.member.Count:" + roomInfo.member.Count);
            for (int i = 0; i < roomInfo.member.Count; i++)
            {
                Server.connMap.TryGetValue(roomInfo.member[i].id.ToString(), out conn);
                byte[] data = Incode.IncodeSecondaryCommand(type, secondCommand, datas);
                conn.SendBts(data);
            }
        }
Example #4
0
        /// <summary>
        /// 退出房间
        /// </summary>
        void ExitRoom()
        {
            RoomMsg  roomMsg  = DataDo.Json2Object <RoomMsg>(Decode.DecodeSecondContendBtyes(bytes));
            RoomInfo roomInfo = GameCommand.GetRoom(roomMsg.roomNum);

            if (roomInfo != null)
            {
                PersonalInfo.ChangeStatusInfo(roomMsg.otherId, "", (int)PersonStatus.OnLine);

                PersonalInfo people = roomInfo.member.Find(it =>
                {
                    if (it.id == roomMsg.otherId)//找到要删的人
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
                roomInfo.RemoveMember(people.id);
                //if (roomMsg.otherId == roomInfo.host_Id && roomInfo.member.Count>0)//退出者的ID为房主
                //{
                //    roomInfo.host_Id = roomInfo.member[0].id;//房主转移
                //}
                Console.WriteLine("剩余人数:" + roomInfo.member.Count);
            }
        }
        /// <summary>
        /// 摸牌
        /// </summary>
        void Draw()
        {
            SingleDraw singleDraw = DataDo.Json2Object <SingleDraw>(Decode.DecodeSecondContendBtyes(bytes));
            RoomInfo   roomInfo   = GetRoom(singleDraw.roomNum);

            //找到自己在成员列表所对应的下标
            if (roomInfo == null)
            {
                return;
            }
            int      cardIndex = singleDraw.cardIndex;
            BaseCard card      = roomInfo.cardsLibrary[cardIndex]; //////出错 “牌不一致”

            card.CardBelongTo = (CardBelongTo)singleDraw.myIndex;  //为每个玩家发牌
            //服务器房间牌库数据修改
            roomInfo.playersCards.Add(card);
            roomInfo.cardsLibrary.Remove(card);
            Console.WriteLine("玩家牌数:" + roomInfo.playersCards.Count + "   牌库:" + roomInfo.cardsLibrary.Count);
            Console.WriteLine("singleDraw:   cardIndex:" + singleDraw.cardIndex + "   myId:" + singleDraw.myId + "   时间:" + DateTime.Now);

            //自动摸牌(托管)
            if (singleDraw.autoTrusteeship)
            {
                card.CardDisplay = CardDisplay.True;
                //每人的计时是_SingleDrawTime + _SelectMyselfCardTime+出牌按钮+再次摸牌时间
                Next(roomInfo);
                Console.WriteLine("Next-------------Draw");
            }
            ForeachSendDraw((int)SecondCommands.DRAW, roomInfo, cardIndex, card);
        }
        /// <summary>
        /// 发牌
        /// </summary>
        //void Deal(RoomInfo roomInfo)
        //{
        //    int cards = 0;
        //    if (roomInfo.member.Count == 3 || roomInfo.member.Count == 2)
        //    {
        //        cards = 4;
        //    }
        //    else if (roomInfo.member.Count == 4)
        //    {
        //        cards = 3;
        //    }

        //    if (cards == 4 || cards == 3)
        //    {
        //        BaseCard card;
        //        roomInfo.playersCards = new List<BaseCard>();
        //        for (int i = 1; i <= roomInfo.member.Count; i++)//人员
        //        {
        //            for (int j = 1; j <= cards; j++)//牌数
        //            {
        //                card = roomInfo.cardsLibrary[0];
        //                card.CardBelongTo = (CardBelongTo)i;//为每个玩家发牌 0是牌库
        //                Console.WriteLine("手牌:" + card.CardName);
        //                roomInfo.playersCards.Add(card);
        //                roomInfo.cardsLibrary.Remove(card);
        //            }
        //        }
        //        Console.WriteLine("手牌数:" + roomInfo.playersCards.Count + " 牌库:  " + roomInfo.cardsLibrary.Count);
        //    }
        //}
        #endregion

        /// <summary>
        /// 公布自选牌
        /// </summary>
        void OpenSelfSelectCard()
        {
            byte[]     content    = Decode.DecodeSecondContendBtyes(bytes);
            SingleDraw singleDraw = DataDo.Json2Object <SingleDraw>(content);
            RoomInfo   roomInfo   = GetRoom(singleDraw.roomNum);

            //找到自己在成员列表所对应的下标
            if (roomInfo == null)
            {
                return;
            }

            Next(roomInfo);
            Console.WriteLine("Next-------------OpenSelfSelectCard");


            //广播成员
            Conn conn;

            for (int i = 0; i < roomInfo.member.Count; i++)
            {
                Server.connMap.TryGetValue(roomInfo.member[i].id.ToString(), out conn);
                byte[] data = Incode.IncodeSecondaryCommand(type, (int)SecondCommands.SelectMyCardToOpen, content);
                conn.SendBts(data);
            }
        }
        /// <summary>
        /// 发送万能牌移动信息
        /// </summary>
        void SendLineCardMoveInfo()
        {
            byte[] content = Decode.DecodeSecondContendBtyes(bytes);
            Info   info    = DataDo.Json2Object <Info>(content);

            Broadcast(GetRoom(info.roomId), SecondCommands.MoveLineCardInFirstDraw, content);
        }
Example #8
0
        void ReturnRoom()
        {
            Info     info     = DataDo.Json2Object <Info>(Decode.DecodeSecondContendBtyes(bytes));
            RoomInfo roomInfo = GameCommand.GetRoom(info.roomId);

            if (roomInfo != null)
            {
                PersonalInfo personal = roomInfo.member.Find(it => {
                    if (it.id == info.myId)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
                if (personal != null)
                {
                    personal.IsInWaitRoom = true;
                }
                //在房间的都知道

                conn.SendBts(Incode.IncodeSecondaryCommand(type, (int)SecondCommands.TurnBackROOM, DataDo.Object2Json(roomInfo)));
                Conn _conn;
                for (int i = 0; i < roomInfo.member.Count; i++)
                {
                    if (roomInfo.member[i].id != info.myId)
                    {
                        Server.connMap.TryGetValue(roomInfo.member[i].id.ToString(), out _conn);
                        _conn.SendBts(Incode.IncodeSecondaryCommand(type, (int)SecondCommands.JOINROOM, DataDo.Object2Json(roomInfo)));
                    }
                }
            }
        }
        public override void DoCommand()
        {
            int    id                   = BitConverter.ToInt32(bytes, 8);
            string strContent           = "SELECT * from  friends right JOIN counter ON friends.f_id=counter.id where friends.user_id = " + id + " ORDER BY status DESC;";
            List <PersonalInfo> friends = SqlConn.FindFriends(strContent);

            Console.WriteLine("用户:" + id + "的好友数:" + friends.Count);
            conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(friends)));
        }
Example #10
0
        /// <summary>
        /// 遍历房间成员发送房间命令
        /// </summary>
        /// <param name="byt">内容</param>
        /// <param name="secondCommand">二级命令</param>
        public static void ForeachSendRoom(int secondCommand, RoomInfo roomInfo)
        {
            Conn conn;

            for (int i = 0; i < roomInfo.member.Count; i++)
            {
                //Console.WriteLine();
                Server.connMap.TryGetValue(roomInfo.member[i].id.ToString(), out conn);
                conn.SendBts(Incode.IncodeSecondaryCommand(type, secondCommand, DataDo.Object2Json(roomInfo)));
            }
        }
Example #11
0
        /// <summary>
        /// 创建房间
        /// </summary>
        public void CreatRoom()
        {
            RoomInfo roomInfo = DataDo.Json2Object <RoomInfo>(Decode.DecodeSecondContendBtyes(bytes));

            roomInfo.CreateExitList();
            allRooms.Add(roomInfo.roomID, roomInfo);

            //房主信息修改
            PersonalInfo.ChangeStatusInfo(roomInfo.member[0].id, roomInfo.roomID, (int)PersonStatus.Combine);

            Console.WriteLine("  房间ID: " + roomInfo.roomID);
            Console.WriteLine("allRooms:" + allRooms.Count + "   noStartRooms:" + freeRooms.Count);
        }
        /// <summary>
        /// 发牌
        /// </summary>
        void DealCards()
        {
            FirstDrawInfo firstDrawInfo = DataDo.Json2Object <FirstDrawInfo>(Decode.DecodeSecondContendBtyes(bytes));

            Console.WriteLine("白牌的数目:" + firstDrawInfo.blackCards + "     白牌的数目:" + firstDrawInfo.whiteCards);
            RoomInfo roomInfo = GetRoom(firstDrawInfo.roomNum);

            if (roomInfo != null)
            {
                roomInfo.sealers.Add(firstDrawInfo.myId);
                DoSeal(roomInfo, firstDrawInfo);
            }
        }
Example #13
0
        /// <summary>
        /// 加入房间(及时响应)
        /// </summary>
        void JoinRoom()
        {
            RoomMsg  roomMsg  = DataDo.Json2Object <RoomMsg>(Decode.DecodeSecondContendBtyes(bytes));
            RoomInfo roomInfo = GameCommand.GetRoom(roomMsg.roomNum);

            if (roomInfo != null)
            {
                PersonalInfo.ChangeStatusInfo(roomMsg.my.id, roomInfo.roomID, (int)PersonStatus.Combine);
                roomMsg.my.IsInWaitRoom = true;
                roomInfo.AddMember(roomMsg.my);
                if (roomInfo.member.Count == RoomInfo.MaxSIZE)//房间人满
                {
                    freeRooms.Remove(roomInfo.roomID);
                }
                ForeachSendRoom((int)SecondCommands.JOINROOM, roomInfo);
                Console.WriteLine("加入成功");
            }
        }
Example #14
0
        public override void DoCommand()
        {
            LoginInfo myInfo = DataDo.Json2Object <LoginInfo>(Decode.DecodeFirstContendBtyes(bytes));
            string    id     = SqlConn.Insert(myInfo.userName, myInfo.passWord); // 添加到数据库 通过访问数据库获取自动分配的id

            Server.AddUser(id, conn);                                            //添加到服务器连接字典里去
            conn.ID = id;                                                        //客户端的id作为属性存起来了便于访问
            //Console.WriteLine("获取id:" + id);
            string       strContent = "SELECT * FROM counter where id=" + id + " ;";
            PersonalInfo user       = SqlConn.Select(strContent);

            if (user != null)
            {
                //Console.WriteLine("用户登陆成功");
                user.status = (int)PersonStatus.OnLine;//在线(发送数据修改)
                PersonalInfo.ChangeStatusInfo(int.Parse(conn.ID), "", (int)PersonStatus.OnLine);
                conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(user)));
            }
        }
        /// <summary>
        /// 猜牌结果发给其他人 并且 执行下一位操作
        /// </summary>
        void SendResult2Other()
        {
            byte[]    content = Decode.DecodeSecondContendBtyes(bytes);
            GuessInfo guess   = DataDo.Json2Object <GuessInfo>(content);

            RoomInfo room = GetRoom(guess.roomNum);

            if (room != null)
            {
                Console.WriteLine("--------SendResult2Other()");
                if (guess.isGuessTrue)
                {
                    ForeachSendGuess((int)SecondCommands.GUESS_T, room, content);
                    //修改计时器【累加】  延长计时(计时器-时间)
                    room.Time -= ((int)Time._ExtraTime + (int)Time._ClickThinkingTime);//如果玩家没选择按钮,托管发送会怎么样(延长时间还加上了_SelectMyselfCardTime,因为托管需要客户端驱动下一位,所以时长要放宽)
                }
                else
                {
                    ForeachSendGuess((int)SecondCommands.GUESS_F, room, content);
                    Next(room);
                }
            }
        }
        /// <summary>
        /// 初始化命令
        /// </summary>
        /// <param name="_1stDrawTime">首摸时间</param>
        /// <param name="_SingleDrawTime">单摸时间</param>
        /// <param name="roomInfo">房间</param>
        void Initialize(RoomInfo roomInfo)
        {
            Dictionary <string, int> times = new Dictionary <string, int>();

            times.Add("_1stDrawTime", (int)Time._1stDrawTime - 1);
            times.Add("_SingleDrawTime", (int)Time._SingleDrawTime);
            times.Add("_DiceTime", (int)Time._DiceTime);
            times.Add("_SelectMyselfCardTime", (int)Time._SelectMyselfCardTime);
            times.Add("_ExtraTime", (int)Time._ExtraTime);
            times.Add("_ClickThinkingTime", (int)Time._ClickThinkingTime);
            times.Add("_MoveCardTime", (int)Time._MoveCardTime);

            Conn conn;

            for (int i = 0; i < roomInfo.member.Count; i++)
            {
                roomInfo.member[i].IsInWaitRoom = false;
                Server.connMap.TryGetValue(roomInfo.member[i].id.ToString(), out conn);
                byte[] data = Incode.IncodeSecondaryCommand(type, (int)SecondCommands.INITIALIZE, DataDo.Object2Json(times));
                conn.SendBts(data);
            }
        }
Example #17
0
        public override void DoCommand()                  //世界排行榜    还有一个没做
        {
            List <PersonalInfo> rank = SqlConn.GetRank(); //直接向数据库查询 获取排行榜

            conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(rank)));
        }
 /// <summary>
 /// 结束
 /// </summary>
 public static void GameOver(RoomInfo roomInfo, List <int> exitList)
 {
     ForeachSendOneOpen((int)SecondCommands.Over, roomInfo, DataDo.Object2Json(exitList));
     Console.WriteLine("发送结束命令");
 }
Example #19
0
 /// <summary>
 /// 查找所有闲置的房间 (间隔刷新)
 /// </summary>
 public void SelectRoom()
 {
     SendRoom(DataDo.Object2Json(freeRooms), (int)SecondCommands.SELECTROOM);
 }