示例#1
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));
            }
        }
示例#2
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));
            }
        }
示例#3
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));
            }
        }
示例#4
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));
            }
        }
示例#5
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);
            }
        }
示例#6
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));
            }
        }
示例#7
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);
            }
        }
示例#8
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);
                    }
                }
            }
        }