コード例 #1
0
        public void Gateway_thread()
        {
            while (true)
            {
                if (!gw_socket.IsConnected())
                {
                    if (!ClientlessAgent.ag_socket.IsConnected())
                    {
                        Globals.UpdateLogs("Disconnected from the server.");
                    }
                    break;
                }
                SocketError err;
                gw_recv_buffer.Size = gw_socket.Receive(gw_recv_buffer.Buffer, 0, gw_recv_buffer.Buffer.Length, SocketFlags.None, out err);
                if (err != SocketError.Success)
                {
                    if (err != SocketError.WouldBlock)
                    {
                        break;
                    }
                }
                else
                {
                    if (gw_recv_buffer.Size > 0)
                    {
                        gw_security.Recv(gw_recv_buffer);
                    }
                    else
                    {
                        break;
                    }
                }
                List <Packet> tmp_packets = gw_security.TransferIncoming();
                if (tmp_packets != null)
                {
                    gw_packets.AddRange(tmp_packets);
                }

                if (gw_packets.Count > 0)
                {
                    foreach (Packet packet in gw_packets)
                    {
                        if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000)
                        {
                            continue;
                        }

                        else if (packet.Opcode == 0xa100)
                        {
                            Packet packet2 = new Packet(0x6106, false, true);
                            packet2.WriteUInt8((byte)1);
                            gw_security.Send(packet2);
                            Packet packet3 = new Packet(0x6102, false, true);
                            packet3.WriteUInt8((byte)1);
                            gw_security.Send(packet3);
                            gw_security.Send(packet3);
                        }
                        else if (packet.Opcode == 0x6005)
                        {
                            Packet packet4 = new Packet(0x2002, false);
                            gw_security.Send(packet4);
                            Packet packet5 = new Packet(0x6102, true);
                            gw_security.Send(packet5);
                        }

                        /* else if (packet.Opcode == 0x2001)
                         * {
                         *   if (packet.ReadSTRING("ascii") == "GatewayServer")
                         *   {
                         *       Globals.Server = Globals.ServerEnum.Gateway;
                         *       Packet response = new Packet(0x6100, true, false);
                         *       response.WriteUInt8(locale);
                         *       response.WriteAscii("SR_Client");
                         *       response.WriteUInt32(version);
                         *       gw_security.Send(response);
                         *   }
                         * }*/

                        else if (packet.Opcode == 0xA323)
                        {
                            if (packet.ReadBYTE() == 1)
                            {
                                Globals.Main.pic.Image.Dispose();
                                Globals.Main.pic.Image = null;
                                //System.IO.File.Delete(Captcha.lastImageName);
                            }
                            else
                            {
                                Globals.Main.pic.Image.Dispose();
                                Globals.Main.pic.Image = null;
                                //System.IO.File.Delete(Captcha.lastImageName);
                                Globals.Main.btnLogin.PerformClick();
                            }
                        }

                        /* else if (packet.Opcode == 0xA100)
                         * {
                         *   byte result = packet.ReadBYTE();
                         *   if (result == 1)
                         *   {
                         *       Packet response = new Packet(0x6101, true);
                         *       gw_security.Send(response);
                         *   }
                         *   else
                         *   {
                         *       return;
                         *   }
                         *
                         * }*/
                        else if (packet.Opcode == 0xA102)
                        {
                            if (packet.ReadBYTE() == 1)
                            {
                                uint            LoginID = packet.ReadDWORD();
                                string          ip      = packet.ReadSTRING("ascii");
                                ushort          port    = packet.ReadWORD();
                                ClientlessAgent ag      = new ClientlessAgent();
                                ag.Start(ip, port.ToString(), LoginID, Globals.Main.id.Text, Globals.Main.pw.Text);
                            }
                            else
                            {
                                byte error = packet.ReadBYTE();
                                MessageBox.Show("errorlar:" + error);
                            }
                        }
                        GatewayHandler.RemotePacketHandler(packet);
                    }
                    gw_packets.Clear();
                }
                List <KeyValuePair <TransferBuffer, Packet> > tmp_buffers = gw_security.TransferOutgoing();
                if (tmp_buffers != null)
                {
                    foreach (var kvp in tmp_buffers)
                    {
                        TransferBuffer buffer = kvp.Key;
                        Packet         packet = kvp.Value;
                        err = SocketError.Success;
                        while (buffer.Offset != buffer.Size)
                        {
                            int sent = gw_socket.Send(buffer.Buffer, buffer.Offset, buffer.Size - buffer.Offset, SocketFlags.None, out err);
                            Analyzer.ClientAnalyze(packet);
                            if (err != SocketError.Success)
                            {
                                if (err != SocketError.WouldBlock)
                                {
                                    break;
                                }
                            }


                            buffer.Offset += sent;
                            Thread.Sleep(1);
                        }
                        if (err != SocketError.Success)
                        {
                            break;
                        }
                    }

                    if (err != SocketError.Success)
                    {
                        break;
                    }
                }
                Thread.Sleep(1);
            }
        }
