Rename AccountService methods

This commit is contained in:
P0nk
2024-09-29 09:14:32 +02:00
parent da4a467453
commit a580e44bc9
8 changed files with 14 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ package client;
* @author Ponk * @author Ponk
*/ */
public class LoginState { public class LoginState {
public static final byte NOT_LOGGED_IN = 0; public static final byte NOT_LOGGED_IN = 0; // TODO: rename to LOGGED_OUT
public static final byte SERVER_TRANSITION = 1; public static final byte SERVER_TRANSITION = 1;
public static final byte LOGGED_IN = 2; public static final byte LOGGED_IN = 2;
} }

View File

@@ -205,7 +205,7 @@ public final class PlayerLoggedinHandler extends AbstractPacketHandler {
return; return;
} }
accountService.logIn(c); accountService.setLoggedIn(c);
} finally { } finally {
releaseAccount(accId); releaseAccount(accId);
} }

View File

@@ -29,7 +29,7 @@ public final class AcceptToSHandler extends AbstractPacketHandler {
throw new GameViolationException("ToS not accepted"); throw new GameViolationException("ToS not accepted");
} }
if (!accountService.logIn(c)) { if (!accountService.setLoggedIn(c)) {
c.sendPacket(PacketCreator.getLoginFailed(7)); c.sendPacket(PacketCreator.getLoginFailed(7));
} }

View File

@@ -62,7 +62,7 @@ public final class AfterLoginHandler extends AbstractPacketHandler {
c.sendPacket(PacketCreator.requestPinAfterFailure()); c.sendPacket(PacketCreator.requestPinAfterFailure());
} }
} else if (c2 == 0 && c3 == 5) { } else if (c2 == 0 && c3 == 5) {
accountService.logOut(c); accountService.setLoggedOutAndDisconnect(c);
} }
} }
} }

View File

@@ -149,7 +149,7 @@ public final class LoginPasswordHandler implements PacketHandler {
return; return;
} }
if (!accountService.logIn(c)) { if (!accountService.setLoggedIn(c)) {
c.sendPacket(PacketCreator.getLoginFailed(7)); c.sendPacket(PacketCreator.getLoginFailed(7));
} }
removeOnlineAccountChrs(c); removeOnlineAccountChrs(c);

View File

@@ -42,7 +42,7 @@ public final class RegisterPinHandler extends AbstractPacketHandler {
public void handlePacket(InPacket p, Client c) { public void handlePacket(InPacket p, Client c) {
boolean cancel = p.readByte() == 0; boolean cancel = p.readByte() == 0;
if (cancel) { if (cancel) {
accountService.logOut(c); accountService.setLoggedOutAndDisconnect(c);
return; return;
} }
@@ -51,6 +51,6 @@ public final class RegisterPinHandler extends AbstractPacketHandler {
c.setPin(pin); c.setPin(pin);
c.sendPacket(PacketCreator.pinRegistered()); c.sendPacket(PacketCreator.pinRegistered());
accountService.logOut(c); accountService.setLoggedOutAndDisconnect(c);
} }
} }

View File

@@ -71,7 +71,7 @@ public class SetGenderHandler extends AbstractPacketHandler {
} }
private void logOut(Client c) { private void logOut(Client c) {
accountService.logOut(c); accountService.setLoggedOutAndDisconnect(c);
} }
} }

View File

@@ -213,7 +213,7 @@ public class AccountService {
return accountRepository.setChrSlots(accountId, chrSlots); return accountRepository.setChrSlots(accountId, chrSlots);
} }
public boolean logIn(Client c) { public boolean setLoggedIn(Client c) {
byte newState = LoginState.LOGGED_IN; byte newState = LoginState.LOGGED_IN;
int currentState = c.getLoginState(); int currentState = c.getLoginState();
if (currentState != LoginState.NOT_LOGGED_IN && currentState != LoginState.SERVER_TRANSITION) { if (currentState != LoginState.NOT_LOGGED_IN && currentState != LoginState.SERVER_TRANSITION) {
@@ -224,8 +224,12 @@ public class AccountService {
return true; return true;
} }
public void logOut(Client c) { public void setLoggedOutAndDisconnect(Client c) {
SessionCoordinator.getInstance().closeSession(c, false); SessionCoordinator.getInstance().closeSession(c, false);
setLoggedOut(c);
}
public void setLoggedOut(Client c) {
setLoginState(c, LoginState.NOT_LOGGED_IN); setLoginState(c, LoginState.NOT_LOGGED_IN);
} }