示例#1
0
        static void AgentLocalThread()
        {
            try
            {
                while (true)
                {
                    lock (exit_lock)
                    {
                        if (should_exit)
                        {
                            break;
                        }
                    }

                    if (ag_local_stream.DataAvailable)
                    {
                        ag_local_recv_buffer.Offset = 0;
                        ag_local_recv_buffer.Size   = ag_local_stream.Read(ag_local_recv_buffer.Buffer, 0, ag_local_recv_buffer.Buffer.Length);
                        ag_local_security.Recv(ag_local_recv_buffer);
                    }

                    ag_local_recv_packets = ag_local_security.TransferIncoming();
                    if (ag_local_recv_packets != null)
                    {
                        foreach (Packet packet in ag_local_recv_packets)
                        {
                            //byte[] packet_bytes = packet.GetBytes();
                            //if (packet.Opcode != (0x2002))
                            //MainWindow.DebugWindow.UpdateAnalyzerLine(String.Format("[C->P][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(packet_bytes), Environment.NewLine));

                            // Do not pass through these packets.
                            if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000 || packet.Opcode == 0x2001)
                            {
                                continue;
                            }

                            if (packet.Opcode == 0x6103 && packet.GetBytes().Length != 33)
                            {
                                Packet NewPacket = new Packet((ushort)LoginServerOpcodes.CLIENT_OPCODES.GAME_LOGIN, true);
                                NewPacket.WriteUInt32(agid);
                                NewPacket.WriteAscii(Globals.MainWindow.ReadText(Globals.MainWindow.username).ToLower());
                                NewPacket.WriteAscii(Globals.MainWindow.ReadText(Globals.MainWindow.password).ToLower());
                                NewPacket.WriteUInt8(22);
                                NewPacket.WriteUInt8(0);
                                NewPacket.WriteUInt8(0);
                                NewPacket.WriteUInt8(0);
                                NewPacket.WriteUInt8(0);
                                NewPacket.WriteUInt8(0);
                                NewPacket.WriteUInt8(0);
                                ag_remote_security.Send(NewPacket);

                                continue;
                            }

                            ag_remote_security.Send(packet);
                        }
                    }

                    ag_local_send_buffers = ag_local_security.TransferOutgoing();
                    if (ag_local_send_buffers != null)
                    {
                        foreach (var kvp in ag_local_send_buffers)
                        {
                            //Packet packet = kvp.Value;
                            TransferBuffer buffer = kvp.Key;
                            //byte[] packet_bytes = packet.GetBytes();
                            //Globals.MainWindow.UpdateAnalyzerLine(String.Format("[P->C][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(packet_bytes), Environment.NewLine));
                            ag_local_stream.Write(buffer.Buffer, 0, buffer.Size);
                        }
                    }
                    Thread.Sleep(1);
                }
            }
            catch
            {
                ExitThread();
            }
        }
