Exemple #1
0
        public void UpdateUser(ClientMessage2 message)
        {
            string[] msgs = message.token.Split(".");
            string   token1;
            string   token2;

            byte[] sendBuffer = Encoding.Default.GetBytes("true");
            if (msgs.Length == 6)
            {
                token1 = $"{msgs[0]}.{msgs[1]}.{msgs[2]}";
                token2 = $"{msgs[3]}.{msgs[4]}.{msgs[5]}";
                if (VerifyToken(token1) && VerifyToken(token2))
                {
                    UserInfo userInfo1 = DecodeToken(token1);
                    UserInfo userInfo2 = DecodeToken(token2);
                    userRuntime.UpdateUserState(userInfo1, userInfo2);
                }
                else
                {
                    sendBuffer = Encoding.Default.GetBytes("false");
                }
            }
            else
            {
                sendBuffer = Encoding.Default.GetBytes("true");
            }
            IPEndPoint ip = message.clientIPEndPoint;

            client.Send(sendBuffer, sendBuffer.Length, ip);
        }
Exemple #2
0
 //监听发来的令牌消息
 public void UdpListener()
 {
     while (true)
     {
         ClientMessage2 message = getToken();
         ProcessMsg(message);
     }
 }
Exemple #3
0
        //从客户端获得令牌
        public ClientMessage2 getToken()
        {
            byte[]     recvBuffer = new byte[1024];
            IPEndPoint ip         = new IPEndPoint(IPAddress.Any, 0);

            recvBuffer = client.Receive(ref ip);
            ClientMessage2 message = new ClientMessage2(ip, Encoding.UTF8.GetString(recvBuffer));

            return(message);
        }
Exemple #4
0
        //发送授权结果给客户端
        public void SendResult(ClientMessage2 clientMessage)
        {
            byte[]     sendBuffer = Encoding.Default.GetBytes("true");
            IPEndPoint ip         = clientMessage.clientIPEndPoint;

            if (GetAuthorization(clientMessage.token))
            {
                client.Send(sendBuffer, sendBuffer.Length, ip);
            }
            else
            {
                sendBuffer = Encoding.Default.GetBytes("false");
                client.Send(sendBuffer, sendBuffer.Length, ip);
            }
        }
Exemple #5
0
        //删除的子用户
        public void DeleteSubUser(ClientMessage2 message)
        {
            byte[] sendBuffer = Encoding.Default.GetBytes("true");
            if (message.token != "" && VerifyToken(message.token))
            {
                UserInfo userInfo = DecodeToken(message.token);
                userRuntime.DeleteSubUser(userInfo);
            }
            else
            {
                sendBuffer = Encoding.Default.GetBytes("false");
            }
            IPEndPoint ip = message.clientIPEndPoint;

            client.Send(sendBuffer, sendBuffer.Length, ip);
        }
Exemple #6
0
        public void ProcessMsg(ClientMessage2 message)
        {
            char   type      = message.token[0];
            string Realtoken = message.token.Remove(0, 2);

            if (type == '1')//请求授权信号
            {
                message.token = Realtoken;
                SendResult(message);
            }
            if (type == '2')//收到正常结束信号
            {
                DeleteSubUser(message.token);
            }
            if (type == '3')//用户更新信号
            {
                UpdateUser(message.token);
            }
        }
Exemple #7
0
        public void ProcessMsg(ClientMessage2 message)
        {
            char   type      = message.token[0];
            string Realtoken = message.token.Remove(0, 2);

            message.token = Realtoken;
            if (type == '1')//请求授权信号
            {
                SendResult(message);
            }
            if (type == '2')//收到正常结束信号
            {
                DeleteSubUser(message);
            }
            if (type == '3')//用户更新信号
            {
                UpdateUser(message);
            }
            if (type == '4')//获取用户是否被授权
            {
                GetAuthorizeState(message);
            }
        }
Exemple #8
0
        public void GetAuthorizeState(ClientMessage2 message)
        {
            byte[] sendBuffer;
            if (message.token != "" && VerifyToken(message.token))
            {
                UserInfo userInfo = DecodeToken(message.token);
                if (userRuntime.GetUserState(userInfo))
                {
                    sendBuffer = Encoding.Default.GetBytes("true");
                }
                else
                {
                    sendBuffer = Encoding.Default.GetBytes("false");
                }
            }
            else
            {
                sendBuffer = Encoding.Default.GetBytes("false");
            }

            IPEndPoint ip = message.clientIPEndPoint;

            client.Send(sendBuffer, sendBuffer.Length, ip);
        }