minor cleanup

This commit is contained in:
CPunch 2020-08-31 17:54:49 -05:00
parent 73c67a814d
commit 4f6c77be4f
3 changed files with 38 additions and 119 deletions

View File

@ -26,26 +26,22 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
int errorCode = 0;
std::string userLogin = U16toU8(login->szID);
std::string userPassword = U16toU8(login->szPassword);
//checking regex
if (!Database::isLoginDataGood(userLogin, userPassword)) {
errorCode = (int)LOGINERRORID::login_error;
}
//if user does not exist in db, add him to and send succ
else if (!Database::doesUserExist(U16toU8(login->szID))) {
if (!Database::isLoginDataGood(userLogin, userPassword)) {
// failed regex
errorCode = (int)LOGINERRORID::login_error;
} else if (!Database::doesUserExist(U16toU8(login->szID))) {
// if user does not exist in db, add him to and send succ
Database::addAccount(U16toU8(login->szID), U16toU8(login->szPassword));
success = true;
}
//if user exists, check if password is correct
else if (Database::isPasswordCorrect((U16toU8(login->szID)), U16toU8(login->szPassword))) {
} else if (Database::isPasswordCorrect((U16toU8(login->szID)), U16toU8(login->szPassword))) {
// if user exists, check if password is correct
success = true;
}
else {
} else {
errorCode = (int)LOGINERRORID::id_and_password_do_not_match;
}
if (success)
{
if (success) {
int userID = Database::getUserID(userLogin);
int charCount = Database::getUserSlotsNum(userID);
@ -75,8 +71,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
std::list<Player> characters = Database::getCharacters(loginSessions[sock].userID);
std::list<Player>::iterator it;
for (it = characters.begin(); it != characters.end(); it++)
{
for (it = characters.begin(); it != characters.end(); it++) {
sP_LS2CL_REP_CHAR_INFO charInfo = sP_LS2CL_REP_CHAR_INFO();
charInfo.iSlot = (int8_t)it->slot;
@ -103,10 +98,6 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
loginSessions[sock].characters[UID].IsGM = false;
loginSessions[sock].characters[UID].money = 9001;
Player test = loginSessions[sock].characters[UID];
for (int i = 0; i < 4; i++) {
//equip char creation clothes and lightning rifle
charInfo.aEquip[i] = it->Equip[i];
@ -134,71 +125,10 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
loginSessions[sock].selectedChar = UID;
sock->sendPacket((void*)&charInfo, P_LS2CL_REP_CHAR_INFO, sizeof(sP_LS2CL_REP_CHAR_INFO));
}
}
//for (int i = 0; i < charCount; i++) {
// sP_LS2CL_REP_CHAR_INFO charInfo = sP_LS2CL_REP_CHAR_INFO();
// charInfo.iSlot = (int8_t)i + 1;
// charInfo.iLevel = (int16_t)36;
// charInfo.sPC_Style.iPC_UID = rand(); // unique identifier for the character
// charInfo.sPC_Style.iNameCheck = 1;
// charInfo.sPC_Style.iGender = (i%2)+1; // can be 1(boy) or 2(girl)
// charInfo.sPC_Style.iFaceStyle = 1;
// charInfo.sPC_Style.iHairStyle = 1;
// charInfo.sPC_Style.iHairColor = (rand()%19) + 1; // 1 - 19
// charInfo.sPC_Style.iSkinColor = (rand()%13) + 1; // 1 - 13
// charInfo.sPC_Style.iEyeColor = (rand()%6) + 1; // 1 - 6
// charInfo.sPC_Style.iHeight = (rand()%6); // 0 -5
// charInfo.sPC_Style.iBody = (rand()%4); // 0 - 3
// charInfo.sPC_Style.iClass = 0;
// charInfo.sPC_Style2.iAppearanceFlag = 1;
// charInfo.sPC_Style2.iPayzoneFlag = 1;
// charInfo.sPC_Style2.iTutorialFlag = 1;
// // past's town hall
// charInfo.iX = settings::SPAWN_X;
// charInfo.iY = settings::SPAWN_Y;
// charInfo.iZ = settings::SPAWN_Z;
// U8toU16(std::string("Player"), charInfo.sPC_Style.szFirstName);
// U8toU16(std::to_string(i + 1), charInfo.sPC_Style.szLastName);
// int64_t UID = charInfo.sPC_Style.iPC_UID;
// loginSessions[sock].characters[UID] = Player();
// loginSessions[sock].characters[UID].level = charInfo.iLevel;
// loginSessions[sock].characters[UID].money = 9001;
// loginSessions[sock].characters[UID].slot = charInfo.iSlot;
// loginSessions[sock].characters[UID].FEKey = sock->getFEKey();
// loginSessions[sock].characters[UID].x = charInfo.iX;
// loginSessions[sock].characters[UID].y = charInfo.iY;
// loginSessions[sock].characters[UID].z = charInfo.iZ;
// loginSessions[sock].characters[UID].PCStyle = charInfo.sPC_Style;
// loginSessions[sock].characters[UID].PCStyle2 = charInfo.sPC_Style2;
// loginSessions[sock].characters[UID].isTrading = false;
// loginSessions[sock].characters[UID].isTradeConfirm = false;
// loginSessions[sock].characters[UID].IsGM = settings::GM;
// for (int i = 0; i < AEQUIP_COUNT; i++) {
// // setup equips
// charInfo.aEquip[i].iID = 0;
// charInfo.aEquip[i].iType = i;
// charInfo.aEquip[i].iOpt = 0;
// loginSessions[sock].characters[UID].Equip[i] = charInfo.aEquip[i];
// }
//
// for (int i = 0; i < AINVEN_COUNT; i++) {
// // setup inventories
// loginSessions[sock].characters[UID].Inven[i].iID = 0;
// loginSessions[sock].characters[UID].Inven[i].iType = 0;
// loginSessions[sock].characters[UID].Inven[i].iOpt = 0;
// }
//}
}
//Failure
else {
} else {
// failed
INITSTRUCT(sP_LS2CL_REP_LOGIN_FAIL, resp);
memcpy(resp.szID, login->szID, sizeof(char16_t) * 33);
@ -206,7 +136,6 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
sock->sendPacket((void*)&resp, P_LS2CL_REP_LOGIN_FAIL, sizeof(sP_LS2CL_REP_LOGIN_FAIL));
}
break;
}
case P_CL2LS_REP_LIVE_CHECK: {
@ -281,34 +210,24 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
DEBUGLOG(
std::cout << "P_CL2LS_REQ_CHAR_CREATE:" << std::endl;
std::cout << "\tPC_UID: " << character->PCStyle.iPC_UID << std::endl;
std::cout << "\tNameCheck: " << (int)character->PCStyle.iNameCheck << std::endl;
std::cout << "\tName: " << U16toU8(character->PCStyle.szFirstName) << " " << U16toU8(character->PCStyle.szLastName) << std::endl;
std::cout << "\tGender: " << (int)character->PCStyle.iGender << std::endl;
std::cout << "\tFace: " << (int)character->PCStyle.iFaceStyle << std::endl;
std::cout << "\tHair: " << (int)character->PCStyle.iHairStyle << std::endl;
std::cout << "\tHair Color: " << (int)character->PCStyle.iHairColor << std::endl;
std::cout << "\tSkin Color: " << (int)character->PCStyle.iSkinColor << std::endl;
std::cout << "\tEye Color: " << (int)character->PCStyle.iEyeColor << std::endl;
std::cout << "\tHeight: " << (int)character->PCStyle.iHeight << std::endl;
std::cout << "\tBody: " << (int)character->PCStyle.iBody << std::endl;
std::cout << "\tClass: " << (int)character->PCStyle.iClass << std::endl;
std::cout << "\tiEquipUBID: " << (int)character->sOn_Item.iEquipUBID << std::endl;
std::cout << "\tiEquipLBID: " << (int)character->sOn_Item.iEquipLBID << std::endl;
std::cout << "\tiEquipFootID: " << (int)character->sOn_Item.iEquipFootID << std::endl;
std::cout << "\tPC_UID: " << character->PCStyle.iPC_UID << std::endl;
std::cout << "\tNameCheck: " << (int)character->PCStyle.iNameCheck << std::endl;
std::cout << "\tName: " << U16toU8(character->PCStyle.szFirstName) << " " << U16toU8(character->PCStyle.szLastName) << std::endl;
std::cout << "\tGender: " << (int)character->PCStyle.iGender << std::endl;
std::cout << "\tFace: " << (int)character->PCStyle.iFaceStyle << std::endl;
std::cout << "\tHair: " << (int)character->PCStyle.iHairStyle << std::endl;
std::cout << "\tHair Color: " << (int)character->PCStyle.iHairColor << std::endl;
std::cout << "\tSkin Color: " << (int)character->PCStyle.iSkinColor << std::endl;
std::cout << "\tEye Color: " << (int)character->PCStyle.iEyeColor << std::endl;
std::cout << "\tHeight: " << (int)character->PCStyle.iHeight << std::endl;
std::cout << "\tBody: " << (int)character->PCStyle.iBody << std::endl;
std::cout << "\tClass: " << (int)character->PCStyle.iClass << std::endl;
std::cout << "\tiEquipUBID: " << (int)character->sOn_Item.iEquipUBID << std::endl;
std::cout << "\tiEquipLBID: " << (int)character->sOn_Item.iEquipLBID << std::endl;
std::cout << "\tiEquipFootID: " << (int)character->sOn_Item.iEquipFootID << std::endl;
)
int64_t UID = character->PCStyle.iPC_UID;
// commented and disabled for now
//bool BecomeGM;
//if (U16toU8(character->PCStyle.szFirstName) == settings::GMPASS) {
// BecomeGM = true;
// U8toU16("GM",character->PCStyle.szFirstName);
//} else {
// BecomeGM = false;
//}
int64_t UID = character->PCStyle.iPC_UID;
character->PCStyle.iNameCheck = 1;
resp.sPC_Style = character->PCStyle;
@ -356,8 +275,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
INITSTRUCT(sP_LS2CL_REP_CHAR_DELETE_SUCC, resp);
resp.iSlotNum = operationResult;
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_DELETE_SUCC, sizeof(sP_LS2CL_REP_CHAR_DELETE_SUCC));
}
else {
} else {
// failure
// client doesnt't care about this packet and softlocks
INITSTRUCT(sP_LS2CL_REP_CHAR_DELETE_FAIL, resp);
@ -377,10 +295,10 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
DEBUGLOG(
std::cout << "P_CL2LS_REQ_CHAR_SELECT:" << std::endl;
std::cout << "\tPC_UID: " << chararacter->iPC_UID << std::endl;
std::cout << "\tPC_UID: " << chararacter->iPC_UID << std::endl;
)
loginSessions[sock].selectedChar = chararacter->iPC_UID;
loginSessions[sock].selectedChar = chararacter->iPC_UID;
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_SELECT_SUCC, sizeof(sP_LS2CL_REP_CHAR_SELECT_SUCC));
break;
@ -395,10 +313,10 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
DEBUGLOG(
std::cout << "P_CL2LS_REQ_SHARD_SELECT:" << std::endl;
std::cout << "\tShard: " << (int)shard->ShardNum << std::endl;
std::cout << "\tShard: " << (int)shard->ShardNum << std::endl;
)
const char* SHARD_IP = settings::SHARDSERVERIP.c_str();
const char* SHARD_IP = settings::SHARDSERVERIP.c_str();
resp.iEnterSerialKey = rand();
resp.g_FE_ServerPort = settings::SHARDPORT;
@ -415,6 +333,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
case P_CL2LS_REQ_SAVE_CHAR_TUTOR: {
if (data->size != sizeof(sP_CL2LS_REQ_SAVE_CHAR_TUTOR))
return;
sP_CL2LS_REQ_SAVE_CHAR_TUTOR* save = (sP_CL2LS_REQ_SAVE_CHAR_TUTOR*)data->buf;
Database::finishTutorial(save->iPC_UID);
loginSessions[sock].characters[save->iPC_UID].PCStyle2.iTutorialFlag = 1;
@ -425,7 +344,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
break;
}
default:
if (settings::VERBOSITY)
if (settings::VERBOSITY > 0)
std::cerr << "OpenFusion: LOGIN UNIMPLM ERR. PacketType: " << Defines::p2str(CL2LS, data->type) << " (" << data->type << ")" << std::endl;
break;
}

View File

@ -24,7 +24,7 @@ void CNShardServer::handlePacket(CNSocket* sock, CNPacketData* data) {
if (ShardPackets.find(data->type) != ShardPackets.end())
ShardPackets[data->type](sock, data);
else if (settings::VERBOSITY)
else if (settings::VERBOSITY > 0)
std::cerr << "OpenFusion: SHARD UNIMPLM ERR. PacketType: " << Defines::p2str(CL2FE, data->type) << " (" << data->type << ")" << std::endl;
}

View File

@ -23,12 +23,12 @@ void Database::open() {
file.close();
// if exists, assign it
db = sqlite3pp::database("data.db");
DEBUGLOG(std::cout << "[DB] Database in operation" << std::endl; )
DEBUGLOG(std::cout << "[DB] Database in operation" << std::endl;)
}
else {
// if doesn't, create all the tables
DEBUGLOG(std::cout << "[DB] Creating new database" << std::endl;)
db = sqlite3pp::database("data.db");
db = sqlite3pp::database("data.db");
// creates accounts
db.execute("CREATE TABLE Accounts(AccountID INTEGER PRIMARY KEY AUTOINCREMENT, Login TEXT NOT NULL, Password TEXT NOT NULL);");