Add permissions
This commit is contained in:
		| @@ -20,7 +20,8 @@ public interface CommandSender | |||||||
|     public void sendMessage(String message); |     public void sendMessage(String message); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Get all groups this user is part of. |      * Get all groups this user is part of. This returns an unmodifiable | ||||||
|  |      * collection. | ||||||
|      * |      * | ||||||
|      * @return the users groups |      * @return the users groups | ||||||
|      */ |      */ | ||||||
|   | |||||||
| @@ -90,6 +90,13 @@ public abstract class ProxyServer | |||||||
|      */ |      */ | ||||||
|     public abstract PluginManager getPluginManager(); |     public abstract PluginManager getPluginManager(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Returns the currently in use configuration adapter. | ||||||
|  |      * | ||||||
|  |      * @return the used configuration adapter | ||||||
|  |      */ | ||||||
|  |     public abstract ConfigurationAdapter getConfigurationAdapter(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Set the configuration adapter to be used. Must be called from |      * Set the configuration adapter to be used. Must be called from | ||||||
|      * {@link Plugin#onLoad()}. |      * {@link Plugin#onLoad()}. | ||||||
|   | |||||||
| @@ -13,6 +13,14 @@ public interface ReconnectHandler | |||||||
|      */ |      */ | ||||||
|     public String getServer(ProxiedPlayer player); |     public String getServer(ProxiedPlayer player); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Save the server of this player before they disconnect so it can be | ||||||
|  |      * retrieved later. | ||||||
|  |      * | ||||||
|  |      * @param player the player to save | ||||||
|  |      */ | ||||||
|  |     public void setServer(ProxiedPlayer player); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Save all pending reconnect locations. Whilst not used for database |      * Save all pending reconnect locations. Whilst not used for database | ||||||
|      * connections, this method will be called at a predefined interval to allow |      * connections, this method will be called at a predefined interval to allow | ||||||
|   | |||||||
| @@ -20,7 +20,8 @@ public interface TabListHandler | |||||||
|     public void onServerChange(ProxiedPlayer player); |     public void onServerChange(ProxiedPlayer player); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Called when a players ping changes. |      * Called when a players ping changes. The new ping will have not updated in | ||||||
|  |      * the player instance until this method returns. | ||||||
|      * |      * | ||||||
|      * @param player the player who's ping changed |      * @param player the player who's ping changed | ||||||
|      * @param ping the player's new ping. |      * @param ping the player's new ping. | ||||||
|   | |||||||
| @@ -1,15 +1,22 @@ | |||||||
| package net.md_5.bungee; | package net.md_5.bungee; | ||||||
|  |  | ||||||
|  | import java.io.ByteArrayInputStream; | ||||||
|  | import java.io.DataInputStream; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| 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.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Collection; | import java.util.Collection; | ||||||
|  | import java.util.Collections; | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.HashSet; | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
| import java.util.Queue; | import java.util.Queue; | ||||||
| import java.util.concurrent.ConcurrentLinkedQueue; | import java.util.concurrent.ConcurrentLinkedQueue; | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
|  | import lombok.Synchronized; | ||||||
| import net.md_5.bungee.api.ProxyServer; | import net.md_5.bungee.api.ProxyServer; | ||||||
| import net.md_5.bungee.api.connection.ProxiedPlayer; | import net.md_5.bungee.api.connection.ProxiedPlayer; | ||||||
| import net.md_5.bungee.api.connection.Server; | import net.md_5.bungee.api.connection.Server; | ||||||
| @@ -37,7 +44,9 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer | |||||||
|     private long pingTime; |     private long pingTime; | ||||||
|     @Getter |     @Getter | ||||||
|     private int ping; |     private int ping; | ||||||
|     public UserConnection instance = this; |     // Permissions | ||||||
|  |     private final Collection<String> groups = new HashSet<>(); | ||||||
|  |     private final Map<String, Boolean> permissions = new HashMap<>(); | ||||||
|  |  | ||||||
|     public UserConnection(Socket socket, PacketInputStream in, OutputStream out, Packet2Handshake handshake, List<byte[]> loginPackets) |     public UserConnection(Socket socket, PacketInputStream in, OutputStream out, Packet2Handshake handshake, List<byte[]> loginPackets) | ||||||
|     { |     { | ||||||
| @@ -135,12 +144,6 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void setPing(int ping) |  | ||||||
|     { |  | ||||||
|         BungeeCord.instance.tabListHandler.onPingChange(this, ping); |  | ||||||
|         this.ping = ping; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private void destroySelf(String reason) |     private void destroySelf(String reason) | ||||||
|     { |     { | ||||||
|         if (BungeeCord.instance.isRunning) |         if (BungeeCord.instance.isRunning) | ||||||
| @@ -159,14 +162,14 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer | |||||||
|         if (server != null) |         if (server != null) | ||||||
|         { |         { | ||||||
|             server.disconnect("Quitting"); |             server.disconnect("Quitting"); | ||||||
|             BungeeCord.instance.config.setServer(this, server.name); |             ProxyServer.getInstance().getReconnectHandler().setServer(this); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void disconnect(String reason) |     public void disconnect(String reason) | ||||||
|     { |     { | ||||||
|         BungeeCord.instance.tabListHandler.onDisconnect(this); |         ProxyServer.getInstance().getTabListHandler().onDisconnect(this); | ||||||
|         super.disconnect(reason); |         super.disconnect(reason); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -185,37 +188,57 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer | |||||||
|     @Override |     @Override | ||||||
|     public InetSocketAddress getAddress() |     public InetSocketAddress getAddress() | ||||||
|     { |     { | ||||||
|         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |         return (InetSocketAddress) socket.getRemoteSocketAddress(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|  |     @Synchronized(value = "permMutex") | ||||||
|     public Collection<String> getGroups() |     public Collection<String> getGroups() | ||||||
|     { |     { | ||||||
|         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |         return Collections.unmodifiableCollection(groups); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|  |     @Synchronized(value = "permMutex") | ||||||
|     public void addGroups(String... groups) |     public void addGroups(String... groups) | ||||||
|     { |     { | ||||||
|         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |         for (String group : groups) | ||||||
|  |         { | ||||||
|  |             this.groups.add(group); | ||||||
|  |             for (String permission : ProxyServer.getInstance().getConfigurationAdapter().getPermissions(group)) | ||||||
|  |             { | ||||||
|  |                 setPermission(permission, true); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|  |     @Synchronized(value = "permMutex") | ||||||
|     public void removeGroups(String... groups) |     public void removeGroups(String... groups) | ||||||
|     { |     { | ||||||
|         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |         for (String group : groups) | ||||||
|  |         { | ||||||
|  |             this.groups.remove(group); | ||||||
|  |             for (String permission : ProxyServer.getInstance().getConfigurationAdapter().getPermissions(group)) | ||||||
|  |             { | ||||||
|  |                 setPermission(permission, false); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|  |     @Synchronized(value = "permMutex") | ||||||
|     public boolean hasPermission(String permission) |     public boolean hasPermission(String permission) | ||||||
|     { |     { | ||||||
|         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |         Boolean val = permissions.get(permission); | ||||||
|  |         return (val == null) ? false : val; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|  |     @Synchronized(value = "permMutex") | ||||||
|     public void setPermission(String permission, boolean value) |     public void setPermission(String permission, boolean value) | ||||||
|     { |     { | ||||||
|         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |         permissions.put(permission, value); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private class UpstreamBridge extends Thread |     private class UpstreamBridge extends Thread | ||||||
| @@ -235,14 +258,16 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer | |||||||
|                 { |                 { | ||||||
|                     byte[] packet = in.readPacket(); |                     byte[] packet = in.readPacket(); | ||||||
|                     boolean sendPacket = true; |                     boolean sendPacket = true; | ||||||
|  |  | ||||||
|                     int id = Util.getId(packet); |                     int id = Util.getId(packet); | ||||||
|  |  | ||||||
|                     switch (id) |                     switch (id) | ||||||
|                     { |                     { | ||||||
|                         case 0x00: |                         case 0x00: | ||||||
|                             if (trackingPingId == new Packet0KeepAlive(packet).id) |                             if (trackingPingId == new Packet0KeepAlive(packet).id) | ||||||
|                             { |                             { | ||||||
|                                 setPing((int) (System.currentTimeMillis() - pingTime)); |                                 int newPing = (int) (System.currentTimeMillis() - pingTime); | ||||||
|  |                                 ProxyServer.getInstance().getTabListHandler().onPingChange(UserConnection.this, newPing); | ||||||
|  |                                 ping = newPing; | ||||||
|                             } |                             } | ||||||
|                             break; |                             break; | ||||||
|                         case 0x03: |                         case 0x03: | ||||||
| @@ -312,8 +337,8 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer | |||||||
|                 while (!reconnecting) |                 while (!reconnecting) | ||||||
|                 { |                 { | ||||||
|                     byte[] packet = server.in.readPacket(); |                     byte[] packet = server.in.readPacket(); | ||||||
|  |  | ||||||
|                     int id = Util.getId(packet); |                     int id = Util.getId(packet); | ||||||
|  |  | ||||||
|                     switch (id) |                     switch (id) | ||||||
|                     { |                     { | ||||||
|                         case 0x00: |                         case 0x00: | ||||||
| @@ -332,7 +357,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer | |||||||
|                             break; |                             break; | ||||||
|                         case 0xC9: |                         case 0xC9: | ||||||
|                             PacketC9PlayerListItem playerList = new PacketC9PlayerListItem(packet); |                             PacketC9PlayerListItem playerList = new PacketC9PlayerListItem(packet); | ||||||
|                             if (!ProxyServer.getInstance().getTabListHandler().onListUpdate(instance, playerList.username, playerList.online, playerList.ping)) |                             if (!ProxyServer.getInstance().getTabListHandler().onListUpdate(UserConnection.this, playerList.username, playerList.online, playerList.ping)) | ||||||
|                             { |                             { | ||||||
|                                 continue; |                                 continue; | ||||||
|                             } |                             } | ||||||
| @@ -340,6 +365,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer | |||||||
|                         case 0xFA: |                         case 0xFA: | ||||||
|                             // Call the onPluginMessage event |                             // Call the onPluginMessage event | ||||||
|                             PacketFAPluginMessage message = new PacketFAPluginMessage(packet); |                             PacketFAPluginMessage message = new PacketFAPluginMessage(packet); | ||||||
|  |                             DataInputStream in = new DataInputStream(new ByteArrayInputStream(message.data)); | ||||||
|                             PluginMessageEvent event = new PluginMessageEvent(server, UserConnection.this, message.tag, message.data); |                             PluginMessageEvent event = new PluginMessageEvent(server, UserConnection.this, message.tag, message.data); | ||||||
|                             ProxyServer.getInstance().getPluginManager().callEvent(event); |                             ProxyServer.getInstance().getPluginManager().callEvent(event); | ||||||
|  |  | ||||||
| @@ -352,8 +378,15 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer | |||||||
|                             { |                             { | ||||||
|                                 case "BungeeCord::Disconnect": |                                 case "BungeeCord::Disconnect": | ||||||
|                                     break outer; |                                     break outer; | ||||||
|  |                                 case "BungeeCord::Forward": | ||||||
|  |                                     String target = in.readUTF(); | ||||||
|  |                                     String channel = in.readUTF(); | ||||||
|  |                                     short len = in.readShort(); | ||||||
|  |                                     byte[] data = new byte[len]; | ||||||
|  |                                     in.readFully(data); | ||||||
|  |                                     break; | ||||||
|                                 case "BungeeCord::Connect": |                                 case "BungeeCord::Connect": | ||||||
|                                     Server server = ProxyServer.getInstance().getServer(new String(message.data)); |                                     Server server = ProxyServer.getInstance().getServer(in.readUTF()); | ||||||
|                                     if (server != null) |                                     if (server != null) | ||||||
|                                     { |                                     { | ||||||
|                                         connect(server); |                                         connect(server); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 md_5
					md_5