Change default birthday and tempban to fix conversion issue

ResultSet#getLong on a timestamp field is not allowed
This commit is contained in:
P0nk
2021-04-02 16:11:41 +02:00
parent 7169a74e94
commit 754ab67de7
5 changed files with 46 additions and 23 deletions

View File

@@ -0,0 +1,19 @@
package client;
import java.time.LocalDate;
import java.time.LocalDateTime;
final public class DefaultDates {
// May 11 2005 is the date MapleGlobal released, so it's a symbolic default value
private DefaultDates() {
}
public static LocalDate getBirthday() {
return LocalDate.parse("2005-05-11");
}
public static LocalDateTime getTempban() {
return LocalDateTime.parse("2005-05-11T00:00:00");
}
}

View File

@@ -30,6 +30,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@@ -11036,8 +11037,13 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
try (PreparedStatement ps = con.prepareStatement("SELECT tempban FROM accounts WHERE id = ?")) {
ps.setInt(1, accountId);
ResultSet rs = ps.executeQuery();
if(!rs.next()) return "Account does not exist.";
if(rs.getLong("tempban") != 0 && !rs.getString("tempban").equals("2018-06-20 00:00:00.0")) return "Account has been banned.";
if (!rs.next()) {
return "Account does not exist.";
}
LocalDateTime tempban = rs.getTimestamp("tempban").toLocalDateTime();
if(!tempban.equals(DefaultDates.getTempban())) {
return "Account has been banned.";
}
} catch(SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e);

View File

@@ -25,10 +25,8 @@ import java.io.*;
import java.net.InetAddress;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@@ -647,23 +645,24 @@ public class MapleClient {
ResultSet rs = null;
final Calendar lTempban = Calendar.getInstance();
try {
con = DatabaseConnection.getConnection();
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT `tempban` FROM accounts WHERE id = ?");
ps.setInt(1, getAccID());
rs = ps.executeQuery();
if (!rs.next()) {
return null;
}
long blubb = rs.getLong("tempban");
if (blubb == 0 || rs.getString("tempban").equals("2018-06-20 00:00:00.0")) { // 0000-00-00 or 2018-06-20 (default set in LoginPasswordHandler)
final Timestamp tempban = rs.getTimestamp("tempban");
if (tempban.toLocalDateTime().equals(DefaultDates.getTempban())) {
return null;
}
lTempban.setTimeInMillis(rs.getTimestamp("tempban").getTime());
lTempban.setTimeInMillis(tempban.getTime());
tempBanCalendar = lTempban;
return lTempban;
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace();
} finally {
try {
if (ps != null) {
@@ -672,11 +671,11 @@ public class MapleClient {
if (rs != null) {
rs.close();
}
if (con != null && !con.isClosed()) {
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace();
}
}
return null;//why oh why!?!

View File

@@ -21,11 +21,11 @@
*/
package net.server.handlers.login;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.*;
import java.time.LocalDateTime;
import java.util.Calendar;
import client.DefaultDates;
import config.YamlConfig;
import net.MaplePacketHandler;
import net.server.Server;
@@ -35,8 +35,7 @@ import tools.HexTool;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleClient;
import java.sql.ResultSet;
import java.sql.Statement;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -100,8 +99,8 @@ public final class LoginPasswordHandler implements MaplePacketHandler {
ps = con.prepareStatement("INSERT INTO accounts (name, password, birthday, tempban) VALUES (?, ?, ?, ?);", Statement.RETURN_GENERATED_KEYS); //Jayd: Added birthday, tempban
ps.setString(1, login);
ps.setString(2, YamlConfig.config.server.BCRYPT_MIGRATION ? BCrypt.hashpw(pwd, BCrypt.gensalt(12)) : hashpwSHA512(pwd));
ps.setString(3, "2018-06-20"); //Jayd's idea: was added to solve the MySQL 5.7 strict checking (birthday)
ps.setString(4, "2018-06-20"); //Jayd's idea: was added to solve the MySQL 5.7 strict checking (tempban)
ps.setDate(3, Date.valueOf(DefaultDates.getBirthday()));
ps.setTimestamp(4, Timestamp.valueOf(DefaultDates.getTempban()));
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();