Exemple #1
0
        /// <summary>
        /// 判断用户是否注册
        /// </summary>
        /// <param msg="ClassMsg"></param>
        /// <param Ip="System.Net.IPAddress"></param>
        /// <param Port="int"></param>
        /// <returns></returns>
        private bool IfRegisterAt(ClassMsg msg, System.Net.IPAddress Ip, int Port)
        {
            bool RegAt = true;
            //RegisterMsg registermsg = (RegisterMsg)new ClassSerializers().DeSerializeBinary(new MemoryStream(msg.Data));
            ClassOptionData OptionData = new ClassOptionData();
            MsgCommand      Sate       = msg.msgCommand;
            String          UserName   = msg.UserName;  //注册用户的名称
            String          PassWord   = msg.PassWord;  //注册用户的密码
            String          vIP        = Ip.ToString(); //注册用户的IP地址
            SqlDataReader   DataReader;

            //查找注册用户
            DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang where UserName="******"'" + UserName + "'");
            if (DataReader.Read())
            {
                RegAt          = true;
                msg.msgCommand = MsgCommand.RegisterAt; //存在注册用户
                SendMsgToOne(Ip, Port, msg);            //将注册命令返回给注册用户
            }
            else
            {
                DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang where IP=" + "'" + Ip.ToString() + "'");
                if (DataReader.Read())
                {
                    OptionData.ExSQL("Delete tb_Gobang where IP=" + "'" + Ip.ToString() + "'");
                }

                RegAt          = false;
                msg.msgCommand = MsgCommand.Registered;//用户注册结束命令
            }
            return(RegAt);
        }
Exemple #2
0
        /// <summary>
        /// 向所有在线用户发送进入大厅及游戏的用户信息
        /// </summary>
        private void UpdateUserList(ClassMsg msg, System.Net.IPAddress Ip, int Port)
        {
            ClassUsers      Users      = new ClassUsers();
            ClassOptionData OptionData = new ClassOptionData();
            SqlDataReader   DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang where (State>=" + Convert.ToInt32(MsgCommand.BeginToGame) + " and State<=" + Convert.ToInt32(MsgCommand.ExitToArea) + ")"); //查询进入大厅,或开始游戏的对象

            while (DataReader.Read())                                                                                                                                                                              //遍历所有用户
            {
                ClassUserInfo UserItem = new ClassUserInfo();                                                                                                                                                      //创建并引用ClassUserInfo类
                UserItem.UserID   = Convert.ToString(DataReader.GetInt32(0));                                                                                                                                      //记录用户用编号
                UserItem.UserIP   = DataReader.GetString(1);                                                                                                                                                       //记录用户的IP地址
                UserItem.UserPort = DataReader.GetString(2);                                                                                                                                                       //记录端口号
                UserItem.UserName = DataReader.GetString(3);                                                                                                                                                       //记录用户名称
                UserItem.Fraction = Convert.ToString(DataReader.GetInt32(5));                                                                                                                                      //当前分数
                UserItem.State    = Convert.ToString(DataReader.GetInt32(6));                                                                                                                                      //记录当前状态
                UserItem.Borough  = Convert.ToString(DataReader.GetInt32(7));                                                                                                                                      //区号
                UserItem.RoomMark = Convert.ToString(DataReader.GetInt32(8));                                                                                                                                      //房间号
                if (msg.msgCommand == MsgCommand.BeginToGame || DataReader.GetInt32(6) == Convert.ToInt32(MsgCommand.BeginToGame))
                {
                    UserItem.DeskMark    = DataReader.GetString(9);         //桌号
                    UserItem.SeatMart    = DataReader.GetString(10);        //坐位号
                    UserItem.UserCaption = DataReader.GetString(11);        //用户名
                }
                UserItem.Caput = Convert.ToString(DataReader.GetInt32(12)); //头像
                UserItem.Sex   = Convert.ToString(DataReader.GetInt32(13)); //头像
                Users.add(UserItem);                                        //将单用户信息添加到用户列表中
            }

            msg.Data       = new ClassSerializers().SerializeBinary(Users).ToArray();//将用户列表写入到二进制流中
            msg.msgCommand = MsgCommand.UserList;
            DataReader.Dispose();
            msg.msgCommand = MsgCommand.UserList;
            //udpSocket1.Send(Ip, Port, new ClassSerializers().SerializeBinary(msg).ToArray());
            MessColley(msg, Ip, Port, msg.msgCommand);//群发
        }
