示例#1
0
        public void onPacketReceived(object sender, packetReceivedEventArgs e)
        {
            switch (e.Type)
            {
                case PacketType.KeepAlive:
                    packets.Enqueue(e.packet);
                    break;
                case PacketType.Login:
                    output("Login success!", true);
                    loggedin = true;
                    Thread packetSenderThread = new Thread(new ThreadStart(packetSender));
                    packetSenderThread.Name = "PacketSender";
                    packetSenderThread.Start();
                    break;
                case PacketType.Handshake:
                    output("Beginning Login...", true);
                    string serverid = ((Packet_Handshake)e.packet).ServerID;
                    packets.Enqueue(new Packet_Login() { Username = name, ProtocolVersion = Protocol, ServerID = serverid, SessionID = sessionid });
                    break;
                case PacketType.Chat:
                    Dictionary<char, ConsoleColor> cc = new Dictionary<char, ConsoleColor>();
                    cc.Add('0', ConsoleColor.Black);
                    cc.Add('1', ConsoleColor.DarkBlue);
                    cc.Add('2', ConsoleColor.DarkGreen);
                    cc.Add('3', ConsoleColor.DarkCyan);
                    cc.Add('4', ConsoleColor.DarkRed);
                    cc.Add('5', ConsoleColor.DarkMagenta);
                    cc.Add('6', ConsoleColor.DarkYellow);
                    cc.Add('7', ConsoleColor.Gray);
                    cc.Add('8', ConsoleColor.DarkGray);
                    cc.Add('9', ConsoleColor.Blue);
                    cc.Add('a', ConsoleColor.Green);
                    cc.Add('b', ConsoleColor.Cyan);
                    cc.Add('c', ConsoleColor.Red);
                    cc.Add('d', ConsoleColor.Magenta);
                    cc.Add('e', ConsoleColor.Yellow);
                    cc.Add('f', ConsoleColor.White);

                    string msg = ((Packet_Chat)e.packet).Message;
                    output(msg);
                    StreamReader sr = new StreamReader(new MemoryStream(Encoding.Default.GetBytes(msg)));
                    char[] tmp = new char[1];
                    while (!sr.EndOfStream)
                    {
                        sr.Read(tmp, 0, 1);
                        if (tmp[0] == (char)65533)
                        {
                            sr.Read(tmp, 0, 1);
                            if (cc.ContainsKey(tmp[0]))
                                Console.ForegroundColor = cc[tmp[0]];
                            else
                                Console.Write(tmp[0]);
                        }
                        else
                        {
                            Console.Write(tmp[0]);
                        }
                    }
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.White;
                    break;
                case PacketType.PlayerPosAndLook:
                    Packet_PlayerPosAndLook p = (Packet_PlayerPosAndLook)e.packet;
                    this.x = p.X;
                    this.y = p.Y;
                    this.z = p.Z;
                    this.stance = p.Stance;
                    this.pitch = p.Pitch;
                    this.yaw = p.Yaw;
                    sendPacket(p);
                    output("Moved!", true);
                    break;
                case PacketType.Kick:
                    output("Kicked: " + ((Packet_Kick)e.packet).Reason, true);
                    break;
            }
        }
