Skip to content

Commit 3e2d5c9

Browse files
committed
Fixed a small exploit, and added a checkuserdata command
1 parent 305c895 commit 3e2d5c9

File tree

7 files changed

+84
-3
lines changed

7 files changed

+84
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ad1tya2</groupId>
88
<artifactId>AdiAuth</artifactId>
9-
<version>1.3</version>
9+
<version>1.4</version>
1010
<packaging>jar</packaging>
1111

1212
<name>AdiAuth</name>

src/main/java/ad1tya2/adiauth/Bungee/AdiAuth.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public boolean isLoggable(LogRecord record) {
5656
getProxy().getPluginManager().registerCommand(this, new forcechangepass());
5757
getProxy().getPluginManager().registerCommand(this, new twofactor());
5858
getProxy().getPluginManager().registerCommand(this, new converter());
59+
getProxy().getPluginManager().registerCommand(this, new checkuserdata());
5960
servers.serversStatusChecker();
6061

6162
}

src/main/java/ad1tya2/adiauth/Bungee/UserProfile.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import ad1tya2.adiauth.Bungee.events.discord;
55
import ad1tya2.adiauth.Bungee.utils.BossBar;
66
import ad1tya2.adiauth.Bungee.utils.pluginMessaging;
7+
import ad1tya2.adiauth.Bungee.utils.tools;
78
import ad1tya2.adiauth.PluginMessages;
9+
import net.md_5.bungee.api.chat.ClickEvent;
10+
import net.md_5.bungee.api.chat.ComponentBuilder;
11+
import net.md_5.bungee.api.chat.HoverEvent;
12+
import net.md_5.bungee.api.chat.TextComponent;
813
import net.md_5.bungee.api.config.ServerInfo;
914
import net.md_5.bungee.api.connection.ProxiedPlayer;
1015
import net.md_5.bungee.api.connection.Server;
@@ -24,6 +29,7 @@ public class UserProfile {
2429
public String discordId;
2530
public boolean discordLoginPending = false;
2631
public Integer twoFactorCode;
32+
public Long lastLogin;
2733
//Full joined is set when a person completely logs into the server for the first time
2834

2935
public long sessionEnd = 1L;
@@ -125,4 +131,22 @@ public String getTwoFactorCode(){
125131
twoFactorCode = twoFactorCode == null? (int)(Math.random()*9000)+1000: twoFactorCode;
126132
return String.valueOf(twoFactorCode);
127133
}
134+
135+
public TextComponent getDataFormatted(){
136+
String data = "&e________________________________________"+
137+
"\n\n&2 Username: &b"+username+
138+
"\n&2 DiscordID: &b"+(discordId == null? "": discordId)+
139+
"\n&2 UUID: &b"+uuid +
140+
"\n&2 PremiumUUID: &b"+(premiumUuid == null? "": premiumUuid.toString());
141+
TextComponent component = new TextComponent();
142+
component.setText(tools.getColoured(data));
143+
TextComponent ipComponent = new TextComponent();
144+
ipComponent.setText(tools.getColoured("\n&2 Ip Address: &b"+ lastIp));
145+
ipComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, lastIp));
146+
ipComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to copy!").create()));
147+
component.addExtra(ipComponent);
148+
component.addExtra(tools.getColoured("\n&e________________________________________"));
149+
return component;
150+
}
151+
128152
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package ad1tya2.adiauth.Bungee.commands;
2+
3+
import ad1tya2.adiauth.Bungee.UserProfile;
4+
import ad1tya2.adiauth.Bungee.data.storage;
5+
import ad1tya2.adiauth.Bungee.utils.tools;
6+
import net.md_5.bungee.api.ChatColor;
7+
import net.md_5.bungee.api.CommandSender;
8+
import net.md_5.bungee.api.plugin.Command;
9+
10+
public class checkuserdata extends Command {
11+
public checkuserdata(){
12+
super("checkuserdata", "adiauth.admin", "viewuserprofile", "checkplayer");
13+
}
14+
@Override
15+
public void execute(CommandSender sender, String[] args) {
16+
if(args.length != 1){
17+
sender.sendMessage(
18+
tools.getColoured("&2Invalid args\n " +
19+
"&bUse /checkuserdata <playername>")
20+
);
21+
return;
22+
}
23+
String pName = args[0];
24+
UserProfile profile = storage.getPlayerMemory(pName);
25+
if(profile == null){
26+
sender.sendMessage(ChatColor.RED+"Invalid username!");
27+
}
28+
else {
29+
sender.sendMessage(profile.getDataFormatted());
30+
}
31+
32+
}
33+
}

