Skip to content

Commit

Permalink
1.0.7: allow-account-relink fix, GeoIP updates, new in-game strings, …
Browse files Browse the repository at this point in the history
…after-unlink-commands, @placeholders in Settings
  • Loading branch information
hevav committed Jan 16, 2023
1 parent a8d39d0 commit bea0c75
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 85 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.6
1.0.7
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

setGroup("net.elytrium")
setVersion("1.0.6")
setVersion("1.0.7")

compileJava {
getOptions().setEncoding("UTF-8")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
limboapiVersion=1.1.0
limboauthVersion=1.1.0
limboauthVersion=1.1.1
velocityVersion=3.2.0-SNAPSHOT
bstatsVersion=3.0.0
spotbugsVersion=4.7.3
Expand Down
86 changes: 44 additions & 42 deletions src/main/java/net/elytrium/limboauth/socialaddon/Addon.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.PluginContainer;
Expand All @@ -34,6 +35,7 @@
import java.io.File;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -42,11 +44,11 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Pattern;
import net.elytrium.commons.config.Placeholders;
import net.elytrium.commons.kyori.serialization.Serializer;
import net.elytrium.commons.kyori.serialization.Serializers;
import net.elytrium.commons.utils.updates.UpdatesChecker;
import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.model.RegisteredPlayer;
import net.elytrium.limboauth.socialaddon.command.ForceSocialUnlinkCommand;
import net.elytrium.limboauth.socialaddon.command.ValidateLinkCommand;
Expand Down Expand Up @@ -126,7 +128,7 @@ public Addon(ProxyServer server, Logger logger, Metrics.Factory metricsFactory,

Optional<PluginContainer> container = this.server.getPluginManager().getPlugin("limboauth");
String version = container.map(PluginContainer::getDescription).flatMap(PluginDescription::getVersion).orElseThrow();

if (!UpdatesChecker.checkVersion(PLUGIN_MINIMUM_VERSION, version)) {
throw new IllegalStateException("Incorrect version of LimboAuth plugin, the addon requires version " + PLUGIN_MINIMUM_VERSION + " or newer");
}
Expand Down Expand Up @@ -222,25 +224,14 @@ private void load() {

String newPassword = Long.toHexString(Double.doubleToLongBits(Math.random()));

RegisteredPlayer player = new RegisteredPlayer(
account,
lowercaseNickname,
AuthSessionHandler.genHash(newPassword),
"",
"",
System.currentTimeMillis(),
"",
"",
"",
0L
);
RegisteredPlayer player = new RegisteredPlayer(account, "", "").setPassword(newPassword);

this.plugin.getPlayerDao().create(player);

this.linkSocial(lowercaseNickname, dbField, id);

this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.REGISTER_SUCCESS.replace("{PASSWORD}", newPassword));
Placeholders.replace(Settings.IMP.MAIN.STRINGS.REGISTER_SUCCESS, newPassword));
}
}

Expand All @@ -267,7 +258,7 @@ private void load() {
int code = ThreadLocalRandom.current().nextInt(Settings.IMP.MAIN.CODE_LOWER_BOUND, Settings.IMP.MAIN.CODE_UPPER_BOUND);
this.codeMap.put(account, code);
this.requestedReverseMap.put(account, new TempAccount(dbField, id));
this.socialManager.broadcastMessage(dbField, id, Settings.IMP.MAIN.STRINGS.LINK_CODE.replace("{CODE}", String.valueOf(code)));
this.socialManager.broadcastMessage(dbField, id, Placeholders.replace(Settings.IMP.MAIN.STRINGS.LINK_CODE, String.valueOf(code)));

return;
}
Expand Down Expand Up @@ -310,23 +301,21 @@ private void load() {
}

ip = player1.getRemoteAddress().getAddress().getHostAddress();
location = Optional.ofNullable(this.geoIp)
.map(nonNullGeo -> "(" + nonNullGeo.getLocation(ip) + ")").orElse("");
location = Optional.ofNullable(this.geoIp).map(nonNullGeo -> nonNullGeo.getLocation(ip)).orElse("");
} else {
server = Settings.IMP.MAIN.STRINGS.STATUS_OFFLINE;
ip = Settings.IMP.MAIN.STRINGS.STATUS_OFFLINE;
location = "";
}

