mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +00:00
moved name checks to name save and name change packets
added a TODO Formatting + sizeof in login server
This commit is contained in:
parent
d85d9d4b12
commit
ea5b7104be
@ -201,12 +201,31 @@ void CNLoginServer::nameCheck(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2LS_REQ_CHECK_CHAR_NAME))
|
||||
return;
|
||||
|
||||
// responding to this packet only makes the client send the next packet (either name save or name change)
|
||||
// so we're always sending SUCC here and actually validating the name when the next packet arrives
|
||||
|
||||
sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck = (sP_CL2LS_REQ_CHECK_CHAR_NAME*)data->buf;
|
||||
|
||||
INITSTRUCT(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC, resp);
|
||||
memcpy(resp.szFirstName, nameCheck->szFirstName, sizeof(resp.szFirstName));
|
||||
memcpy(resp.szLastName, nameCheck->szLastName, sizeof(resp.szLastName));
|
||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHECK_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC));
|
||||
|
||||
loginSessions[sock].lastHeartbeat = getTime();
|
||||
}
|
||||
|
||||
void CNLoginServer::nameSave(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2LS_REQ_SAVE_CHAR_NAME))
|
||||
return;
|
||||
|
||||
sP_CL2LS_REQ_SAVE_CHAR_NAME* save = (sP_CL2LS_REQ_SAVE_CHAR_NAME*)data->buf;
|
||||
INITSTRUCT(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC, resp);
|
||||
|
||||
int errorCode = 0;
|
||||
if (!CNLoginServer::isCharacterNameGood(U16toU8(nameCheck->szFirstName), U16toU8(nameCheck->szLastName))) {
|
||||
if (!CNLoginServer::isCharacterNameGood(U16toU8(save->szFirstName), U16toU8(save->szLastName))) {
|
||||
errorCode = 4;
|
||||
}
|
||||
else if (!Database::isNameFree(nameCheck)) {
|
||||
else if (!Database::isNameFree(U16toU8(save->szFirstName), U16toU8(save->szLastName))) {
|
||||
errorCode = 1;
|
||||
}
|
||||
|
||||
@ -221,32 +240,12 @@ void CNLoginServer::nameCheck(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
return;
|
||||
}
|
||||
loginSessions[sock].lastHeartbeat = getTime();
|
||||
|
||||
INITSTRUCT(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC, resp);
|
||||
memcpy(resp.szFirstName, nameCheck->szFirstName, sizeof(nameCheck->szFirstName));
|
||||
memcpy(resp.szLastName, nameCheck->szLastName, sizeof(nameCheck->szLastName));
|
||||
|
||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHECK_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC));
|
||||
|
||||
DEBUGLOG(
|
||||
std::cout << "Login Server: name check success" << std::endl;
|
||||
std::cout << "\tFirstName: " << U16toU8(nameCheck->szFirstName) << " LastName: " << U16toU8(nameCheck->szLastName) << std::endl;
|
||||
)
|
||||
}
|
||||
|
||||
void CNLoginServer::nameSave(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2LS_REQ_SAVE_CHAR_NAME))
|
||||
return;
|
||||
|
||||
sP_CL2LS_REQ_SAVE_CHAR_NAME* save = (sP_CL2LS_REQ_SAVE_CHAR_NAME*)data->buf;
|
||||
INITSTRUCT(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC, resp);
|
||||
|
||||
resp.iSlotNum = save->iSlotNum;
|
||||
resp.iGender = save->iGender;
|
||||
resp.iPC_UID = Database::createCharacter(save, loginSessions[sock].userID);
|
||||
memcpy(resp.szFirstName, save->szFirstName, sizeof(save->szFirstName));
|
||||
memcpy(resp.szLastName, save->szLastName, sizeof(save->szLastName));
|
||||
memcpy(resp.szFirstName, save->szFirstName, sizeof(resp.szFirstName));
|
||||
memcpy(resp.szLastName, save->szLastName, sizeof(resp.szLastName));
|
||||
|
||||
loginSessions[sock].lastHeartbeat = getTime();
|
||||
|
||||
@ -432,12 +431,32 @@ void CNLoginServer::changeName(CNSocket* sock, CNPacketData* data) {
|
||||
if (!Database::validateCharacter(save->iPCUID, loginSessions[sock].userID))
|
||||
return invalidCharacter(sock);
|
||||
|
||||
int errorCode = 0;
|
||||
if (!CNLoginServer::isCharacterNameGood(U16toU8(save->szFirstName), U16toU8(save->szLastName))) {
|
||||
errorCode = 4;
|
||||
}
|
||||
else if (!Database::isNameFree(U16toU8(save->szFirstName), U16toU8(save->szLastName))) {
|
||||
errorCode = 1;
|
||||
}
|
||||
|
||||
if (errorCode != 0) {
|
||||
INITSTRUCT(sP_LS2CL_REP_CHECK_CHAR_NAME_FAIL, resp);
|
||||
resp.iErrorCode = errorCode;
|
||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHECK_CHAR_NAME_FAIL, sizeof(sP_LS2CL_REP_CHECK_CHAR_NAME_FAIL));
|
||||
|
||||
DEBUGLOG(
|
||||
std::cout << "Login Server: name check fail. Error code " << errorCode << std::endl;
|
||||
)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Database::changeName(save);
|
||||
|
||||
INITSTRUCT(sP_LS2CL_REP_CHANGE_CHAR_NAME_SUCC, resp);
|
||||
resp.iPC_UID = save->iPCUID;
|
||||
memcpy(resp.szFirstName, save->szFirstName, sizeof(save->szFirstName));
|
||||
memcpy(resp.szLastName, save->szLastName, sizeof(save->szLastName));
|
||||
memcpy(resp.szFirstName, save->szFirstName, sizeof(resp.szFirstName));
|
||||
memcpy(resp.szLastName, save->szLastName, sizeof(resp.szLastName));
|
||||
resp.iSlotNum = save->iSlotNum;
|
||||
|
||||
loginSessions[sock].lastHeartbeat = getTime();
|
||||
@ -454,6 +473,8 @@ void CNLoginServer::duplicateExit(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2LS_REQ_PC_EXIT_DUPLICATE))
|
||||
return;
|
||||
|
||||
// TODO: FIX THIS PACKET
|
||||
|
||||
sP_CL2LS_REQ_PC_EXIT_DUPLICATE* exit = (sP_CL2LS_REQ_PC_EXIT_DUPLICATE*)data->buf;
|
||||
auto account = Database::findAccount(U16toU8(exit->szID));
|
||||
|
||||
|
@ -198,15 +198,13 @@ bool Database::validateCharacter(int characterID, int userID) {
|
||||
.size() > 0;
|
||||
}
|
||||
|
||||
bool Database::isNameFree(sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck) {
|
||||
bool Database::isNameFree(std::string firstName, std::string lastName) {
|
||||
std::lock_guard<std::mutex> lock(dbCrit);
|
||||
|
||||
std::string First = U16toU8(nameCheck->szFirstName);
|
||||
std::string Last = U16toU8(nameCheck->szLastName);
|
||||
return
|
||||
(db.get_all<DbPlayer>
|
||||
(where((c(&DbPlayer::FirstName) == First)
|
||||
and (c(&DbPlayer::LastName) == Last)))
|
||||
(where((c(&DbPlayer::FirstName) == firstName)
|
||||
and (c(&DbPlayer::LastName) == lastName)))
|
||||
.empty());
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ namespace Database {
|
||||
void updateSelected(int accountId, int playerId);
|
||||
std::unique_ptr<Account> findAccount(std::string login);
|
||||
bool validateCharacter(int characterID, int userID);
|
||||
bool isNameFree(sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck);
|
||||
bool isNameFree(std::string firstName, std::string lastName);
|
||||
// called after chosing name, returns ID
|
||||
int createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID);
|
||||
// called after finishing creation
|
||||
|
Loading…
Reference in New Issue
Block a user