mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2025-09-30 11:40:06 +00:00
fixed pc exit duplicate
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
#include "settings.hpp"
|
||||
|
||||
std::map<CNSocket*, CNLoginData> CNLoginServer::loginSessions;
|
||||
/// account Id -> sock
|
||||
std::map<int32_t, CNSocket*> CNLoginServer::shardSessions;
|
||||
std::mutex lsCrit;
|
||||
|
||||
CNLoginServer::CNLoginServer(uint16_t p) {
|
||||
port = p;
|
||||
@@ -510,8 +513,6 @@ 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;
|
||||
Database::Account account = {};
|
||||
Database::findAccount(&account, U16toU8(exit->szID));
|
||||
@@ -561,27 +562,34 @@ void CNLoginServer::onStep() {
|
||||
|
||||
#pragma region helperMethods
|
||||
bool CNLoginServer::isAccountInUse(int accountId) {
|
||||
std::map<CNSocket*, CNLoginData>::iterator it;
|
||||
for (it = CNLoginServer::loginSessions.begin(); it != CNLoginServer::loginSessions.end(); it++) {
|
||||
// check login server connections
|
||||
for (std::map<CNSocket*, CNLoginData>::iterator it = CNLoginServer::loginSessions.begin(); it != CNLoginServer::loginSessions.end(); it++) {
|
||||
if (it->second.userID == accountId)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// check shard server connections
|
||||
std::lock_guard<std::mutex> lock(lsCrit);
|
||||
return (shardSessions.find(accountId) != shardSessions.end());
|
||||
}
|
||||
|
||||
bool CNLoginServer::exitDuplicate(int accountId) {
|
||||
void CNLoginServer::exitDuplicate(int accountId) {
|
||||
// login server
|
||||
std::map<CNSocket*, CNLoginData>::iterator it;
|
||||
for (it = CNLoginServer::loginSessions.begin(); it != CNLoginServer::loginSessions.end(); it++) {
|
||||
if (it->second.userID == accountId) {
|
||||
CNSocket* sock = it->first;
|
||||
INITSTRUCT(sP_LS2CL_REP_PC_EXIT_DUPLICATE, resp);
|
||||
resp.iErrorCode = 0;
|
||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_PC_EXIT_DUPLICATE, sizeof(sP_LS2CL_REP_PC_EXIT_DUPLICATE));
|
||||
sock->kill();
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
// shard server
|
||||
std::lock_guard<std::mutex> lock(lsCrit);
|
||||
if (shardSessions.find(accountId) == shardSessions.end())
|
||||
return;
|
||||
CNSocket* sock = shardSessions[accountId];
|
||||
PlayerManager::exitDuplicate(sock);
|
||||
}
|
||||
|
||||
bool CNLoginServer::isLoginDataGood(std::string login, std::string password) {
|
||||
@@ -601,4 +609,15 @@ bool CNLoginServer::isCharacterNameGood(std::string Firstname, std::string Lastn
|
||||
std::regex lastnamecheck(R"(((?! )(?!\.)[a-zA-Z0-9]*\.{0,1}(?!\.+ +)[a-zA-Z0-9]* {0,1}(?! +))*$)");
|
||||
return (std::regex_match(Firstname, firstnamecheck) && std::regex_match(Lastname, lastnamecheck));
|
||||
}
|
||||
|
||||
void CNLoginServer::addShardConnection(int32_t id, CNSocket* sock) {
|
||||
std::lock_guard<std::mutex> lock(lsCrit);
|
||||
shardSessions[id] = sock;
|
||||
}
|
||||
|
||||
void CNLoginServer::removeShardConnection(int32_t id) {
|
||||
std::lock_guard<std::mutex> lock(lsCrit);
|
||||
shardSessions.erase(id);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
@@ -28,6 +28,7 @@ class CNLoginServer : public CNServer {
|
||||
private:
|
||||
static void handlePacket(CNSocket* sock, CNPacketData* data);
|
||||
static std::map<CNSocket*, CNLoginData> loginSessions;
|
||||
static std::map<int32_t, CNSocket*> shardSessions;
|
||||
|
||||
static void login(CNSocket* sock, CNPacketData* data);
|
||||
static void nameCheck(CNSocket* sock, CNPacketData* data);
|
||||
@@ -44,12 +45,14 @@ private:
|
||||
static bool isAccountInUse(int accountId);
|
||||
static bool isCharacterNameGood(std::string Firstname, std::string Lastname);
|
||||
static void newAccount(CNSocket* sock, std::string userLogin, std::string userPassword, int32_t clientVerC);
|
||||
// returns true if success
|
||||
static bool exitDuplicate(int accountId);
|
||||
static void exitDuplicate(int accountId);
|
||||
public:
|
||||
CNLoginServer(uint16_t p);
|
||||
|
||||
void newConnection(CNSocket* cns);
|
||||
void killConnection(CNSocket* cns);
|
||||
void onStep();
|
||||
// shard sessions logic
|
||||
static void addShardConnection(int32_t id, CNSocket* sock);
|
||||
static void removeShardConnection(int32_t id);
|
||||
};
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include "CNProtocol.hpp"
|
||||
#include "PlayerManager.hpp"
|
||||
#include "NPCManager.hpp"
|
||||
#include "CNLoginServer.hpp"
|
||||
#include "CNShardServer.hpp"
|
||||
#include "CNShared.hpp"
|
||||
#include "MissionManager.hpp"
|
||||
@@ -58,6 +59,9 @@ void PlayerManager::addPlayer(CNSocket* key, Player plr) {
|
||||
p->viewableChunks = new std::set<Chunk*>();
|
||||
p->lastHeartbeat = 0;
|
||||
|
||||
|
||||
CNLoginServer::addShardConnection(plr.accountId, key);
|
||||
|
||||
std::cout << getPlayerName(p) << " has joined!" << std::endl;
|
||||
std::cout << players.size() << " players" << std::endl;
|
||||
}
|
||||
@@ -66,6 +70,8 @@ void PlayerManager::removePlayer(CNSocket* key) {
|
||||
Player* plr = getPlayer(key);
|
||||
uint64_t fromInstance = plr->instanceID;
|
||||
|
||||
CNLoginServer::removeShardConnection(plr->accountId);
|
||||
|
||||
GroupManager::groupKickPlayer(plr);
|
||||
|
||||
// remove player's bullets
|
||||
@@ -184,12 +190,6 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
|
||||
std::cout << "\tPC_UID: " << plr.PCStyle.iPC_UID << std::endl;
|
||||
)
|
||||
|
||||
// check if account is already in use
|
||||
if (isAccountInUse(plr.accountId)) {
|
||||
// kick the other player
|
||||
exitDuplicate(plr.accountId);
|
||||
}
|
||||
|
||||
response.iID = plr.iID;
|
||||
response.uiSvrTime = getTime();
|
||||
response.PCLoadData2CL.iUserLevel = plr.accountLevel;
|
||||
@@ -943,23 +943,12 @@ bool PlayerManager::isAccountInUse(int accountId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void PlayerManager::exitDuplicate(int accountId) {
|
||||
void PlayerManager::exitDuplicate(CNSocket* sock) {
|
||||
std::map<CNSocket*, Player*>::iterator it;
|
||||
|
||||
// disconnect any duplicate players
|
||||
for (it = players.begin(); it != players.end(); it++) {
|
||||
if (it->second->accountId == accountId) {
|
||||
CNSocket* sock = it->first;
|
||||
|
||||
INITSTRUCT(sP_FE2CL_REP_PC_EXIT_DUPLICATE, resp);
|
||||
resp.iErrorCode = 0;
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_EXIT_DUPLICATE, sizeof(sP_FE2CL_REP_PC_EXIT_DUPLICATE));
|
||||
|
||||
sock->kill();
|
||||
CNShardServer::_killConnection(sock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
INITSTRUCT(sP_FE2CL_REP_PC_EXIT_DUPLICATE, resp2);
|
||||
sock->sendPacket((void*)&resp2, P_FE2CL_REP_PC_EXIT_DUPLICATE, sizeof(sP_FE2CL_REP_PC_EXIT_DUPLICATE));
|
||||
CNShardServer::_killConnection(sock);
|
||||
}
|
||||
|
||||
void PlayerManager::setSpecialState(CNSocket* sock, CNPacketData* data) {
|
||||
|
@@ -57,7 +57,7 @@ namespace PlayerManager {
|
||||
WarpLocation* getRespawnPoint(Player *plr);
|
||||
|
||||
bool isAccountInUse(int accountId);
|
||||
void exitDuplicate(int accountId);
|
||||
void exitDuplicate(CNSocket* sock);
|
||||
void setSpecialState(CNSocket* sock, CNPacketData* data);
|
||||
Player *getPlayerFromID(int32_t iID);
|
||||
CNSocket *getSockFromID(int32_t iID);
|
||||
|
Reference in New Issue
Block a user