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))); } } }
public ChatInstance(ServerRecord channel, Uri baseUri) { Channel = channel; this.baseUri = baseUri; lastConnect = DateTime.Now; LastUpdate = DateTime.Now; Users = new ModelList <ChatUser>(); Users.CollectionChanged += OnUsersChanged; Messages = new ModelList <ChatMessage>(); Messages.CollectionChanged += OnMessagesChanged; scribble = new RoomScribble(); outPackets = new ConcurrentQueue <IPacket>(); if (!Channel.SupportJson) // use ib0t proto { prefMsgType = WebSocketMessageType.Text; } }
public bool Load(object state) { if (scribble != null) { LoadCallback(state); return(true); } try { string path = Path.Combine(script.Directory, Source); if (Uri.TryCreate(Source, UriKind.Absolute, out Uri 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); }
//Used for Sending scribble objects from another client // private void OnRoomScribbleComplete(RoomScribble scribble) { AddMessage(new ChatScribble(Convert.ToBase64String(Zlib.Decompress(scribble.RawImage())))); }