示例#1
0
        private void OnStatusChanged(object client, ClientStatusChanged e)
        {
            var oper = client as ClientOperator;

            if (oper == null)
            {
                return;
            }
            Broadcast(new ClientStatusChanged()
            {
                Status   = e.Status,
                Username = e.Username + "@" + (oper.TcpClient.Client.RemoteEndPoint as IPEndPoint)
            });
            if (e.Status == "online")
            {
                var username = e.Username + "@" + (oper.TcpClient.Client.RemoteEndPoint as IPEndPoint);
                Users.Add(username, oper);

                UniCast(new StatusReport()
                {
                    Usernames = Users.Keys.ToList()
                }, new List <string>()
                {
                    username
                });
            }
        }
示例#2
0
 protected override void OnClientStatusChanged(bool isInThread, ClientStatusChangedEventArgs args, HashSet <string> clientGroups)
 {
     if (args.Status == ClientStatus.Closed)
     {
         RemoveClientFromGroup(args.ClientID, clientGroups);
     }
     ClientStatusChanged?.Invoke(this, args);
 }
示例#3
0
 protected void NotifyStatusChanged(ClientStatus newStatus)
 {
     if (_status != newStatus)
     {
         _status = newStatus;
         ClientStatusChanged?.Invoke(this, new PipeClientStatusChangedEventArgs()
         {
             Status = _status
         });
     }
 }
示例#4
0
 private void SetStatusAndNotify(ClientStatus status)
 {
     if (status == _clientStatus)
     {
         return;
     }
     _clientStatus = status;
     ClientStatusChanged?.Invoke(this, new ClientStatusChangedEventArgs()
     {
         ClientID   = _clientID,
         IPEndPoint = (IPEndPoint)_serverEndPoint,
         Status     = _clientStatus
     });
 }
示例#5
0
 private void _client_ClientStatusChanged(object sender, ClientStatusChanged e)
 {
     if (e.Status == "offline")
     {
         ClientData.Users.Remove(ClientData.Users.Single(user => user.UserName == e.Username));
         foreach (var roomUsers in Rooms.Where(room => room.UserNames.Contains(e.Username)))
         {
             roomUsers.UserNames.Remove(e.Username);
         }
     }
     else
     {
         ClientData.Users.Add(new UserViewModel()
         {
             UserName = e.Username
         });
     }
 }
示例#6
0
        private void SetStatusAndNotify(ClientStatus status)
        {
            if (status == _clientStatus)
            {
                return;
            }
            _clientStatus = status;
            var args = new ClientStatusChangedEventArgs()
            {
                ClientID   = _clientID,
                IPEndPoint = (IPEndPoint)_serverEndPoint,
                Status     = _clientStatus
            };

            Task.Factory.StartNew((obj) =>
            {
                ClientStatusChanged?.Invoke(this, (ClientStatusChangedEventArgs)obj);
            }, args);
        }
        public async Task Observe()
        {
            while (true)
            {
                await waitForGame();

                ClientStatusChanged?.Invoke(true);
                ClientConnected?.Invoke(players, activePlayerName);
#if CHARM_BOT
                if (players.FirstOrDefault(p => p["summonerName"].ToString() == activePlayerName && p["championName"].ToString() == "Ahri") != null)
                {
                    charmBotThread = new Thread(StartCharmBot);
                    charmBotThread.Start();
                }
#endif
                await processEvents();

                ClientStatusChanged?.Invoke(false);
#if CHARM_BOT
                charmBotThread?.Interrupt();
#endif
                ClientDisconnected?.Invoke();
            }
        }
示例#8
0
        private void HandleStatusChanged(ClientStatusChanged msg)
        {
            if (_clients.ContainsKey(msg.Client))
            {
                _clients[msg.Client].Status = msg.Status;

                var c = _clients.Values.First(x => x.Id == msg.Client);
                var changedClient = new ClientTracking.ClientChanged(new ConnectedClient(c.Id, c.Username, c.Status));
                foreach (var client in _clients.Values)
                {
                    client.ClientsHandler.Tell(changedClient);
                }
            }
        }
 protected void RaiseClientStatusChanged()
 {
     ClientStatusChanged?.Invoke(this, EventArgs.Empty);
 }
