Example #1
0
        private async Task EndpointDisconnected(IEndpoint endpoint, DisconnectedArgs args)
        {
            log.Info("endpoint disconnected (id: " + endpoint.Connection.Id + ", by " + (args.RemoteDisconnect ? "client" : "server") + ")");

            Connection connection = endpoint.Connection as Connection;

            //wait for connection to pass 'connecting' state
            using (var aLock = await connection.StateMutex.Lock(Const.DEADLOCK_TIMEOUT))
            {
                while (connection.State == ConnectionState.Connecting)
                {
                    await connection.StateMutex.Wait(aLock, Const.DEADLOCK_TIMEOUT);
                }
            }

            Data.RemoveConnection(connection);

            using (var aLock = await Mutex.Lock(Const.DEADLOCK_TIMEOUT))
            {
                _ = Messenger.BroadcastMessage(Messages.ClientDisconnected(connection));
                _ = Data.SetConnectionState(connection, ConnectionState.Disconnected);
            }

            await Modules.HandleDisconnect(connection);
        }
Example #2
0
        private async Task BroadcastMessage(Message msg)
        {
            HashSet <IConnection> connections = Messenger.Connections.Connections.Where((c) => Data.ConnectionDic.ContainsKey(c.Id)).ToHashSet();

            await Messenger.BroadcastMessage(connections, msg);
        }
Example #3
0
 private async Task ChatBroadcast(ChatRoom chat, MessageUtilities.Message msg)
 {
     await Messenger.BroadcastMessage(chat.Connections, msg);
 }
 private Task GameBroadcast(GameInstance game, Message msg)
 {
     return(Messenger.BroadcastMessage(game.Connections.Select(c => c.Connection), msg));
 }