DB v2 Tweaks

This commit is contained in:
Gent S 2020-12-19 20:39:35 -05:00
parent 1fb48536c2
commit 2e173df2ca
3 changed files with 17 additions and 9 deletions

View File

@ -7,7 +7,7 @@ ALTER TABLE RaceResults ADD Time INTEGER NOT NULL;
INSERT INTO Meta (Key, Value) VALUES ('Created', 0); INSERT INTO Meta (Key, Value) VALUES ('Created', 0);
INSERT INTO Meta (Key, Value) VALUES ('LastMigration', strftime('%s', 'now')); INSERT INTO Meta (Key, Value) VALUES ('LastMigration', strftime('%s', 'now'));
UPDATE Meta SET Value = (SELECT Created FROM Meta WHERE Key = 'ProtocolVersion') Where Key = 'Created'; UPDATE Meta SET Value = (SELECT Created FROM Meta WHERE Key = 'ProtocolVersion') Where Key = 'Created';
-- Get rid of 'Created' Collumn -- Get rid of 'Created' Column
CREATE TABLE Temp(Key TEXT NOT NULL UNIQUE, Value INTEGER NOT NULL); CREATE TABLE Temp(Key TEXT NOT NULL UNIQUE, Value INTEGER NOT NULL);
INSERT INTO Temp SELECT Key, Value FROM Meta; INSERT INTO Temp SELECT Key, Value FROM Meta;
DROP TABLE Meta; DROP TABLE Meta;

View File

@ -144,15 +144,14 @@ void CNLoginServer::login(CNSocket* sock, CNPacketData* data) {
return loginFail(LoginError::ID_AND_PASSWORD_DO_NOT_MATCH, userLogin, sock); return loginFail(LoginError::ID_AND_PASSWORD_DO_NOT_MATCH, userLogin, sock);
// is the account banned // is the account banned
if (findUser.BannedUntil > getTimestamp()) if (findUser.BannedUntil > getTimestamp()) {
{
// send a custom error message // send a custom error message
INITSTRUCT(sP_FE2CL_GM_REP_PC_ANNOUNCE, msg); INITSTRUCT(sP_FE2CL_GM_REP_PC_ANNOUNCE, msg);
// ceiling devision // ceiling devision
int64_t remainingDays = (findUser.BannedUntil-getTimestamp()) / 86400 + ((findUser.BannedUntil - getTimestamp()) % 86400 != 0); int64_t remainingDays = (findUser.BannedUntil-getTimestamp()) / 86400 + ((findUser.BannedUntil - getTimestamp()) % 86400 != 0);
std::string text = "Your account has been banned by game master\nReason: "; std::string text = "Your account has been banned. \nReason: ";
text += findUser.BanReason; text += findUser.BanReason;
text += "\nBan expires in " + std::to_string(remainingDays) + " day"; text += "\nBan expires in " + std::to_string(remainingDays) + " day";
if (remainingDays > 1) if (remainingDays > 1)
@ -161,7 +160,7 @@ void CNLoginServer::login(CNSocket* sock, CNPacketData* data) {
U8toU16(text, msg.szAnnounceMsg, sizeof(msg.szAnnounceMsg)); U8toU16(text, msg.szAnnounceMsg, sizeof(msg.szAnnounceMsg));
msg.iDuringTime = 99999999; msg.iDuringTime = 99999999;
sock->sendPacket((void*)&msg, P_FE2CL_GM_REP_PC_ANNOUNCE, sizeof(sP_FE2CL_GM_REP_PC_ANNOUNCE)); sock->sendPacket((void*)&msg, P_FE2CL_GM_REP_PC_ANNOUNCE, sizeof(sP_FE2CL_GM_REP_PC_ANNOUNCE));
// don't send fail packet to softlock sucker's client // don't send fail packet
return; return;
} }

View File

@ -16,6 +16,7 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <filesystem>
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
#include "mingw/mingw.mutex.h" #include "mingw/mingw.mutex.h"
@ -134,6 +135,16 @@ void Database::checkMetaTable() {
if (dbVersion > DATABASE_VERSION) { if (dbVersion > DATABASE_VERSION) {
std::cout << "[FATAL] Server Build is incompatible with DB Version" << std::endl; std::cout << "[FATAL] Server Build is incompatible with DB Version" << std::endl;
exit(1); exit(1);
} else if (dbVersion < DATABASE_VERSION) {
// we're gonna migrate; back up the DB
try {
std::cout << "[INFO] Backing up database" << std::endl;
std::filesystem::copy_file(settings::DBPATH, settings::DBPATH + ".old." + std::to_string(dbVersion));
}
catch (std::filesystem::filesystem_error& e) {
std::cout << "[FATAL] Failed to backup database before migration" << std::endl;
exit(1);
}
} }
while (dbVersion != DATABASE_VERSION) { while (dbVersion != DATABASE_VERSION) {
@ -158,7 +169,7 @@ void Database::checkMetaTable() {
} }
dbVersion++; dbVersion++;
std::cout << "[INFO] Successfull Database Migration to Version " << dbVersion << std::endl; std::cout << "[INFO] Successful Database Migration to Version " << dbVersion << std::endl;
} }
} }
@ -226,14 +237,12 @@ void Database::createTables() {
std::string read = stream.str(); std::string read = stream.str();
const char* sql = read.c_str(); const char* sql = read.c_str();
dbCrit.lock();
char* errMsg = 0; char* errMsg = 0;
int rc = sqlite3_exec(db, sql, NULL, NULL, &errMsg); int rc = sqlite3_exec(db, sql, NULL, NULL, &errMsg);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
std::cout << "[FATAL] Database failed to create tables: " << errMsg << std::endl; std::cout << "[FATAL] Database failed to create tables: " << errMsg << std::endl;
exit(1); exit(1);
} }
dbCrit.unlock();
} }
int Database::getTableSize(std::string tableName) { int Database::getTableSize(std::string tableName) {