Exemple #3
0
        /// <summary>
        /// 更新用户列表
        /// </summary>
        private void UpdateUser()
        {
            ClassOptionData OptionData = new ClassOptionData();
            SqlDataReader   DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang" + fellin);

            LV_SysUser.Items.Clear();
            bool DRbool = false;

            if (DataReader.HasRows)
            {
                DRbool = DataReader.Read();
                while (DRbool)
                {
                    ListViewItem listItem = new ListViewItem();
                    listItem.Text = Convert.ToString(DataReader.GetInt32(0));
                    listItem.SubItems.Add(DataReader.GetString(1));
                    listItem.SubItems.Add(DataReader.GetString(2));
                    listItem.SubItems.Add(DataReader.GetString(3));
                    listItem.SubItems.Add(Convert.ToString(DataReader.GetInt32(5)));
                    listItem.SubItems.Add(Convert.ToString(DataReader.GetInt32(6)));
                    LV_SysUser.Items.Add(listItem);
                    DRbool = DataReader.Read();
                }
                DataReader.Dispose();
            }
        }
Exemple #4
0
        /// <summary>
        /// 更新用户在线状态
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Ip"></param>
        /// <param name="Port"></param>
        private void UpdateUserState(ClassMsg msg, IPAddress Ip, int Port)
        {
            ClassOptionData OptionData = new ClassOptionData();

            OptionData.ExSQL("Update CurreneyUser Set Sign = " + Convert.ToString((int)(msg.msgCommand)) + " Where ID = " + msg.SID);
            DataTable DataReader = OptionData.ExSQLReDr("Select * From CurreneyUser Where Sign = " + Convert.ToString((int)(MsgCommand.Logined)));

            if (msg.msgCommand == MsgCommand.Close)
            {
                msg.msgID = "Down";
            }
            else if (msg.msgCommand == MsgCommand.Logined)
            {
                msg.msgID = "Up";
            }
            msg.msgCommand = MsgCommand.UpdateState;
            int i = 0;

            while (DataReader.Rows.Count == i)
            {
                udpSocket1.Send(IPAddress.Parse(DataReader.Rows[i]["IP"].ToString()),
                                Convert.ToInt16(DataReader.Rows[i]["Port"]), new ClassSerializers().SerializeBinary(msg).ToArray());
                i++;
            }
            OptionData.Dispose();
            LoadUsrLst();
            //UpdateUser();
        }
Exemple #5
0
        /// <summary>
        /// 更改登录用户
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Ip"></param>
        /// <param name="Port"></param>
        /// <returns></returns>
        private ClassMsg UpdateLoginUser(ClassMsg msg, System.Net.IPAddress Ip, int Port)
        {
            //RegisterMsg registermsg = (RegisterMsg)new ClassSerializers().DeSerializeBinary(new MemoryStream(msg.Data));

            ClassOptionData OptionData = new ClassOptionData(); //创建并引用ClassOptionData
            MsgCommand      msgState   = msg.msgCommand;        //获取接收消息的命令
            String          UserName   = msg.UserName;          //登录用户名称
            String          PassWord   = msg.PassWord;          //用户密码
            String          vIP        = Ip.ToString();         //用户IP地址

            SqlDataReader DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang Where UserName = "******"'" + UserName + "'" + " and PassWord = "******"'" + PassWord + "'");//在数据库中通过用户名和密码进行查找

            if (DataReader.HasRows)
            {
                DataReader.Read();                                    //读取查找到的记录
                string ID = Convert.ToString(DataReader.GetInt32(0)); //获取第一条记录中的ID字段值
                msg.Fraction = DataReader.GetInt32(5);                //获取当前用户的分数
                msg.Sex      = DataReader.GetInt32(13);               //获取当前用户性别
                //修改当前记录的标识为上线状态
                OptionData.ExSQL("Update tb_Gobang Set State = " + Convert.ToString((int)(MsgCommand.Logined)) + ",IP = " + "'" + vIP + "',Port = " + "'" + Port.ToString() + "'" + " Where ID = " + ID);
                msg.msgCommand = MsgCommand.Logined; //设置为上线命令
                SendMsgToOne(Ip, Port, msg);         //将消息返回给发送用户/////--------------------------------////
                UpdateUser();                        //更新用户列表
            }
            return(msg);
        }