this.socialManager.broadcastMessage(dbField, id, Settings.IMP.MAIN.STRINGS.INFO_MSG
.replace("{NICKNAME}", player.getLowercaseNickname())
.replace("{SERVER}", server)
.replace("{IP}", ip)
.replace("{LOCATION}", location)
.replace("{NOTIFY_STATUS}", player.isNotifyEnabled()
? Settings.IMP.MAIN.STRINGS.NOTIFY_ENABLED : Settings.IMP.MAIN.STRINGS.NOTIFY_DISABLED)
.replace("{BLOCK_STATUS}", player.isBlocked() ? Settings.IMP.MAIN.STRINGS.BLOCK_ENABLED : Settings.IMP.MAIN.STRINGS.BLOCK_DISABLED)
.replace("{TOTP_STATUS}", player.isTotpEnabled() ? Settings.IMP.MAIN.STRINGS.TOTP_ENABLED : Settings.IMP.MAIN.STRINGS.TOTP_DISABLED),
this.socialManager.broadcastMessage(dbField, id, Placeholders.replace(Settings.IMP.MAIN.STRINGS.INFO_MSG,
player.getLowercaseNickname(),
server,
ip,
location,
player.isNotifyEnabled() ? Settings.IMP.MAIN.STRINGS.NOTIFY_ENABLED : Settings.IMP.MAIN.STRINGS.NOTIFY_DISABLED,
player.isBlocked() ? Settings.IMP.MAIN.STRINGS.BLOCK_ENABLED : Settings.IMP.MAIN.STRINGS.BLOCK_DISABLED,
player.isTotpEnabled() ? Settings.IMP.MAIN.STRINGS.TOTP_ENABLED : Settings.IMP.MAIN.STRINGS.TOTP_DISABLED),
this.keyboard
);
});
Expand All @@ -343,7 +332,7 @@ private void load() {
if (player.isBlocked()) {
player.setBlocked(false);
this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.UNBLOCK_SUCCESS.replace("{NICKNAME}", player.getLowercaseNickname()), this.keyboard
Placeholders.replace(Settings.IMP.MAIN.STRINGS.UNBLOCK_SUCCESS, player.getLowercaseNickname()), this.keyboard
);
} else {
player.setBlocked(true);
Expand All @@ -354,7 +343,7 @@ private void load() {
.ifPresent(e -> e.disconnect(Addon.getSerializer().deserialize(Settings.IMP.MAIN.STRINGS.KICK_GAME_MESSAGE)));

this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.BLOCK_SUCCESS.replace("{NICKNAME}", player.getLowercaseNickname()), this.keyboard
Placeholders.replace(Settings.IMP.MAIN.STRINGS.BLOCK_SUCCESS, player.getLowercaseNickname()), this.keyboard
);
}

Expand All @@ -373,12 +362,12 @@ private void load() {
if (player.isTotpEnabled()) {
player.setTotpEnabled(false);
this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.TOTP_DISABLE_SUCCESS.replace("{NICKNAME}", player.getLowercaseNickname()), this.keyboard
Placeholders.replace(Settings.IMP.MAIN.STRINGS.TOTP_DISABLE_SUCCESS, player.getLowercaseNickname()), this.keyboard
);
} else {
player.setTotpEnabled(true);
this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.TOTP_ENABLE_SUCCESS.replace("{NICKNAME}", player.getLowercaseNickname()), this.keyboard
Placeholders.replace(Settings.IMP.MAIN.STRINGS.TOTP_ENABLE_SUCCESS, player.getLowercaseNickname()), this.keyboard
);
}

Expand All @@ -397,12 +386,12 @@ private void load() {
if (player.isNotifyEnabled()) {
player.setNotifyEnabled(false);
this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.NOTIFY_DISABLE_SUCCESS.replace("{NICKNAME}", player.getLowercaseNickname()), this.keyboard
Placeholders.replace(Settings.IMP.MAIN.STRINGS.NOTIFY_DISABLE_SUCCESS, player.getLowercaseNickname()), this.keyboard
);
} else {
player.setNotifyEnabled(true);
this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.NOTIFY_ENABLE_SUCCESS.replace("{NICKNAME}", player.getLowercaseNickname()), this.keyboard
Placeholders.replace(Settings.IMP.MAIN.STRINGS.NOTIFY_ENABLE_SUCCESS, player.getLowercaseNickname()), this.keyboard
);
}

