Esempio n. 1
0
        /// <summary>
        /// 更改下棋后的分数
        /// </summary>
        private void UpdatePlayChess(ClassMsg msg, System.Net.IPAddress Ip, int Port, MsgCommand Nsign)
        {
            ClassOptionData OptionData = new ClassOptionData();

            OptionData.ExSQL("Update tb_Gobang Set Fraction =" + msg.Fraction + " Where IP ='" + msg.RIP + "'");
            UpdateUser();//更新用户列表
        }
Esempio n. 2
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Ip"></param>
        /// <param name="Port"></param>
        /// <param name="State"></param>
        private void UserLogin(ClassMsg msg, System.Net.IPAddress Ip, int Port, int State)
        {
            RegisterMsg registermsg = (RegisterMsg) new ClassSerializers().DeSerializerBinary(new MemoryStream(msg.Data));

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

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

            DataReader.Read();                                                         //读取查找到的记录
            string ID = Convert.ToString(DataReader.GetInt32(0));                      //获取第一条记录中的ID字段值

            if (DataReader.HasRows)                                                    //当DataReader中有记录信息时
            {
                //修改当前记录的标识为上线状态
                OptionData.ExSQL("Update tb_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);      //更新用户在线状态
            }
            OptionData.Dispose();
            UpdateUser();//更新用户列表
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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();
        }
Esempio n. 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();//更新用户列表
        }
Esempio n. 7
0
        private void Frm_Server_FormClosed(object sender, FormClosedEventArgs e)
        {
            udpSocket1.Active = false;
            udpSocket1.Dispose();
            ClassOptionData OptionData = new ClassOptionData();

            OptionData.ExSQL("Update tb_Gobang Set State =" + Convert.ToInt32(MsgCommand.Close) + ",Borough = 0 ,RoomMark=0 ,DeskMark='0',SeatMark='0' Where ID >0");
        }
Esempio n. 8
0
        private void F_Server_FormClosed(object sender, FormClosedEventArgs e)
        {
            udpSocket1.Active = false;
            ClassOptionData OptionData = new ClassOptionData();

            OptionData.ExSQL("Update tb_CurreneyUser Set Sign =12 Where ID >0");
            OptionData.Dispose();
        }
Esempio n. 9
0
        string fellin = "";//设置排名的SQL语句
        #endregion

        private void Tool_Open_Click(object sender, EventArgs e)
        {
            if (((ToolStripMenuItem)sender).Text == "开始服务")
            {
                ((ToolStripMenuItem)sender).Text = "结束服务";
                udpSocket1.Active = true;
            }
            else
            {
                ((ToolStripMenuItem)sender).Text = "开始服务";
                ClassOptionData OptionData = new ClassOptionData();
                OptionData.ExSQL("Update tb_Gobang Set State =" + Convert.ToInt32(MsgCommand.Close) + ",Borough = 0 ,RoomMark=0 ,DeskMark='0',SeatMark='0' Where ID >0");
                udpSocket1.Active = false;
                UpdateUser();
            }
        }
Esempio n. 10
0
        string fellin = "";//设置排名的SQL语句
        #endregion

        private void Tool_Open_Click(object sender, EventArgs e)
        {
            if (((ToolStripMenuItem)sender).Text == "开始服务")
            {
                ((ToolStripMenuItem)sender).Text = "结束服务"; //设置菜单项的文本信息
                udpSocket1.Active = true;                  //打开监听
            }
            else
            {
                ((ToolStripMenuItem)sender).Text = "开始服务";
                ClassOptionData OptionData = new ClassOptionData();//创建ClassOptionData对象
                //将数据表中的用户状态都设为退出状态
                OptionData.ExSQL("Update tb_Gobang Set State =" + Convert.ToInt32(MsgCommand.Close) + ",Borough = 0 ,RoomMark=0 ,DeskMark='0',SeatMark='0' Where ID >0");
                udpSocket1.Active = false; //关闭监听
                UpdateUser();              //刷新列表
            }
        }
Esempio n. 11
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().DeSerializerBinary(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 tb_CurreneyUser (IP,Port,Name,PassWord,Sign) values ('" + vIP + "'," +
                             Port.ToString() + ",'" + UserName + "','" + PassWord + "'," + Convert.ToString((int)(MsgCommand.Registered)) + ")");
            SqlDataReader DataReader = OptionData.ExSQLReader("Select * From tb_CurreneyUser");

            UpdateUser();                           //更新用户列表
            OptionData.Dispose();
            msg.msgCommand = MsgCommand.Registered; //用户注册结束命令
            SendMsgToOne(Ip, Port, msg);            //将注册命令返回给注册用户
            return(msg);
        }
Esempio n. 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);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        /// <summary>
        /// 更新用户在线状态
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="Ip"></param>
        /// <param name="Port"></param>
        private void UpdateUserState(ClassMsg msg, System.Net.IPAddress Ip, int Port)
        {
            ClassOptionData OptionData = new ClassOptionData();

            OptionData.ExSQL("Update tb_CurreneyUser Set Sign = " + Convert.ToString((int)(msg.msgCommand)) + " Where ID = " + msg.SID);
            SqlDataReader DataReader = OptionData.ExSQLReader("Select * From tb_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;
            while (DataReader.Read())
            {
                udpSocket1.Send(IPAddress.Parse(DataReader.GetString(1)),
                                DataReader.GetInt32(2), new ClassSerializers().SerializerBinary(msg).ToArray());
            }
            OptionData.Dispose();
            UpdateUser();
        }
Esempio n. 15
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);
        }