示例#1
0
        private void UserUpdateState(UdpPacket packet)
        {
            UdpPacketUserStateExtend extend = packet.Extend as UdpPacketUserStateExtend;

            //更新用户状态
            ClientUser user = this[packet.FromMAC];

            user.Update(extend.User, extend.UpdateState);

            //用户一览信息回给上线者
            UdpPacket packetUsers = new UdpPacket();

            packetUsers.Address = packet.Address;
            packetUsers.Port    = packet.Port;
            packetUsers.ToMAC   = packet.FromMAC;
            packetUsers.FromMAC = this.MAC;
            packetUsers.Command = UdpPacket.CMD_USER_LIST;
            UdpPacketUserListExtend extendUserList = new UdpPacketUserListExtend();

            packetUsers.Extend = extendUserList;
            foreach (User u in _users)
            {
                extendUserList.AddUser(u);
            }
            _client.Send(packetUsers);

            //上线信息广播给各位
            foreach (IPAddress brdIp in LanServerConfig.Instance.BroadcastAddress)
            {
                SendUpdateStatePacket(extend.UpdateState, user, brdIp);
                Thread.Sleep(50);
            }
        }
示例#2
0
        private object ResolveUserListExtend(BinaryReader rdr)
        {
            UdpPacketUserListExtend extend = new UdpPacketUserListExtend();

            int count = rdr.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                User u = new User();
                u.Address = IPAddress.Parse(rdr.ReadString());
                u.Port    = rdr.ReadInt32();
                u.MAC     = rdr.ReadString();
                u.Status  = (UserStatus)rdr.ReadInt32();

                int bc = rdr.ReadInt32();
                u.SecurityKeys.Public = rdr.ReadBytes(bc);

                extend.AddUser(u);
            }

            return(extend);
        }