public void ReadSpells() { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetWarrior(); Console.WriteLine(tkMemory.Spells.ToString()); }
protected virtual void AddClient(IActiveClient client) { lock (ActiveClients) { ActiveClients.Add(client); } }
/// <summary> /// A client has connected /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnClientConnected(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args) { if (sender == null) { throw new ArgumentNullException("sender"); } if (args == null) { throw new ArgumentNullException("args"); } Debug.WriteLine("Connection from {0}:{1} to {2}:{3} was established", args.Socket.Information.RemoteHostName.DisplayName, args.Socket.Information.RemotePort, args.Socket.Information.LocalAddress.DisplayName, args.Socket.Information.LocalPort); var clientKey = Guid.NewGuid(); ActiveClients.Add(clientKey, args.Socket); ClientReader(args.Socket); args.Socket.Dispose(); ActiveClients.Remove(clientKey); Debug.WriteLine("Connection from {0}:{1} to {2}:{3} was disconnected", args.Socket.Information.RemoteHostName.DisplayName, args.Socket.Information.RemotePort, args.Socket.Information.LocalAddress.DisplayName, args.Socket.Information.LocalPort); }
public PoetTrainer(PoetConfiguration config) { TkTrainerFactory.Initialize(TkClient.BasePath.Poet.ToString()); _clients = new ActiveClients(config.Process); _poet = string.IsNullOrWhiteSpace(config.Name) ? _clients.GetPoet() : _clients.GetPoet(config.Name); _poet.Activity.DefaultCommandCooldown = config.CommandDelay; Log.Debug($"Key item assignments:\n{_poet.Inventory.KeyItems}\n"); Log.Debug($"Key spell assignments:\n{_poet.Spells.KeySpells}\n"); _isRunning = new AutoHotkeyToggle("^F2", "isRunning", true); _isPaused = new AutoHotkeySuspendToggle("F2", "isPaused", false); _shouldHardenBody = new AutoHotkeyToggle("F5", "shouldHardenBody", config.HardenBody.Value); _resetCurses = new AutoHotkeyToggle("F12", "resetCurses", false); _shouldEsunaExternalGroupMembers = new AutoHotkeyToggle("^F12", "shouldEsunaExternalGroupMembers", false); var toggles = new[] { _isRunning, _isPaused, _shouldHardenBody, _resetCurses, _shouldEsunaExternalGroupMembers }; _ahk = AutoHotkeyEngine.Instance; _ahk.LoadToggles(toggles); }
/// <summary> /// Initializes settings and defines hotkeys. /// </summary>. public DemoBot() { TkBotFactory.Initialize(); _clients = new ActiveClients(TkBotFactory.ProcessName); //Log.Information("Got list of clients"); _client = _clients.GetRogue(); _client.Activity.DefaultCommandCooldown = TkBotFactory.CommandCooldown; _isBotRunning = new AutoHotkeyToggle("^F2", "isBotRunning", true); _isBotPaused = new AutoHotkeyToggle("F2", "isBotPaused", false); _shouldEsunaExternalGroupMembers = new AutoHotkeyToggle("F12", "shouldEsunaExternalGroupMembers", false); _shouldRing = new AutoHotkeyToggle("NumpadDiv", "shouldRing", false); _shouldGate = new AutoHotkeyToggle("^NumpadDiv", "shouldGate", false); _shouldReturn = new AutoHotkeyToggle("!NumpadDiv", "shouldReturn", false); var toggles = new[] { _isBotRunning, _isBotPaused, _shouldEsunaExternalGroupMembers, _shouldRing, _shouldGate, _shouldReturn }; var ahk = AutoHotkeyEngine.Instance; ahk.LoadToggles(toggles); ahk.LoadScript("NumpadAdd::Send {Ctrl down},{Ctrl up}"); }
public void ReadInventory() { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetRogue(); tkMemory.Inventory.Update(); Console.WriteLine(tkMemory.Inventory.ToString()); }
public static void ReleaseClient(int user, int pipe_id) { if (ActiveClients.TryGetValue(user, out var c)) { Server.ReleaseClient(pipe_id, c.Id); ActiveClients.Remove(user); } }
public void SendKeystrokes(string keystrokes) { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetPoet(); tkMemory.Send(keystrokes); Console.WriteLine($"Sent keystrokes: \"{keystrokes}\""); }
public void RemoveUser(Client client) { var c = ActiveClients.FirstOrDefault(x => x.GridID == client.GridID | x.ID == client.ID); if (c != default(Client)) { ActiveClients.Remove(c); } }
public void Release() { Disconnect(); lock (active_client_lock) { ActiveClients.Remove(Id); } }
public void ReadChat() { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetRogue(); Console.WriteLine("----------Chat----------"); Console.WriteLine($"Chat/Blue Spell = {tkMemory.Chat.ChatOrBlueSpell}"); Console.WriteLine($"Sage/Whisper = {tkMemory.Chat.SageOrWhisper}"); }
public void ReadTargets() { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetRogue(); Console.WriteLine("----------TargetUids----------"); Console.WriteLine($"TargetUidSpell = {tkMemory.Targeting.Spell}"); Console.WriteLine($"TargetUidTab = {tkMemory.Targeting.Npc}"); Console.WriteLine($"TargetUidV = {tkMemory.Targeting.Player}"); }
public override void RemoveClient(IActiveClient client) { lock (ActiveClients) { if (ActiveClients.Any(c => c.ClientGuid == client.ClientGuid)) { ActiveClients.Remove(client); } } }
public void ReadTargets() { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetMage(); Console.WriteLine("----------TargetUids----------"); Console.WriteLine($"Auto-Target UID = {tkMemory.Targeting.AutoTarget}"); Console.WriteLine($"Item/Orb Target UID = {tkMemory.Targeting.Item}"); Console.WriteLine($"Spell Target UID = {tkMemory.Targeting.Spell}"); Console.WriteLine($"Target Lock UID = {tkMemory.Targeting.TargetLock}"); }
public async Task IsTargetOffScreen(uint uid) { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetMage(); var result = await tkMemory.IsTargetOffScreen(uid, tkMemory.Spells.KeySpells.Zap) ? "Target is off screen." : "Target is on screen."; Console.WriteLine(result); }
public void ReadEnvironment() { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetRogue(); Console.WriteLine("----------Environment----------"); Console.WriteLine($"MapCoordinateX = {tkMemory.Environment.Map.Coordinates.X}"); Console.WriteLine($"MapCoordinateY = {tkMemory.Environment.Map.Coordinates.Y}"); Console.WriteLine($"MapName = {tkMemory.Environment.Map.Name}"); Console.WriteLine($"Time = {tkMemory.Environment.Time}"); }
public void ReadActivity() { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetRogue(); Console.WriteLine("----------Activity----------"); #pragma warning disable 612 Console.WriteLine($"LatestActivity = {tkMemory.Activity.LatestActivity}"); Console.WriteLine($"StatusLatestChange = {tkMemory.Activity.LatestStatusEffectChanged}"); #pragma warning restore 612 Console.WriteLine($"StatusActiveEffects =\n{tkMemory.Activity.ActiveStatusEffects}"); }
public void WriteVTarget() { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetMage(); tkMemory.Targeting.TargetLock = 12211; Assert.AreEqual(tkMemory.Targeting.TargetLock, 12211); Console.WriteLine($"TargetUidSpell = {tkMemory.Targeting.TargetLock}"); tkMemory.Targeting.TargetLock = 831791; Assert.AreEqual(tkMemory.Targeting.TargetLock, 831791); Console.WriteLine($"TargetUidSpell = {tkMemory.Targeting.TargetLock}"); }
private void ClientHandler(Object client) { TcpClient User = (TcpClient)client; ActiveClients.Add(User); //Main Receiver while (_active) { byte[] dataSegment = new byte[Program.BufferSize]; int bytesRead = 0; byte[] ReceivedData; try { //Blocks until data is received bytesRead = User.GetStream().Read(dataSegment, 0, Program.BufferSize); ReceivedData = new byte[bytesRead]; Buffer.BlockCopy(dataSegment, 0, ReceivedData, 0, bytesRead); } catch //Socket Error { Console.WriteLine($"Client Disconnected (Socket Read Error): {User.Client.RemoteEndPoint}"); break; } if (!_active) { break; } if (bytesRead == 0) //Disconnect { Console.WriteLine($"Client Disconnected: {User.Client.RemoteEndPoint}"); break; } if (ReceivedDataHandler != null) { ReceivedDataHandler(ReceivedData, User); } else { Console.WriteLine("Data received, but no method has registered to handle it"); } } //Close client TCP stream ActiveClients.Remove(User); User.Close(); ConnectToServer(); }
public bool UpdateUser(Client client) { var c = ActiveClients.FirstOrDefault(x => x.GridID == client.GridID | x.ID == client.ID); if (c != default(Client)) { ActiveClients[ActiveClients.IndexOf(c)] = client; } else { ActiveClients.Add(client); } return(true); }
public async Task ReadNpcs() { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetMage(); await tkMemory.UpdateNpcs(tkMemory.Spells.KeySpells.Zap); var sb = new StringBuilder(); sb.AppendLine("NPC UIDs:"); foreach (var npc in tkMemory.Npcs) { sb.AppendLine(npc.Uid.ToString()); } Console.WriteLine(sb.ToString()); }
public bool TryGetClientFromName(string id, out Client client) { var c = (ActiveClients.FirstOrDefault(x => x.Name == id)); if (c != null) { client = c; return(true); } else { client = null; return(false); } }
public bool TryGetClientFromID(long id, out Client client) { var c = (ActiveClients.FirstOrDefault(x => x.GridID == id | x.ID == id)); if (c != null) { client = c; return(true); } else { client = null; return(false); } }
public async Task AutoFollow() { var activeClients = new ActiveClients(Path.GetFileNameWithoutExtension(_config.Process)); var leader = activeClients.GetClient(_config.Leader); var distance = _config.Distance; var followers = activeClients.Clients.Where(client => !string.Equals(leader.Self.Name, client.Self.Name, StringComparison.OrdinalIgnoreCase)) .ToArray(); Log.Information($"Following {leader.Self.Name} at a distance of no more than {distance} space(s)."); while (_isRunning.Value) { try { if (_isPaused.Value) { continue; } foreach (var follower in followers) { switch (follower.Self.BasePath) { case TkClient.BasePath.Mage: await((MageClient)follower).Commands.Movement.Follow(leader, distance); break; case TkClient.BasePath.Poet: await((PoetClient)follower).Commands.Movement.Follow(leader, distance); break; case TkClient.BasePath.Rogue: await((RogueClient)follower).Commands.Movement.Follow(leader, distance); break; case TkClient.BasePath.Warrior: await((WarriorClient)follower).Commands.Movement.Follow(leader, distance); break; } } } catch (Exception ex) { TkTrainerFactory.Terminate(ex); } } }
private void ClientHandler(Object client) { var user = (TcpClient)client; ActiveClients.Add(user); //Main Receiver while (_active) { var dataSegment = new byte[Program.BufferSize]; try { //Blocks until data is received var bytesRead = user.GetStream().Read(dataSegment, 0, Program.BufferSize); if (bytesRead == 0) //Disconnected { Console.WriteLine($"Client Disconnected: {user.Client.RemoteEndPoint}"); break; } //Resize the dataSegment to the actual packet length Array.Resize(ref dataSegment, bytesRead); //Dispatch the incoming packet if (ReceivedDataHandler != null) { ReceivedDataHandler(dataSegment, user); } else { Console.WriteLine($"Data received, but no method has registered to handle it"); } } //Socket Error catch { Console.WriteLine($"Client Disconnected (Socket Read Error): {user.Client.RemoteEndPoint}"); break; } if (!_active) { break; } } //Close client TCP stream ActiveClients.Remove(user); user.Close(); }
public override void Close() { if (Status == ServiceHostStatus.Stopped) { throw new InvalidOperationException("服务已经关闭。"); } Status = ServiceHostStatus.Stopped; HostSocket.Close(); HostSocket.Dispose(); ConnectionCheckTimer.Enabled = false; while (ActiveClients.Count > 0) { var client = (SocketActiveClient)ActiveClients[0]; client.Close(); } ActiveClients.Clear(); HostSocket = null; }
protected void ConnectionCheck(object sender, ElapsedEventArgs e) { lock (ActiveClients) { var checkTime = DateTime.Now; for (var i = 0; i < ActiveClients.Count; i++) { var activeClient = ActiveClients[i]; if (checkTime - activeClient.LastAliveDateTime <= DisconnectInterval) { continue; } var client = (SocketActiveClient)activeClient; client.Close(); ActiveClients.Remove(activeClient); } } }
public MageTrainer(MageConfiguration config) { TkTrainerFactory.Initialize(TkClient.BasePath.Mage.ToString()); _clients = new ActiveClients(config.Process); _mage = string.IsNullOrWhiteSpace(config.Name) ? _clients.GetMage() : _clients.GetMage(config.Name); _mage.Activity.DefaultCommandCooldown = config.CommandDelay; Log.Debug($"Key item assignments:\n{_mage.Inventory.KeyItems}\n"); Log.Debug($"Key spell assignments:\n{_mage.Spells.KeySpells}\n"); _isRunning = new AutoHotkeyToggle("^F1", "isRunning", true); _isPaused = new AutoHotkeySuspendToggle("F1", "isPaused", false); _shouldEsunaExternalGroupMembers = new AutoHotkeyToggle("F11", "shouldEsunaExternalGroupMembers", false); _shouldHeal = new AutoHotkeyToggle("`", "shouldHeal", config.Heal.Value); _shouldBlind = new AutoHotkeyToggle("1", "shouldBlind", config.Blind.Value); _shouldParalyze = new AutoHotkeyToggle("2", "shouldParalyze", config.Paralyze.Value); _shouldVenom = new AutoHotkeyToggle("3", "shouldVenom", config.Venom.Value); _shouldVex = new AutoHotkeyToggle("4", "shouldVex", config.Vex.Value); _shouldZap = new AutoHotkeyToggle("5", "shouldZap", config.Zap.Value); _shouldUpdateNpcs = new AutoHotkeyToggle("6", "shouldUpdateNpcs", false); var toggles = new[] { _isRunning, _isPaused, _shouldEsunaExternalGroupMembers, _shouldHeal, _shouldBlind, _shouldParalyze, _shouldVenom, _shouldVex, _shouldZap, _shouldUpdateNpcs }; _ahk = AutoHotkeyEngine.Instance; _ahk.LoadToggles(toggles); }
public void ReadGroup(int groupPosition) { var clients = new ActiveClients(ConfigurationManager.AppSettings["ProcessName"]); var tkMemory = clients.GetRogue(); Console.WriteLine($"---Group Member {groupPosition}---"); Console.WriteLine($"Name = {tkMemory.Group.GetName(groupPosition)}"); Console.WriteLine($"UID = {tkMemory.Group.GetUid(groupPosition)}"); Console.WriteLine("--------------------"); Console.WriteLine($"Mana Current = {tkMemory.Group.Mana.GetCurrent(groupPosition):N0}"); Console.WriteLine($"Mana Deficit = {tkMemory.Group.Mana.GetDeficit(groupPosition):N0}"); Console.WriteLine($"Mana Max = {tkMemory.Group.Mana.GetMax(groupPosition):N0}"); Console.WriteLine($"Mana Percent = {tkMemory.Group.Mana.GetPercent(groupPosition):P}"); Console.WriteLine("--------------------"); Console.WriteLine($"Vita Current = {tkMemory.Group.Vita.GetCurrent(groupPosition):N0}"); Console.WriteLine($"Vita Deficit = {tkMemory.Group.Vita.GetDeficit(groupPosition):N0}"); Console.WriteLine($"Vita Max = {tkMemory.Group.Vita.GetMax(groupPosition):N0}"); Console.WriteLine($"Vita Percent = {tkMemory.Group.Vita.GetPercent(groupPosition):P}"); }
/// <summary> /// A message was recived /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnMessageReceived(object sender, MessageReceivedEventArgs args) { foreach (var client in ActiveClients.ToList()) { var results = SendMessage(client.Value, args.Message); if (results == false) { Debug.WriteLine("Connection from {0}:{1} to {2}:{3} was disconnected", client.Value.Information.RemoteHostName.DisplayName, client.Value.Information.RemotePort, client.Value.Information.LocalAddress.DisplayName, client.Value.Information.LocalPort); client.Value.Dispose(); ActiveClients.Remove(client.Key); } } }