Log out everyone on startup

This commit is contained in:
P0nk
2024-10-03 21:36:19 +02:00
parent e295a24d98
commit a4f8086da1
3 changed files with 16 additions and 7 deletions

View File

@@ -61,6 +61,17 @@ public class AccountRepository {
}
}
public void setAllLoginState(LoginState loginState) {
String sql = """
UPDATE account
SET login_state = :loginState""";
try (Handle handle = connection.getHandle()) {
handle.createUpdate(sql)
.bind("loginState", loginState.getValue())
.execute();
}
}
public Integer insert(Account account) {
String sql = """
INSERT INTO account (name, password, birthdate, chr_slots, login_state)

View File

@@ -731,7 +731,7 @@ public class Server {
final int worldCount = Math.min(GameConstants.WORLD_NAMES.length, YamlConfig.config.server.WORLDS);
try (Connection con = DatabaseConnection.getConnection()) {
setAllLoggedOut(con);
channelDependencies.accountService().setAllLoggedOut();
setAllMerchantsInactive(con);
cleanNxcodeCoupons(con);
loadCouponRates(con);
@@ -873,12 +873,6 @@ public class Server {
return loginServer;
}
private static void setAllLoggedOut(Connection con) throws SQLException {
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = 0")) {
ps.executeUpdate();
}
}
private static void setAllMerchantsInactive(Connection con) throws SQLException {
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET HasMerchant = 0")) {
ps.executeUpdate();

View File

@@ -95,6 +95,10 @@ public class AccountService {
return accountRepository.findByChrNameIgnoreCase(chrName);
}
public void setAllLoggedOut() {
accountRepository.setAllLoginState(LoginState.LOGGED_OUT);
}
public boolean acceptTos(int accountId) {
acceptTosMysql(accountId);
acceptTosPostgres(accountId);