Skip to content

Commit

Permalink
Fix auto register
Browse files Browse the repository at this point in the history
  • Loading branch information
games647 committed Dec 15, 2017
1 parent 3fb067d commit 49f5073
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ public static void main(String[] args) {
});

instance = new LambdaAttack();
new MainGui(instance);
}

private final MainGui mainGui = new MainGui(this);

private boolean running = false;
private GameVersion gameVersion = GameVersion.VERSION_1_12;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.games647.lambdaattack;

import com.github.games647.lambdaattack.version.v1_12.ProtocolWrapper;
import com.github.steveice10.packetlib.Session;

public class UniversalFactory {

public static UniversalProtocol authenticate(GameVersion gameVersion, String username) {
switch (gameVersion) {
case VERSION_1_11:
return new ProtocolWrapper(username);
return new com.github.games647.lambdaattack.version.v1_11.ProtocolWrapper(username);
case VERSION_1_12:
return new com.github.games647.lambdaattack.version.v1_12.ProtocolWrapper(username);
default:
Expand All @@ -19,10 +18,10 @@ public static UniversalProtocol authenticate(GameVersion gameVersion, String use
public static void sendChatMessage(GameVersion gameVersion, String message, Session session) {
switch (gameVersion) {
case VERSION_1_11:
session.send(new com.github.steveice10.mc.protocol.v1_11.packet.ingame.client.ClientChatPacket(message));
session.send(new com.github.steveice10.protocol.v1_11.packet.ingame.client.ClientChatPacket(message));
break;
case VERSION_1_12:
session.send(new com.github.steveice10.mc.protocol.v1_12.packet.ingame.client.ClientChatPacket(message));
session.send(new com.github.steveice10.protocol.v1_12.packet.ingame.client.ClientChatPacket(message));
break;
default:
throw new IllegalArgumentException("Invalid game version");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.github.games647.lambdaattack.LambdaAttack;
import com.github.games647.lambdaattack.bot.Bot;
import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter;

Expand All @@ -22,7 +21,7 @@ public void disconnected(DisconnectedEvent disconnectedEvent) {
owner.getLogger().log(Level.INFO, "Disconnected: {0}", reason);
}

public void onJoin(GameProfile profile) {
public void onJoin() {
if (LambdaAttack.getInstance().isAutoRegister()) {
String password = LambdaAttack.PROJECT_NAME;
owner.sendMessage(Bot.COMMAND_IDENTIFIER + "register " + password + password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.github.games647.lambdaattack.bot.Bot;
import com.github.games647.lambdaattack.bot.EntitiyLocation;
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
import com.github.steveice10.mc.protocol.v1_11.packet.login.server.LoginSuccessPacket;
import com.github.steveice10.mc.protocol.v1_11.data.message.Message;
import com.github.steveice10.mc.protocol.v1_11.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.mc.protocol.v1_11.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
import com.github.steveice10.mc.protocol.v1_11.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
import com.github.steveice10.protocol.v1_11.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.protocol.v1_11.data.message.Message;
import com.github.steveice10.protocol.v1_11.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.protocol.v1_11.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
import com.github.steveice10.protocol.v1_11.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;

import java.util.logging.Level;

Expand Down Expand Up @@ -36,9 +36,9 @@ public void packetReceived(PacketReceivedEvent receiveEvent) {
ServerPlayerHealthPacket healthPacket = receiveEvent.<ServerPlayerHealthPacket>getPacket();
owner.setHealth(healthPacket.getHealth());
owner.setFood(healthPacket.getFood());
} else if (receiveEvent.getPacket() instanceof LoginSuccessPacket) {
LoginSuccessPacket loginSuccessPacket = receiveEvent.<LoginSuccessPacket>getPacket();
super.onJoin(loginSuccessPacket.getProfile());
} else if (receiveEvent.getPacket() instanceof ServerJoinGamePacket) {
ServerJoinGamePacket loginSuccessPacket = receiveEvent.<ServerJoinGamePacket>getPacket();
super.onJoin();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.github.games647.lambdaattack.bot.listener;

import com.github.games647.lambdaattack.LambdaAttack;
import com.github.games647.lambdaattack.bot.Bot;
import com.github.games647.lambdaattack.bot.EntitiyLocation;
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
import com.github.steveice10.mc.protocol.v1_12.packet.login.server.LoginSuccessPacket;
import com.github.steveice10.mc.protocol.v1_12.data.message.Message;
import com.github.steveice10.mc.protocol.v1_12.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.mc.protocol.v1_12.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
import com.github.steveice10.mc.protocol.v1_12.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
import com.github.steveice10.protocol.v1_12.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.protocol.v1_12.data.message.Message;
import com.github.steveice10.protocol.v1_12.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.protocol.v1_12.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
import com.github.steveice10.protocol.v1_12.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;

import java.util.logging.Level;

Expand Down Expand Up @@ -36,9 +37,9 @@ public void packetReceived(PacketReceivedEvent receiveEvent) {
ServerPlayerHealthPacket healthPacket = receiveEvent.<ServerPlayerHealthPacket>getPacket();
owner.setHealth(healthPacket.getHealth());
owner.setFood(healthPacket.getFood());
} else if (receiveEvent.getPacket() instanceof LoginSuccessPacket) {
LoginSuccessPacket loginSuccessPacket = receiveEvent.<LoginSuccessPacket>getPacket();
super.onJoin(loginSuccessPacket.getProfile());
} else if (receiveEvent.getPacket() instanceof ServerJoinGamePacket) {
ServerJoinGamePacket loginSuccessPacket = receiveEvent.<ServerJoinGamePacket>getPacket();
super.onJoin();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.awt.BorderLayout;
import java.awt.event.ItemEvent;
import java.util.Arrays;
import java.util.Comparator;
import java.util.logging.Level;

import javax.swing.JButton;
Expand Down Expand Up @@ -66,6 +68,7 @@ private JPanel setTopPane() {

topPanel.add(new JLabel("Auto Register: "));
JCheckBox autoRegister = new JCheckBox();
autoRegister.addActionListener(e -> botManager.setAutoRegister(!botManager.isAutoRegister()));
topPanel.add(autoRegister);

topPanel.add(new JLabel("Amount: "));
Expand All @@ -77,7 +80,11 @@ private JPanel setTopPane() {
JTextField nameFormat = new JTextField("Bot-%d");
topPanel.add(nameFormat);

JComboBox<String> versionBox = new JComboBox<>(new String[]{"1.11", "1.10", "1.9", "1.8", "1.7"});
JComboBox<String> versionBox = new JComboBox<>();
Arrays.stream(GameVersion.values())
.sorted(Comparator.reverseOrder())
.map(GameVersion::getVersion)
.forEach(versionBox::addItem);
versionBox.addItemListener(itemEvent -> {
if (itemEvent.getStateChange() == ItemEvent.SELECTED) {
botManager.setGameVersion(GameVersion.findByName((String) itemEvent.getItem()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

public enum GameVersion {

VERSION_1_11,
VERSION_1_11("1.11"),

VERSION_1_12;
VERSION_1_12("1.12.2");

public static GameVersion findByName(String name) {
switch (name) {
Expand All @@ -16,4 +16,14 @@ public static GameVersion findByName(String name) {

return null;
}

private final String version;

GameVersion(String version) {
this.version = version;
}

public String getVersion() {
return version;
}
}
2 changes: 1 addition & 1 deletion version_1_11/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<relocations>
<relocation>
<pattern>com.github.steveice10.mc.protocol</pattern>
<shadedPattern>com.github.steveice10.mc.protocol.v1_11</shadedPattern>
<shadedPattern>com.github.steveice10.protocol.v1_11</shadedPattern>
</relocation>
</relocations>

Expand Down
2 changes: 1 addition & 1 deletion version_1_12/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<relocations>
<relocation>
<pattern>com.github.steveice10.mc.protocol</pattern>
<shadedPattern>com.github.steveice10.mc.protocol.v1_12</shadedPattern>
<shadedPattern>com.github.steveice10.protocol.v1_12</shadedPattern>
</relocation>
</relocations>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public PacketProtocol getProtocol() {

@Override
public GameVersion getGameVersion() {
return GameVersion.VERSION_1_11;
return GameVersion.VERSION_1_12;
}
}

0 comments on commit 49f5073

Please sign in to comment.