add chat and colon filtering
This commit is contained in:
parent
8a6f280997
commit
468e7703bd
3 changed files with 40 additions and 26 deletions
|
@ -184,7 +184,8 @@ public class Proxy {
|
|||
final String cmd = line;
|
||||
Proxy.this.schedule(new Runnable() {
|
||||
public void run() {
|
||||
Proxy.this.runCommand(null, Formatter.filterSpaces(cmd).split(" ", -1), cmd);
|
||||
String msg = Formatter.filterSpaces(cmd);
|
||||
Proxy.this.runCommand(null, msg.isEmpty() ? new String[0] : msg.split(" ", -1), msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -444,6 +445,7 @@ public class Proxy {
|
|||
player.sendMessage(Formatter.DARK_RED + "Internal error trying to execute command");
|
||||
Log.error(t, "Could not execute '%s'" + (player != null ? " as %s" : ""), line, player != null ? player.getUsername() : null);
|
||||
}
|
||||
Log.info((player != null ? "%s executed" : "Executed") + ": %s", player != null ? player.getUsername() : line, line);
|
||||
if(player != null)
|
||||
Log.info("%s executed: %s", player.getUsername(), line);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.net.IDN;
|
|||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
@ -116,11 +117,11 @@ public class ProxyHandler implements Handler {
|
|||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
this.sendToClient(new S02PacketChat(message));
|
||||
this.sendToClient(new S02PacketChat(message, (byte)0));
|
||||
}
|
||||
|
||||
public void sendMessage(String fmt, Object... args) {
|
||||
this.sendToClient(new S02PacketChat(String.format(fmt, args)));
|
||||
this.sendToClient(new S02PacketChat(String.format(fmt, args), (byte)0));
|
||||
}
|
||||
|
||||
public void update(Connection connection) {
|
||||
|
@ -354,32 +355,39 @@ public class ProxyHandler implements Handler {
|
|||
if(this.connected) {
|
||||
Handler.syncToMain(packetIn, this, this.proxy);
|
||||
String msg = packetIn.getMessage();
|
||||
if(!isValidString(msg))
|
||||
return;
|
||||
msg = Formatter.filterSpaces(msg);
|
||||
if(msg.isEmpty())
|
||||
return;
|
||||
if(msg.startsWith("/")) {
|
||||
if(msg.indexOf(' ') == -1) {
|
||||
if(msg.equals("/vproxy")) {
|
||||
if(!this.admin) {
|
||||
this.sendMessage(Formatter.DARK_RED + "You are not allowed to execute this command");
|
||||
return;
|
||||
}
|
||||
this.proxy.runCommand(this, new String[0], msg);
|
||||
if(msg.equals("/vproxy")) {
|
||||
if(!this.admin) {
|
||||
this.sendMessage(Formatter.DARK_RED + "You are not allowed to execute this command");
|
||||
return;
|
||||
}
|
||||
this.proxy.runCommand(this, new String[0], msg);
|
||||
}
|
||||
else if(msg.startsWith("/vproxy ")) {
|
||||
if(!this.admin) {
|
||||
this.sendMessage(Formatter.DARK_RED + "You are not allowed to execute this command");
|
||||
return;
|
||||
}
|
||||
String[] args = msg.split(" ", -1);
|
||||
String[] argv = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, argv, 0, argv.length);
|
||||
this.proxy.runCommand(this, argv, msg);
|
||||
}
|
||||
else {
|
||||
if(msg.startsWith("/vproxy ")) {
|
||||
if(!this.admin) {
|
||||
this.sendMessage(Formatter.DARK_RED + "You are not allowed to execute this command");
|
||||
return;
|
||||
}
|
||||
String[] args = Formatter.filterSpaces(msg).split(" ", -1);
|
||||
String[] argv = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, argv, 0, argv.length);
|
||||
this.proxy.runCommand(this, argv, msg);
|
||||
return;
|
||||
}
|
||||
this.sendToServer(msg.split(" ", -1)[0].indexOf(':') != -1 ? new C01PacketChatMessage("/") : packetIn);
|
||||
}
|
||||
}
|
||||
else {
|
||||
msg = String.format(Formatter.BLUE + "%s" + Formatter.DARK_GRAY + ": " + Formatter.GRAY + "%s", this.username, packetIn.getMessage());
|
||||
for(ProxyHandler player : this.proxy.getPlayers()) {
|
||||
player.sendToClient(new S02PacketChat(msg, (byte)1));
|
||||
}
|
||||
}
|
||||
this.sendToServer(packetIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,7 +408,11 @@ public class ProxyHandler implements Handler {
|
|||
List<String> list = null;
|
||||
if(this.completion.startsWith("/")) {
|
||||
if(this.completion.indexOf(' ') == -1) {
|
||||
list = Lists.newArrayList(packetIn.getMatches());
|
||||
list = this.completion.indexOf(':') != -1 ? Lists.newArrayList() : Lists.newArrayList(packetIn.getMatches());
|
||||
for(Iterator<String> iter = list.iterator(); iter.hasNext();) {
|
||||
if(iter.next().indexOf(':') != -1)
|
||||
iter.remove();
|
||||
}
|
||||
if(this.admin && "/vproxy".regionMatches(true, 0, this.completion, 0, this.completion.length()))
|
||||
list.add("/vproxy");
|
||||
Collections.sort(list);
|
||||
|
|
|
@ -16,10 +16,10 @@ public class S02PacketChat implements Packet<ProxyHandler>
|
|||
{
|
||||
}
|
||||
|
||||
public S02PacketChat(String message)
|
||||
public S02PacketChat(String message, byte type)
|
||||
{
|
||||
this.chatComponent = Formatter.toJsonString(message);
|
||||
this.type = 0;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue