コード例 #1
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);
 }
コード例 #2
0
ファイル: PipeBase.cs プロジェクト: xingx001/SiS.Communcation
 protected void NotifyStatusChanged(ClientStatus newStatus)
 {
     if (_status != newStatus)
     {
         _status = newStatus;
         ClientStatusChanged?.Invoke(this, new PipeClientStatusChangedEventArgs()
         {
             Status = _status
         });
     }
 }
コード例 #3
0
 private void SetStatusAndNotify(ClientStatus status)
 {
     if (status == _clientStatus)
     {
         return;
     }
     _clientStatus = status;
     ClientStatusChanged?.Invoke(this, new ClientStatusChangedEventArgs()
     {
         ClientID   = _clientID,
         IPEndPoint = (IPEndPoint)_serverEndPoint,
         Status     = _clientStatus
     });
 }
コード例 #4
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);
        }
コード例 #5
0
        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();
            }
        }
 protected void RaiseClientStatusChanged()
 {
     ClientStatusChanged?.Invoke(this, EventArgs.Empty);
 }
コード例 #7
0
ファイル: ServerConnection.cs プロジェクト: razluta/jazz2
        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
            }
        }
コード例 #8
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!");
        }