private static void ConnectionThread() { try { DateTime dateTime_ = DateTime.Now; while (true) { TimeSpan ts = (DateTime.Now - Client.lastPacket); if (!Server.IsConnected() || ts.TotalSeconds > 70.0) { BotSession.Sessionreconnects++; break; } TimeSpan ts2 = (DateTime.Now - dateTime_); if (ts2.TotalMinutes >= 1.0) { GC.Collect(); GC.WaitForPendingFinalizers(); HelpTools.ClearMemory(HelpTools.GetCurrentProcess()); dateTime_ = DateTime.Now; } TimeSpan ts3 = (DateTime.Now - BotSession.dailyQuestFinishTime); if (ts3.TotalHours >= 24 && ts3.TotalMinutes >= 1 && ts3.TotalSeconds >= 1 && !BotSession.Sessioncandodailyquest) { BotSession.Sessioncandodailyquest = true; } Thread.Sleep(1000); } Thread.Sleep(2000); Bot.Running = false; if (Server._targetSocket != null && Server._targetSocket.Connected) { Server._targetSocket.Close(); } if (Bot.Running) { BotLogic.StopBotThread(); } if (BotLogic.OnAttackRunning) { BotLogic.StoponAttackThrad(); } Server.Connected = false; if (BotSettings.tasksDoneLogout && TaskSystem.TasksSystem.LogginOut) { return; } BotSession.lostConnection = true; } catch (Exception ex) { BotMethods.WriteLine("There was an error in the connection-Thread!\n\n" + ex.Message); ConnectionThread(); return; } }
public void Start() { try { Server.Local = new IPEndPoint(IPAddress.Parse("127.0.0.1"), Server.LocalPort); _mainSocket.Bind(Local); _mainSocket.Listen(10); while (true) { var source = _mainSocket.Accept(); var destination = new Server(); _targetSocket = destination._mainSocket; var state = new State(source, destination._mainSocket); destination.Connect(Remote, source); source.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, OnDataReceive, state); } } catch (Exception ex) { if (ex is SocketException && (ex as SocketException).SocketErrorCode == SocketError.AddressAlreadyInUse) { Server.LocalPort++; Server.FiddlerPort++; this.Start(); } BotMethods.WriteLine(ex.ToString()); BotMethods.WriteLine(string.Join("", new string[] { HelpTools.FromByteToString(80), HelpTools.FromByteToString(114), HelpTools.FromByteToString(111), HelpTools.FromByteToString(120), HelpTools.FromByteToString(121), HelpTools.FromByteToString(32), HelpTools.FromByteToString(99), HelpTools.FromByteToString(108), HelpTools.FromByteToString(111), HelpTools.FromByteToString(115), HelpTools.FromByteToString(101), HelpTools.FromByteToString(100), HelpTools.FromByteToString(46) })); Form1.form1.StartLocalProxy(); BotSession.lostConnection = true; } }
private static void OnDataReceive(IAsyncResult result) { var state = (State)result.AsyncState; try { var bytesRead = state.SourceSocket.EndReceive(result); if (bytesRead > 0) { var buffer = new byte[bytesRead]; Array.Copy(state.Buffer, buffer, bytesRead); if (state.SourceSocket.RemoteEndPoint.ToString().Equals(Remote.ToString())) { Client.Read(buffer); if (!Server.Connected && Account.gClass.entityInfo != null) { Server.Connected = true; BotSession.logginIn = false; BotMethods.WriteLine("Map Loaded."); BotCalculator.StartThreads(); } } if (state.DestinationSocket.RemoteEndPoint.ToString().Equals(Remote.ToString())) { //Client.Out(buffer); } state.DestinationSocket.Send(buffer, buffer.Length, SocketFlags.None); state.SourceSocket.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, OnDataReceive, state); } } catch { state.DestinationSocket.Close(); state.SourceSocket.Close(); } }