mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +00:00
The login server now sends live checks.
This should stop server providers from kicking tutorial players as inactive TCP connections. The interval is generous for that reason. Also snuck in a change that makes mobs retreat all the way to their spawn points, to aid during mob gruntwork with /toggleai.
This commit is contained in:
parent
1fe23b97fd
commit
bae834fefa
@ -55,6 +55,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
loginSessions[sock] = CNLoginData();
|
loginSessions[sock] = CNLoginData();
|
||||||
loginSessions[sock].userID = Database::addAccount(userLogin, userPassword);
|
loginSessions[sock].userID = Database::addAccount(userLogin, userPassword);
|
||||||
loginSessions[sock].slot = 1;
|
loginSessions[sock].slot = 1;
|
||||||
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
// if user exists, check if password is correct
|
// if user exists, check if password is correct
|
||||||
@ -72,6 +73,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
loginSessions[sock] = CNLoginData();
|
loginSessions[sock] = CNLoginData();
|
||||||
loginSessions[sock].userID = findUser->AccountID;
|
loginSessions[sock].userID = findUser->AccountID;
|
||||||
loginSessions[sock].slot = findUser->Selected;
|
loginSessions[sock].slot = findUser->Selected;
|
||||||
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +145,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case P_CL2LS_REP_LIVE_CHECK: {
|
case P_CL2LS_REP_LIVE_CHECK: {
|
||||||
// stubbed, the client really doesn't care LOL
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case P_CL2LS_REQ_CHECK_CHAR_NAME: {
|
case P_CL2LS_REQ_CHECK_CHAR_NAME: {
|
||||||
@ -163,6 +165,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
errorcode = 1;
|
errorcode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
INITSTRUCT(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC, resp);
|
INITSTRUCT(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC, resp);
|
||||||
|
|
||||||
@ -201,6 +205,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
memcpy(resp.szFirstName, save->szFirstName, sizeof(char16_t) * 9);
|
memcpy(resp.szFirstName, save->szFirstName, sizeof(char16_t) * 9);
|
||||||
memcpy(resp.szLastName, save->szLastName, sizeof(char16_t) * 17);
|
memcpy(resp.szLastName, save->szLastName, sizeof(char16_t) * 17);
|
||||||
|
|
||||||
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_SAVE_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC));
|
sock->sendPacket((void*)&resp, P_LS2CL_REP_SAVE_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC));
|
||||||
|
|
||||||
Database::updateSelected(loginSessions[sock].userID, save->iSlotNum);
|
Database::updateSelected(loginSessions[sock].userID, save->iSlotNum);
|
||||||
@ -245,6 +251,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
loginSessions[sock].characters[UID] = Player(player);
|
loginSessions[sock].characters[UID] = Player(player);
|
||||||
loginSessions[sock].characters[UID].FEKey = sock->getFEKey();
|
loginSessions[sock].characters[UID].FEKey = sock->getFEKey();
|
||||||
|
|
||||||
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC));
|
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC));
|
||||||
Database::updateSelected(loginSessions[sock].userID, player.slot);
|
Database::updateSelected(loginSessions[sock].userID, player.slot);
|
||||||
break;
|
break;
|
||||||
@ -259,7 +267,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
INITSTRUCT(sP_LS2CL_REP_CHAR_DELETE_SUCC, resp);
|
INITSTRUCT(sP_LS2CL_REP_CHAR_DELETE_SUCC, resp);
|
||||||
resp.iSlotNum = operationResult;
|
resp.iSlotNum = operationResult;
|
||||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_DELETE_SUCC, sizeof(sP_LS2CL_REP_CHAR_DELETE_SUCC));
|
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_DELETE_SUCC, sizeof(sP_LS2CL_REP_CHAR_DELETE_SUCC));
|
||||||
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case P_CL2LS_REQ_CHAR_SELECT: {
|
case P_CL2LS_REQ_CHAR_SELECT: {
|
||||||
@ -274,6 +282,9 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
std::cout << "P_CL2LS_REQ_CHAR_SELECT:" << std::endl;
|
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].lastHeartbeat = getTime();
|
||||||
|
|
||||||
loginSessions[sock].selectedChar = chararacter->iPC_UID;
|
loginSessions[sock].selectedChar = chararacter->iPC_UID;
|
||||||
Database::updateSelected(loginSessions[sock].userID, loginSessions[sock].characters[chararacter->iPC_UID].slot);
|
Database::updateSelected(loginSessions[sock].userID, loginSessions[sock].characters[chararacter->iPC_UID].slot);
|
||||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_SELECT_SUCC, sizeof(sP_LS2CL_REP_CHAR_SELECT_SUCC));
|
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_SELECT_SUCC, sizeof(sP_LS2CL_REP_CHAR_SELECT_SUCC));
|
||||||
@ -315,6 +326,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
auto key = loginSessions[sock].characters[save->iPC_UID].FEKey;
|
auto key = loginSessions[sock].characters[save->iPC_UID].FEKey;
|
||||||
loginSessions[sock].characters[save->iPC_UID] = Player(Database::getPlayer(save->iPC_UID));
|
loginSessions[sock].characters[save->iPC_UID] = Player(Database::getPlayer(save->iPC_UID));
|
||||||
loginSessions[sock].characters[save->iPC_UID].FEKey = key;
|
loginSessions[sock].characters[save->iPC_UID].FEKey = key;
|
||||||
|
|
||||||
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
// no response here
|
// no response here
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -331,6 +344,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
memcpy(resp.szLastName, save->szLastName, sizeof(char16_t) * 17);
|
memcpy(resp.szLastName, save->szLastName, sizeof(char16_t) * 17);
|
||||||
resp.iSlotNum = save->iSlotNum;
|
resp.iSlotNum = save->iSlotNum;
|
||||||
|
|
||||||
|
loginSessions[sock].lastHeartbeat = getTime();
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHANGE_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_CHANGE_CHAR_NAME_SUCC));
|
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHANGE_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_CHANGE_CHAR_NAME_SUCC));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -370,6 +385,25 @@ void CNLoginServer::killConnection(CNSocket* cns) {
|
|||||||
loginSessions.erase(cns);
|
loginSessions.erase(cns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CNLoginServer::onStep() {
|
||||||
|
time_t currTime = getTime();
|
||||||
|
static time_t lastCheck = 0;
|
||||||
|
|
||||||
|
if (currTime - lastCheck < 16000)
|
||||||
|
return;
|
||||||
|
lastCheck = currTime;
|
||||||
|
|
||||||
|
for (auto& pair : loginSessions) {
|
||||||
|
if (pair.second.lastHeartbeat != 0 && currTime - pair.second.lastHeartbeat > 32000) {
|
||||||
|
pair.first->kill();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
INITSTRUCT(sP_LS2CL_REQ_LIVE_CHECK, pkt);
|
||||||
|
pair.first->sendPacket((void*)&pkt, P_LS2CL_REQ_LIVE_CHECK, sizeof(sP_LS2CL_REQ_LIVE_CHECK));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma region helperMethods
|
#pragma region helperMethods
|
||||||
bool CNLoginServer::isAccountInUse(int accountId) {
|
bool CNLoginServer::isAccountInUse(int accountId) {
|
||||||
std::map<CNSocket*, CNLoginData>::iterator it;
|
std::map<CNSocket*, CNLoginData>::iterator it;
|
||||||
|
@ -10,6 +10,7 @@ struct CNLoginData {
|
|||||||
std::map<int64_t, Player> characters;
|
std::map<int64_t, Player> characters;
|
||||||
int64_t selectedChar;
|
int64_t selectedChar;
|
||||||
int userID; int slot;
|
int userID; int slot;
|
||||||
|
time_t lastHeartbeat;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class LoginError {
|
enum class LoginError {
|
||||||
@ -41,4 +42,5 @@ public:
|
|||||||
|
|
||||||
void newConnection(CNSocket* cns);
|
void newConnection(CNSocket* cns);
|
||||||
void killConnection(CNSocket* cns);
|
void killConnection(CNSocket* cns);
|
||||||
|
void onStep();
|
||||||
};
|
};
|
||||||
|
@ -419,7 +419,8 @@ void MobManager::retreatStep(Mob *mob, time_t currTime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we got there
|
// if we got there
|
||||||
if (distance <= mob->data["m_iIdleRange"]) {
|
//if (distance <= mob->data["m_iIdleRange"]) {
|
||||||
|
if (distance <= 10) { // retreat back to the spawn point
|
||||||
mob->state = MobState::ROAMING;
|
mob->state = MobState::ROAMING;
|
||||||
mob->appearanceData.iHP = mob->maxHealth;
|
mob->appearanceData.iHP = mob->maxHealth;
|
||||||
mob->killedTime = 0;
|
mob->killedTime = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user