Ejemplo n.º 1
0
        protected bool ApplySendedPermission(SecurityTCP.Client client, string msgName)
        {
            //请求发送
            var sendPermit = false;

            using (var signal = new ManualResetEventSlim(false))
            {
                EventHandler <Tuple <SecurityTCP.Client, string> > allowback = (object sender, Tuple <SecurityTCP.Client, string> pair) =>
                {
                    if (client == pair.Item1 && pair.Item2 == msgName)
                    {
                        signal.Set();
                    }
                };
                this.AllowEvent += allowback;
                sendPermit       = false;
                this.SendMsg(client, Commands[0], msgName);
                //等待允许
                if (signal.Wait(1500))
                {
                    //获得准许
                    sendPermit = true;
                }
                //this.PushError(this, UserList[client], $"No permission to sending from {user.Name} !");
                this.AllowEvent -= allowback;
            }
            return(sendPermit);
        }
Ejemplo n.º 2
0
 protected void RemoveUser(SecurityTCP.Client client)
 {
     UserList[client].Client = null;
     MsgList.Remove(client);
     BigMsgList.Remove(client);
     UserList.Remove(client);
 }
Ejemplo n.º 3
0
 public void AcceptUser(object sender, SecurityTCP.Client client)
 {
     this.AddUser(client, new UIUser("null", "未知用户")
     {
         Client = client
     });
 }
Ejemplo n.º 4
0
 private void PostOffineEvent(object obj, SecurityTCP.Client c)
 {
     Task.Run(() =>
     {
         this.Disconnect();
         OfflineEvent?.Invoke();
     });
 }
Ejemplo n.º 5
0
        private void SendMsg(SecurityTCP.Client client, Command cmd, string text)
        {
            cmd.Data.CopyTo(_sendBuff, 0);
            var data = Encoding.Unicode.GetBytes(text);

            data.CopyTo(_sendBuff, cmd.Data.Length);
            this.TCP.Send(client, _sendBuff, cmd.Data.Length + data.Length);
        }
Ejemplo n.º 6
0
        private void CommandOfEntity(byte[] data, int size, SecurityTCP.Client client)
        {
            var queue = MsgList[client];

            while (queue.Count > 0)
            {
                var msgClass = queue.Dequeue();
                var realMsg  = Message.SetMessageEntity(msgClass.MsgName, data, CommandSize, size - CommandSize);
                if (realMsg != null)
                {
                    realMsg.User = UserList[client];
                    this.PushMessge(realMsg);
                    break;
                }
            }
        }
Ejemplo n.º 7
0
        private void CommandOfApply(byte[] data, int size, SecurityTCP.Client client)
        {
            if (size - CommandSize > 128)
            {
                return;
            }
            string  msgName  = Encoding.Unicode.GetString(data, CommandSize, size - CommandSize);
            Message msgClass = Message.CreateInstance(msgName);

            if (msgClass != null)
            {
                msgClass.User = UserList[client];
                MsgList[client].Enqueue(msgClass);
                //允许发送
                this.SendMsg(client, Commands[1], msgClass.MsgName);
            }
        }
Ejemplo n.º 8
0
 protected void AddUser(SecurityTCP.Client client, UIUser user)
 {
     UserList.Add(client, user);
     BigMsgList.Add(client, new Queue <byte[]>());
     MsgList.Add(client, new Queue <Message>());
 }
Ejemplo n.º 9
0
 public void MissUser(object sender, SecurityTCP.Client client)
 {
     this.RemoveUser(client);
 }
Ejemplo n.º 10
0
 private void CommandOfFlush(byte[] data, int size, SecurityTCP.Client client)
 {
 }
Ejemplo n.º 11
0
        private void CommandOfAllow(byte[] data, int size, SecurityTCP.Client client)
        {
            string msgStr = Encoding.Unicode.GetString(data, CommandSize, size - CommandSize);

            AllowEvent?.Invoke(this, new Tuple <SecurityTCP.Client, string>(client, msgStr));
        }