Esempio n. 1
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. 2
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. 3
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. 4
0
 private void F_Server_FormClosed(object sender, FormClosedEventArgs e)
 {
     udpSocket1.Active = false;
     ClassOptionData OptionData = new ClassOptionData();
     OptionData.ExSQL("Update CurreneyUser Set Sign =12 Where ID >0");
     OptionData.Dispose();
 }