Exemple #6
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="state"></param>
        private void UserLogin(ClassMsg msg, IPAddress ip, int port, int state)
        {
            LoginMsg        loginmsg   = (LoginMsg) new ClassSerializers().DeSerializeBinary(new MemoryStream(msg.Data));
            ClassOptionData OptionData = new ClassOptionData(); //创建并引用ClassOptionData
            MsgCommand      msgState   = msg.msgCommand;        //获取接收消息的命令
            String          UserName   = loginmsg.UserName;     //登录用户名称
            String          PassWord   = loginmsg.PassWord;     //用户密码
            String          vIP        = ip.ToString();         //用户IP地址

            DataTable DataReader = OptionData.ExSQLReDr("Select * From user Where UserAccount = " + "'" + UserName + "'" + " and UserPassWord = "******"'" + PassWord + "'");//在数据库中通过用户名和密码进行查找


            if (DataReader.Rows.Count != 0)                          //当DataReader中有记录信息时
            {
                string ID = DataReader.Rows[0]["UserID"].ToString(); //获取第一条记录中的ID字段值
                //修改当前记录的标识为上线状态
                OptionData.ExSQL("Update CurreneyUser Set Sign = " + Convert.ToString((int)(MsgCommand.Logined)) + ",IP = " + "'" + vIP + "',Port = " + "'" + port.ToString() + "'" + " Where ID = " + ID);
                msg.msgCommand = MsgCommand.Logined; //设置为上线命令
                msg.SID        = ID;                 //用户ID值
                SendMsgToOne(ip, port, msg);         //将消息返回给发送用户
                UpdateUserState(msg, ip, port);      //更新用户在线状态
            }
            else
            {
                SendMsgToOne(ip, port, msg);
            }
            OptionData.Dispose();
            LoadUsrLst();
            //UpdateUser();//更新用户列表
        }
Exemple #7
0
        /// <summary>
        /// 获取玩家的分数
        /// </summary>
        private void GameF(ClassMsg msg, System.Net.IPAddress Ip, int Port, MsgCommand Nsign)
        {
            ClassOptionData OptionData = new ClassOptionData();
            SqlDataReader   DataReader = OptionData.ExSQLReDr("Select Fraction From tb_Gobang where (IP=" + msg.RIP.Trim() + ")"); //查询进入大厅,或开始游戏的对象

            DataReader.Read();                                                                                                     //读取玩家信息

            msg.Fraction = DataReader.GetInt32(0);                                                                                 //记录用户的IP地址
            udpSocket1.Send(Ip, Port, new ClassSerializers().SerializeBinary(msg).ToArray());
        }
Exemple #8
0
        /// <summary>
        /// 向用户发送信息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Ip"></param>
        /// <param name="Port"></param>
        private void SendUserMsg(ClassMsg msg, IPAddress Ip, int Port)
        {
            ClassOptionData OptionData = new ClassOptionData();
            DataTable       DataReader = OptionData.ExSQLReDr("Select * From CurreneyUser Where ID = " + msg.RID);
            string          ip         = DataReader.Rows[0]["IP"].ToString();
            int             port       = Convert.ToInt16(DataReader.Rows[0]["Port"]);

            udpSocket1.Send(IPAddress.Parse(ip), port, new ClassSerializers().SerializeBinary(msg).ToArray());
            OptionData.Dispose();
            DataReader.Dispose();
        }
Exemple #9
0
        /// <summary>
        /// 发送消息给单用户
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Ip"></param>
        /// <param name="Port"></param>
        private void SendUserMsg(ClassMsg msg, System.Net.IPAddress Ip, int Port)
        {
            ClassOptionData OptionData = new ClassOptionData();
            SqlDataReader   DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang Where ID = " + msg.RID);

            DataReader.Read();
            string ip   = DataReader.GetString(1);
            int    port = DataReader.GetInt32(2);

            udpSocket1.Send(IPAddress.Parse(ip), port, new ClassSerializers().SerializeBinary(msg).ToArray());
            DataReader.Dispose();
        }
