add random username

This commit is contained in:
ChomeNS 2023-03-21 11:57:12 +07:00
parent 9a13af0887
commit 7246f0a36f
2 changed files with 12 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import com.github.steveice10.packetlib.tcp.TcpClientSession;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.chayapak1.chomensbot_mabe.plugins.*; import me.chayapak1.chomensbot_mabe.plugins.*;
import org.apache.commons.lang3.RandomStringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -22,10 +23,12 @@ public class Bot {
@Getter private final String host; @Getter private final String host;
@Getter private final int port; @Getter private final int port;
@Getter private final String username; private final String _username;
@Getter private final List<Bot> allBots; @Getter private final List<Bot> allBots;
@Getter private final Map<String, String> keys; @Getter private final Map<String, String> keys;
@Getter private String username;
@Getter private Session session; @Getter private Session session;
@Getter private final int reconnectDelay; @Getter private final int reconnectDelay;
@ -43,11 +46,11 @@ public class Bot {
@Getter private final HashingPlugin hashing = new HashingPlugin(this); @Getter private final HashingPlugin hashing = new HashingPlugin(this);
@Getter private final MusicPlayerPlugin music = new MusicPlayerPlugin(this); @Getter private final MusicPlayerPlugin music = new MusicPlayerPlugin(this);
public Bot (String host, int port, int reconnectDelay, String username, List<Bot> allBots, Map<String, String> keys) { public Bot (String host, int port, int reconnectDelay, String _username, List<Bot> allBots, Map<String, String> keys) {
this.host = host; this.host = host;
this.port = port; this.port = port;
this.reconnectDelay = reconnectDelay; this.reconnectDelay = reconnectDelay;
this.username = username; this._username = _username;
this.allBots = allBots; this.allBots = allBots;
this.keys = keys; this.keys = keys;
@ -55,6 +58,9 @@ public class Bot {
} }
public void reconnect () { public void reconnect () {
if (_username == null) username = RandomStringUtils.randomAlphabetic(8);
else username = _username;
Session session = new TcpClientSession(host, port, new MinecraftProtocol(username), null); Session session = new TcpClientSession(host, port, new MinecraftProtocol(username), null);
this.session = session; this.session = session;

View file

@ -1,8 +1,9 @@
reconnectDelay: 7000 reconnectDelay: 7000
keys: keys:
normalKey: '<EFBFBD>iB_D<EFBFBD><EFBFBD><EFBFBD>k<EFBFBD><EFBFBD>j8H<EFBFBD>{?[/ڭ<>f<EFBFBD><>^-=<3D>Ț<EFBFBD><C89A>v]<5D><>g><3E><>=c' normalKey: 'normal hash key here'
ownerKey: 'b)R<><52>nF<6E>CW<43><57><EFBFBD>#<23>\\[<5B>S*8"t^eia<69>Z<EFBFBD><5A>k<EFBFBD><6B><EFBFBD><EFBFBD>K1<4B>8zȢ<7A>' ownerKey: 'OwnerHash™ key here'
bots: bots:
# username is optional, if doesn't exist it will default to random username
- host: 'localhost' - host: 'localhost'
port: 25565 port: 25565
username: 'ChomeNS_Bot' username: 'ChomeNS_Bot'