コード例 #1
0
        private static void LeafLogin(Leaf leaf, TCPPacketReader packet, ulong time, LinkMode mode)
        {
            if (leaf.LoginPhase != LinkLogin.AwaitingLogin)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            byte[] credentials = packet.ReadBytes(20);
            leaf.Protocol = packet;
            leaf.Port     = packet;

            Leaf existing = LeafPool.Leaves.Find(x => x.ExternalIP.Equals(leaf.ExternalIP) && x.Port == leaf.Port && x.Ident != leaf.Ident);

            if (existing != null)
            {
                existing.Disconnect();
            }

            TrustedLeafItem item = TrustedLeavesManager.GetTrusted(leaf.ExternalIP, leaf.Port, credentials);

            if (item == null)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.Untrusted));
                leaf.Disconnect();
                return;
            }

            if (mode != LinkMode.Hub)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.Unavailable));
                leaf.Disconnect();
                return;
            }

            leaf.Name = item.Name;
            leaf.Guid = item.Guid;

            if (leaf.Protocol < Settings.LINK_PROTO)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.ExpiredProtocol));
                leaf.Disconnect();
                return;
            }

            leaf.LoginPhase = LinkLogin.AwaitingUserlist;
            leaf.Key        = Crypto.CreateKey;
            leaf.IV         = Crypto.CreateIV;
            leaf.SendPacket(HubOutbound.HubAck(leaf));
        }
コード例 #2
0
        private static void LeafIUser(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint target_leaf = packet;
            Leaf l           = LeafPool.Leaves.Find(x => x.Ident == target_leaf && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                String        name    = packet.ReadString(leaf);
                String        command = packet.ReadString(leaf);
                List <String> args    = new List <String>();

                while (packet.Remaining > 0)
                {
                    args.Add(packet.ReadString(leaf));
                }

                l.SendPacket(HubOutbound.HubIUser(l, name, command, args.ToArray()));
            }
        }
コード例 #3
0
        private static void LeafAdmin(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint target_ident = packet;
            Leaf l            = LeafPool.Leaves.Find(x => x.Ident == target_ident && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                String   sender_name = packet.ReadString(leaf);
                LinkUser admin       = leaf.Users.Find(x => x.Name == sender_name);
                String   target_name = packet.ReadString(leaf);
                LinkUser target      = l.Users.Find(x => x.Name == target_name);

                if (admin != null && target_name != null)
                {
                    String command = packet.ReadString(leaf);
                    String args    = packet.ReadString(leaf);
                    l.SendPacket(HubOutbound.HubAdmin(l, admin, command, target, args));
                }
            }
        }
コード例 #4
0
        private static void LeafPublicText(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            String name = packet.ReadString(leaf);
            String text = packet.ReadString(leaf);

            LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubPublicText(x, leaf.Ident, name, text)),
                                         x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);
        }
コード例 #5
0
        private static void LeafNoAdmin(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint ident = packet;
            Leaf l     = LeafPool.Leaves.Find(x => x.Ident == ident && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                String name = packet.ReadString(leaf);
                l.SendPacket(HubOutbound.HubNoAdmin(l, leaf.Ident, name));
            }
        }
コード例 #6
0
        private static void LeafCustomDataAll(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            ushort vroom  = packet;
            String sender = packet.ReadString(leaf);
            String ident  = packet.ReadString(leaf);

            byte[] data = packet;

            LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubCustomDataAll(x, vroom, sender, ident, data)),
                                         x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);
        }
コード例 #7
0
        private static void LeafPrivateIgnored(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint   sender_leaf = packet;
            String sender      = packet.ReadString(leaf);
            String target      = packet.ReadString(leaf);
            Leaf   l           = LeafPool.Leaves.Find(x => x.Ident == sender_leaf && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                l.SendPacket(HubOutbound.HubPrivateIgnored(l, sender, target));
            }
        }
コード例 #8
0
        private static void LeafNudge(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint leaf_ident = packet;
            Leaf l          = LeafPool.Leaves.Find(x => x.Ident == leaf_ident && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                String target = packet.ReadString(leaf);
                String sender = packet.ReadString(leaf);
                l.SendPacket(HubOutbound.HubNudge(l, target, sender));
            }
        }
コード例 #9
0
        private static void LeafBrowseData(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint leaf_ident = packet;
            Leaf l          = LeafPool.Leaves.Find(x => x.Ident == leaf_ident && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                String browser = packet.ReadString(leaf);
                byte[] data    = packet;
                l.SendPacket(HubOutbound.HubBrowseData(l, browser, data));
            }
        }
コード例 #10
0
        private static void LeafPrintLevel(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint leaf_ident = packet;
            Leaf l          = LeafPool.Leaves.Find(x => x.Ident == leaf_ident && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                iconnect.ILevel level = (iconnect.ILevel)((byte)packet);
                String          text  = packet.ReadString(leaf);
                l.SendPacket(HubOutbound.HubPrintLevel(l, level, text));
            }
        }
コード例 #11
0
        private static void LeafPrintVroom(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint leaf_ident = packet;
            Leaf l          = LeafPool.Leaves.Find(x => x.Ident == leaf_ident && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                ushort vroom = packet;
                String text  = packet.ReadString(leaf);
                l.SendPacket(HubOutbound.HubPrintVroom(l, vroom, text));
            }
        }
