Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Clientless_login
- {
- using SilkroadSecurityApi;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Net.Sockets;
- using System.Threading;
- public class Agent
- {
- private static List<Packet> ag_packets = new List<Packet>();
- private static TransferBuffer ag_recv_buffer = new TransferBuffer(0x1000, 0, 0);
- private static Security ag_security = new Security();
- private static Socket ag_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- private static uint locale = uint.Parse(Globals.MainWindow.slocale.Text);
- private static uint loginID;
- private static Thread loop;
- private static string password;
- private static string username;
- private static uint version = uint.Parse(Globals.MainWindow.sversion.Text);
- public void Agent_thread()
- {
- while (true)
- {
- SocketError success;
- Packet current;
- byte[] bytes;
- ag_recv_buffer.Size = ag_socket.Receive(ag_recv_buffer.Buffer, 0, ag_recv_buffer.Buffer.Length, SocketFlags.None, out success);
- if (success != SocketError.Success)
- {
- if (success != SocketError.WouldBlock)
- {
- return;
- }
- }
- else if (ag_recv_buffer.Size > 0)
- {
- ag_security.Recv(ag_recv_buffer);
- }
- else
- {
- return;
- }
- List<Packet> collection = ag_security.TransferIncoming();
- if (collection != null)
- {
- ag_packets.AddRange(collection);
- }
- if (ag_packets.Count > 0)
- {
- using (List<Packet>.Enumerator enumerator = ag_packets.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- current = enumerator.Current;
- bytes = current.GetBytes();
- if (current.Opcode == 0x3026)
- {
- string str3;
- string str4;
- switch (current.ReadUInt8())
- {
- case 2:
- this.test("[PM] " + current.ReadAscii() + ": " + current.ReadAscii(), Color.LightBlue, new object[0]);
- break;
- case 6:
- str3 = current.ReadAscii();
- str4 = current.ReadAscii();
- this.test("[GLOBAL] " + str3 + ": " + str4, Color.Yellow, new object[0]);
- break;
- case 1:
- {
- uint num2 = current.ReadUInt32();
- string str5 = current.ReadAscii();
- this.test(string.Concat(new object[] { "[Public] (ID:", num2, ") : ", str5 }), Color.White, new object[0]);
- break;
- }
- case 3:
- {
- uint num3 = current.ReadUInt32();
- string str6 = current.ReadAscii();
- this.test(string.Concat(new object[] { "[GM] (ID:", num3, ") - ", str6, ": " }), Color.Red, new object[0]);
- break;
- }
- case 4:
- str3 = current.ReadAscii();
- str4 = current.ReadAscii();
- this.textdata("[PARTY]" + str3 + ": " + str4, new object[0]);
- break;
- case 5:
- str3 = current.ReadAscii();
- this.textdata("[GUILD]" + str3 + ": " + current.ReadAscii(), new object[0]);
- break;
- case 7:
- this.test("[Notice]" + current.ReadAscii(), Color.HotPink, new object[0]);
- break;
- }
- }
- if (((current.Opcode == 0x2113) && (current.ReadUInt8() == 1)) && Globals.MainWindow.checkBox1.Checked)
- {
- this.Meldung("Xtrap packet was sent !", new object[0]);
- Packet packet = new Packet(0);
- packet.WriteUInt8((byte) 1);
- packet.WriteUInt8((byte) 1);
- Send(packet);
- }
- if (current.Opcode == 0x3013)
- {
- this.Meldung("Spawned successfully !", new object[0]);
- }
- if ((current.Opcode == 0x3017) && (current.ReadUInt8() == 2))
- {
- Packet packet3 = new Packet(0x34b6);
- Send(packet3);
- }
- this.Log("[S->C][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", new object[] { current.Opcode, bytes.Length, current.Encrypted ? "[Encrypted]" : "", current.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(bytes), Environment.NewLine });
- if ((current.Opcode != 0x5000) && (current.Opcode != 0x9000))
- {
- Packet packet4;
- Packet packet5;
- Packet packet6;
- if (current.Opcode == 0x2001)
- {
- if (current.ReadAscii() == "GatewayServer")
- {
- Globals.Server = Globals.ServerEnum.Gateway;
- packet4 = new Packet(0x6100, true, false);
- packet4.WriteUInt8(locale);
- packet4.WriteAscii("SR_Client");
- packet4.WriteUInt32(version);
- ag_security.Send(packet4);
- }
- else
- {
- Globals.Server = Globals.ServerEnum.Agent;
- packet5 = new Packet(0x6103);
- packet5.WriteUInt32(loginID);
- packet5.WriteAscii(username);
- packet5.WriteAscii(password);
- packet5.WriteUInt8((byte) 0x16);
- packet5.WriteUInt32((uint) 0);
- packet5.WriteUInt16((ushort) 0);
- ag_security.Send(packet5);
- }
- }
- else if (current.Opcode == 0xa103)
- {
- if (current.ReadUInt8() == 1)
- {
- packet4 = new Packet(0x7007);
- packet4.WriteUInt8((byte) 2);
- ag_security.Send(packet4);
- }
- }
- else if (current.Opcode == 0xb007)
- {
- Login.HandleCharList(current);
- }
- else if (current.Opcode == 0x3020)
- {
- packet5 = new Packet(0x3012);
- Send(packet5);
- }
- }
- }
- }
- ag_packets.Clear();
- }
- List<KeyValuePair<TransferBuffer, Packet>> list2 = ag_security.TransferOutgoing();
- if (list2 != null)
- {
- foreach (KeyValuePair<TransferBuffer, Packet> pair in list2)
- {
- TransferBuffer key = pair.Key;
- current = pair.Value;
- success = SocketError.Success;
- while (key.Offset != key.Size)
- {
- int num6 = ag_socket.Send(key.Buffer, key.Offset, key.Size - key.Offset, SocketFlags.None, out success);
- if ((success != SocketError.Success) && (success != SocketError.WouldBlock))
- {
- break;
- }
- key.Offset += num6;
- Thread.Sleep(1);
- }
- if (success != SocketError.Success)
- {
- break;
- }
- bytes = current.GetBytes();
- this.Log("[C->S][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", new object[] { current.Opcode, bytes.Length, current.Encrypted ? "[Encrypted]" : "", current.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(bytes), Environment.NewLine });
- }
- if (success != SocketError.Success)
- {
- return;
- }
- }
- Thread.Sleep(1);
- }
- }
- public void Log(string msg, params object[] values)
- {
- msg = string.Format(msg, values);
- }
- public void Meldung(string msg, params object[] values)
- {
- msg = string.Format(msg, values);
- Globals.MainWindow.globalchat.AppendText(msg + "\r\n");
- }
- public static void Send(Packet packet)
- {
- ag_security.Send(packet);
- }
- public void Start(string IP, string Port, uint _loginID, string _username, string _password)
- {
- loginID = _loginID;
- username = _username;
- password = _password;
- loop = new Thread(new ThreadStart(this.Agent_thread));
- ag_socket.Connect(IP, int.Parse(Port));
- loop.Start();
- ag_socket.Blocking = false;
- ag_socket.NoDelay = true;
- }
- public void test(string msg, Color color, params object[] values)
- {
- msg = string.Format(msg, color, values);
- int length = Globals.MainWindow.richTextBox1.Text.Length;
- Globals.MainWindow.richTextBox1.Text = Globals.MainWindow.richTextBox1.Text + msg + "\r\n";
- Globals.MainWindow.richTextBox1.Select(length, msg.Length);
- Globals.MainWindow.richTextBox1.SelectionColor = color;
- }
- public void textdata(string msg, params object[] values)
- {
- msg = string.Format(msg, values);
- Globals.MainWindow.globalchat.AppendText(msg + "\r\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement