コード例 #1
0
        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("账号不存在");
                //回客户端消息
            }
        }
コード例 #2
0
        /// <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);
            }
        }
コード例 #3
0
        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)));
        }
コード例 #4
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)));
            }
        }
コード例 #5
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)));
            }
        }
コード例 #6
0
        public override void DoCommand()                  //世界排行榜    还有一个没做
        {
            List <PersonalInfo> rank = SqlConn.GetRank(); //直接向数据库查询 获取排行榜

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