コード例 #2
0
        public void Agent_thread()
        {
            while (true)
            {
                if (!ag_socket.IsConnected())
                {
                    Globals.UpdateLogs("Disconnected from the server.");
                    break;
                }
                SocketError err;
                ag_recv_buffer.Size = ag_socket.Receive(ag_recv_buffer.Buffer, 0, ag_recv_buffer.Buffer.Length, SocketFlags.None, out err);
                if (err != SocketError.Success)
                {
                    if (err != SocketError.WouldBlock)
                    {
                        break;
                    }
                }
                else
                {
                    if (ag_recv_buffer.Size > 0)
                    {
                        ag_security.Recv(ag_recv_buffer);
                    }
                    else
                    {
                        break;
                    }
                }

                // Obtain all queued packets and add them to our own queue to process later.
                List <Packet> tmp_packets = ag_security.TransferIncoming();
                if (tmp_packets != null)
                {
                    ag_packets.AddRange(tmp_packets);
                }

                if (ag_packets.Count > 0)
                {
                    foreach (Packet packet in ag_packets)
                    {
                        if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000)
                        {
                            continue;
                        }
                        if (packet.Opcode == 0x2001)
                        {
                            if (packet.ReadSTRING("ascii") == "GatewayServer")
                            {
                                Globals.Server = Globals.ServerEnum.Gateway;
                                Packet response = new Packet(0x6100, true, false);
                                response.AddBYTE((byte)locale);
                                response.AddSTRING("SR_Client", "ascii");
                                response.AddDWORD(version);
                                ag_security.Send(response);
                            }
                            else
                            {
                                Globals.Server = Globals.ServerEnum.Agent;
                                Packet p = new Packet(0x6103);
                                p.AddDWORD(loginID);
                                p.WriteAscii(username);
                                p.WriteAscii(password);
                                p.AddBYTE(22);
                                p.AddDWORD(0);
                                p.AddWORD(0);
                                ag_security.Send(p);
                            }
                        }
                        else if (packet.Opcode == 0xA103)
                        {
                            byte flag = packet.ReadBYTE();
                            if (flag == 1)
                            {
                                Packet response = new Packet(0x7007);
                                response.AddBYTE(2);
                                ag_security.Send(response);
                            }
                            else if (flag == 2)
                            {
                                if (packet.ReadBYTE() == 4)
                                {
                                    Globals.UpdateLogs("Server is full");
                                    Globals.Main.btnLogin.Enabled = true;
                                }
                            }
                        }
                        else if (packet.Opcode == 0xB007)
                        {
                            Login.HandleCharList(packet);
                        }
                        else if (packet.Opcode == 0x3020)
                        {
                            Packet p = new Packet(0x3012);
                            Send(p);
                        }
                        AgentHandler.RemotePacketHandler(packet);
                    }
                    ag_packets.Clear();
                }
                List <KeyValuePair <TransferBuffer, Packet> > tmp_buffers = ag_security.TransferOutgoing();
                if (tmp_buffers != null)
                {
                    foreach (var kvp in tmp_buffers)
                    {
                        TransferBuffer buffer = kvp.Key;
                        Packet         packet = kvp.Value;
                        err = SocketError.Success;
                        while (buffer.Offset != buffer.Size)
                        {
                            int sent = ag_socket.Send(buffer.Buffer, buffer.Offset, buffer.Size - buffer.Offset, SocketFlags.None, out err);
                            Analyzer.ClientAnalyze(packet);
                            if (err != SocketError.Success)
                            {
                                if (err != SocketError.WouldBlock)
                                {
                                    break;
                                }
                            }
                            buffer.Offset += sent;
                            Thread.Sleep(1);
                        }
                        if (err != SocketError.Success)
                        {
                            break;
                        }
                    }
                    if (err != SocketError.Success)
                    {
                        break;
                    }
                }

                Thread.Sleep(1);
            }
        }