Exemple #10
0
        private void SendFriendList(ClassMsg msg, IPAddress ip, int port)
        {
            LoginMsg   loginmsg   = (LoginMsg) new ClassSerializers().DeSerializeBinary(new MemoryStream(msg.Data));
            MsgCommand msgState   = msg.msgCommand;
            string     UserName   = loginmsg.UserName; //登录用户名称
            string     vIP        = ip.ToString();     //用户IP地址
            FriendList FriendList = new MyIM.FriendList();
            DataTable  dt         = OptionData.ExSQLReDr("select * from user Where UserAccount=" + "'" + UserName + "'");
            string     UserID     = dt.Rows[0]["UserID"].ToString();
            DataTable  dt1        = OptionData.ExSQLReDr(string.Format("select * from friendgroup where UserID={0}", UserID));

            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                DataRow dtr = dt1.NewRow();
                dtr = dt1.Rows[i];
                FriendList.Group[i].GroupName = dtr["GrouName"].ToString();
                FriendList.Group[i].GroupID   = dtr["GrouID"].ToString();
                DataTable dt2 = OptionData.ExSQLReDr("select GrouID,Use_UserID,AlternateName,frs.UserID from friendrelationship frs"
                                                     + " join user user on frs.UserID=user.UserID"
                                                     + string.Format(" where user.UserAccount='{0}' and frs.GrouID='{1}'", UserName, FriendList.Group[i].GroupID)
                                                     + " order by GrouID");
                for (int l = 0; l < dt2.Rows.Count; l++)
                {
                    DataTable dt3  = OptionData.ExSQLReDr("select * from user where UserID='" + dt2.Rows[l]["Use_UserID"] + "'");
                    DataRow   dtr1 = dt3.NewRow();
                    dtr1 = dt3.Rows[0];
                    FriendList.Group[i].Friend[l].NickName            = dtr1["UserNickName"].ToString();
                    FriendList.Group[i].Friend[l].UserID              = dtr1["UserID"].ToString();
                    FriendList.Group[i].Friend[l].AlternateName       = dt2.Rows[l]["AlternateName"].ToString();
                    FriendList.Group[i].Friend[l].UserPersonalMessage = dtr1["UserPersonalMessage"].ToString();
                }
                loginmsg.FriendList = FriendList;
                msg.sendKind        = SendKind.SendCommand;
                msg.msgCommand      = MsgCommand.GetFriendList;
                msg.Data            = new ClassSerializers().SerializeBinary(loginmsg).ToArray();
                SendMsgToOne(ip, port, msg);
            }
        }
Exemple #11
0
        /// <summary>
        /// 更新用户列表
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        private void UpdateUserList(ClassMsg msg, IPAddress ip, int port)
        {
            ClassUsers      Users      = new ClassUsers();
            ClassOptionData OptionData = new ClassOptionData();
            DataTable       DataReader = OptionData.ExSQLReDr("select * from CurreneyUser");
            int             i          = 0;

            while (DataReader.Rows.Count != i)
            {
                DataRow dtr = DataReader.NewRow();
                dtr = DataReader.Rows[i];
                ClassUserInfo UserItem = new ClassUserInfo();           //创建并引用ClassUserInfo类
                UserItem.UserID   = dtr["ID"].ToString();               //记录用户用编号
                UserItem.UserIP   = dtr["IP"].ToString();               //记录用户的IP地址
                UserItem.UserPort = dtr["Port"].ToString();             //记录端口号
                UserItem.UserName = dtr["Name"].ToString();             //记录用户名称
                UserItem.State    = dtr["Sign"].ToString();             //记录当前状态
                Users.add(UserItem);                                    //将单用户信息添加到用户列表中
                i++;
            }

            BinaryFormatter serializer = new BinaryFormatter();
            MemoryStream    memStream  = new MemoryStream(); //创建一个内存流存储区

            serializer.Serialize(memStream, Users);          //将对象序列化为二进制流

            msg.Data = memStream.ToArray();                  //new ClassSerializers().SerializeBinary(Users).ToArray();//将用户列表写入到二进制流中
            //查找当前已上线的用户
            DataReader = OptionData.ExSQLReDr("Select * From CurreneyUser Where Sign = " + MsgCommand.Logined);
            i          = 0;
            while (DataReader.Rows.Count == i)//向所有上线用户发送用户列表
            {
                udpSocket1.Send(IPAddress.Parse(DataReader.Rows[i]["IP"].ToString()), Convert.ToInt16(DataReader.Rows[i]["Port"]), new ClassSerializers().SerializeBinary(msg).ToArray());
                i++;
            }
            OptionData.Dispose();
        }
