Esempio n. 1
0
        public void Broadcast()
        {
            try
            {
                var server = new ProtocolUdpClient(new UdpClient(Protocol.UDP_PORT));

                while (_flag.Retrieve((x) => x))
                {
                    var msg = server.RecvMessage();

                    _rooms.Act(x =>
                    {
                        foreach (var room in x.Values.ToList())
                        {
                            if (msg != null && room.Consume(msg, server))
                            {
                                msg = null;
                            }
                            else if (room.CheckExpired())
                            {
                                Console.WriteLine("Room {0} timed out, removing", room.Name);
                                x.Remove(room.PublicName);
                            }
                        }
                    });
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 2
0
        public void Send(UdpMessage message, ProtocolUdpClient client)
        {
            if (EndPoint == null)
            {
                return;
            }

            message.EndPoint = EndPoint;

            try
            {
                client.SendMessage(message);
            }
            catch
            {
                ConnectedUser.Id = -1;
            }
        }
Esempio n. 3
0
        public bool Consume(UdpMessage message, ProtocolUdpClient server)
        {
            if (!_clients.ContainsKey(message.UserId))
            {
                return(false);
            }

            var client = _clients[message.UserId];

            client.EndPoint = message.EndPoint;

            foreach (var roommate in _clients.Values)
            {
                if (message.colorLine.Valid != (roommate == client))
                {
                    roommate.Send(message, server);
                }
            }

            return(true);
        }