Added ability to intercept all chat and to set TabList names
This commit is contained in:
parent
b4c13285ff
commit
52455d3249
@ -15,15 +15,7 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import static net.md_5.bungee.Logger.$;
|
import static net.md_5.bungee.Logger.$;
|
||||||
import net.md_5.bungee.command.Command;
|
import net.md_5.bungee.command.*;
|
||||||
import net.md_5.bungee.command.CommandAlert;
|
|
||||||
import net.md_5.bungee.command.CommandEnd;
|
|
||||||
import net.md_5.bungee.command.CommandIP;
|
|
||||||
import net.md_5.bungee.command.CommandList;
|
|
||||||
import net.md_5.bungee.command.CommandMotd;
|
|
||||||
import net.md_5.bungee.command.CommandSender;
|
|
||||||
import net.md_5.bungee.command.CommandServer;
|
|
||||||
import net.md_5.bungee.command.ConsoleCommandSender;
|
|
||||||
import net.md_5.bungee.packet.DefinedPacket;
|
import net.md_5.bungee.packet.DefinedPacket;
|
||||||
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
||||||
import net.md_5.bungee.plugin.JavaPluginManager;
|
import net.md_5.bungee.plugin.JavaPluginManager;
|
||||||
@ -37,10 +29,11 @@ import net.md_5.bungee.tablist.TabListHandler;
|
|||||||
*/
|
*/
|
||||||
public class BungeeCord
|
public class BungeeCord
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server protocol version.
|
* Server protocol version.
|
||||||
*/
|
*/
|
||||||
public static final int PROTOCOL_VERSION= 49;
|
public static final int PROTOCOL_VERSION = 49;
|
||||||
/**
|
/**
|
||||||
* Server game version.
|
* Server game version.
|
||||||
*/
|
*/
|
||||||
|
@ -21,6 +21,7 @@ public class GenericConnection
|
|||||||
protected final PacketInputStream in;
|
protected final PacketInputStream in;
|
||||||
protected final OutputStream out;
|
protected final OutputStream out;
|
||||||
public String username;
|
public String username;
|
||||||
|
public String tabListName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the socket with the specified reason.
|
* Close the socket with the specified reason.
|
||||||
|
@ -3,21 +3,16 @@ package net.md_5.bungee;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import javax.crypto.SecretKey;
|
|
||||||
import net.md_5.bungee.packet.DefinedPacket;
|
import net.md_5.bungee.packet.DefinedPacket;
|
||||||
import net.md_5.bungee.packet.Packet1Login;
|
import net.md_5.bungee.packet.Packet1Login;
|
||||||
import net.md_5.bungee.packet.Packet2Handshake;
|
import net.md_5.bungee.packet.Packet2Handshake;
|
||||||
import net.md_5.bungee.packet.PacketCDClientStatus;
|
import net.md_5.bungee.packet.PacketCDClientStatus;
|
||||||
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
||||||
import net.md_5.bungee.packet.PacketFCEncryptionResponse;
|
|
||||||
import net.md_5.bungee.packet.PacketFDEncryptionRequest;
|
import net.md_5.bungee.packet.PacketFDEncryptionRequest;
|
||||||
import net.md_5.bungee.packet.PacketFFKick;
|
import net.md_5.bungee.packet.PacketFFKick;
|
||||||
import net.md_5.bungee.packet.PacketInputStream;
|
import net.md_5.bungee.packet.PacketInputStream;
|
||||||
import org.bouncycastle.crypto.io.CipherInputStream;
|
|
||||||
import org.bouncycastle.crypto.io.CipherOutputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing a connection from the proxy to the server; ie upstream.
|
* Class representing a connection from the proxy to the server; ie upstream.
|
||||||
|
@ -10,18 +10,11 @@ import java.util.List;
|
|||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import net.md_5.bungee.command.CommandSender;
|
import net.md_5.bungee.command.CommandSender;
|
||||||
import net.md_5.bungee.packet.DefinedPacket;
|
import net.md_5.bungee.packet.*;
|
||||||
import net.md_5.bungee.packet.Packet0KeepAlive;
|
import net.md_5.bungee.plugin.ChatEvent;
|
||||||
import net.md_5.bungee.packet.Packet1Login;
|
|
||||||
import net.md_5.bungee.packet.Packet2Handshake;
|
|
||||||
import net.md_5.bungee.packet.Packet3Chat;
|
|
||||||
import net.md_5.bungee.packet.Packet9Respawn;
|
|
||||||
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
|
||||||
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
|
||||||
import net.md_5.bungee.packet.PacketInputStream;
|
|
||||||
import net.md_5.bungee.plugin.ServerConnectEvent;
|
|
||||||
import net.md_5.bungee.plugin.PluginMessageEvent;
|
import net.md_5.bungee.plugin.PluginMessageEvent;
|
||||||
import net.md_5.bungee.plugin.PluginMessageEvent.Destination;
|
import net.md_5.bungee.plugin.PluginMessageEvent.Destination;
|
||||||
|
import net.md_5.bungee.plugin.ServerConnectEvent;
|
||||||
|
|
||||||
public class UserConnection extends GenericConnection implements CommandSender
|
public class UserConnection extends GenericConnection implements CommandSender
|
||||||
{
|
{
|
||||||
@ -47,11 +40,19 @@ public class UserConnection extends GenericConnection implements CommandSender
|
|||||||
super(socket, in, out);
|
super(socket, in, out);
|
||||||
this.handshake = handshake;
|
this.handshake = handshake;
|
||||||
username = handshake.username;
|
username = handshake.username;
|
||||||
|
tabListName = handshake.username;
|
||||||
this.loginPackets = loginPackets;
|
this.loginPackets = loginPackets;
|
||||||
BungeeCord.instance.connections.put(username, this);
|
BungeeCord.instance.connections.put(username, this);
|
||||||
BungeeCord.instance.tabListHandler.onJoin(this);
|
BungeeCord.instance.tabListHandler.onJoin(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTabListName(String newName)
|
||||||
|
{
|
||||||
|
BungeeCord.instance.tabListHandler.onDisconnect(this);
|
||||||
|
tabListName = newName;
|
||||||
|
BungeeCord.instance.tabListHandler.onJoin(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void connect(String server)
|
public void connect(String server)
|
||||||
{
|
{
|
||||||
ServerConnectEvent event = new ServerConnectEvent(this.server == null, this, server);
|
ServerConnectEvent event = new ServerConnectEvent(this.server == null, this, server);
|
||||||
@ -171,7 +172,7 @@ public class UserConnection extends GenericConnection implements CommandSender
|
|||||||
|
|
||||||
public void sendPluginMessage(String tag, byte[] data)
|
public void sendPluginMessage(String tag, byte[] data)
|
||||||
{
|
{
|
||||||
server.packetQueue.add(new PacketFAPluginMessage(tag, data));
|
server.packetQueue.add(new PacketFAPluginMessage(tag, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -219,6 +220,12 @@ public class UserConnection extends GenericConnection implements CommandSender
|
|||||||
if (message.startsWith("/"))
|
if (message.startsWith("/"))
|
||||||
{
|
{
|
||||||
sendPacket = !BungeeCord.instance.dispatchCommand(message.substring(1), UserConnection.this);
|
sendPacket = !BungeeCord.instance.dispatchCommand(message.substring(1), UserConnection.this);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
ChatEvent chatEvent = new ChatEvent(ChatEvent.Destination.SERVER, instance);
|
||||||
|
chatEvent.setText(message);
|
||||||
|
BungeeCord.instance.pluginManager.onChat(chatEvent);
|
||||||
|
sendPacket = !chatEvent.isCancelled();
|
||||||
}
|
}
|
||||||
} else if (id == 0x00)
|
} else if (id == 0x00)
|
||||||
{
|
{
|
||||||
@ -304,6 +311,17 @@ public class UserConnection extends GenericConnection implements CommandSender
|
|||||||
{
|
{
|
||||||
trackingPingId = new Packet0KeepAlive(packet).id;
|
trackingPingId = new Packet0KeepAlive(packet).id;
|
||||||
pingTime = System.currentTimeMillis();
|
pingTime = System.currentTimeMillis();
|
||||||
|
} else if (id == 0x03)
|
||||||
|
{
|
||||||
|
Packet3Chat chat = new Packet3Chat(packet);
|
||||||
|
String message = chat.message;
|
||||||
|
ChatEvent chatEvent = new ChatEvent(ChatEvent.Destination.CLIENT, instance);
|
||||||
|
chatEvent.setText(message);
|
||||||
|
BungeeCord.instance.pluginManager.onChat(chatEvent);
|
||||||
|
if (chatEvent.isCancelled())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
} else if (id == 0xC9)
|
} else if (id == 0xC9)
|
||||||
{
|
{
|
||||||
if (!BungeeCord.instance.tabListHandler.onPacketC9(UserConnection.this, new PacketC9PlayerListItem(packet)))
|
if (!BungeeCord.instance.tabListHandler.onPacketC9(UserConnection.this, new PacketC9PlayerListItem(packet)))
|
||||||
|
36
src/main/java/net/md_5/bungee/plugin/ChatEvent.java
Normal file
36
src/main/java/net/md_5/bungee/plugin/ChatEvent.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package net.md_5.bungee.plugin;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.md_5.bungee.UserConnection;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ChatEvent implements Cancellable
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canceled state.
|
||||||
|
*/
|
||||||
|
private boolean cancelled;
|
||||||
|
/**
|
||||||
|
* Whether this packet is destined for the server or the client.
|
||||||
|
*/
|
||||||
|
private final Destination destination;
|
||||||
|
/**
|
||||||
|
* User in question.
|
||||||
|
*/
|
||||||
|
private final UserConnection connection;
|
||||||
|
/**
|
||||||
|
* Text contained in this chat.
|
||||||
|
*/
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enum that signifies the destination for this packet.
|
||||||
|
*/
|
||||||
|
public enum Destination
|
||||||
|
{
|
||||||
|
|
||||||
|
SERVER,
|
||||||
|
CLIENT
|
||||||
|
}
|
||||||
|
}
|
@ -58,6 +58,13 @@ public abstract class JavaPlugin
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a chat message is sent to the client or server
|
||||||
|
*/
|
||||||
|
public void onChat(ChatEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a command for use with the proxy.
|
* Register a command for use with the proxy.
|
||||||
*/
|
*/
|
||||||
|
@ -115,4 +115,13 @@ public class JavaPluginManager extends JavaPlugin
|
|||||||
p.onPluginMessage(event);
|
p.onPluginMessage(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChat(ChatEvent event)
|
||||||
|
{
|
||||||
|
for (JavaPlugin p : plugins)
|
||||||
|
{
|
||||||
|
p.onChat(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import net.md_5.bungee.UserConnection;
|
|||||||
@Data
|
@Data
|
||||||
public class PluginMessageEvent implements Cancellable
|
public class PluginMessageEvent implements Cancellable
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Canceled state.
|
* Canceled state.
|
||||||
*/
|
*/
|
||||||
@ -39,6 +40,7 @@ public class PluginMessageEvent implements Cancellable
|
|||||||
*/
|
*/
|
||||||
public enum Destination
|
public enum Destination
|
||||||
{
|
{
|
||||||
|
|
||||||
SERVER,
|
SERVER,
|
||||||
CLIENT
|
CLIENT
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package net.md_5.bungee.tablist;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.UserConnection;
|
import net.md_5.bungee.UserConnection;
|
||||||
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||||
@ -20,7 +19,7 @@ public class GlobalPingTabList extends GlobalTabList
|
|||||||
Integer lastPing = lastPings.get(con);
|
Integer lastPing = lastPings.get(con);
|
||||||
if (lastPing == null || (ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing))
|
if (lastPing == null || (ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing))
|
||||||
{
|
{
|
||||||
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.username, true, ping));
|
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.tabListName, true, ping));
|
||||||
lastPings.put(con, ping);
|
lastPings.put(con, ping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package net.md_5.bungee.tablist;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.UserConnection;
|
import net.md_5.bungee.UserConnection;
|
||||||
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||||
@ -18,7 +17,7 @@ public class GlobalTabList implements TabListHandler
|
|||||||
{
|
{
|
||||||
for (UserConnection c : BungeeCord.instance.connections.values())
|
for (UserConnection c : BungeeCord.instance.connections.values())
|
||||||
{
|
{
|
||||||
con.packetQueue.add(new PacketC9PlayerListItem(c.username, true, c.getPing()));
|
con.packetQueue.add(new PacketC9PlayerListItem(c.tabListName, true, c.getPing()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ public class GlobalTabList implements TabListHandler
|
|||||||
{
|
{
|
||||||
if (!sentPings.contains(con))
|
if (!sentPings.contains(con))
|
||||||
{
|
{
|
||||||
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.username, true, con.getPing()));
|
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.tabListName, true, con.getPing()));
|
||||||
sentPings.add(con);
|
sentPings.add(con);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,7 +39,7 @@ public class GlobalTabList implements TabListHandler
|
|||||||
@Override
|
@Override
|
||||||
public void onDisconnect(final UserConnection con)
|
public void onDisconnect(final UserConnection con)
|
||||||
{
|
{
|
||||||
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.username, false, 9999));
|
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.tabListName, false, 9999));
|
||||||
sentPings.remove(con);
|
sentPings.remove(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import net.md_5.bungee.UserConnection;
|
import net.md_5.bungee.UserConnection;
|
||||||
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user