Change default birthday and tempban to fix conversion issue
ResultSet#getLong on a timestamp field is not allowed
This commit is contained in:
+2
-2
@@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS `accounts` (
|
|||||||
`loggedin` tinyint(4) NOT NULL DEFAULT '0',
|
`loggedin` tinyint(4) NOT NULL DEFAULT '0',
|
||||||
`lastlogin` timestamp NULL DEFAULT NULL,
|
`lastlogin` timestamp NULL DEFAULT NULL,
|
||||||
`createdat` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`createdat` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`birthday` date NOT NULL DEFAULT '0000-00-00',
|
`birthday` date NOT NULL DEFAULT '2005-05-11',
|
||||||
`banned` tinyint(1) NOT NULL DEFAULT '0',
|
`banned` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
`banreason` text,
|
`banreason` text,
|
||||||
`macs` tinytext,
|
`macs` tinytext,
|
||||||
@@ -30,7 +30,7 @@ CREATE TABLE IF NOT EXISTS `accounts` (
|
|||||||
`nxPrepaid` int(11) DEFAULT NULL,
|
`nxPrepaid` int(11) DEFAULT NULL,
|
||||||
`characterslots` tinyint(2) NOT NULL DEFAULT '3',
|
`characterslots` tinyint(2) NOT NULL DEFAULT '3',
|
||||||
`gender` tinyint(2) NOT NULL DEFAULT '10',
|
`gender` tinyint(2) NOT NULL DEFAULT '10',
|
||||||
`tempban` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
|
`tempban` timestamp NOT NULL DEFAULT '2005-05-11 00:00:00',
|
||||||
`greason` tinyint(4) NOT NULL DEFAULT '0',
|
`greason` tinyint(4) NOT NULL DEFAULT '0',
|
||||||
`tos` tinyint(1) NOT NULL DEFAULT '0',
|
`tos` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
`sitelogged` text,
|
`sitelogged` text,
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -11036,8 +11037,13 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
|
|||||||
try (PreparedStatement ps = con.prepareStatement("SELECT tempban FROM accounts WHERE id = ?")) {
|
try (PreparedStatement ps = con.prepareStatement("SELECT tempban FROM accounts WHERE id = ?")) {
|
||||||
ps.setInt(1, accountId);
|
ps.setInt(1, accountId);
|
||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
if(!rs.next()) return "Account does not exist.";
|
if (!rs.next()) {
|
||||||
if(rs.getLong("tempban") != 0 && !rs.getString("tempban").equals("2018-06-20 00:00:00.0")) return "Account has been banned.";
|
return "Account does not exist.";
|
||||||
|
}
|
||||||
|
LocalDateTime tempban = rs.getTimestamp("tempban").toLocalDateTime();
|
||||||
|
if(!tempban.equals(DefaultDates.getTempban())) {
|
||||||
|
return "Account has been banned.";
|
||||||
|
}
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e);
|
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e);
|
||||||
|
|||||||
@@ -25,10 +25,8 @@ import java.io.*;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.PreparedStatement;
|
import java.time.LocalDateTime;
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -647,23 +645,24 @@ public class MapleClient {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
final Calendar lTempban = Calendar.getInstance();
|
final Calendar lTempban = Calendar.getInstance();
|
||||||
try {
|
try {
|
||||||
con = DatabaseConnection.getConnection();
|
con = DatabaseConnection.getConnection();
|
||||||
ps = con.prepareStatement("SELECT `tempban` FROM accounts WHERE id = ?");
|
ps = con.prepareStatement("SELECT `tempban` FROM accounts WHERE id = ?");
|
||||||
ps.setInt(1, getAccID());
|
ps.setInt(1, getAccID());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
if (!rs.next()) {
|
if (!rs.next()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long blubb = rs.getLong("tempban");
|
|
||||||
|
final Timestamp tempban = rs.getTimestamp("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)
|
if (tempban.toLocalDateTime().equals(DefaultDates.getTempban())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
lTempban.setTimeInMillis(rs.getTimestamp("tempban").getTime());
|
|
||||||
|
lTempban.setTimeInMillis(tempban.getTime());
|
||||||
tempBanCalendar = lTempban;
|
tempBanCalendar = lTempban;
|
||||||
return lTempban;
|
return lTempban;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (ps != null) {
|
if (ps != null) {
|
||||||
@@ -672,11 +671,11 @@ public class MapleClient {
|
|||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
rs.close();
|
rs.close();
|
||||||
}
|
}
|
||||||
if (con != null && !con.isClosed()) {
|
if (con != null && !con.isClosed()) {
|
||||||
con.close();
|
con.close();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;//why oh why!?!
|
return null;//why oh why!?!
|
||||||
|
|||||||
@@ -21,11 +21,11 @@
|
|||||||
*/
|
*/
|
||||||
package net.server.handlers.login;
|
package net.server.handlers.login;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.PreparedStatement;
|
import java.time.LocalDateTime;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import client.DefaultDates;
|
||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
import net.MaplePacketHandler;
|
import net.MaplePacketHandler;
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
@@ -35,8 +35,7 @@ import tools.HexTool;
|
|||||||
import tools.MaplePacketCreator;
|
import tools.MaplePacketCreator;
|
||||||
import tools.data.input.SeekableLittleEndianAccessor;
|
import tools.data.input.SeekableLittleEndianAccessor;
|
||||||
import client.MapleClient;
|
import client.MapleClient;
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
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 = con.prepareStatement("INSERT INTO accounts (name, password, birthday, tempban) VALUES (?, ?, ?, ?);", Statement.RETURN_GENERATED_KEYS); //Jayd: Added birthday, tempban
|
||||||
ps.setString(1, login);
|
ps.setString(1, login);
|
||||||
ps.setString(2, YamlConfig.config.server.BCRYPT_MIGRATION ? BCrypt.hashpw(pwd, BCrypt.gensalt(12)) : hashpwSHA512(pwd));
|
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.setDate(3, Date.valueOf(DefaultDates.getBirthday()));
|
||||||
ps.setString(4, "2018-06-20"); //Jayd's idea: was added to solve the MySQL 5.7 strict checking (tempban)
|
ps.setTimestamp(4, Timestamp.valueOf(DefaultDates.getTempban()));
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
|
||||||
ResultSet rs = ps.getGeneratedKeys();
|
ResultSet rs = ps.getGeneratedKeys();
|
||||||
|
|||||||
Reference in New Issue
Block a user