Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using SilkroadSecurityApi;
- using System.Net.Sockets;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ArionClientless
- {
- public class Agent
- {
- public static Security ag_security = new Security();
- static TransferBuffer ag_recv_buffer = new TransferBuffer(4096, 0, 0);
- static List<Packet> ag_packets = new List<Packet>();
- static Socket ag_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- static uint loginID;
- static string username;
- static string password;
- object recv_obj = new object();
- private static bool EventStarting = false;
- //Async Connecting & Starting threads.
- #region AsyncConnect
- public void Start(string IP, string Port, uint _loginID, string _username, string _password)
- {
- loginID = _loginID;
- username = _username;
- password = _password;
- ag_socket.BeginConnect(IP, Int32.Parse(Port), new AsyncCallback(AcceptedCallBack), null);
- }
- void AcceptedCallBack(IAsyncResult result)
- {
- ag_socket.EndConnect(result);
- //Globals.MainWindow.LogMain("Agent socket successfully connected.");
- Thread Send = new Thread(SendToServer);
- Thread Recv = new Thread(AsyncRecv);
- Send.Start();
- Recv.Start();
- }
- #endregion
- #region AsyncReceiving
- void AsyncRecv()
- {
- ag_socket.BeginReceive(ag_recv_buffer.Buffer, 0, 0x1000, SocketFlags.None, new AsyncCallback(AsyncRecvFromServer), null);
- }
- void AsyncRecvFromServer(IAsyncResult iar)
- {
- lock (recv_obj)
- {
- int nReceived = ag_socket.EndReceive(iar);
- if (nReceived != 0)
- {
- ag_recv_buffer.Offset = 0;
- ag_recv_buffer.Size = nReceived;
- ag_security.Recv(ag_recv_buffer);
- List<Packet> RemotePackets = ag_security.TransferIncoming();
- if (RemotePackets != null)
- {
- foreach (Packet packet in RemotePackets)
- {
- byte[] packet_bytes = packet.GetBytes();
- //Globals.MainWindow.Log("[S->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);
- if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000)
- {
- continue;
- }
- if (packet.Opcode == 0x2001)
- {
- if (packet.ReadAscii() == "AgentServer")
- {
- Globals.Server = Globals.ServerEnum.Agent;
- Packet p = new Packet(0x6103);
- p.WriteUInt32(loginID);
- p.WriteAscii(username);
- p.WriteAscii(password);
- p.WriteUInt8(22);
- p.WriteUInt32(0);
- p.WriteUInt16(0);
- ag_security.Send(p);
- }
- }
- else if (packet.Opcode == 0xA103)
- {
- if (packet.ReadUInt8() == 1)
- {
- Packet response = new Packet(0x7007);
- response.WriteUInt8(2);
- ag_security.Send(response);
- }
- }
- else if (packet.Opcode == 0xB007)
- {
- Login.HandleCharList(packet);
- }
- else if (packet.Opcode == 0x3020)
- {
- Packet p = new Packet(0x3012);
- Send(p);
- }
- else if (packet.Opcode == 0x34b5)
- {
- Packet packet3 = new Packet(0x34b6);
- Send(packet3);
- //LogMain("[NOTIFY] Spawn Confirmed !!! " + System.DateTime.Now);
- }
- else if (packet.Opcode == 0x3026)
- {
- //LogMain("[GMCMD][NOTICE]: "); /*IN-COMPLETE*/
- }
- else if (packet.Opcode == 0x3013)
- {
- Timer lordTime = new Timer(lordEventTime, 0, 0, 10000);
- }
- else if (packet.Opcode == 0x34A6)
- {
- Logger.LogIt("Character spawned succesfully", LogType.Notify);
- Main.LogWindow.button4.Enabled = true;
- //Main.LogWindow.button7.Enabled = true;
- }
- }
- AsyncRecv();
- ag_packets.Clear();
- }
- }
- }
- }
- #endregion
- #region AsyncSending
- void AsyncSend(IAsyncResult iar)
- {
- int nSent = ag_socket.EndSend(iar);
- }
- void SendToServer()
- {
- try
- {
- while (true)
- {
- List<KeyValuePair<TransferBuffer, Packet>> list = ag_security.TransferOutgoing();
- if (list != null)
- {
- foreach (var kvp in list)
- {
- byte[] packet_bytes = kvp.Value.GetBytes();
- //Globals.MainWindow.Log("[C->S][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", kvp.Value.Opcode, packet_bytes.Length, kvp.Value.Encrypted ? "[Encrypted]" : "", kvp.Value.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(packet_bytes), Environment.NewLine);
- ag_socket.BeginSend(kvp.Key.Buffer, 0, kvp.Key.Size, SocketFlags.None, new AsyncCallback(AsyncSend), null);
- if (kvp.Value.Opcode == 0x2002)
- {
- /*Globals.MainWindow.label6.ForeColor = Color.Green;
- Globals.MainWindow.label6.Text = "Responsive(Agent) " + DateTime.Now.ToString("h:mm:ss"); ;*/
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- Logger.LogIt("Cannot Send Data(Agent).", LogType.Notify);
- }
- }
- #endregion
- #region AsyncDisconnecting
- public static void DisconnectModuleSocket()
- {
- try
- {
- if (ag_socket != null)
- {
- ag_socket.BeginDisconnect(true, new AsyncCallback(EndDC), null);
- Logger.LogIt("Succsefully disconnect Agent.", LogType.Success);
- }
- //gw_socket = null;
- }
- catch (Exception ex)
- {
- Logger.LogIt("Cannot disconnect Agent.", LogType.Notify);
- }
- }
- private static void lordEventTime(object state)
- {
- lordYarkan();
- }
- public static async void lordYarkan()
- {
- Random lordRandom = new Random();
- int worldid = lordRandom.Next(98, 102);
- await Task.Delay(3000);
- Packet packet = new Packet(0x7010);
- packet.WriteUInt8(0x10); //static
- packet.WriteUInt8(0); //static
- packet.WriteInt16(27006); //regionID
- packet.WriteSingle(1678); //x
- packet.WriteSingle(404.6); //Y
- packet.WriteSingle(524); //Z
- packet.WriteInt8(worldid.ToString()); //worldid
- packet.WriteUInt8(0); //static
- Agent.Send(packet);
- Thread.Sleep(5000);
- Packet packet1 = new Packet(0x7010);
- packet1.WriteUInt8(6);
- packet1.WriteUInt8(0);
- packet1.WriteUInt32(0x0EE2);
- packet1.WriteUInt8(1);
- packet1.WriteUInt8(3);
- Agent.Send(packet1);
- Console.WriteLine("Lord Yarkan has appeared ! Word ID = " + worldid.ToString());
- }
- static void EndDC(IAsyncResult iar)
- {
- ag_socket.EndDisconnect(iar);
- }
- #endregion
- public static void Send(Packet packet)
- {
- ag_security.Send(packet);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement