コード例 #1
0
ファイル: Client.cs プロジェクト: v0icer/poltools
        void HandleClient()
        {
            NetworkStream ns = client_sock.GetStream();
            int           c  = -1;

            // Seed Start
            c = ns.ReadByte();
            if (c == 0xEF)
            {
                Packets.SeedPacket(ref ns, ref client_version);
            }
            else
            {
                byte[] seed = new byte[3];
                ns.Read(seed, 0, 3);
            }
            // Seed End

            while ((c = ns.ReadByte()) >= 0)
            {
                switch (c)
                {
                case 0x80:
                    Console.WriteLine("Login Packet!");
                    Packets.LoginPacket(ref ns, this);
                    break;

                case 0xA0:
                    Console.WriteLine("Server Select!");
                    Packets.ServerSelectPacket(ref ns, this);
                    break;

                default:
                    byte[] tmp = new byte[1024];
                    int    len = ns.Read(tmp, 0, 1024);
                    HexDump.DumpUnk((byte)c, tmp, len, SockUtils.GetIP(client_sock));
                    break;
                }
            }
            Console.WriteLine("Client Disconnected!");
            _disconnected = true;
        }
コード例 #2
0
ファイル: Listener.cs プロジェクト: v0icer/poltools
        private void ListenForClients(object listener)
        {
            TcpListener listen = listener as TcpListener;

            if (listen == null)
            {
                return;
            }

            while (Program.running)
            {
                TcpClient client = listen.AcceptTcpClient();
                Console.WriteLine("New client connected: {0}", SockUtils.GetIP(client));
                _clients.Add(new Client(client));

                _clients.RemoveAll(c => c.Disconnected == false);
            }

            listen.Stop();
        }