示例#2
0
        static void GatewayRemoteThread()
        {
            {
                while (true)
                {
                    lock (exit_lock)
                    {
                        if (should_exit)
                        {
                            break;
                        }
                    }

                    if (gw_remote_stream.DataAvailable)
                    {
                        gw_remote_recv_buffer.Offset = 0;
                        gw_remote_recv_buffer.Size   = gw_remote_stream.Read(gw_remote_recv_buffer.Buffer, 0, gw_remote_recv_buffer.Buffer.Length);
                        gw_remote_security.Recv(gw_remote_recv_buffer);
                    }

                    gw_remote_recv_packets = gw_remote_security.TransferIncoming();
                    if (gw_remote_recv_packets != null)
                    {
                        foreach (Packet packet in gw_remote_recv_packets)
                        {
                            byte[] packet_bytes = packet.GetBytes();
                            //Globals.MainWindow.UpdateAnalyzerLine(String.Format("[S->P][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(packet_bytes), Environment.NewLine));

                            //WritePacket(packet, packet_bytes, "S->C");

                            // Do not pass through these packets.
                            if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000)
                            {
                                continue;
                            }

                            LoginHandler.Handler(packet);

                            if (packet.Opcode == 0xA102)
                            {
                                byte result = packet.ReadUInt8();
                                if (result == 1)
                                {
                                    Globals.MainWindow.UnEnable(Globals.MainWindow.username);
                                    Globals.MainWindow.UnEnable(Globals.MainWindow.password);
                                    Globals.MainWindow.UnEnable(Globals.MainWindow.autologin);
                                    Globals.MainWindow.UnEnable(Globals.MainWindow.serverlist);

                                    uint id = packet.ReadUInt32();
                                    agid = id;
                                    string ip   = packet.ReadAscii();
                                    ushort port = packet.ReadUInt16();

                                    xfer_remote_ip   = ip;
                                    xfer_remote_port = port;

                                    Packet new_packet = new Packet(0xA102, true);
                                    new_packet.WriteUInt8(result);
                                    new_packet.WriteUInt32(id);
                                    new_packet.WriteAscii("127.0.0.1");
                                    new_packet.WriteUInt16(port);

                                    gw_local_security.Send(new_packet);
                                    ag = new Thread(AgentThread);
                                    ag.Start();
                                    ag.IsBackground = true;
                                    ag.Join();

                                    continue;
                                }
                                else
                                {
                                    byte subcode = packet.ReadUInt8();
                                    switch (subcode)
                                    {
                                    case 1:
                                        uint maxTry = packet.ReadUInt32();
                                        uint curTry = packet.ReadUInt32();
                                        Globals.MainWindow.UpdateLogs(string.Format("Wrong ID/PW. You have {0} attempts left!", (maxTry - curTry)));
                                        Globals.MainWindow.UnCheck(Globals.MainWindow.autologin);
                                        break;

                                    case 2:
                                        if (packet.ReadUInt8() == 1)
                                        {
                                            string reason = packet.ReadAscii();
                                            string date   = packet.ReadUInt16() + "." + packet.ReadUInt16() + "." + packet.ReadUInt16() + " " + packet.ReadUInt16() + ":" + packet.ReadUInt16();
                                            Globals.MainWindow.UpdateLogs("Your account has been banned! Reason: " + reason + ". Till: " + date);
                                        }
                                        Globals.MainWindow.UnCheck(Globals.MainWindow.autologin);
                                        break;

                                    case 3:     // User Already Connected
                                        Globals.MainWindow.UpdateLogs("User already connected!");
                                        System.Threading.Thread.Sleep(5000);
                                        Globals.MainWindow.UnCheck(Globals.MainWindow.autologin);
                                        break;

                                    case 5:     // Server Full
                                        Globals.MainWindow.UpdateLogs("The server is full!");
                                        Packet NewPacket = new Packet((ushort)LoginServerOpcodes.CLIENT_OPCODES.LOGIN, true);
                                        NewPacket.WriteUInt8(22);
                                        NewPacket.WriteAscii(Globals.MainWindow.ReadText(Globals.MainWindow.username));
                                        NewPacket.WriteAscii(Globals.MainWindow.ReadText(Globals.MainWindow.password));
                                        NewPacket.WriteUInt16(Data.ServerID[Data.ServerName.IndexOf(Globals.MainWindow.ReadText1(Globals.MainWindow.serverlist))]);
                                        System.Threading.Thread.Sleep(500);
                                        Proxy.gw_remote_security.Send(NewPacket);
                                        break;

                                    default:
                                        Globals.MainWindow.UpdateLogs("Unknown login error code: " + subcode);
                                        Globals.MainWindow.UnCheck(Globals.MainWindow.autologin);
                                        System.Threading.Thread.Sleep(5000);
                                        break;
                                    }
                                }
                            }
                            gw_local_security.Send(packet);
                        }
                    }

                    gw_remote_send_buffers = gw_remote_security.TransferOutgoing();
                    if (gw_remote_send_buffers != null)
                    {
                        foreach (var kvp in gw_remote_send_buffers)
                        {
                            //Packet packet = kvp.Value;
                            TransferBuffer buffer = kvp.Key;
                            //byte[] packet_bytes = packet.GetBytes();
                            //Globals.MainWindow.UpdateAnalyzerLine(String.Format("[P->S][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(packet_bytes), Environment.NewLine));
                            //WritePacket(packet, packet_bytes, "C->S");
                            gw_remote_stream.Write(buffer.Buffer, 0, buffer.Size);
                        }
                    }
                    Thread.Sleep(1);
                }
            }
        }
示例#3
0
        static void AgentRemoteThread()
        {
            try
            {
                while (true)
                {
                    lock (exit_lock)
                    {
                        if (should_exit)
                        {
                            break;
                        }
                    }

                    if (ag_remote_stream.DataAvailable)
                    {
                        ag_remote_recv_buffer.Offset = 0;
                        ag_remote_recv_buffer.Size   = ag_remote_stream.Read(ag_remote_recv_buffer.Buffer, 0, ag_remote_recv_buffer.Buffer.Length);
                        ag_remote_security.Recv(ag_remote_recv_buffer);
                    }

                    ag_remote_recv_packets = ag_remote_security.TransferIncoming();
                    if (ag_remote_recv_packets != null)
                    {
                        foreach (Packet packet in ag_remote_recv_packets)
                        {
                            //byte[] packet_bytes = packet.GetBytes();
                            //Globals.MainWindow1.UpdateLogs(String.Format("[S->P][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(packet_bytes), Environment.NewLine));
                            //WritePacket(packet, packet_bytes, "S->C");
                            // Do not pass through these packets.
                            if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000)
                            {
                                continue;
                            }

                            OpcodeParser.Handler(packet);

                            if (packet.Opcode != ((ushort)WorldServerOpcodes.SERVER_OPCODES.SERVER_INVENTORYMOVEMENT) && packet.Opcode != (ushort)WorldServerOpcodes.SERVER_OPCODES.SERVER_NPCSELECT)
                            {
                                ag_local_security.Send(packet);
                            }
                        }
                    }

                    ag_remote_send_buffers = ag_remote_security.TransferOutgoing();
                    if (ag_remote_send_buffers != null)
                    {
                        foreach (var kvp in ag_remote_send_buffers)
                        {
                            //Packet packet = kvp.Value;
                            TransferBuffer buffer = kvp.Key;
                            //byte[] packet_bytes = packet.GetBytes();
                            //if (packet.Opcode != (0x2002))
                            //Globals.MainWindow1.UpdateLogs(String.Format("[P->S][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(packet_bytes), Environment.NewLine));
                            ag_remote_stream.Write(buffer.Buffer, 0, buffer.Size);
                            //WritePacket(packet, packet_bytes, "C->S");
                        }
                    }
                    Thread.Sleep(1);
                }
            }
            catch { }
        }