Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoginPacketRequest extends InboundPacket {
- User user;
- long packetId;
- int clientVersion;
- ChatManager chatManager;
- String login;
- String password;
- final String salt = "7CHSEIoTv7";
- public LoginPacketRequest(User user, ChatManager chatManager) {
- this.user = user;
- this.chatManager = chatManager;
- }
- @Override
- public void run() {
- Connection con = HikariCP.getInstance().getConnection();
- try {
- boolean userExists = DatabaseRequests.getUserInfo(con, user, login);
- if (!userExists) {
- thisSession.send(new LoginPacketResponse(packetId, PacketErrorCodes.PACKET_WRONG_USERNAME_OR_PASSWORD));
- return;
- }
- String enteredPasswdUppercase = password.toUpperCase();
- String dbPasswd = user.getPasswd().toUpperCase();
- //password verification
- if (!dbPasswd.equals(enteredPasswdUppercase)) {
- thisSession.send(new LoginPacketResponse(packetId, PacketErrorCodes.PACKET_WRONG_USERNAME_OR_PASSWORD));
- return;
- }
- boolean userValid = DatabaseRequests.checkUserValid(con, user);
- if (!userValid) {
- thisSession.send(new LoginPacketResponse(packetId, PacketErrorCodes.PACKET_USER_IS_NOT_VALID));
- return;
- }
- user.setClientVersion(clientVersion);
- UserManager.getInstance().add(user);
- chatManager.onConnectToChat(user.getLogin(), thisSession);
- FileLog.getInstance().d("UserManager size = " + UserManager.getInstance().count() +
- ", chatManager size = " + chatManager.size());
- thisSession.send(new LoginPacketResponse(packetId, PacketErrorCodes.PACKET_OK,
- KartofanServer.SERVER_VERSION, user.getRole(), user.getTicket()));
- } catch (Exception e) {
- FileLog.getInstance().e(e);
- thisSession.send(new LoginPacketResponse(packetId, PacketErrorCodes.PACKET_COULDNT_VERIFY_LOGIN_PASS));
- } finally {
- try {
- con.close();
- } catch (SQLException e) {
- FileLog.getInstance().e(e);
- }
- }
- }
- @Override
- public boolean read() {
- try {
- packetId = readQword();
- login = readString();
- password = readString();
- clientVersion = readDword();
- //user.setEmail(readString());
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment