示例#1
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()));
            }
        }
示例#2
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));
                }
            }
        }
示例#3
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));
        }
示例#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 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);
            }
        }
示例#13
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));
            }
        }
示例#14
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));
            }
        }
示例#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
        public static void Eval(Leaf leaf, LinkMsg msg, TCPPacketReader packet, ulong time, LinkMode mode)
        {
            switch (msg)
            {
            case LinkMsg.MSG_LINK_LEAF_AVATAR:
                break;

            case LinkMsg.MSG_LINK_LEAF_CUSTOM_NAME:
                break;

            case LinkMsg.MSG_LINK_LEAF_EMOTE_TEXT:
                break;

            case LinkMsg.MSG_LINK_LEAF_LOGIN:
                LeafLogin(leaf, packet, time, mode);
                break;

            case LinkMsg.MSG_LINK_LEAF_PERSONAL_MESSAGE:
                break;

            case LinkMsg.MSG_LINK_LEAF_PRIVATE_IGNORED:
                break;

            case LinkMsg.MSG_LINK_LEAF_PRIVATE_TEXT:
                break;

            case LinkMsg.MSG_LINK_LEAF_PUBLIC_TEXT:
                break;

            case LinkMsg.MSG_LINK_LEAF_USERLIST_END:
                break;

            case LinkMsg.MSG_LINK_LEAF_USERLIST_ITEM:
                break;
            }
        }
示例#18
0
        private static void InstallScript(DwmForm form, String filename)
        {
            if (form.InvokeRequired)
            {
                form.BeginInvoke(new InstallScriptHandler(InstallScript), form, filename);
            }
            else
            {
                if (!form.Visible)
                {
                    form.Show();
                }

                if (form.WindowState == FormWindowState.Minimized)
                {
                    form.WindowState = FormWindowState.Normal;
                }

                form.Activate();

                if (Settings.IsAway)
                {
                    if (form.OverlayIcon != null)
                    {
                        form.OverlayIcon.Show();
                    }
                }

                DialogResult result = MessageBox.Show(form,
                                                      "Confirm you would like to install the script: " + filename,
                                                      "cb0t script installer",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    bool install_success = false;

                    try
                    {
                        String     url     = "http://chatrooms.marsproject.net/cb0t/" + filename;
                        byte[]     data    = null;
                        WebRequest request = WebRequest.Create(url);

                        using (WebResponse response = request.GetResponse())
                            using (Stream stream = response.GetResponseStream())
                            {
                                List <byte> list   = new List <byte>();
                                int         size   = 0;
                                byte[]      buffer = new byte[1024];

                                while ((size = stream.Read(buffer, 0, 1024)) > 0)
                                {
                                    list.AddRange(buffer.Take(size));
                                }

                                if (list.Count > 0)
                                {
                                    data = list.ToArray();
                                }
                            }

                        if (data != null)
                        {
                            data = Zip.Decompress(data);

                            if (data != null)
                            {
                                if (data.Length > 0)
                                {
                                    TCPPacketReader reader   = new TCPPacketReader(data);
                                    String          dir_path = Path.Combine(Settings.ScriptPath, filename);

                                    if (!Directory.Exists(dir_path))
                                    {
                                        Directory.CreateDirectory(dir_path);
                                    }

                                    String data_path = Path.Combine(dir_path, "data");

                                    if (!Directory.Exists(data_path))
                                    {
                                        Directory.CreateDirectory(data_path);
                                    }

                                    while (reader.Remaining > 0)
                                    {
                                        String name   = reader.ReadString();
                                        byte   type   = reader;
                                        uint   size   = reader;
                                        byte[] buffer = reader.ReadBytes((int)size);

                                        if (type == 1)
                                        {
                                            File.WriteAllBytes(Path.Combine(data_path, name), buffer);
                                        }
                                        else if (type == 0)
                                        {
                                            File.WriteAllBytes(Path.Combine(dir_path, name), buffer);
                                        }
                                    }

                                    AddToAutoLoad(filename);
                                    install_success = true;
                                }
                            }
                        }
                    }
                    catch { }

                    if (install_success)
                    {
                        MessageBox.Show(form,
                                        filename + " was installed successfully.  Please complete the installation by restarting cb0t now.",
                                        "cb0t script installer",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show(form,
                                        filename + " was unable to be installed at this time.",
                                        "cb0t script installer",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
            }
        }
示例#19
0
 private static void LeafLogin(Leaf leaf, TCPPacketReader packet, ulong time, LinkMode mode)
 {
 }
示例#20
0
        public static void Eval(Leaf leaf, LinkMsg msg, TCPPacketReader packet, ulong time, LinkMode mode)
        {
            switch (msg)
            {
            case LinkMsg.MSG_LINK_LEAF_AVATAR:
                LeafAvatar(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_CUSTOM_NAME:
                LeafCustomName(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_EMOTE_TEXT:
                LeafEmoteText(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_LOGIN:
                LeafLogin(leaf, packet, time, mode);
                break;

            case LinkMsg.MSG_LINK_LEAF_PERSONAL_MESSAGE:
                LeafPersonalMessage(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PRIVATE_IGNORED:
                LeafPrivateIgnored(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PRIVATE_TEXT:
                LeafPrivateText(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PUBLIC_TEXT:
                LeafPublicText(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_USERLIST_END:
                LeafUserlistEnd(leaf);
                break;

            case LinkMsg.MSG_LINK_LEAF_USERLIST_ITEM:
                LeafUserlistItem(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_JOIN:
                LeafJoin(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PART:
                LeafPart(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PING:
                LeafPing(leaf, time);
                break;

            case LinkMsg.MSG_LINK_LEAF_USER_UPDATED:
                LeafUserUpdated(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_NICK_CHANGED:
                LeafNickChanged(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_VROOM_CHANGED:
                LeafVroomChanged(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_IUSER:
                LeafIUser(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_IUSER_BIN:
                LeafIUserBin(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_ADMIN:
                LeafAdmin(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_NO_ADMIN:
                LeafNoAdmin(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_BROWSE:
                LeafBrowse(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_BROWSE_DATA:
                LeafBrowseData(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_CUSTOM_DATA_TO:
                LeafCustomDataTo(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_CUSTOM_DATA_ALL:
                LeafCustomDataAll(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PRINT_ALL:
                LeafPrintAll(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PRINT_VROOM:
                LeafPrintVroom(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PRINT_LEVEL:
                LeafPrintLevel(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PUBLIC_TO_USER:
                LeafPublicToUser(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_EMOTE_TO_USER:
                LeafEmoteToUser(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_PUBLIC_TO_LEAF:
                LeafPublicToLeaf(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_EMOTE_TO_LEAF:
                LeafEmoteToLeaf(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_NUDGE:
                LeafNudge(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_SCRIBBLE_USER:
                LeafScribbleUser(leaf, packet);
                break;

            case LinkMsg.MSG_LINK_LEAF_SCRIBBLE_LEAF:
                LeafScribbleLeaf(leaf, packet);
                break;
            }
        }