Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tpa Flooding Button #1108

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 38 additions & 20 deletions src/main/java/net/wurstclient/hacks/MassTpaHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ public final class MassTpaHack extends Hack
"Stop when accepted", "Whether to stop sending more teleportation"
+ " requests when someone accepts one of them.",
true);


private final CheckboxSetting isActiveMassTpaFlooding = new CheckboxSetting(
"TPA Flood", "Re-request TPA from all players except my friend",
false);

private final Random random = new Random();
private final ArrayList<String> players = new ArrayList<>();

private String command;
private int index;
private int sendTpaCount;
private int timer;

public MassTpaHack()
Expand All @@ -72,44 +76,46 @@ public MassTpaHack()
addSetting(delay);
addSetting(ignoreErrors);
addSetting(stopWhenAccepted);
addSetting(isActiveMassTpaFlooding);
}

@Override
protected void onEnable()
{
// reset state
players.clear();
index = 0;
sendTpaCount = 0;
timer = 0;

// cache command in case the setting is changed mid-run
command = commandSetting.getValue().substring(1);

// collect player names
String playerName = MC.getSession().getUsername();
for(PlayerListEntry info : MC.player.networkHandler.getPlayerList())
{
for (PlayerListEntry info : MC.player.networkHandler.getPlayerList()) {
String name = info.getProfile().getName();
name = StringHelper.stripTextFormat(name);
if(name.equalsIgnoreCase(playerName))

if (isActiveMassTpaFlooding.isChecked() && WURST.getFriends().contains(name))
continue;


if (name.equalsIgnoreCase(playerName))
continue;

players.add(name);
}

Collections.shuffle(players, random);

EVENTS.add(ChatInputListener.class, this);
EVENTS.add(UpdateListener.class, this);

if(players.isEmpty())
{

if (players.isEmpty()) {
ChatUtils.error("Couldn't find any players.");
setEnabled(false);
}
}

@Override
protected void onDisable()
{
Expand All @@ -125,17 +131,29 @@ public void onUpdate()
timer--;
return;
}

if(index >= players.size())

if (isActiveMassTpaFlooding.isChecked() && sendTpaCount >= players.size())
{
sendTpaCount = 0;

if (command.equals("tpa"))
command = "tpacancel";

else if (command.equals("tpacancel"))
command = "tpa";
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add safeguards to command toggling logic.

Several improvements needed for the command toggling implementation:

  1. Command strings should be constants to avoid typos and enable easier maintenance
  2. Add rate limiting to prevent server spam detection
  3. Consider adding a safety check for maximum continuous cycles
+	private static final String CMD_TPA = "tpa";
+	private static final String CMD_TPA_CANCEL = "tpacancel";
+	private static final int MAX_CONTINUOUS_CYCLES = 3;
+	private int cycleCount = 0;
+
 		if (isActiveMassTpaFlooding.isChecked() && sendTpaCount >= players.size())
 		{
 			sendTpaCount = 0;
+			cycleCount++;
+
+			if (cycleCount >= MAX_CONTINUOUS_CYCLES) {
+				ChatUtils.message("Maximum flood cycles reached. Stopping to prevent detection.");
+				setEnabled(false);
+				return;
+			}
 
-			if (command.equals("tpa"))
-				command = "tpacancel";
-			else if (command.equals("tpacancel"))
-				command = "tpa";
+			command = command.equals(CMD_TPA) ? CMD_TPA_CANCEL : CMD_TPA;
 		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (isActiveMassTpaFlooding.isChecked() && sendTpaCount >= players.size())
{
sendTpaCount = 0;
if (command.equals("tpa"))
command = "tpacancel";
else if (command.equals("tpacancel"))
command = "tpa";
}
private static final String CMD_TPA = "tpa";
private static final String CMD_TPA_CANCEL = "tpacancel";
private static final int MAX_CONTINUOUS_CYCLES = 3;
private int cycleCount = 0;
if (isActiveMassTpaFlooding.isChecked() && sendTpaCount >= players.size())
{
sendTpaCount = 0;
cycleCount++;
if (cycleCount >= MAX_CONTINUOUS_CYCLES) {
ChatUtils.message("Maximum flood cycles reached. Stopping to prevent detection.");
setEnabled(false);
return;
}
command = command.equals(CMD_TPA) ? CMD_TPA_CANCEL : CMD_TPA;
}


if(!isActiveMassTpaFlooding.isChecked() && sendTpaCount >= players.size())
{
command = "/tpa";
setEnabled(false);
return;
}

MC.getNetworkHandler()
.sendChatCommand(command + " " + players.get(index));
.sendChatCommand(command + " " + players.get(sendTpaCount));

index++;
sendTpaCount++;
Comment on lines +158 to +160
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add rate limiting and error handling for network calls.

The command execution should include:

  1. Rate limiting to prevent server timeouts
  2. Error handling for network failures
  3. Logging for debugging purposes
+		try {
+			if (System.currentTimeMillis() - lastCommandTime < MIN_COMMAND_INTERVAL) {
+				return;
+			}
 			MC.getNetworkHandler()
 				.sendChatCommand(command + " " + players.get(sendTpaCount));
+			lastCommandTime = System.currentTimeMillis();
 			sendTpaCount++;
+		} catch (Exception e) {
+			ChatUtils.error("Failed to send command: " + e.getMessage());
+			setEnabled(false);
+		}

Committable suggestion skipped: line range outside the PR's diff.

timer = delay.getValueI() - 1;
}

Expand Down
Loading