Ejemplo n.º 1
0
        public override bool OnTextCommand(IClient client, string cmd, string args)
        {
            switch (cmd)
            {
            case "scribble":
                var scribble = RoomScribble.GetScribble(client);
                if (Uri.TryCreate(args, UriKind.Absolute, out Uri uri))
                {
                    if (uri.IsFile)
                    {
                        Server.SendAnnounce((s) => s.Vroom == client.Vroom, "File uri is not suppored by the scribble command.");
                    }

                    else if (uri.IsWellFormedOriginalString())
                    {
                        scribble.Download(uri, (s) => {
                            SendRoomScribble((c) => c.Vroom == client.Vroom, client.Name, scribble);
                        },
                                          uri);
                    }
                }
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
 //Used for Sending scribble objects from another client
 //
 private void SendRoomScribble(IClient client, RoomScribble scribble)
 {
     SendRoomScribble(
         (s) => s != client && s.Vroom == client.Vroom,
         client.Name,
         scribble);
 }
Ejemplo n.º 3
0
        internal void SendRoomScribble(Predicate <IClient> pred, string name, RoomScribble scribble)
        {
            scribble.Index = 0;

            int length = Math.Min((int)scribble.Received, 4000);

            byte[] buffer = scribble.Read();

            server.SendAnnounce(pred, string.Format("\x000314--- From {0}", name));
            server.SendPacket(pred, new ClientCustom(server.Config.BotName, "cb0t_scribble_first", buffer));

            while (scribble.Remaining > 0)
            {
                buffer = scribble.Read();

                if (scribble.Remaining > 0)
                {
                    server.SendPacket(pred, new ClientCustom(server.Config.BotName, "cb0t_scribble_chunk", buffer));
                }
                else
                {
                    server.SendPacket(pred, new ClientCustom(server.Config.BotName, "cb0t_scribble_last", buffer));
                }
            }
        }
Ejemplo n.º 4
0
        internal void SendRoomScribble(Predicate <IClient> pred, string name, RoomScribble scribble)
        {
            byte[] buffer;
            if (scribble.Size <= 4000)
            {
                Server.SendAnnounce(pred, string.Format("\x000314--- From {0}", name));
                Server.SendPacket(pred, new ClientCustom(string.Empty, "cb0t_scribble_once", scribble.RawImage()));
            }
            else
            {
                scribble.Index = 0;

                int length = Math.Min((int)scribble.Received, 4000);

                buffer = scribble.Read();

                Server.SendAnnounce(pred, string.Format("\x000314--- From {0}", name));
                Server.SendPacket(pred, new ClientCustom(string.Empty, "cb0t_scribble_first", buffer));

                while (scribble.Remaining > 0)
                {
                    buffer = scribble.Read();

                    if (scribble.Remaining > 0)
                    {
                        Server.SendPacket(pred, new ClientCustom(string.Empty, "cb0t_scribble_chunk", buffer));
                    }
                    else
                    {
                        Server.SendPacket(pred, new ClientCustom(string.Empty, "cb0t_scribble_last", buffer));
                    }
                }
            }

            var ib0ts = Server.Users.Where(s => s.Socket.Isib0tSocket && pred(s));

            if (ib0ts.Count() > 0)
            {
                buffer = Zlib.Decompress(scribble.RawImage());

                int    height = RoomScribble.GetHeight(buffer);
                string base64 = Convert.ToBase64String(buffer);

                string[] chunks = new string[(int)Math.Round((double)(base64.Length / 1024), MidpointRounding.AwayFromZero)];

                for (int i = 0; i < chunks.Length; i++)
                {
                    chunks[i] = base64.Substring(i * 1024, 1024);
                }

                ib0ts.ForEach(s => s.SendPacket(new ScribbleHead(name, height, chunks.Length)));

                foreach (string chunk in chunks)
                {
                    ib0ts.ForEach(s => s.SendPacket(new ScribbleBlock(chunk)));
                }
            }
        }
Ejemplo n.º 5
0
        private void OnScribbleChunk(IClient client, ClientScribbleChunk chunk)
        {
            var scribble = RoomScribble.GetScribble(client);

            scribble.Write(chunk.Data);

            if (scribble.IsComplete)
            {
                SendRoomScribble(client, scribble);
            }
        }
Ejemplo n.º 6
0
        public static RoomScribble GetScribble(IClient client)
        {
            if (client.Extended.TryGetValue("Scribble", out object tmp))
            {
                return((RoomScribble)tmp);
            }

            var scribble = new RoomScribble();

            client.Extended["Scribble"] = scribble;

            return(scribble);
        }
Ejemplo n.º 7
0
        private void OnScribbleFirst(IClient client, ClientScribbleFirst first)
        {
            var scribble = RoomScribble.GetScribble(client);

            scribble.Reset();
            scribble.Size   = first.Size;
            scribble.Chunks = (ushort)(first.Chunks + 1);//scribble object counts first chunk
            scribble.Write(first.Data);

            if (scribble.IsComplete)
            {
                SendRoomScribble(client, scribble);
            }
        }
Ejemplo n.º 8
0
 private void OnCommand(IClient client, string text)
 {
     if (text.Length > 9 && text.Substring(0, 9) == "scribble ")
     {
         Uri uri      = null;
         var scribble = RoomScribble.GetScribble(client);
         if (Uri.TryCreate(text.Substring(9), UriKind.Absolute, out uri))
         {
             if (uri.IsFile)
             {
                 server.SendAnnounce("Not valid");
             }
             else
             {
                 scribble.Download(uri, (s) => {
                     SendRoomScribble((c) => c.Vroom == client.Vroom, client.Name, scribble);
                 }, null);
             }
         }
     }
 }
Ejemplo n.º 9
0
        public bool Load(object state)
        {
            if (scribble != null)
            {
                LoadCallback(state);
                return(true);
            }

            try {
                Uri    toGet = null;
                string path  = Path.Combine(script.Directory, Source);

                if (Uri.TryCreate(Source, UriKind.Absolute, out toGet) ||
                    Uri.TryCreate(path, UriKind.Absolute, out toGet))
                {
                    if (toGet.IsFile)
                    {
                        FileInfo file = new FileInfo(toGet.AbsolutePath);
                        if (file.Exists && file.Directory.FullName != script.Directory)
                        {
                            throw new UnauthorizedAccessException("You are not allowed to access this file.");
                        }
                    }
                }
                else
                {
                    throw new UriFormatException(Source);
                }

                scribble = new RoomScribble();
                scribble.Download(toGet, LoadCallback, state);
            }
            catch (Exception ex) {
                OnError(ex);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 10
0
        private void OnCommand(IClient client, string text)
        {
            if (text.Length > 9 && text.Substring(0, 9) == "scribble ")
            {
                var scribble = RoomScribble.GetScribble(client);

                if (Uri.TryCreate(text.Substring(9), UriKind.Absolute, out Uri uri))
                {
                    if (uri.IsFile)
                    {
                        Server.SendAnnounce((s) => s.Vroom == client.Vroom, "File uri is not suppored by the scribble command.");
                    }

                    else if (uri.IsWellFormedOriginalString())
                    {
                        scribble.Download(uri, (s) => {
                            SendRoomScribble((c) => c.Vroom == client.Vroom, client.Name, scribble);
                        },
                                          uri);
                    }
                }
            }
        }