示例#10
0
        private void OnMessage()
        {
            try {
                while (true)
                {
                    server.MessageReceivedEvent.WaitOne();

                    NetIncomingMessage msg;
                    while (server.ReadMessage(out msg))
                    {
                        switch (msg.MessageType)
                        {
                        case NetIncomingMessageType.StatusChanged: {
                            NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
#if DEBUG
                            Console.ForegroundColor = ConsoleColor.DarkCyan;
                            Console.Write("    S ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine("[" + msg.SenderEndPoint + "] " + status);
#endif
                            ClientStatusChangedEventArgs args = new ClientStatusChangedEventArgs(msg.SenderConnection, status);
                            ClientStatusChanged?.Invoke(args);
                            break;
                        }

                        case NetIncomingMessageType.Data: {
#if DEBUG__
                            Console.ForegroundColor = ConsoleColor.Cyan;
                            Console.Write("    R ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine("[" + msg.SenderEndPoint + "] " + msg.LengthBytes + " bytes");
#endif

                            MessageReceivedEventArgs args = new MessageReceivedEventArgs(msg, false);
                            MessageReceived?.Invoke(args);

                            break;
                        }

                        case NetIncomingMessageType.UnconnectedData: {
#if DEBUG
                            Console.ForegroundColor = ConsoleColor.Cyan;
                            Console.Write("    R ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine("Unconnected [" + msg.SenderEndPoint + "] " + msg.LengthBytes + " bytes");
#endif

                            MessageReceivedEventArgs args = new MessageReceivedEventArgs(msg, true);
                            MessageReceived?.Invoke(args);

                            break;
                        }

                        case NetIncomingMessageType.ConnectionApproval: {
                            ClientConnectedEventArgs args = new ClientConnectedEventArgs(msg);
                            ClientConnected?.Invoke(args);

                            if (args.Allow)
                            {
                                msg.SenderConnection.Approve();
                            }
                            else
                            {
                                msg.SenderConnection.Deny("Incompatible version");
                            }
                            break;
                        }

                        case NetIncomingMessageType.DiscoveryRequest: {
#if DEBUG
                            Console.ForegroundColor = ConsoleColor.Cyan;
                            Console.Write("    Q ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine("[" + msg.SenderEndPoint + "] " + msg.LengthBytes + " bytes");
#endif

                            DiscoveryRequestEventArgs args = new DiscoveryRequestEventArgs();
                            DiscoveryRequest?.Invoke(args);

                            server.SendDiscoveryResponse(args.Message, msg.SenderEndPoint);
                            break;
                        }

#if DEBUG
                        case NetIncomingMessageType.VerboseDebugMessage:
                            Console.ForegroundColor = ConsoleColor.DarkGray;
                            Console.Write("    D ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine(msg.ReadString());
                            break;

                        case NetIncomingMessageType.DebugMessage:
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.Write("    D ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine(msg.ReadString());
                            break;

                        case NetIncomingMessageType.WarningMessage:
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.Write("    W ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine(msg.ReadString());
                            break;

                        case NetIncomingMessageType.ErrorMessage:
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write("    E ");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine(msg.ReadString());
                            break;
#endif
                        }

                        server.Recycle(msg);
                    }
                }
            } catch (ThreadAbortException) {
                // Server is stopped
            }
        }
示例#11
0
        private void OnHandleMessagesThread()
        {
            while (server.Status != NetPeerStatus.NotRunning)
            {
                server.MessageReceivedEvent.WaitOne();

                NetIncomingMessage msg;
                while (server.ReadMessage(out msg))
                {
                    switch (msg.MessageType)
                    {
                    case NetIncomingMessageType.StatusChanged: {
                        NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
#if NETWORK_DEBUG
                        Console.ForegroundColor = ConsoleColor.DarkCyan;
                        Console.Write("    S ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine("[" + msg.SenderEndPoint + "] " + status);
#endif
                        ClientStatusChangedEventArgs args = new ClientStatusChangedEventArgs(msg.SenderConnection, status);
                        ClientStatusChanged?.Invoke(args);
                        break;
                    }

                    case NetIncomingMessageType.Data: {
#if NETWORK_DEBUG__
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.Write("    R ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine("[" + msg.SenderEndPoint + "] " + msg.LengthBytes + " bytes");
#endif

                        MessageReceivedEventArgs args = new MessageReceivedEventArgs(msg, false);
                        MessageReceived?.Invoke(args);

                        break;
                    }

                    case NetIncomingMessageType.UnconnectedData: {
#if NETWORK_DEBUG
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.Write("    R ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine("Unconnected [" + msg.SenderEndPoint + "] " + msg.LengthBytes + " bytes");
#endif

                        MessageReceivedEventArgs args = new MessageReceivedEventArgs(msg, true);
                        MessageReceived?.Invoke(args);

                        break;
                    }

                    case NetIncomingMessageType.ConnectionApproval: {
                        ClientConnectedEventArgs args = new ClientConnectedEventArgs(msg);
                        ClientConnected?.Invoke(args);

                        if (args.DenyReason == null)
                        {
                            msg.SenderConnection.Approve();
                        }
                        else
                        {
                            msg.SenderConnection.Deny(args.DenyReason);
                        }
                        break;
                    }

                    case NetIncomingMessageType.DiscoveryRequest: {
#if NETWORK_DEBUG
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.Write("    Q ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine("[" + msg.SenderEndPoint + "] " + msg.LengthBytes + " bytes");
#endif

                        DiscoveryRequestEventArgs args = new DiscoveryRequestEventArgs();
                        DiscoveryRequest?.Invoke(args);

                        server.SendDiscoveryResponse(args.Message, msg.SenderEndPoint);
                        break;
                    }

#if NETWORK_DEBUG
                    case NetIncomingMessageType.VerboseDebugMessage:
                        Console.ForegroundColor = ConsoleColor.DarkGray;
                        Console.Write("    D ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine(msg.ReadString());
                        break;

                    case NetIncomingMessageType.DebugMessage:
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write("    D ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine(msg.ReadString());
                        break;

                    case NetIncomingMessageType.WarningMessage:
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Write("    W ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine(msg.ReadString());
                        break;

                    case NetIncomingMessageType.ErrorMessage:
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("    E ");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine(msg.ReadString());
                        break;
#endif
                    }

                    server.Recycle(msg);
                }
            }

            server = null;

            Debug.WriteLine("ServerConnection: OnHandleMessagesThread exited!");
        }
示例#12
0
 private void ClientStatus(ClientStatusChanged statusChanged)
 {
 }