예제 #1
0
        /// <summary>
        /// Broadcast a message to all clients.
        /// </summary>
        /// <param name="type">The type of message</param>
        /// <param name="body">The body of the message.</param>
        public void Broadcast(ServerBroadcastType type, byte[] body)
        {
            var dat = getBcBytes(type, body);

            foreach (var q in _connected)
            {
                q.Enqueue(dat);
            }
        }
예제 #2
0
 /// <summary>
 /// Creates a new instance of the <see cref="PlexBroadcast"/> class.
 /// </summary>
 /// <param name="type">The type of the broadcast</param>
 /// <param name="content">The content of the broadcast's body.</param>
 public PlexBroadcast(ServerBroadcastType type, byte[] content)
 {
     if (content.Length == 0)
     {
         content = new byte[0];
     }
     _data = content;
     Type  = type;
 }
예제 #3
0
        internal void BroadcastToPlayer(ServerBroadcastType message, byte[] body, string playerId)
        {
            if (playerId == null)
            {
                return;
            }
            AwaitableQueue <byte[]> q;

            if (!_playerIds.TryGetValue(playerId, out q))
            {
                return;
            }
            q.Enqueue(getBcBytes(message, body));
        }
예제 #4
0
 byte[] getBcBytes(ServerBroadcastType type, byte[] body)
 {
     byte[] dat;
     using (var ms = new MemoryStream())
     {
         using (var writer = new BinaryWriter(ms, Encoding.UTF8, true))
         {
             writer.Write("broadcast");
             writer.Write((int)type);
             writer.Write(body?.Length ?? 0);
             if (body != null)
             {
                 writer.Write(body);
             }
             writer.Flush();
         }
         dat = ms.ToArray();
     }
     return(dat);
 }