Sanity checks for creating and deleting characters.

Co-authored-by: kamilprzyb <kamilprzybspam@wp.pl>
This commit is contained in:
darkredtitan 2020-09-13 22:29:30 +02:00 committed by dongresource
parent c7189a5cef
commit 38d5998a6e
3 changed files with 43 additions and 38 deletions

View File

@ -268,7 +268,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
return; return;
sP_CL2LS_REQ_CHAR_DELETE* del = (sP_CL2LS_REQ_CHAR_DELETE*)data->buf; sP_CL2LS_REQ_CHAR_DELETE* del = (sP_CL2LS_REQ_CHAR_DELETE*)data->buf;
int operationResult = Database::deleteCharacter(del->iPC_UID); int operationResult = Database::deleteCharacter(del->iPC_UID, loginSessions[sock].userID);
INITSTRUCT(sP_LS2CL_REP_CHAR_DELETE_SUCC, resp); INITSTRUCT(sP_LS2CL_REP_CHAR_DELETE_SUCC, resp);
resp.iSlotNum = operationResult; resp.iSlotNum = operationResult;

View File

@ -125,40 +125,45 @@ bool Database::isNameFree(sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck)
int Database::createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID) int Database::createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID)
{ {
DbPlayer create = {}; if (db.count<DbPlayer>(where(c(&DbPlayer::AccountID) == AccountID))<4) {
//save packet data DbPlayer create = {};
create.FirstName = U16toU8(save->szFirstName); //save packet data
create.LastName = U16toU8(save->szLastName); create.FirstName = U16toU8(save->szFirstName);
create.slot = save->iSlotNum; create.LastName = U16toU8(save->szLastName);
create.AccountID = AccountID; create.slot = save->iSlotNum;
//set flags create.AccountID = AccountID;
create.AppearanceFlag = 0; //set flags
create.TutorialFlag = 0; create.AppearanceFlag = 0;
create.PayZoneFlag = 0; create.TutorialFlag = 0;
//set namecheck based on setting create.PayZoneFlag = 0;
if (settings::APPROVEALLNAMES || save->iFNCode) //set namecheck based on setting
create.NameCheck = 1; if (settings::APPROVEALLNAMES || save->iFNCode)
else create.NameCheck = 1;
create.NameCheck = 0; else
//create default body character create.NameCheck = 0;
create.Body= 0; //create default body character
create.Class= 0; create.Body = 0;
create.EyeColor= 1; create.Class = 0;
create.FaceStyle= 1; create.EyeColor = 1;
create.Gender= 1; create.FaceStyle = 1;
create.HP= 1000; create.Gender = 1;
create.HairColor= 1; create.HP = 1000;
create.HairStyle = 1; create.HairColor = 1;
create.Height= 0; create.HairStyle = 1;
create.Level= 1; create.Height = 0;
create.SkinColor= 1; create.Level = 1;
create.isGM = settings::GM; create.SkinColor = 1;
create.x_coordinates = settings::SPAWN_X; create.isGM = false;
create.y_coordinates= settings::SPAWN_Y; create.x_coordinates = settings::SPAWN_X;
create.z_coordinates= settings::SPAWN_Z; create.y_coordinates = settings::SPAWN_Y;
create.angle = settings::SPAWN_ANGLE; create.z_coordinates = settings::SPAWN_Z;
create.QuestFlag = std::vector<char>(); create.angle = settings::SPAWN_ANGLE;
return db.insert(create); create.QuestFlag = std::vector<char>();
return db.insert(create);
}
else {
return -1;
}
} }
void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character) void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character)
@ -229,10 +234,10 @@ void Database::finishTutorial(int PlayerID)
db.update(playerToDb(finish)); db.update(playerToDb(finish));
} }
int Database::deleteCharacter(int characterID) int Database::deleteCharacter(int characterID, int userID)
{ {
auto find = auto find =
db.get_all<DbPlayer>(where(c(&DbPlayer::PlayerID) == characterID)); db.get_all<DbPlayer>(where(c(&DbPlayer::PlayerID) == characterID and c(&DbPlayer::AccountID)==userID));
int slot = find.front().slot; int slot = find.front().slot;
db.remove<DbPlayer>(find.front().PlayerID); db.remove<DbPlayer>(find.front().PlayerID);
db.remove_all<Inventory>(where(c(&Inventory::playerId) == characterID)); db.remove_all<Inventory>(where(c(&Inventory::playerId) == characterID));

View File

@ -83,7 +83,7 @@ namespace Database {
//called after tutorial //called after tutorial
void finishTutorial(int PlayerID); void finishTutorial(int PlayerID);
//returns slot number //returns slot number
int deleteCharacter(int characterID); int deleteCharacter(int characterID, int userID);
std::vector <Player> getCharacters(int userID); std::vector <Player> getCharacters(int userID);
//accepting/declining custom name //accepting/declining custom name
enum class CUSTOMNAME { enum class CUSTOMNAME {