/// <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);
            }
        }
        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("账号不存在");
                //回客户端消息
            }
        }
Пример #3
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)));
                    }
                }
            }
        }
        /// <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);
            }
        }
Пример #5
0
    /// <summary>
    /// 发送单摸结果
    /// </summary>
    public static void SendLineCardIndexs(List <LineCardMoveInfo> lineCardMoveInfos)
    {
        Info info = new Info(DataDo.Object2Json(lineCardMoveInfos));

        byte[] byt = Incode.IncodeSecondaryCommand(TYPE, (int)SecondCommands.MoveLineCardInFirstDraw, DataDo.Object2Json(info));
        NetStart.SendContend(byt);
        Debug.Log("--------SendLineCardIndexs---------");
    }
        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)));
        }
Пример #7
0
 /// <summary>
 /// 发送自己的id
 /// </summary>
 public static void SendMyID(int secondCommand)
 {
     byte[] data_1 = BitConverter.GetBytes(NetStart.myInfo.id);
     byte[] data_2 = System.Text.Encoding.UTF8.GetBytes(currentRoom.roomID); //BitConverter.GetBytes(int.Parse(currentRoom.roomID));
     byte[] datas  = new byte[data_1.Length + data_2.Length];
     Buffer.BlockCopy(data_1, 0, datas, 0, 4);
     Buffer.BlockCopy(data_2, 0, datas, 4, data_2.Length);
     byte[] byt = Incode.IncodeSecondaryCommand(TYPE, secondCommand, datas);
     NetStart.SendContend(byt);
 }
Пример #8
0
    /// <summary>
    /// 加入房间
    /// </summary>
    /// <param name="roomNum">房间号</param>
    public static void JoinRoom(string roomNum, PersonalInfo my)
    {
        RoomMsg roomMsg = new RoomMsg
        {
            roomNum = roomNum,
            my      = my,
        };

        byte[] byt = Incode.IncodeSecondaryCommand(TYPE, (int)SecondCommands.JOINROOM, DataDo.Object2Json(roomMsg));
        NetStart.SendContend(byt);
    }
Пример #9
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)));
            }
        }
        /// <summary>
        /// 遍历房间成员发送猜错命令
        /// </summary>
        void ForeachSendGuess(int secondCommand, RoomInfo roomInfo, byte[] guess)
        {
            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, secondCommand, guess);
                conn.SendBts(data);
            }
        }
Пример #11
0
    /// <summary>
    /// 退出房间
    /// </summary>
    /// <param name="roomNum">房间号</param>
    public static void ExitRoom(string roomNum, int peopleId)
    {
        RoomMsg roomMsg = new RoomMsg
        {
            roomNum = roomNum,
            otherId = peopleId,
        };

        byte[] byt = Incode.IncodeSecondaryCommand(TYPE, (int)SecondCommands.EXITROOM, DataDo.Object2Json(roomMsg));
        NetStart.SendContend(byt);
    }
Пример #12
0
    /// <summary>
    /// 战斗结束后返回房间界面
    /// </summary>
    /// <param name="roomNum">房间号</param>
    public static void TurnBackCurrRoom(string roomNum)
    {
        Info info = new Info
        {
            myId    = NetStart.myInfo.id,
            roomId  = roomNum,
            content = new byte[0]
        };

        byte[] byt = Incode.IncodeSecondaryCommand(TYPE, (int)SecondCommands.TurnBackROOM, DataDo.Object2Json(info));
        NetStart.SendContend(byt);
    }
        /// <summary>
        /// 遍历房间成员发送公布玩家手牌  命令
        /// </summary>
        /// <param name="byt">内容</param>
        /// <param name="secondCommand">二级命令</param>
        static void ForeachSendOneOpen(int secondCommand, RoomInfo roomInfo, byte[] id)
        {
            if (id == null)
            {
                id = new byte[0];
            }
            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, secondCommand, id);
                conn.SendBts(data);
            }
        }
        /// <summary>
        /// 遍历房间成员发送出牌者  命令
        /// </summary>
        /// <param name="byt">内容</param>
        /// <param name="secondCommand">二级命令</param>
        public static void ForeachSendForthgoer(int secondCommand, RoomInfo roomInfo, int[] diceIndex)
        {
            byte[] datas  = new byte[8];
            byte[] dice_1 = BitConverter.GetBytes(diceIndex[0]);
            byte[] dice_2 = BitConverter.GetBytes(diceIndex[1]);
            Buffer.BlockCopy(dice_1, 0, datas, 0, 4);
            Buffer.BlockCopy(dice_2, 0, datas, 4, 4);
            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, secondCommand, datas);
                conn.SendBts(data);
            }
        }
        /// <summary>
        /// 广播
        /// </summary>
        /// <param name="roomInfo"></param>
        /// <param name="secondCommand"></param>
        /// <param name="content"></param>
        void Broadcast(RoomInfo roomInfo, SecondCommands secondCommand, byte[] content)
        {
            if (roomInfo == null)
            {
                Console.WriteLine("该房间不存在");
                return;
            }
            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)secondCommand, content);
                conn.SendBts(data);
            }
        }