src/main/java/ad1tya2/adiauth/Bungee/data/storage.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public enum AccountType {
3232
private static final ConcurrentHashMap<UUID, UserProfile> pMapByPremiumUuid = new ConcurrentHashMap<UUID, UserProfile>();
3333
private static final ConcurrentHashMap<String, List<UserProfile>> profilesByIp = new ConcurrentHashMap<String, List<UserProfile>>();
3434
private static final ConcurrentHashMap<String, UserProfile> pMapByDiscord = new ConcurrentHashMap<String, UserProfile>();
35+
3536
public static Integer getAccounts(String ip, AccountType type){
3637
List<UserProfile> profiles = profilesByIp.get(ip);
3738
if(profiles == null){
@@ -123,10 +124,23 @@ public static Optional<UserProfile> getPlayerForLogin(String name, String ip){
123124
UserProfile user = new UserProfile();
124125
user.username = name;
125126
user.lastIp = ip;
127+
user.lastLogin = System.currentTimeMillis();
126128
UserProfile oldUserByName = pMap.get(name);
127129
if(oldUserByName == null && getAccounts(ip, AccountType.TOTAL)>=Config.maxTotalAccounts){
128130
return null;
129131
}
132+
if(oldUserByName != null) {
133+
134+
if(ip != oldUserByName.lastIp){
135+
oldUserByName.endSession();
136+
}
137+
//Only call api if it has been 5 minutes since lastlogin
138+
if (oldUserByName.lastLogin != null && oldUserByName.lastLogin + 300000L > System.currentTimeMillis()) {
139+
return Optional.of(oldUserByName);
140+
}
141+
142+
oldUserByName.lastLogin = System.currentTimeMillis();
143+
}
130144
Optional<UUID> uuid;
131145
if(Config.forceBackupServer){
132146
uuid = Uuids.getBackupServerUUID(name);

src/main/java/ad1tya2/adiauth/Bungee/events/Handler.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import ad1tya2.adiauth.Bungee.utils.pluginMessaging;
99
import ad1tya2.adiauth.Bungee.utils.tools;
1010
import ad1tya2.adiauth.PluginMessages;
11+
import net.md_5.bungee.api.ProxyServer;
1112
import net.md_5.bungee.api.config.ServerInfo;
1213
import net.md_5.bungee.api.connection.PendingConnection;
1314
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -16,13 +17,12 @@
1617
import net.md_5.bungee.connection.InitialHandler;
1718
import net.md_5.bungee.connection.LoginResult;
1819
import net.md_5.bungee.event.EventHandler;
19-
2020
import java.lang.reflect.Field;
2121
import java.util.Optional;
2222
import java.util.logging.Level;
2323

2424
public class Handler implements Listener {
25-
@EventHandler(priority = 127)
25+
@EventHandler(priority = Byte.MAX_VALUE)
2626
public void onPreLogin(PreLoginEvent event){
2727
if(event.isCancelled()){
2828
return;
@@ -33,6 +33,14 @@ public void onPreLogin(PreLoginEvent event){
3333
@Override
3434
public void run() {
3535
PendingConnection conn = event.getConnection();
36+
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(conn.getName());
37+
if(player != null && player.isConnected()){
38+
conn.disconnect(tools.getColoured(
39+
"&eAnother player with that name is already online!"
40+
));
41+
event.setCancelled(true);
42+
return;
43+
}
3644
Optional<UserProfile> optional = storage.getPlayerForLogin(conn.getName(), tools.getIp(conn.getSocketAddress()));
3745
if(optional == null){
3846
conn.disconnect(Config.Messages.tooManyAccounts);

src/main/java/ad1tya2/adiauth/Bungee/events/discord.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public void onButtonClick(ButtonClickEvent event){
8080
if(event.getComponentId().equals("AdiAuthLogin")){
8181
UserProfile profile = storage.getPlayerByDiscord(event.getUser().getId());
8282
if(profile == null){
83+
event.getInteraction().reply("Are you sure you need to use this?").setEphemeral(true).queue();
8384
return;
8485
}
8586
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(profile.username);

0 commit comments

Comments
 (0)