Exemple #12
0
        /// <summary>
        /// 插入用户
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <returns></returns>
        private ClassMsg InsertUser(ClassMsg msg, IPAddress ip, int port)
        {
            RegisterMsg registermsg = (RegisterMsg) new ClassSerializers().DeSerializeBinary(new MemoryStream(msg.Data));

            ClassOptionData OptionData = new ClassOptionData();
            MsgCommand      Sate       = msg.msgCommand;
            string          UserName   = registermsg.UserName; // 注册用户名称
            string          PassWord   = registermsg.PassWord; //注册用户密码
            string          vIP        = ip.ToString();        //注册用户的IP地址

            //向数据库中添加注册信息
            OptionData.ExSQL("insert into CurreneyUser (IP,Port,Name,PassWord,Sign) values ('" + vIP + "'," +
                             port.ToString() + ",'" + UserName + "','" + PassWord + "'," + Convert.ToString((int)(MsgCommand.Registered)) + ")");
            DataTable DataReader = OptionData.ExSQLReDr("select * from CurreneyUser");

            LoadUsrLst();
            //UpdateUser();//更新用户列表
            OptionData.Dispose();
            msg.msgCommand = MsgCommand.Registered; //用户注册结束命令
            SendMsgToOne(ip, port, msg);            //将注册命令返回给注册用户
            return(msg);
        }
Exemple #13
0
        /// <summary>
        /// 获取玩家的信息
        /// </summary>
        private void UserGame(ClassMsg msg, System.Net.IPAddress Ip, int Port, MsgCommand Nsign)
        {
            ClassUsers      Users      = new ClassUsers();
            ClassOptionData OptionData = new ClassOptionData();
            SqlDataReader   DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang where (IP=" + msg.SIP.Trim() + ")"); //查询进入大厅,或开始游戏的对象

            DataReader.Read();                                                                                              //读取玩家信息

            ClassUserInfo UserItem = new ClassUserInfo();                                                                   //创建并引用ClassUserInfo类

            UserItem.UserIP   = DataReader.GetString(1);                                                                    //记录用户的IP地址
            UserItem.UserPort = DataReader.GetString(2);                                                                    //记录端口号
            UserItem.UserName = DataReader.GetString(3);                                                                    //记录用户名称
            UserItem.Fraction = Convert.ToString(DataReader.GetInt32(5));                                                   //当前分数
            UserItem.Caput    = Convert.ToString(DataReader.GetInt32(12));                                                  //头像
            UserItem.Sex      = Convert.ToString(DataReader.GetInt32(13));                                                  //头像
            Users.add(UserItem);                                                                                            //将单用户信息添加到用户列表中

            msg.Data       = new ClassSerializers().SerializeBinary(Users).ToArray();                                       //将用户列表写入到二进制流中
            msg.msgCommand = MsgCommand.EndRival;
            DataReader.Dispose();
            udpSocket1.Send(Ip, Port, new ClassSerializers().SerializeBinary(msg).ToArray());
        }