Пример #16
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>
        /// <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);
            }
        }
Пример #18
0
 /// <summary>
 /// 发送猜错了创建自选计时器//正在自选要公布的手牌
 /// </summary>
 public static void SelectMyCardTimer()
 {
     byte[] byt = Incode.IncodeSecondaryCommand(TYPE, (int)SecondCommands.CreateSelectMyCardTimer, System.Text.Encoding.UTF8.GetBytes(currentRoom.roomID));
     NetStart.SendContend(byt);
 }
Пример #19
0
 /// <summary>
 /// 发送猜牌时的结果
 /// </summary>
 public static void SendGuessCard(GuessInfo guessInfo)
 {
     byte[] byt = Incode.IncodeSecondaryCommand(TYPE, (int)SecondCommands.GUESS, DataDo.Object2Json(guessInfo));
     NetStart.SendContend(byt);
 }
Пример #20
0
 /// <summary>
 /// 发送单摸结果
 /// </summary>
 public static void SendSingleDrow(int secondCommands, SingleDraw singleDraw)
 {
     byte[] byt = Incode.IncodeSecondaryCommand(TYPE, secondCommands, DataDo.Object2Json(singleDraw));
     NetStart.SendContend(byt);
 }
Пример #21
0
 /// <summary>
 /// 发送手牌选择(开局首摸)
 /// </summary>
 public static void SendSeletFirstHandCards(SelectCards selectCards)
 {
     byte[] byt = Incode.IncodeSecondaryCommand(TYPE, (int)SecondCommands.DEAL, DataDo.Object2Json(selectCards));
     NetStart.SendContend(byt);
 }
Пример #22
0
 public static void Already(string roomNum)
 {
     byte[] byt = Incode.IncodeSecondaryCommand(TYPE, (int)SecondCommands.Already, System.Text.Encoding.UTF8.GetBytes(roomNum));
     NetStart.SendContend(byt);
 }
Пример #23
0
 public static void Registe_Send(LoginInfo info)
 {
     NetStart.SendContend(Incode.IncodeFirstCommand(TYPE, DataDo.Object2Json <LoginInfo>(info)));
 }
Пример #24
0
 /// <summary>
 /// 排行榜查询
 /// </summary>
 public static void Rank_Send()
 {
     byte[] byt = System.Text.Encoding.UTF8.GetBytes("");
     NetStart.SendContend(Incode.IncodeFirstCommand(TYPE, byt));//获取查询排行的命令
     //Debug.Log("发送排行榜命令");
 }
Пример #25
0
 public static void Send(MessageInfo message)
 {
     NetStart.SendContend(Incode.IncodeSecondaryCommand(TYPE, PrivateChat, DataDo.Object2Json(message)));
 }
Пример #26
0
 /// <summary>
 /// 断线重连
 /// </summary>
 public static void ReLink()
 {
     NetStart.SendContend(Incode.IncodeSecondaryCommand(TYPE, _ReLink, System.BitConverter.GetBytes(NetStart.myInfo.id)));
     Debug.Log("----------发送重连命令");
 }
Пример #27
0
 /// <summary>
 /// 发送单纯的信号
 /// </summary>
 /// <param name="secondCommand"></param>
 public static void SendSign(int secondCommand)
 {
     byte[] byt = Incode.IncodeSecondaryCommand(TYPE, secondCommand, System.Text.Encoding.UTF8.GetBytes(currentRoom.roomID));
     NetStart.SendContend(byt);
 }
Пример #28
0
        public override void DoCommand()                  //世界排行榜    还有一个没做
        {
            List <PersonalInfo> rank = SqlConn.GetRank(); //直接向数据库查询 获取排行榜

            conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(rank)));
        }
Пример #29
0
 /// <summary>
 /// 查找好友
 /// </summary>
 public static void SelectFriendList()//加载在线好友列表
 {
     byte[] select = Incode.IncodeFirstCommand(TYPE, BitConverter.GetBytes(NetStart.myInfo.id));
     NetStart.SendContend(select);//发送查好友命令到服务器
     Debug.Log("查找好友命令发送");
 }
Пример #30
0
 /// <summary>
 /// 心跳命令发送
 /// </summary>
 public static void Heartbeat_Send()
 {
     NetStart.SendContend(Incode.IncodeSecondaryCommand(TYPE, _HeartBeat, System.BitConverter.GetBytes(NetStart.myInfo.id)));
     //Debug.Log("发送心跳命令");
 }