Make name checking case insensitive.

Co-authored-by: kamilprzyb <kamilprzybspam@wp.pl>
This commit is contained in:
darkredtitan 2020-09-09 14:36:35 +02:00 committed by dongresource
parent 3d83f93167
commit 480cca82fa
3 changed files with 28 additions and 12 deletions

View File

@ -131,7 +131,6 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
//Equip info
for (int i = 0; i < AEQUIP_COUNT; i++) {
//equip char creation clothes and lightning rifle
charInfo.aEquip[i] = it->Equip[i];
}
@ -162,13 +161,22 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2LS_REQ_CHECK_CHAR_NAME))
return;
// naughty words allowed!!!!!!!! (also for some reason, the client will always show 'Player 0' if you manually type a name. It will show up for other connected players though)
sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck = (sP_CL2LS_REQ_CHECK_CHAR_NAME*)data->buf;
//check if name is occupied
if (Database::isNameFree(nameCheck))
{
// naughty words allowed!!!!!!!! (also for some reason, the client will always show 'Player + ID' if you manually type a name. It will show up for other connected players though)
bool success = true;
int errorcode = 0;
//check regex
if (!CNLoginServer::isCharacterNameGood(U16toU8(nameCheck->szFirstName), U16toU8(nameCheck->szLastName))) {
success = false;
errorcode = 4;
}
//check if name isn't already occupied
else if (!Database::isNameFree(nameCheck)){
success = false;
errorcode = 1;
}
if (success){
INITSTRUCT(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC, resp);
DEBUGLOG(
@ -178,17 +186,15 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
memcpy(resp.szFirstName, nameCheck->szFirstName, sizeof(char16_t) * 9);
memcpy(resp.szLastName, nameCheck->szLastName, sizeof(char16_t) * 17);
// fr*ck allowed!!!
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHECK_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC));
}
else {
INITSTRUCT(sP_LS2CL_REP_CHECK_CHAR_NAME_FAIL, resp);
resp.iErrorCode = 1;
resp.iErrorCode = errorcode;
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHECK_CHAR_NAME_FAIL, sizeof(sP_LS2CL_REP_CHECK_CHAR_NAME_FAIL));
}
break;
}
case P_CL2LS_REQ_SAVE_CHAR_NAME: {
if (data->size != sizeof(sP_CL2LS_REQ_SAVE_CHAR_NAME))
@ -411,4 +417,10 @@ bool CNLoginServer::isPasswordCorrect(std::string actualPassword, std::string tr
{
return BCrypt::validatePassword(tryPassword, actualPassword);
}
bool CNLoginServer::isCharacterNameGood(std::string Firstname, std::string Lastname)
{
std::regex firstnamecheck("[a-zA-Z0-9]+(?: [a-zA-Z0-9]+)*$");
std::regex lastnamecheck("[a-zA-Z0-9]+(?: [a-zA-Z0-9]+)*$");
return (std::regex_match(Firstname, firstnamecheck) && std::regex_match(Lastname, lastnamecheck));
}
#pragma endregion helperMethods

View File

@ -33,6 +33,7 @@ private:
static bool isLoginDataGood(std::string login, std::string password);
static bool isPasswordCorrect(std::string actualPassword, std::string tryPassword);
static bool isAccountInUse(int accountId);
static bool isCharacterNameGood(std::string Firstname, std::string Lastname);
//returns true if success
static bool exitDuplicate(int accountId);
public:

View File

@ -23,8 +23,8 @@ auto db = make_storage("database.db",
make_column("PlayerID", &Database::DbPlayer::PlayerID, autoincrement(), primary_key()),
make_column("AccountID", &Database::DbPlayer::AccountID),
make_column("Slot", &Database::DbPlayer::slot),
make_column("Firstname", &Database::DbPlayer::FirstName),
make_column("LastName", &Database::DbPlayer::LastName),
make_column("Firstname", &Database::DbPlayer::FirstName, collate_nocase()),
make_column("LastName", &Database::DbPlayer::LastName, collate_nocase()),
make_column("Level", &Database::DbPlayer::Level),
make_column("Nano1", &Database::DbPlayer::Nano1),
make_column("Nano2", &Database::DbPlayer::Nano2),
@ -361,6 +361,8 @@ Player Database::getPlayer(int id) {
#pragma endregion LoginServer
#pragma region ShardServer
void Database::updatePlayer(Player player) {
DbPlayer toUpdate = playerToDb(player);
db.update(toUpdate);
@ -459,3 +461,4 @@ void Database::getNanos(Player* player) {
toSet->iStamina = current.iStamina;
}
}
#pragma endregion ShardServer