Exemple #14
0
        /// <summary>
        /// 插入用户
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Ip"></param>
        /// <param name="Port"></param>
        /// <returns></returns>
        private ClassMsg InsertUser(ClassMsg msg, System.Net.IPAddress Ip, int Port)
        {
            //RegisterMsg registermsg = (RegisterMsg)new ClassSerializers().DeSerializeBinary(new MemoryStream(msg.Data));

            ClassOptionData OptionData = new ClassOptionData();
            MsgCommand      Sate       = msg.msgCommand;
            String          UserName   = msg.UserName;  //注册用户的名称
            String          PassWord   = msg.PassWord;  //注册用户的密码
            String          vIP        = Ip.ToString(); //注册用户的IP地址
            int             CPhot      = msg.CPhoto;    //注册用户的头象
            int             Sex        = msg.Sex;       //用户的性别

            //向数据表中添加注册信息
            OptionData.ExSQL("insert into tb_Gobang (IP,Port,UserName,PassWord,State,Caput,Sex) values ('" + vIP + "'," +
                             Port.ToString() + ",'" + UserName + "','" + PassWord + "'," + Convert.ToString((int)(MsgCommand.Registered)) + "," + CPhot + "," + Sex + ")");
            SqlDataReader DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang");

            UpdateUser();                           //更新用户列表
            //OptionData.Dispose();
            msg.msgCommand = MsgCommand.Registered; //用户注册结束命令
            SendMsgToOne(Ip, Port, msg);            //将注册命令返回给注册用户
            return(msg);
        }
Exemple #15
0
        /// <summary>
        /// 将信息发送给所有用户
        /// </summary>
        private void MessColley(ClassMsg msg, System.Net.IPAddress Ip, int Port, MsgCommand Nsign)
        {
            MsgCommand MsgSign = new MsgCommand();

            MsgSign = Nsign;
            if (Nsign == MsgCommand.ComeToHall)
            {
                MsgSign = MsgCommand.ComeToHallH;
            }

            if (Nsign == MsgCommand.BeginToGame)
            {
                MsgSign = MsgCommand.BeginToGameH;
            }

            if (Nsign == MsgCommand.EndToGame)
            {
                MsgSign = MsgCommand.EndToGameH;
            }
            ClassOptionData OptionData = new ClassOptionData();                                                                                                                                                 //创建并引用ClassOptionData
            bool            DRbool     = false;
            SqlDataReader   DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang where (State>=" + Convert.ToInt32(MsgCommand.Logining) + " and State<=" + Convert.ToInt32(MsgCommand.ExitToArea) + ")"); // and (IP<>'" + Ip.ToString() + "')");

            if (DataReader.HasRows)
            {
                DRbool = DataReader.Read();
                while (DRbool)
                {
                    msg.msgCommand = MsgSign;
                    SendMsgToOne(IPAddress.Parse(DataReader.GetString(1)), Convert.ToInt32(DataReader.GetString(2)), msg);//群发给所有在线用户
                    DRbool = DataReader.Read();
                }
                DataReader.Dispose();
            }
            UpdateUser();//更新用户列表
        }
Exemple #16
0
        /// <summary>
        /// 发送用户信息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        private void SendUserList(ClassMsg msg, IPAddress ip, int port)
        {
            ClassUsers      Users      = new ClassUsers();
            ClassOptionData OptionData = new ClassOptionData();
            DataTable       DataReader = OptionData.ExSQLReDr("Select * From CurreneyUser");
            int             i          = 0;

            while (DataReader.Rows.Count != i)
            {
                DataRow dtr = DataReader.NewRow();
                dtr = DataReader.Rows[i];
                ClassUserInfo UserItem = new ClassUserInfo();           //创建并引用ClassUserInfo类
                UserItem.UserID   = dtr["ID"].ToString();               //记录用户用编号
                UserItem.UserIP   = dtr["IP"].ToString();               //记录用户的IP地址
                UserItem.UserPort = dtr["Port"].ToString();             //记录端口号
                UserItem.UserName = dtr["Name"].ToString();             //记录用户名称
                UserItem.State    = dtr["Sign"].ToString();             //记录当前状态
                Users.add(UserItem);                                    //将单用户信息添加到用户列表中
                i++;
            }
            OptionData.Dispose();
            msg.Data = new ClassSerializers().SerializeBinary(Users).ToArray();
            udpSocket1.Send(ip, port, new ClassSerializers().SerializeBinary(msg).ToArray());
        }
