Save pin to PG

This commit is contained in:
P0nk
2024-09-27 06:50:07 +02:00
parent 0f2ef341ce
commit f33d4fbc1c
5 changed files with 63 additions and 22 deletions

View File

@@ -291,7 +291,7 @@ public final class PacketProcessor {
registerHandler(RecvOpcode.DELETE_CHAR, new DeleteCharHandler());
registerHandler(RecvOpcode.VIEW_ALL_CHAR, new ViewAllCharHandler());
registerHandler(RecvOpcode.PICK_ALL_CHAR, new ViewAllCharSelectedHandler());
registerHandler(RecvOpcode.REGISTER_PIN, new RegisterPinHandler());
registerHandler(RecvOpcode.REGISTER_PIN, new RegisterPinHandler(channelDeps.accountService()));
registerHandler(RecvOpcode.GUEST_LOGIN, new GuestLoginHandler());
registerHandler(RecvOpcode.REGISTER_PIC, new RegisterPicHandler());
registerHandler(RecvOpcode.CHAR_SELECT_WITH_PIC, new CharSelectedWithPicHandler());

View File

@@ -25,27 +25,35 @@ import client.Client;
import net.AbstractPacketHandler;
import net.packet.InPacket;
import net.server.coordinator.session.SessionCoordinator;
import service.AccountService;
import tools.PacketCreator;
/*
/**
* @author Rob
* @author Ponk
*/
public final class RegisterPinHandler extends AbstractPacketHandler {
private final AccountService accountService;
public RegisterPinHandler(final AccountService accountService) {
this.accountService = accountService;
}
@Override
public final void handlePacket(InPacket p, Client c) {
byte c2 = p.readByte();
if (c2 == 0) {
public void handlePacket(InPacket p, Client c) {
boolean cancel = p.readByte() == 0;
if (cancel) {
SessionCoordinator.getInstance().closeSession(c, false);
c.updateLoginState(Client.LOGIN_NOTLOGGEDIN);
} else {
String pin = p.readString();
if (pin != null) {
c.setPin(pin);
c.sendPacket(PacketCreator.pinRegistered());
SessionCoordinator.getInstance().closeSession(c, false);
c.updateLoginState(Client.LOGIN_NOTLOGGEDIN);
}
return;
}
String pin = p.readString();
accountService.setPin(c.getAccID(), pin);
c.setPin(pin);
c.sendPacket(PacketCreator.pinRegistered());
SessionCoordinator.getInstance().closeSession(c, false);
c.updateLoginState(Client.LOGIN_NOTLOGGEDIN);
}
}