示例#2
0
        public void onPacketReceived(object sender, packetReceivedEventArgs e)
        {
            switch (e.Type)
            {
                case PacketType.KeepAlive:
                    packets.Enqueue(e.packet);
                    break;
                case PacketType.Login:
                    output("Login success!", true);
                    loggedin = true;
                    Thread packetSenderThread = new Thread(new ThreadStart(packetSender));
                    packetSenderThread.Name = "PacketSender";
                    packetSenderThread.Start();
                    break;
                case PacketType.ClientStatus:
                    output("-"+((Packet_ClientStatus)e.packet).Payload.ToString());
                    break;
                case PacketType.EncryptionRequest:
                    output("Negotiating Encryption...", true);
                    packets.Enqueue(new Packet_ClientStatus() { Payload = 0x00 });
                    break;
                    Packet_EncryptionRequest enc = (Packet_EncryptionRequest)e.packet;
                    server = new Server();
                    server.ServerID = enc.ServerID;
                    server.PublicKey = enc.Key;
                    server.PrivateKey = GenerateKey();
                    server.Token = enc.Token;

                    packets.Enqueue(new Packet_EncryptionResponse() {
                        Key=RSAEncrypt(server.PrivateKey,server.PublicKey),
                        Token = RSAEncrypt(server.Token, server.PublicKey)
                    });
                    break;
                case PacketType.EncryptionResponse:
                    output("Encryption ready!", true);
                    //NetStream = new AesStream(NetStream, server.PrivateKey);
                    //NetStream = new blockingStream(new AesStream(client.GetStream(), server.PrivateKey),false);
                    NetStream = new AesStream(client.GetStream(), server.PrivateKey);
                    packets.Enqueue(new Packet_ClientStatus() { Payload = 0 });
                    //packets.Enqueue(new Packet_Login() { Username = name, ProtocolVersion = Protocol, ServerID = server.ServerID, SessionID = sessionid });
                    break;
                case PacketType.Chat:
                    Dictionary<char, ConsoleColor> cc = new Dictionary<char, ConsoleColor>();
                    cc.Add('0', ConsoleColor.Black);
                    cc.Add('1', ConsoleColor.DarkBlue);
                    cc.Add('2', ConsoleColor.DarkGreen);
                    cc.Add('3', ConsoleColor.DarkCyan);
                    cc.Add('4', ConsoleColor.DarkRed);
                    cc.Add('5', ConsoleColor.DarkMagenta);
                    cc.Add('6', ConsoleColor.DarkYellow);
                    cc.Add('7', ConsoleColor.Gray);
                    cc.Add('8', ConsoleColor.DarkGray);
                    cc.Add('9', ConsoleColor.Blue);
                    cc.Add('a', ConsoleColor.Green);
                    cc.Add('b', ConsoleColor.Cyan);
                    cc.Add('c', ConsoleColor.Red);
                    cc.Add('d', ConsoleColor.Magenta);
                    cc.Add('e', ConsoleColor.Yellow);
                    cc.Add('f', ConsoleColor.White);

                    string msg = ((Packet_Chat)e.packet).Message;
                    output(msg);
                    StreamReader sr = new StreamReader(new MemoryStream(Encoding.Default.GetBytes(msg)));
                    char[] tmp = new char[1];
                    while (!sr.EndOfStream)
                    {
                        sr.Read(tmp, 0, 1);
                        if (tmp[0] == (char)65533)
                        {
                            sr.Read(tmp, 0, 1);
                            if (cc.ContainsKey(tmp[0]))
                                Console.ForegroundColor = cc[tmp[0]];
                            else
                                Console.Write(tmp[0]);
                        }
                        else
                        {
                            Console.Write(tmp[0]);
                        }
                    }
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.White;
                    break;
                case PacketType.PlayerPosAndLook:
                    Packet_PlayerPosAndLook p = (Packet_PlayerPosAndLook)e.packet;
                    this.x = p.X;
                    this.y = p.Y;
                    this.z = p.Z;
                    this.stance = p.Stance;
                    this.pitch = p.Pitch;
                    this.yaw = p.Yaw;
                    sendPacket(p);
                    output("Moved!", true);
                    break;
                case PacketType.Kick:
                    output("Kicked: " + ((Packet_Kick)e.packet).Reason, true);
                    break;
            }
        }
        public void onPacketReceived(object sender, packetReceivedEventArgs e)
        {
            switch (e.Type)
            {
            case PacketType.KeepAlive:
                packets.Enqueue(e.packet);
                break;

            case PacketType.Login:
                output("Login success!", true);
                loggedin = true;
                Thread packetSenderThread = new Thread(new ThreadStart(packetSender));
                packetSenderThread.Name = "PacketSender";
                packetSenderThread.Start();
                break;

            case PacketType.ClientStatus:
                output("-" + ((Packet_ClientStatus)e.packet).Payload.ToString());
                break;

            case PacketType.EncryptionRequest:
                output("Negotiating Encryption...", true);
                packets.Enqueue(new Packet_ClientStatus()
                {
                    Payload = 0x00
                });
                break;
                Packet_EncryptionRequest enc = (Packet_EncryptionRequest)e.packet;
                server            = new Server();
                server.ServerID   = enc.ServerID;
                server.PublicKey  = enc.Key;
                server.PrivateKey = GenerateKey();
                server.Token      = enc.Token;

                packets.Enqueue(new Packet_EncryptionResponse()
                {
                    Key   = RSAEncrypt(server.PrivateKey, server.PublicKey),
                    Token = RSAEncrypt(server.Token, server.PublicKey)
                });
                break;

            case PacketType.EncryptionResponse:
                output("Encryption ready!", true);
                //NetStream = new AesStream(NetStream, server.PrivateKey);
                //NetStream = new blockingStream(new AesStream(client.GetStream(), server.PrivateKey),false);
                NetStream = new AesStream(client.GetStream(), server.PrivateKey);
                packets.Enqueue(new Packet_ClientStatus()
                {
                    Payload = 0
                });
                //packets.Enqueue(new Packet_Login() { Username = name, ProtocolVersion = Protocol, ServerID = server.ServerID, SessionID = sessionid });
                break;

            case PacketType.Chat:
                Dictionary <char, ConsoleColor> cc = new Dictionary <char, ConsoleColor>();
                cc.Add('0', ConsoleColor.Black);
                cc.Add('1', ConsoleColor.DarkBlue);
                cc.Add('2', ConsoleColor.DarkGreen);
                cc.Add('3', ConsoleColor.DarkCyan);
                cc.Add('4', ConsoleColor.DarkRed);
                cc.Add('5', ConsoleColor.DarkMagenta);
                cc.Add('6', ConsoleColor.DarkYellow);
                cc.Add('7', ConsoleColor.Gray);
                cc.Add('8', ConsoleColor.DarkGray);
                cc.Add('9', ConsoleColor.Blue);
                cc.Add('a', ConsoleColor.Green);
                cc.Add('b', ConsoleColor.Cyan);
                cc.Add('c', ConsoleColor.Red);
                cc.Add('d', ConsoleColor.Magenta);
                cc.Add('e', ConsoleColor.Yellow);
                cc.Add('f', ConsoleColor.White);

                string msg = ((Packet_Chat)e.packet).Message;
                output(msg);
                StreamReader sr  = new StreamReader(new MemoryStream(Encoding.Default.GetBytes(msg)));
                char[]       tmp = new char[1];
                while (!sr.EndOfStream)
                {
                    sr.Read(tmp, 0, 1);
                    if (tmp[0] == (char)65533)
                    {
                        sr.Read(tmp, 0, 1);
                        if (cc.ContainsKey(tmp[0]))
                        {
                            Console.ForegroundColor = cc[tmp[0]];
                        }
                        else
                        {
                            Console.Write(tmp[0]);
                        }
                    }
                    else
                    {
                        Console.Write(tmp[0]);
                    }
                }
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;
                break;

            case PacketType.PlayerPosAndLook:
                Packet_PlayerPosAndLook p = (Packet_PlayerPosAndLook)e.packet;
                this.x      = p.X;
                this.y      = p.Y;
                this.z      = p.Z;
                this.stance = p.Stance;
                this.pitch  = p.Pitch;
                this.yaw    = p.Yaw;
                sendPacket(p);
                output("Moved!", true);
                break;

            case PacketType.Kick:
                output("Kicked: " + ((Packet_Kick)e.packet).Reason, true);
                break;
            }
        }