Skip to content

Commit 4ed7349

Browse files
author
YoFuzzy3
committed
Version 2.3.
Allow spaces in /sync for command block support. Add version to protocol check. Fix null password bug.
1 parent 08b61a9 commit 4ed7349

8 files changed

Lines changed: 63 additions & 37 deletions

File tree

CommandSyncClient/src/com/fuzzoland/CommandSyncClient/CSC.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class CSC extends JavaPlugin {
2020
public List<String> oq = Collections.synchronizedList(new ArrayList<String>());
2121
public Integer qc = 0;
2222
public String spacer = "@#@";
23-
public String pass;
2423
public Debugger debugger;
2524

2625
public void onEnable() {
@@ -30,12 +29,11 @@ public void onEnable() {
3029
return;
3130
}
3231
try {
33-
client = new ClientThread(this, InetAddress.getByName(data[0]), Integer.parseInt(data[1]), Integer.parseInt(data[2]), data[3]);
32+
client = new ClientThread(this, InetAddress.getByName(data[0]), Integer.parseInt(data[1]), Integer.parseInt(data[2]), data[3], data[4]);
3433
client.start();
3534
} catch(Exception e) {
3635
e.printStackTrace();
3736
}
38-
pass = data[4];
3937
loadData();
4038
getCommand("Sync").setExecutor(new CommandSynchronize(this));
4139
}

CommandSyncClient/src/com/fuzzoland/CommandSyncClient/ClientThread.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ public class ClientThread extends Thread {
2020
private BufferedReader in;
2121
private Integer heartbeat = 0;
2222
private String name;
23+
private String pass;
24+
private String version = "2.3";
2325

24-
public ClientThread(CSC plugin, InetAddress ip, Integer port, Integer heartbeat, String name) {
26+
public ClientThread(CSC plugin, InetAddress ip, Integer port, Integer heartbeat, String name, String pass) {
2527
this.plugin = plugin;
2628
this.ip = ip;
2729
this.port = port;
2830
this.heartbeat = heartbeat;
2931
this.name = name;
32+
this.pass = pass;
3033
connect(false);
3134
}
3235

@@ -92,13 +95,21 @@ private void connect(Boolean sleep) {
9295
out.println(name);
9396
if(in.readLine().equals("n")) {
9497
plugin.debugger.debug("The name " + name + " is already connected.");
98+
socket.close();
9599
return;
96100
}
97-
out.println(plugin.pass);
101+
out.println(pass);
98102
if(in.readLine().equals("n")) {
99-
plugin.debugger.debug("The password is invalid.");
103+
plugin.debugger.debug("The password you provided is invalid.");
104+
socket.close();
100105
return;
101106
}
107+
out.println(version);
108+
if(in.readLine().equals("n")) {
109+
plugin.debugger.debug("The client's version of " + version + " does not match the server's version of " + in.readLine() + ".");
110+
socket.close();
111+
return;
112+
}
102113
connected = true;
103114
plugin.debugger.debug("Connected to " + ip.getHostName() + ":" + String.valueOf(port) + " under name " + name + ".");
104115
} catch(IOException e) {

CommandSyncClient/src/com/fuzzoland/CommandSyncClient/CommandSynchronize.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
2121
sender.sendMessage(ChatColor.BLUE + "CommandSync by YoFuzzy3");
2222
if(args.length >= 1) {
2323
if(args[0].equalsIgnoreCase("console")){
24-
sender.sendMessage(ChatColor.GREEN + "/sync console single <command+args> <server>");
25-
sender.sendMessage(ChatColor.GREEN + "/sync console all <command+args>");
26-
sender.sendMessage(ChatColor.GREEN + "/sync console bungee <command+args>");
24+
sender.sendMessage(ChatColor.GREEN + "/sync console <server> <command args...>");
25+
sender.sendMessage(ChatColor.GREEN + "/sync console all <command args...>");
26+
sender.sendMessage(ChatColor.GREEN + "/sync console bungee <command args...>");
2727
} else if(args[0].equalsIgnoreCase("player")) {
28-
sender.sendMessage(ChatColor.GREEN + "/sync player single <command+args> <player>");
29-
sender.sendMessage(ChatColor.GREEN + "/sync player all <command+args>");
28+
sender.sendMessage(ChatColor.GREEN + "/sync player <player> <command args...>");
29+
sender.sendMessage(ChatColor.GREEN + "/sync player all <command args...>");
3030
} else {
3131
sender.sendMessage(ChatColor.RED + "Type /sync for help.");
3232
}
@@ -37,17 +37,22 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
3737
}
3838
sender.sendMessage(ChatColor.BLUE + "Visit www.spigotmc.org/resources/commandsync.115 for help.");
3939
} else if(args.length >= 3) {
40-
if(args[0].equalsIgnoreCase("console")) {
41-
if(args[1].equalsIgnoreCase("single") || args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("bungee")) {
42-
makeData(args, sender);
40+
if(args[0].equalsIgnoreCase("console") || args[0].equalsIgnoreCase("player")) {
41+
String[] newArgs = new String[3];
42+
newArgs[0] = args[0];
43+
newArgs[1] = args[1];
44+
StringBuilder sb = new StringBuilder();
45+
for(int i = 2; i < args.length; i++) {
46+
sb.append(args[i]);
47+
if(i < args.length - 1) {
48+
sb.append("+");
49+
}
50+
}
51+
newArgs[2] = sb.toString();
52+
if(args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("bungee")) {
53+
makeData(newArgs, false, sender);
4354
} else {
44-
sender.sendMessage(ChatColor.RED + "Type /sync for help!");
45-
}
46-
} else if(args[0].equalsIgnoreCase("player")) {
47-
if(args[1].equalsIgnoreCase("single") || args[1].equalsIgnoreCase("all")) {
48-
makeData(args, sender);
49-
} else {
50-
sender.sendMessage(ChatColor.RED + "Type /sync for help!");
55+
makeData(newArgs, true, sender);
5156
}
5257
} else {
5358
sender.sendMessage(ChatColor.RED + "Type /sync for help!");
@@ -60,13 +65,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
6065
return true;
6166
}
6267

63-
private void makeData(String[] args, CommandSender sender) {
64-
String data = args[0].toLowerCase() + plugin.spacer + args[1].toLowerCase() + plugin.spacer + args[2];
68+
private void makeData(String[] args, Boolean single, CommandSender sender) {
69+
String data;
6570
String message = ChatColor.GREEN + "Syncing command /" + args[2].replaceAll("\\+", " ") + " to " + args[0];
66-
if(args.length == 4) {
67-
data = data + plugin.spacer + args[3];
68-
message = message + " [" + args[3] + "]...";
71+
if(single) {
72+
data = args[0].toLowerCase() + plugin.spacer + "single" + plugin.spacer + args[2] + plugin.spacer + args[1];
73+
message = message + " [" + args[1] + "]...";
6974
} else {
75+
data = args[0].toLowerCase() + plugin.spacer + args[1].toLowerCase() + plugin.spacer + args[2];
7076
message = message + " [" + WordUtils.capitalizeFully(args[1]) + "]...";
7177
}
7278
plugin.oq.add(data);

CommandSyncClient/src/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CommandSync
22
main: com.fuzzoland.CommandSyncClient.CSC
3-
version: 2.2
3+
version: 2.3
44
author: YoFuzzy3
55

66
commands:

CommandSyncServer/src/com/fuzzoland/CommandSyncServer/CSS.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class CSS extends Plugin {
3131
public Map<String, List<String>> pq = Collections.synchronizedMap(new HashMap<String, List<String>>());
3232
public Map<String, Integer> qc = Collections.synchronizedMap(new HashMap<String, Integer>());
3333
public String spacer = "@#@";
34-
public String pass;
3534
public Debugger debugger;
3635

3736
public void onEnable() {
@@ -43,11 +42,10 @@ public void onEnable() {
4342
try {
4443
server = new ServerSocket(Integer.parseInt(data[1]), 50, InetAddress.getByName(data[0]));
4544
debugger.debug("Opened server on " + data[0] + ":" + data[1] + ".");
46-
new ClientListener(this, Integer.parseInt(data[2])).start();
45+
new ClientListener(this, Integer.parseInt(data[2]), data[3]).start();
4746
} catch(Exception e) {
4847
e.printStackTrace();
4948
}
50-
pass = data[3];
5149
loadData();
5250
try {
5351
Metrics metrics = new Metrics(this);

CommandSyncServer/src/com/fuzzoland/CommandSyncServer/ClientHandler.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ public class ClientHandler extends Thread {
1919
private BufferedReader in;
2020
private Integer heartbeat = 0;
2121
private String name;
22+
private String pass;
23+
private String version = "2.3";
2224

23-
public ClientHandler(CSS plugin, Socket socket, Integer heartbeat) throws IOException {
25+
public ClientHandler(CSS plugin, Socket socket, Integer heartbeat, String pass) throws IOException {
2426
this.plugin = plugin;
2527
this.socket = socket;
2628
this.heartbeat = heartbeat;
29+
this.pass = pass;
2730
out = new PrintWriter(socket.getOutputStream(), true);
2831
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
2932
plugin.debugger.debug("Received new connection from " + socket.getInetAddress().getHostName() + ":" + socket.getPort() + ".");
@@ -35,16 +38,24 @@ public ClientHandler(CSS plugin, Socket socket, Integer heartbeat) throws IOExce
3538
return;
3639
}
3740
out.println("y");
38-
String pass = in.readLine();
39-
if(!pass.equals(plugin.pass)) {
41+
if(!in.readLine().equals(this.pass)) {
4042
plugin.debugger.debug("[" + socket.getInetAddress().getHostName() + ":" + socket.getPort() + "] [" + name + "] Provided an invalid password.");
4143
out.println("n");
4244
socket.close();
4345
return;
4446
}
4547
out.println("y");
48+
String version = in.readLine();
49+
if(!version.equals(this.version)) {
50+
plugin.debugger.debug("[" + socket.getInetAddress().getHostName() + ":" + socket.getPort() + "] [" + name + "] Client's version of " + version + " does not match the server's version of " + this.version + ".");
51+
out.println("n");
52+
out.println(this.version);
53+
socket.close();
54+
return;
55+
}
56+
out.println("y");
4657
if(!plugin.qc.containsKey(name)) {
47-
plugin.qc.put(name, 0);
58+
plugin.qc.put(name, 0);
4859
}
4960
plugin.c.add(name);
5061
plugin.debugger.debug("Connection from " + socket.getInetAddress().getHostName() + ":" + socket.getPort() + " under name " + name + " has been authorised.");

CommandSyncServer/src/com/fuzzoland/CommandSyncServer/ClientListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ public class ClientListener extends Thread {
66

77
private CSS plugin;
88
private Integer heartbeat;
9+
private String pass;
910

10-
public ClientListener(CSS plugin, Integer heartbeat) {
11+
public ClientListener(CSS plugin, Integer heartbeat, String pass) {
1112
this.plugin = plugin;
1213
this.heartbeat = heartbeat;
14+
this.pass = pass;
1315
}
1416

1517
public void run() {
1618
while(true) {
1719
try {
18-
new ClientHandler(plugin, plugin.server.accept(), heartbeat).start();
20+
new ClientHandler(plugin, plugin.server.accept(), heartbeat, pass).start();
1921
} catch(IOException e) {
2022
e.printStackTrace();
2123
}

CommandSyncServer/src/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: CommandSync
22
main: com.fuzzoland.CommandSyncServer.CSS
3-
version: 2.2
3+
version: 2.3
44
author: YoFuzzy3

0 commit comments

Comments
 (0)