mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-05 06:50:04 +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))
|
if (data->size != sizeof(sP_CL2LS_REQ_CHECK_CHAR_NAME))
|
||||||
return;
|
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;
|
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;
|
int errorCode = 0;
|
||||||
if (!CNLoginServer::isCharacterNameGood(U16toU8(nameCheck->szFirstName), U16toU8(nameCheck->szLastName))) {
|
if (!CNLoginServer::isCharacterNameGood(U16toU8(save->szFirstName), U16toU8(save->szLastName))) {
|
||||||
errorCode = 4;
|
errorCode = 4;
|
||||||
}
|
}
|
||||||
else if (!Database::isNameFree(nameCheck)) {
|
else if (!Database::isNameFree(U16toU8(save->szFirstName), U16toU8(save->szLastName))) {
|
||||||
errorCode = 1;
|
errorCode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,32 +240,12 @@ void CNLoginServer::nameCheck(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
return;
|
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.iSlotNum = save->iSlotNum;
|
||||||
resp.iGender = save->iGender;
|
resp.iGender = save->iGender;
|
||||||
resp.iPC_UID = Database::createCharacter(save, loginSessions[sock].userID);
|
resp.iPC_UID = Database::createCharacter(save, loginSessions[sock].userID);
|
||||||
memcpy(resp.szFirstName, save->szFirstName, sizeof(save->szFirstName));
|
memcpy(resp.szFirstName, save->szFirstName, sizeof(resp.szFirstName));
|
||||||
memcpy(resp.szLastName, save->szLastName, sizeof(save->szLastName));
|
memcpy(resp.szLastName, save->szLastName, sizeof(resp.szLastName));
|
||||||
|
|
||||||
loginSessions[sock].lastHeartbeat = getTime();
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
|
|
||||||
@ -313,7 +312,7 @@ void CNLoginServer::characterCreate(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
sP_CL2LS_REQ_CHAR_CREATE* character = (sP_CL2LS_REQ_CHAR_CREATE*)data->buf;
|
sP_CL2LS_REQ_CHAR_CREATE* character = (sP_CL2LS_REQ_CHAR_CREATE*)data->buf;
|
||||||
|
|
||||||
if (! (Database::validateCharacter(character->PCStyle.iPC_UID, loginSessions[sock].userID) && validateCharacterCreation(character)))
|
if (!(Database::validateCharacter(character->PCStyle.iPC_UID, loginSessions[sock].userID) && validateCharacterCreation(character)))
|
||||||
return invalidCharacter(sock);
|
return invalidCharacter(sock);
|
||||||
|
|
||||||
Database::finishCharacter(character);
|
Database::finishCharacter(character);
|
||||||
@ -432,12 +431,32 @@ void CNLoginServer::changeName(CNSocket* sock, CNPacketData* data) {
|
|||||||
if (!Database::validateCharacter(save->iPCUID, loginSessions[sock].userID))
|
if (!Database::validateCharacter(save->iPCUID, loginSessions[sock].userID))
|
||||||
return invalidCharacter(sock);
|
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);
|
Database::changeName(save);
|
||||||
|
|
||||||
INITSTRUCT(sP_LS2CL_REP_CHANGE_CHAR_NAME_SUCC, resp);
|
INITSTRUCT(sP_LS2CL_REP_CHANGE_CHAR_NAME_SUCC, resp);
|
||||||
resp.iPC_UID = save->iPCUID;
|
resp.iPC_UID = save->iPCUID;
|
||||||
memcpy(resp.szFirstName, save->szFirstName, sizeof(save->szFirstName));
|
memcpy(resp.szFirstName, save->szFirstName, sizeof(resp.szFirstName));
|
||||||
memcpy(resp.szLastName, save->szLastName, sizeof(save->szLastName));
|
memcpy(resp.szLastName, save->szLastName, sizeof(resp.szLastName));
|
||||||
resp.iSlotNum = save->iSlotNum;
|
resp.iSlotNum = save->iSlotNum;
|
||||||
|
|
||||||
loginSessions[sock].lastHeartbeat = getTime();
|
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))
|
if (data->size != sizeof(sP_CL2LS_REQ_PC_EXIT_DUPLICATE))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// TODO: FIX THIS PACKET
|
||||||
|
|
||||||
sP_CL2LS_REQ_PC_EXIT_DUPLICATE* exit = (sP_CL2LS_REQ_PC_EXIT_DUPLICATE*)data->buf;
|
sP_CL2LS_REQ_PC_EXIT_DUPLICATE* exit = (sP_CL2LS_REQ_PC_EXIT_DUPLICATE*)data->buf;
|
||||||
auto account = Database::findAccount(U16toU8(exit->szID));
|
auto account = Database::findAccount(U16toU8(exit->szID));
|
||||||
|
|
||||||
|
@ -198,15 +198,13 @@ bool Database::validateCharacter(int characterID, int userID) {
|
|||||||
.size() > 0;
|
.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::lock_guard<std::mutex> lock(dbCrit);
|
||||||
|
|
||||||
std::string First = U16toU8(nameCheck->szFirstName);
|
|
||||||
std::string Last = U16toU8(nameCheck->szLastName);
|
|
||||||
return
|
return
|
||||||
(db.get_all<DbPlayer>
|
(db.get_all<DbPlayer>
|
||||||
(where((c(&DbPlayer::FirstName) == First)
|
(where((c(&DbPlayer::FirstName) == firstName)
|
||||||
and (c(&DbPlayer::LastName) == Last)))
|
and (c(&DbPlayer::LastName) == lastName)))
|
||||||
.empty());
|
.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ namespace Database {
|
|||||||
void updateSelected(int accountId, int playerId);
|
void updateSelected(int accountId, int playerId);
|
||||||
std::unique_ptr<Account> findAccount(std::string login);
|
std::unique_ptr<Account> findAccount(std::string login);
|
||||||
bool validateCharacter(int characterID, int userID);
|
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
|
// called after chosing name, returns ID
|
||||||
int createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID);
|
int createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID);
|
||||||
// called after finishing creation
|
// called after finishing creation
|
||||||
|
Loading…
Reference in New Issue
Block a user