コード例 #12
0
        private static void LeafScribbleLeaf(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint leaf_ident = packet;
            Leaf l          = LeafPool.Leaves.Find(x => x.Ident == leaf_ident && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                String sender = packet.ReadString(leaf);
                uint   height = packet;
                byte[] img    = packet;
                l.SendPacket(HubOutbound.HubScribbleLeaf(l, sender, height, img));
            }
        }
コード例 #13
0
        private static void LeafPart(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            String   name = packet.ReadString(leaf);
            LinkUser user = leaf.Users.Find(x => x.Name == name);

            if (user != null)
            {
                LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubPart(x, leaf.Ident, user)),
                                             x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);

                leaf.Users.RemoveAll(x => x.Name == name);
            }
        }
コード例 #14
0
        private static void LeafIUserBin(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            uint target_leaf = packet;
            Leaf l           = LeafPool.Leaves.Find(x => x.Ident == target_leaf && x.LoginPhase == LinkLogin.Ready);

            if (l != null)
            {
                String name    = packet.ReadString(leaf);
                String command = packet.ReadString(leaf);
                byte[] args    = packet;
                l.SendPacket(HubOutbound.HubIUserBin(l, name, command, args));
            }
        }
コード例 #15
0
        private static void LeafJoin(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            LinkUser user = new LinkUser(leaf.Ident);

            user.OrgName         = packet.ReadString(leaf);
            user.Name            = packet.ReadString(leaf);
            user.Version         = packet.ReadString(leaf);
            user.Guid            = packet;
            user.FileCount       = packet;
            user.ExternalIP      = packet;
            user.LocalIP         = packet;
            user.Port            = packet;
            user.DNS             = packet.ReadString(leaf);
            user.Browsable       = ((byte)packet) == 1;
            user.Age             = packet;
            user.Sex             = packet;
            user.Country         = packet;
            user.Region          = packet.ReadString(leaf);
            user.Level           = (iconnect.ILevel)((byte)packet);
            user.Vroom           = packet;
            user.CustomClient    = ((byte)packet) == 1;
            user.Muzzled         = ((byte)packet) == 1;
            user.WebClient       = ((byte)packet) == 1;
            user.Encrypted       = ((byte)packet) == 1;
            user.Registered      = ((byte)packet) == 1;
            user.Idle            = ((byte)packet) == 1;
            user.PersonalMessage = String.Empty;
            user.CustomName      = String.Empty;
            user.Avatar          = new byte[] { };
            leaf.Users.Add(user);

            LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubUserlistItem(x, leaf.Ident, user)),
                                         x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);
        }
コード例 #16
0
        private static void LeafUserUpdated(Leaf leaf, TCPPacketReader packet)
        {
            if (leaf.LoginPhase != LinkLogin.Ready)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            String   name = packet.ReadString(leaf);
            LinkUser user = leaf.Users.Find(x => x.Name == name);

            if (user != null)
            {
                user.Level      = (iconnect.ILevel)((byte)packet);
                user.Muzzled    = ((byte)packet) == 1;
                user.Registered = ((byte)packet) == 1;
                user.Idle       = ((byte)packet) == 1;

                LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubUserUpdated(x, leaf.Ident, user)),
                                             x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);
            }
        }
コード例 #17
0
        private static void LeafUserlistEnd(Leaf leaf)
        {
            if (leaf.LoginPhase != LinkLogin.AwaitingUserlist)
            {
                leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol));
                leaf.Disconnect();
                return;
            }

            leaf.LoginPhase = LinkLogin.Ready;

            LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubLeafConnected(x, leaf)),
                                         x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);

            foreach (LinkUser u in leaf.Users)
            {
                LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubUserlistItem(x, leaf.Ident, u)),
                                             x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);

                if (u.CustomName.Length > 0)
                {
                    LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubCustomName(x, leaf.Ident, u)),
                                                 x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);
                }

                if (u.Avatar.Length > 0)
                {
                    LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubAvatar(x, leaf.Ident, u)),
                                                 x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);
                }

                if (u.PersonalMessage.Length > 0)
                {
                    LeafPool.Leaves.ForEachWhere(x => x.SendPacket(HubOutbound.HubPersonalMessage(x, leaf.Ident, u)),
                                                 x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);
                }
            }

            LeafPool.Leaves.ForEachWhere(x =>
            {
                leaf.SendPacket(HubOutbound.HubLeafConnected(leaf, x));

                foreach (LinkUser u in x.Users)
                {
                    leaf.SendPacket(HubOutbound.HubUserlistItem(leaf, x.Ident, u));

                    if (u.CustomName.Length > 0)
                    {
                        leaf.SendPacket(HubOutbound.HubCustomName(leaf, x.Ident, u));
                    }

                    if (u.Avatar.Length > 0)
                    {
                        leaf.SendPacket(HubOutbound.HubAvatar(leaf, x.Ident, u));
                    }

                    if (u.PersonalMessage.Length > 0)
                    {
                        leaf.SendPacket(HubOutbound.HubPersonalMessage(leaf, x.Ident, u));
                    }
                }
            },
                                         x => x.Ident != leaf.Ident && x.LoginPhase == LinkLogin.Ready);
        }