public static byte[] LeafScribbleLeaf(LinkClient x, uint target_leaf, String sender, int height, byte[] img)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(target_leaf);
            packet.WriteString(x, sender);
            packet.WriteUInt32((uint)height);
            packet.WriteBytes(img);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_SCRIBBLE_LEAF);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafScribbleUser(LinkClient x, LinkUser target, String sender, int height, byte[] img)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(target.LinkCredentials.Ident);
            packet.WriteString(x, target.Name);
            packet.WriteString(x, sender);
            packet.WriteUInt32((uint)height);
            packet.WriteBytes(img);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_SCRIBBLE_USER);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubUserlistItem(Leaf x, uint ident, LinkUser user)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, user.OrgName);
            packet.WriteString(x, user.Name);
            packet.WriteString(x, user.Version);
            packet.WriteGuid(user.Guid);
            packet.WriteUInt16(user.FileCount);
            packet.WriteIP(user.ExternalIP);
            packet.WriteIP(user.LocalIP);
            packet.WriteUInt16(user.Port);
            packet.WriteString(x, user.DNS);
            packet.WriteByte((byte)(user.Browsable ? 1 : 0));
            packet.WriteByte(user.Age);
            packet.WriteByte(user.Sex);
            packet.WriteByte(user.Country);
            packet.WriteString(x, user.Region);
            packet.WriteByte((byte)user.Level);
            packet.WriteUInt16(user.Vroom);
            packet.WriteByte((byte)(user.CustomClient ? 1 : 0));
            packet.WriteByte((byte)(user.Muzzled ? 1 : 0));
            packet.WriteByte((byte)(user.WebClient ? 1 : 0));
            packet.WriteByte((byte)(user.Encrypted ? 1 : 0));
            packet.WriteByte((byte)(user.Registered ? 1 : 0));
            packet.WriteByte((byte)(user.Idle ? 1 : 0));
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_USERLIST_ITEM);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubLeafDisconnected(Leaf x, Leaf leaf)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(leaf.Ident);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_LEAF_DISCONNECTED);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubPart(Leaf x, uint ident, LinkUser user)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, user.Name);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_PART);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafPrintAll(LinkClient x, uint ident, String text)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, text, false);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_PRINT_ALL);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafNoAdmin(LinkClient x, uint ident, String name)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, name, false);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_NO_ADMIN);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafPrivateIgnored(LinkClient x, uint sender_ident, String sender, String target)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(sender_ident);
            packet.WriteString(x, sender);
            packet.WriteString(x, target, false);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_PRIVATE_IGNORED);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafNudge(LinkClient x, LinkUser target, String sender)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(target.LinkCredentials.Ident);
            packet.WriteString(x, target.Name);
            packet.WriteString(x, sender, false);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_NUDGE);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubNickChanged(Leaf x, uint ident, String old_name, String new_name)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, old_name);
            packet.WriteString(x, new_name, false);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_NICK_CHANGED);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubVroomChanged(Leaf x, uint ident, LinkUser user)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, user.Name);
            packet.WriteUInt16(user.Vroom);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_VROOM_CHANGED);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafBrowseData(LinkClient x, uint destination, String browser, byte[] data)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(destination);
            packet.WriteString(x, browser);
            packet.WriteBytes(data);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_BROWSE_DATA);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubPersonalMessage(Leaf x, uint ident, LinkUser user)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, user.Name);
            packet.WriteString(x, user.PersonalMessage, false);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_PERSONAL_MESSAGE);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafEmoteTextToLeaf(LinkClient x, uint target_ident, String name, String text)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(target_ident);
            packet.WriteString(x, name);
            packet.WriteString(x, text, false);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_EMOTE_TO_LEAF);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubScribbleLeaf(Leaf x, String sender, uint height, byte[] img)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteString(x, sender);
            packet.WriteUInt32(height);
            packet.WriteBytes(img);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_SCRIBBLE_LEAF);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubEmoteText(Leaf x, uint ident, String name, String text)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, name);
            packet.WriteString(x, text, false);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_EMOTE_TEXT);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafIUserBin(LinkClient x, LinkUser target, String command, byte[] args)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(target.Link.Ident);
            packet.WriteString(x, target.Name);
            packet.WriteString(x, command);
            packet.WriteBytes(args);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_IUSER_BIN);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubPrivateText(Leaf x, uint ident, String sender, String target, String text)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, sender);
            packet.WriteString(x, target);
            packet.WriteString(x, text);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_PRIVATE_TEXT);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubLeafConnected(Leaf x, Leaf leaf)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(leaf.Ident);
            packet.WriteString(x, leaf.Name);
            packet.WriteIP(leaf.ExternalIP);
            packet.WriteUInt16(leaf.Port);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_LEAF_CONNECTED);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafPrivateText(LinkClient x, String sender, IClient target, String text)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(target.IUser.Link.Ident);
            packet.WriteString(x, target.Name);
            packet.WriteString(x, sender);
            packet.WriteString(x, text);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_PRIVATE_TEXT);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafBrowse(LinkClient x, uint leaf_ident, String browsee, String browser, ushort browse_ident, byte mime)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(leaf_ident);
            packet.WriteString(x, browsee);
            packet.WriteString(x, browser);
            packet.WriteUInt16(browse_ident);
            packet.WriteByte(mime);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_BROWSE);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubAdmin(Leaf x, LinkUser admin, String command, LinkUser target, String args)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(admin.Ident);
            packet.WriteString(x, admin.Name);
            packet.WriteString(x, target.Name);
            packet.WriteString(x, command);
            packet.WriteString(x, args);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_HUB_ADMIN);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafCustomDataTo(LinkClient x, uint destination, String sender, String target, String ident, byte[] data)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(destination);
            packet.WriteString(x, sender);
            packet.WriteString(x, target);
            packet.WriteString(x, ident);
            packet.WriteBytes(data);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_CUSTOM_DATA_TO);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubBrowse(Leaf x, uint source, String browsee, String browser, ushort browse_ident, byte mime)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(source);
            packet.WriteString(x, browsee);
            packet.WriteString(x, browser);
            packet.WriteUInt16(browse_ident);
            packet.WriteByte(mime);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_BROWSE);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafAdmin(LinkClient x, IClient admin, String command, IClient target, String args)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(target.IUser.Link.Ident);
            packet.WriteString(x, admin.Name);
            packet.WriteString(x, target.Name);
            packet.WriteString(x, command);
            packet.WriteString(x, args, false);
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_ADMIN);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubUserUpdated(Leaf x, uint ident, LinkUser user)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(ident);
            packet.WriteString(x, user.Name);
            packet.WriteByte((byte)user.Level);
            packet.WriteByte((byte)(user.Muzzled ? 1 : 0));
            packet.WriteByte((byte)(user.Registered ? 1 : 0));
            packet.WriteByte((byte)(user.Idle ? 1 : 0));
            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_HUB_USER_UPDATED);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] LeafIUser(LinkClient x, LinkUser target, String command, params String[] args)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt32(target.Link.Ident);
            packet.WriteString(x, target.Name);
            packet.WriteString(x, command);

            foreach (String str in args)
            {
                packet.WriteString(x, str);
            }

            byte[] buf = packet.ToLinkPacket(LinkHub.LinkMsg.MSG_LINK_LEAF_IUSER);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }
        public static byte[] HubAck(Leaf leaf)
        {
            byte[] guid = leaf.Guid.ToByteArray();

            using (MD5 md5 = MD5.Create())
                guid = md5.ComputeHash(guid);

            byte[] key = leaf.IV.Concat(leaf.Key).ToArray();

            for (int i = 0; i < guid.Length; i += 2)
            {
                key = Crypto.e67(key, BitConverter.ToUInt16(guid, i));
            }

            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteBytes(key);
            packet.WriteUInt32(leaf.Ident);
            byte[] buf = packet.ToLinkPacket(LinkMsg.MSG_LINK_HUB_ACK);
            packet = new TCPPacketWriter();
            packet.WriteBytes(buf);
            return(packet.ToAresPacket(TCPMsg.MSG_LINK_PROTO));
        }