Ejemplo n.º 1
0
        public void Run(UserConsole user)
        {
            Instance     = this;
            this.Console = user;

            this.NetworkManager = new ServerNetworkManager();
            this.NetworkManager.Start();

            this.UserManager           = new ChatUserManager();
            this.UserManager.Logined  += this.OnUserManagerLogined;
            this.UserManager.Logouted += this.OnUserManagerLogouted;

            this.TickThread = new Thread(this.Ticking);
            this.TickThread.Start();

            while (true)
            {
                var input = user.ReadInput().ToLowerInvariant();

                if (input.Equals("stop") == true)
                {
                    this.Stop();
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            var user          = new UserConsole();
            var authUser      = args.Length > 0 ? new UserFile(args[0]) : (UserAbstract)user;
            var clientId      = authUser.ReadInput("Client-Id");
            var redirectURI   = authUser.ReadInput("Redirect-URI");
            var nickName      = authUser.ReadInput("Nickname").ToLowerInvariant();
            var authorization = Auth(clientId, redirectURI);

            using (var client = new TwitchChatClient())
            {
                client.Type     = ProtocolType.WebSocket;
                client.Security = ProtocolSecurity.Default;
                client.OAuth    = authorization.AccessToken;
                client.Nick     = nickName;
                client.Capabilities.Add(KnownCapabilities.Commands);
                client.Capabilities.Add(KnownCapabilities.Membership);
                client.Capabilities.Add(KnownCapabilities.Tags);
                client.Connect();

                new Thread(() =>
                {
                    while (true)
                    {
                        var input   = user.ReadInput();
                        var message = new IRCMessage();
                        message.Parse(input);

                        client.Send(message);
                    }
                }).Start();

                var program = new Program(user, client);
                program.Run();
            }
        }
Ejemplo n.º 3
0
        public void Run(UserConsole user)
        {
            Instance     = this;
            this.Console = user;

            var tcpClient = new TcpClient();

            tcpClient.NoDelay = true;
            tcpClient.Connect(new IPEndPoint(IPAddress.Parse("124.58.147.98"), 1653));

            var client = new NetworkManager(tcpClient);

            new Thread(() =>
            {
                try
                {
                    while (true)
                    {
                        client.ReadPackets();

                        if (client.CloseMessage != null)
                        {
                            user.SendMessage($"Network Closed : {client.CloseMessage}");
                            return;
                        }
                        else
                        {
                            client.Tick();
                            Thread.Sleep(10);
                        }
                    }
                }
                catch (Exception e)
                {
                    user.SendMessage(e.ToString());
                }
            }).Start();


            try
            {
                var loginToken  = Guid.NewGuid().ToString();
                var displayName = user.ReadInput("Enter DisplayName");
                client.SendPacket(new PacketLoginRequest()
                {
                    LoginToken = loginToken, DisplayName = displayName
                });

                while (true)
                {
                    var line = user.ReadInput();
                    client.SendPacket(new PacketChat()
                    {
                        Message = line
                    });
                }
            }
            catch (Exception e)
            {
                user.SendMessage(e.ToString());
            }
        }