Ejemplo n.º 1
0
        public bool ClientLogoff(string nick)
        {
            var result = ConnectedClients.Remove(nick);

            if (result)
            {
                OnClientEvent?.Invoke(this, new ServerEvent(ServerEventType.UserLogoff, nick));
                Log.Logger.Information("CLIENT {Nick} LoggedOff", nick);
            }
            return(result);
        }
Ejemplo n.º 2
0
        protected virtual void Run()
        {
            Task.Run(async() =>
            {
                try
                {
                    QueuedEvent.OnNew = (e) =>
                    {
                        OnClientEvent?.Invoke(e);
                    };
                    var inFault = false;
                    var running = true;
                    RunOpen();
                    while (running)
                    {
                        if (await QueuedEvent.Next() is var nextEvent && nextEvent.Ok)
                        {
                            switch (nextEvent.Value)
                            {
                            case ClientEvent.Dispose:
                                RunClose();
                                running = false;
                                break;

                            case ClientEvent.Opening:
                                break;

                            case ClientEvent.Opened:
                                IsConnected = true;
                                break;

                            case ClientEvent.Restart:
                            case ClientEvent.Faulted:
                                if (!inFault)
                                {
                                    inFault = true;
                                    Client.Abort();
                                    RunClose();
                                    await Task.Delay(WaitOnFault.Milliseconds);
                                    RunOpen();
                                    inFault = false;
                                }
                                break;

                            case ClientEvent.Closing:
                                break;

                            case ClientEvent.Closed:
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.LogException();
                    QueuedEvent.New(ClientEvent.Exception);
                }
                finally
                {
                    RunClose();
                    Disposed          = true;
                    QueuedEvent.OnNew = null;
                }
            });
        }
Ejemplo n.º 3
0
 private void AddNewClient(string nick)
 {
     ConnectedClients.Add(nick);
     OnClientEvent?.Invoke(this, new ServerEvent(ServerEventType.UserLogon, nick));
 }