Save client addresses async on chr select

Almost rid of all db queries in Client
This commit is contained in:
P0nk
2024-10-03 08:28:22 +02:00
parent e38344ceae
commit 2b6ef9feb5
10 changed files with 91 additions and 83 deletions

View File

@@ -7,7 +7,9 @@ import database.account.Account;
import database.account.AccountRepository;
import lombok.extern.slf4j.Slf4j;
import net.server.Server;
import net.server.coordinator.session.Hwid;
import net.server.coordinator.session.SessionCoordinator;
import server.TimerManager;
import tools.BCrypt;
import tools.DatabaseConnection;
@@ -301,6 +303,19 @@ public class AccountService {
}
}
public void setIpAndMacsAndHwidAsync(int accountId, final String ip, final String macs, Hwid hwid) {
final String hwidToSave = hwid != null ? hwid.hwid() : null;
TimerManager.getInstance().schedule(() -> {
try {
accountRepository.setIpAndMacsAndHwid(accountId, ip, hwidToSave, macs);
} catch (Exception e) {
log.error("Failed to save ip: {}, macs: {}, hwid: {} for accountId: {}", ip, hwidToSave, macs,
accountId, e);
}
}, 0);
}
public boolean ban(int accountId, Instant bannedUntil, byte banReason, String description) {
return accountRepository.setBanned(accountId, bannedUntil, banReason, description);
}