Expand All @@ -423,7 +412,7 @@ private void load() {
if (proxyPlayer.isPresent()) {
proxyPlayer.get().disconnect(Addon.getSerializer().deserialize(Settings.IMP.MAIN.STRINGS.KICK_GAME_MESSAGE));
this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.KICK_SUCCESS.replace("{NICKNAME}", player.getLowercaseNickname()), this.keyboard
Placeholders.replace(Settings.IMP.MAIN.STRINGS.KICK_SUCCESS, player.getLowercaseNickname()), this.keyboard
);
} else {
this.socialManager.broadcastMessage(dbField, id,
Expand All @@ -446,7 +435,7 @@ private void load() {
if (Settings.IMP.MAIN.PROHIBIT_PREMIUM_RESTORE
&& this.plugin.isPremiumInternal(player.getLowercaseNickname()).getState() != LimboAuth.PremiumState.CRACKED) {
this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.RESTORE_MSG_PREMIUM.replace("{NICKNAME}", player.getLowercaseNickname()),
Placeholders.replace(Settings.IMP.MAIN.STRINGS.RESTORE_MSG_PREMIUM, player.getLowercaseNickname()),
this.keyboard
);
return;
Expand All @@ -458,17 +447,17 @@ private void load() {

UpdateBuilder<RegisteredPlayer, String> updateBuilder = playerDao.updateBuilder();
updateBuilder.where().eq(RegisteredPlayer.LOWERCASE_NICKNAME_FIELD, player.getLowercaseNickname());
updateBuilder.updateColumnValue(RegisteredPlayer.HASH_FIELD, AuthSessionHandler.genHash(newPassword));
updateBuilder.updateColumnValue(RegisteredPlayer.HASH_FIELD, RegisteredPlayer.genHash(newPassword));
boolean updated = updateBuilder.update() != 0;

if (updated) {
this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.RESTORE_MSG.replace("{NICKNAME}", player.getLowercaseNickname()).replace("{PASSWORD}", newPassword),
Placeholders.replace(Settings.IMP.MAIN.STRINGS.RESTORE_MSG, player.getLowercaseNickname(), newPassword),
this.keyboard
);
} else {
this.socialManager.broadcastMessage(dbField, id,
Settings.IMP.MAIN.STRINGS.RESTORE_MSG_PREMIUM.replace("{NICKNAME}", player.getLowercaseNickname()),
Placeholders.replace(Settings.IMP.MAIN.STRINGS.RESTORE_MSG_PREMIUM, player.getLowercaseNickname()),
this.keyboard
);
}
Expand Down Expand Up @@ -497,9 +486,16 @@ private void load() {
return;
}

if (Settings.IMP.MAIN.UNLINK_BTN_ALL) {
SocialPlayer.DatabaseField.valueOf(dbField).setIdFor(player, null);
boolean allUnlinked = Arrays.stream(SocialPlayer.DatabaseField.values())
.noneMatch(v -> v.getIdFor(player) != null);

if (Settings.IMP.MAIN.UNLINK_BTN_ALL || allUnlinked) {
this.dao.delete(player);
this.socialManager.unregisterHook(player);

Settings.IMP.MAIN.AFTER_UNLINKAGE_COMMANDS.forEach(command ->
this.server.getCommandManager().executeAsync(p -> Tristate.TRUE, command.replace("{NICKNAME}", player.getLowercaseNickname())));
} else {
UpdateBuilder<SocialPlayer, String> updateBuilder = this.dao.updateBuilder();
updateBuilder.where().eq(SocialPlayer.LOWERCASE_NICKNAME_FIELD, player.getLowercaseNickname());
Expand All @@ -510,6 +506,8 @@ private void load() {
}

this.socialManager.broadcastMessage(dbField, id, Settings.IMP.MAIN.STRINGS.UNLINK_SUCCESS);
this.server.getPlayer(player.getLowercaseNickname()).ifPresent(p ->
p.sendMessage(SERIALIZER.deserialize(Settings.IMP.MAIN.STRINGS.UNLINK_SUCCESS_GAME)));
});
}

Expand All @@ -536,7 +534,7 @@ public void onReload() throws SQLException {

commandManager.register(
Settings.IMP.MAIN.LINKAGE_MAIN_CMD,
new ValidateLinkCommand(this, this.dao),
new ValidateLinkCommand(this),
Settings.IMP.MAIN.LINKAGE_ALIAS_CMD.toArray(new String[0])
);
commandManager.register(
Expand All @@ -559,9 +557,13 @@ public void unregisterPlayer(String nickname) {
}

public void linkSocial(String lowercaseNickname, String dbField, Long id) throws SQLException {
if (this.dao.queryForId(lowercaseNickname) == null) {
SocialPlayer socialPlayer = this.dao.queryForId(lowercaseNickname);
if (socialPlayer == null) {
Settings.IMP.MAIN.AFTER_LINKAGE_COMMANDS.forEach(command ->
this.server.getCommandManager().executeAsync(p -> Tristate.TRUE, command.replace("{NICKNAME}", lowercaseNickname)));

this.dao.create(new SocialPlayer(lowercaseNickname));
} else if (!Settings.IMP.MAIN.ALLOW_ACCOUNT_RELINK) {
} else if (!Settings.IMP.MAIN.ALLOW_ACCOUNT_RELINK && SocialPlayer.DatabaseField.valueOf(dbField).getIdFor(socialPlayer) != null) {
this.socialManager.broadcastMessage(dbField, id, Settings.IMP.MAIN.STRINGS.LINK_ALREADY);
return;
}
Expand Down
30 changes: 27 additions & 3 deletions src/main/java/net/elytrium/limboauth/socialaddon/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public static class MAIN {
@Comment("Allow linking social to the player, who already has linked this type of social")
public boolean ALLOW_ACCOUNT_RELINK = true;

public List<String> AFTER_LINKAGE_COMMANDS = List.of("alert {NICKNAME} ({UUID}) has linked a social account");
public List<String> AFTER_LINKAGE_COMMANDS = List.of("alert {NICKNAME} has linked a social account");
public List<String> AFTER_UNLINKAGE_COMMANDS = List.of();
public List<String> START_MESSAGES = List.of("/start", "Начать");
public String START_REPLY = "Send '!account link <nickname>' to link your account";

Expand Down Expand Up @@ -167,8 +168,9 @@ public static class TELEGRAM {
public static class GEOIP {
public boolean ENABLED = false;
@Comment({
"Available placeholders: {CITY}, {COUNTRY}"
"Available placeholders: {CITY}, {COUNTRY}, {LEAST_SPECIFIC_SUBDIVISION}, {MOST_SPECIFIC_SUBDIVISION}"
})
@Placeholders({"{CITY}", "{COUNTRY}", "{LEAST_SPECIFIC_SUBDIVISION}", "{MOST_SPECIFIC_SUBDIVISION}"})
public String FORMAT = "{CITY}, {COUNTRY}";
@Comment("ISO 639-1")
public String LOCALE = "en";
Expand All @@ -184,7 +186,11 @@ public static class GEOIP {
public long UPDATE_INTERVAL = 1209600000L;
public String DEFAULT_VALUE = "Unknown";

@Comment("It is not necessary to change {LICENSE_KEY}")
@Placeholders({"{LICENSE_KEY}"})
public String MMDB_CITY_DOWNLOAD = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key={LICENSE_KEY}&suffix=tar.gz";

@Placeholders({"{LICENSE_KEY}"})
public String MMDB_COUNTRY_DOWNLOAD = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key={LICENSE_KEY}&suffix=tar.gz";
}

Expand All @@ -193,24 +199,31 @@ public static class GEOIP {

public static class STRINGS {

@Placeholders({"{NICKNAME}"})
public String LINK_CMD_USAGE = "{PRFX} Send '!account link {NICKNAME}' to our Social Bot{NL} VK: vk.com/123{NL} DS: Bot#0000{NL} TG: @bot";
@Placeholders({"{NICKNAME}"})
public String LINK_WRONG_CODE = "{PRFX} Wrong code, run '!account link {NICKNAME}' again";
public String LINK_SUCCESS_GAME = "{PRFX} Social was successfully linked";
public String LINK_SUCCESS = "✅ Social was successfully linked{NL}Use '!keyboard' to show keyboard";
public String LINK_ALREADY = "Account is already linked";
public String LINK_SOCIAL_REGISTER_CMD_USAGE = "You didn't specify a nickname. Enter '!account register <nickname>'";
public String LINK_SOCIAL_CMD_USAGE = "You didn't specify a nickname. Enter '!account link <nickname>'";
public String LINK_UNKNOWN_ACCOUNT = "There is no account with this nickname";
@Placeholders({"{CODE}"})
public String LINK_CODE = "🔑 Enter '/addsocial {CODE}' in game to complete account linking";
public String REGISTER_INCORRECT_NICKNAME = "There is no account with this nickname";
public String REGISTER_TAKEN_NICKNAME = "This nickname is already taken";
@Placeholders({"{PASSWORD}"})
public String REGISTER_SUCCESS = "✅ Account was successfully registered{NL}Your password: {PASSWORD}{NL}Use '!keyboard' to show keyboard";

public String FORCE_UNLINK_CMD_USAGE = "{PRFX} Usage: /forcesocialunregister <username>";

public String NOTIFY_LEAVE = "➖ You've left the server";
@Placeholders({"{IP}", "{LOCATION}"})
public String NOTIFY_JOIN = "➕ You've joined the server {NL}🌐 IP: {IP} {LOCATION}{NL}You can block your account if that is not you";

public String NOTIFY_ASK_KICK_MESSAGE = "{PRFX} You were kicked by the Social";
@Placeholders({"{IP}", "{LOCATION}"})
public String NOTIFY_ASK_VALIDATE = "❔ Someone tries to join the server.{NL}🌐 IP: {IP} {LOCATION}{NL}Is it you?";
public String NOTIFY_ASK_VALIDATE_GAME = "{PRFX} You have 2FA enabled, check your social and validate your login!";
public String NOTIFY_ASK_YES = "It's me";
Expand All @@ -220,24 +233,34 @@ public static class STRINGS {

public String BLOCK_TOGGLE_BTN = "Toggle block";
public String BLOCK_KICK_MESSAGE = "{PRFX} Your account was blocked by the Social";
@Placeholders({"{NICKNAME}"})
public String BLOCK_SUCCESS = "Account {NICKNAME} was successfully blocked";
@Placeholders({"{NICKNAME}"})
public String UNBLOCK_SUCCESS = "Account {NICKNAME} was successfully unblocked";

@Placeholders({"{NICKNAME}"})
public String TOTP_ENABLE_SUCCESS = "Account {NICKNAME} now uses 2FA";
@Placeholders({"{NICKNAME}"})
public String TOTP_DISABLE_SUCCESS = "Account {NICKNAME} doesn't use 2FA anymore";

@Placeholders({"{NICKNAME}"})
public String NOTIFY_ENABLE_SUCCESS = "Account {NICKNAME} now receives notifications";
@Placeholders({"{NICKNAME}"})
public String NOTIFY_DISABLE_SUCCESS = "Account {NICKNAME} doesn't receive notifications anymore";

public String KICK_IS_OFFLINE = "Cannot kick player - player is offline";
public String KICK_SUCCESS = "Player was successfully kicked";
@Placeholders("{NICKNAME}")
public String KICK_SUCCESS = "Player {NICKNAME} was successfully kicked";
public String KICK_GAME_MESSAGE = "{PRFX} You were kicked by the Social";

public String RESTORE_BTN = "Restore";
@Placeholders({"{NICKNAME}", "{PASSWORD}"})
public String RESTORE_MSG = "The new password for {NICKNAME} is: {PASSWORD}";
@Placeholders({"{NICKNAME}"})
public String RESTORE_MSG_PREMIUM = "We can't change your password, {NICKNAME}, perhaps you are a premium player.";

public String INFO_BTN = "Info";
@Placeholders({"{NICKNAME}", "{SERVER}", "{IP}", "{LOCATION}", "{NOTIFY_STATUS}", "{BLOCK_STATUS}", "{TOTP_STATUS}"})
public String INFO_MSG = "👤 IGN: {NICKNAME}{NL}🌍 Current status: {SERVER}{NL}🌐 IP: {IP} {LOCATION}{NL}⏰ Notifications: {NOTIFY_STATUS}{NL}❌ Blocked: {BLOCK_STATUS}{NL}🔑 2FA: {TOTP_STATUS}";
public String STATUS_OFFLINE = "OFFLINE";
public String NOTIFY_ENABLED = "Enabled";
Expand All @@ -253,6 +276,7 @@ public static class STRINGS {
public String UNLINK_BTN = "Unlink social";
public String UNLINK_DISABLED = "Unlinking disabled";
public String UNLINK_SUCCESS = "Unlink successful";
public String UNLINK_SUCCESS_GAME = "{PRFX} Unlink successful";
public String UNLINK_BLOCK_CONFLICT = "You cannot unlink the social while your account is blocked. Unblock it first";
public String UNLINK_2FA_CONFLICT = "You cannot unlink the social while 2FA is enabled. Disable it first";

Expand Down
Loading

0 comments on commit bea0c75

Please sign in to comment.