Exemple #17
0
        /// <summary>
        /// 更改游戏中的用户状态
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Ip"></param>
        /// <param name="Port"></param>
        /// <param Nsign="MsgCommand"></param>
        /// <returns></returns>
        private ClassMsg UpdateUser(ClassMsg msg, System.Net.IPAddress Ip, int Port, MsgCommand Nsign)
        {
            ClassOptionData OptionData = new ClassOptionData(); //创建并引用ClassOptionData
            MsgCommand      msgState   = msg.msgCommand;        //获取接收消息的命令
            String          vIP        = Ip.ToString();         //用户IP地址
            String          Uname      = "";


            SqlDataReader DataReader = OptionData.ExSQLReDr("Select * From tb_Gobang Where IP = " + "'" + vIP + "'"); //在数据库中通过IP进行查找

            if (DataReader.Read())                                                                                    //读取查找到的记录
            {
                Uname = DataReader.GetString(3);
                MsgCommand msgCsign = Nsign;
                string     ID       = Convert.ToString(DataReader.GetInt32(0));//获取第一条记录中的ID字段值
                //修改当前记录的标识为上线状态
                if (msg.msgCommand == MsgCommand.ComeToHall || msg.msgCommand == MsgCommand.BeginToGame)
                {
                    if (msg.msgCommand == MsgCommand.ComeToHall)
                    {
                        msgCsign = MsgCommand.ComeToHallL;
                        OptionData.ExSQL("Update tb_Gobang Set State = " + Convert.ToInt32(Nsign) + ",IP = " + "'" + vIP + "',Port = " + "'" + Port.ToString() + "',Borough = " + Convert.ToInt32(msg.AreaMark) + " ,RoomMark=" + Convert.ToInt32(msg.RoomMark) + " Where ID = " + ID);
                    }
                    if (msg.msgCommand == MsgCommand.BeginToGame)
                    {
                        msgCsign = MsgCommand.BeginToGameL;
                        OptionData.ExSQL("Update tb_Gobang Set State = " + Convert.ToInt32(Nsign) + ",IP = " + "'" + vIP + "',Port = " + "'" + Port.ToString() + "',Borough = " + Convert.ToInt32(msg.AreaMark) + " ,RoomMark=" + Convert.ToInt32(msg.RoomMark) + " ,DeskMark='" + msg.DeskMark + "',SeatMark='" + msg.SeatMark + "',UserCaption='" + msg.UserCaption + "' Where ID = " + ID);
                    }
                }
                else
                {
                    if (msg.msgCommand == MsgCommand.ExitToHall || msg.msgCommand == MsgCommand.EndToGame)
                    {
                        if (msg.msgCommand == MsgCommand.ExitToHall)
                        {
                            OptionData.ExSQL("Update tb_Gobang Set State = " + Convert.ToInt32(Nsign) + ",IP = " + "'" + vIP + "',Port = " + "'" + Port.ToString() + "',Borough = 0 ,RoomMark=0 ,DeskMark='0',SeatMark='0'" + " Where ID = " + ID);
                        }
                        if (msg.msgCommand == MsgCommand.EndToGame)
                        {
                            msgCsign = MsgCommand.EndToGameL;
                            OptionData.ExSQL("Update tb_Gobang Set State = " + Convert.ToInt32(MsgCommand.BeginToGame) + ",IP = " + "'" + vIP + "',Port = " + "'" + Port.ToString() + "',DeskMark='0',SeatMark='0'" + " Where ID = " + ID);
                        }
                    }
                    else
                    {
                        OptionData.ExSQL("Update tb_Gobang Set State = " + Convert.ToInt32(Nsign) + ",IP = " + "'" + vIP + "',Port = " + "'" + Port.ToString() + "'" + " Where ID = " + ID);
                    }
                }
                if (msg.msgCommand == MsgCommand.ExitToHall)//如果当前用户退出大厅
                {
                    msg.msgCommand = MsgCommand.Close;
                    SendMsgToOne(Ip, Port, msg);//将消息返回给发送用户
                }
                else
                {
                    msg.msgCommand = msgCsign;
                    msg.sendKind   = SendKind.SendCommand;
                    SendMsgToOne(Ip, Port, msg);//将消息返回给发送用户
                }
                DataReader.Dispose();
                FurbishMsg(msg);
                //应有一个群发的方法
                MessColley(msg, Ip, Port, Nsign);
            }
            return(msg);
        }