mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-24 06:27:24 +00:00
Server: Secure Master packet handling
This commit is contained in:
parent
b33e9935f5
commit
e10351bde6
@ -110,40 +110,20 @@ Packet* dServer::ReceiveFromMaster() {
|
|||||||
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
||||||
mLogger->Log("dServer", "Lost our connection to master, shutting DOWN!");
|
mLogger->Log("dServer", "Lost our connection to master, shutting DOWN!");
|
||||||
mMasterConnectionActive = false;
|
mMasterConnectionActive = false;
|
||||||
|
mMasterPeer->DeallocatePacket(packet);
|
||||||
|
packet = nullptr;
|
||||||
//ConnectToMaster(); //We'll just shut down now
|
//ConnectToMaster(); //We'll just shut down now
|
||||||
}
|
} else if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) {
|
||||||
|
|
||||||
if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) {
|
|
||||||
mLogger->Log("dServer", "Established connection to master, zone (%i), instance (%i)", this->GetZoneID(), this->GetInstanceID());
|
mLogger->Log("dServer", "Established connection to master, zone (%i), instance (%i)", this->GetZoneID(), this->GetInstanceID());
|
||||||
mMasterConnectionActive = true;
|
mMasterConnectionActive = true;
|
||||||
mMasterSystemAddress = packet->systemAddress;
|
mMasterSystemAddress = packet->systemAddress;
|
||||||
MasterPackets::SendServerInfo(this, packet);
|
MasterPackets::SendServerInfo(this, packet);
|
||||||
|
mMasterPeer->DeallocatePacket(packet);
|
||||||
|
packet = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet->data[0] == ID_USER_PACKET_ENUM) {
|
|
||||||
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::MASTER) {
|
|
||||||
switch (static_cast<eMasterMessageType>(packet->data[3])) {
|
|
||||||
case eMasterMessageType::REQUEST_ZONE_TRANSFER_RESPONSE: {
|
|
||||||
uint64_t requestID = PacketUtils::ReadU64(8, packet);
|
|
||||||
ZoneInstanceManager::Instance()->HandleRequestZoneTransferResponse(requestID, packet);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case eMasterMessageType::SHUTDOWN:
|
|
||||||
*mShouldShutdown = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
//When we handle these packets in World instead dServer, we just return the packet's pointer.
|
|
||||||
default:
|
|
||||||
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mMasterPeer->DeallocatePacket(packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet* dServer::Receive() {
|
Packet* dServer::Receive() {
|
||||||
|
@ -97,6 +97,7 @@ void WorldShutdownSequence();
|
|||||||
void WorldShutdownProcess(uint32_t zoneId);
|
void WorldShutdownProcess(uint32_t zoneId);
|
||||||
void FinalizeShutdown();
|
void FinalizeShutdown();
|
||||||
void SendShutdownMessageToMaster();
|
void SendShutdownMessageToMaster();
|
||||||
|
void HandleMasterPacket(Packet* packet);
|
||||||
|
|
||||||
dLogger* SetupLogger(uint32_t zoneID, uint32_t instanceID);
|
dLogger* SetupLogger(uint32_t zoneID, uint32_t instanceID);
|
||||||
void HandlePacketChat(Packet* packet);
|
void HandlePacketChat(Packet* packet);
|
||||||
@ -413,7 +414,7 @@ int main(int argc, char** argv) {
|
|||||||
//Check for packets here:
|
//Check for packets here:
|
||||||
packet = Game::server->ReceiveFromMaster();
|
packet = Game::server->ReceiveFromMaster();
|
||||||
if (packet) { //We can get messages not handle-able by the dServer class, so handle them if we returned anything.
|
if (packet) { //We can get messages not handle-able by the dServer class, so handle them if we returned anything.
|
||||||
HandlePacket(packet);
|
HandleMasterPacket(packet);
|
||||||
Game::server->DeallocateMasterPacket(packet);
|
Game::server->DeallocateMasterPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,64 +678,7 @@ void HandlePacketChat(Packet* packet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandlePacket(Packet* packet) {
|
void HandleMasterPacket(Packet* packet) {
|
||||||
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
|
||||||
auto user = UserManager::Instance()->GetUser(packet->systemAddress);
|
|
||||||
if (!user) return;
|
|
||||||
|
|
||||||
auto c = user->GetLastUsedChar();
|
|
||||||
if (!c) {
|
|
||||||
UserManager::Instance()->DeleteUser(packet->systemAddress);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* entity = Game::entityManager->GetEntity(c->GetObjectID());
|
|
||||||
|
|
||||||
if (!entity) {
|
|
||||||
entity = Player::GetPlayer(packet->systemAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity) {
|
|
||||||
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
|
||||||
|
|
||||||
if (skillComponent != nullptr) {
|
|
||||||
skillComponent->Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
entity->GetCharacter()->SaveXMLToDatabase();
|
|
||||||
|
|
||||||
Game::logger->Log("WorldServer", "Deleting player %llu", entity->GetObjectID());
|
|
||||||
|
|
||||||
Game::entityManager->DestroyEntity(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
CBITSTREAM;
|
|
||||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION);
|
|
||||||
bitStream.Write(user->GetLoggedInChar());
|
|
||||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
UserManager::Instance()->DeleteUser(packet->systemAddress);
|
|
||||||
|
|
||||||
if (PropertyManagementComponent::Instance() != nullptr) {
|
|
||||||
PropertyManagementComponent::Instance()->Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
CBITSTREAM;
|
|
||||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PLAYER_REMOVED);
|
|
||||||
bitStream.Write((LWOMAPID)Game::server->GetZoneID());
|
|
||||||
bitStream.Write((LWOINSTANCEID)instanceID);
|
|
||||||
Game::server->SendToMaster(&bitStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packet->data[0] != ID_USER_PACKET_ENUM || packet->length < 4) return;
|
|
||||||
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::SERVER) {
|
|
||||||
if (static_cast<eServerMessageType>(packet->data[3]) == eServerMessageType::VERSION_CONFIRM) {
|
|
||||||
AuthPackets::HandleHandshake(Game::server, packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::MASTER) {
|
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::MASTER) {
|
||||||
switch (static_cast<eMasterMessageType>(packet->data[3])) {
|
switch (static_cast<eMasterMessageType>(packet->data[3])) {
|
||||||
case eMasterMessageType::REQUEST_PERSISTENT_ID_RESPONSE: {
|
case eMasterMessageType::REQUEST_PERSISTENT_ID_RESPONSE: {
|
||||||
@ -873,6 +817,65 @@ void HandlePacket(Packet* packet) {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandlePacket(Packet* packet) {
|
||||||
|
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
||||||
|
auto user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||||
|
if (!user) return;
|
||||||
|
|
||||||
|
auto c = user->GetLastUsedChar();
|
||||||
|
if (!c) {
|
||||||
|
UserManager::Instance()->DeleteUser(packet->systemAddress);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* entity = Game::entityManager->GetEntity(c->GetObjectID());
|
||||||
|
|
||||||
|
if (!entity) {
|
||||||
|
entity = Player::GetPlayer(packet->systemAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity) {
|
||||||
|
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
||||||
|
|
||||||
|
if (skillComponent != nullptr) {
|
||||||
|
skillComponent->Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
entity->GetCharacter()->SaveXMLToDatabase();
|
||||||
|
|
||||||
|
Game::logger->Log("WorldServer", "Deleting player %llu", entity->GetObjectID());
|
||||||
|
|
||||||
|
Game::entityManager->DestroyEntity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
CBITSTREAM;
|
||||||
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION);
|
||||||
|
bitStream.Write(user->GetLoggedInChar());
|
||||||
|
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
UserManager::Instance()->DeleteUser(packet->systemAddress);
|
||||||
|
|
||||||
|
if (PropertyManagementComponent::Instance() != nullptr) {
|
||||||
|
PropertyManagementComponent::Instance()->Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
CBITSTREAM;
|
||||||
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PLAYER_REMOVED);
|
||||||
|
bitStream.Write((LWOMAPID)Game::server->GetZoneID());
|
||||||
|
bitStream.Write((LWOINSTANCEID)instanceID);
|
||||||
|
Game::server->SendToMaster(&bitStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packet->data[0] != ID_USER_PACKET_ENUM || packet->length < 4) return;
|
||||||
|
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::SERVER) {
|
||||||
|
if (static_cast<eServerMessageType>(packet->data[3]) == eServerMessageType::VERSION_CONFIRM) {
|
||||||
|
AuthPackets::HandleHandshake(Game::server, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (static_cast<eConnectionType>(packet->data[1]) != eConnectionType::WORLD) return;
|
if (static_cast<eConnectionType>(packet->data[1]) != eConnectionType::WORLD) return;
|
||||||
|
|
||||||
@ -964,7 +967,7 @@ void HandlePacket(Packet* packet) {
|
|||||||
CheckType::Entity,
|
CheckType::Entity,
|
||||||
"Sending GM with a sending player that does not match their own. GM ID: %i",
|
"Sending GM with a sending player that does not match their own. GM ID: %i",
|
||||||
static_cast<int32_t>(messageID)
|
static_cast<int32_t>(messageID)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isSender) GameMessageHandler::HandleMessage(&dataStream, packet->systemAddress, objectID, messageID);
|
if (isSender) GameMessageHandler::HandleMessage(&dataStream, packet->systemAddress, objectID, messageID);
|
||||||
break;
|
break;
|
||||||
@ -988,7 +991,7 @@ void HandlePacket(Packet* packet) {
|
|||||||
CheckType::User,
|
CheckType::User,
|
||||||
"Sending login request with a sending player that does not match their own. Player ID: %llu",
|
"Sending login request with a sending player that does not match their own. Player ID: %llu",
|
||||||
playerID
|
playerID
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
|
|
||||||
@ -1059,23 +1062,23 @@ void HandlePacket(Packet* packet) {
|
|||||||
if (!levelComponent) return;
|
if (!levelComponent) return;
|
||||||
|
|
||||||
auto version = levelComponent->GetCharacterVersion();
|
auto version = levelComponent->GetCharacterVersion();
|
||||||
switch(version) {
|
switch (version) {
|
||||||
case eCharacterVersion::RELEASE:
|
case eCharacterVersion::RELEASE:
|
||||||
// TODO: Implement, super low priority
|
// TODO: Implement, super low priority
|
||||||
case eCharacterVersion::LIVE:
|
case eCharacterVersion::LIVE:
|
||||||
Game::logger->Log("WorldServer", "Updating Character Flags");
|
Game::logger->Log("WorldServer", "Updating Character Flags");
|
||||||
c->SetRetroactiveFlags();
|
c->SetRetroactiveFlags();
|
||||||
levelComponent->SetCharacterVersion(eCharacterVersion::PLAYER_FACTION_FLAGS);
|
levelComponent->SetCharacterVersion(eCharacterVersion::PLAYER_FACTION_FLAGS);
|
||||||
case eCharacterVersion::PLAYER_FACTION_FLAGS:
|
case eCharacterVersion::PLAYER_FACTION_FLAGS:
|
||||||
Game::logger->Log("WorldServer", "Updating Vault Size");
|
Game::logger->Log("WorldServer", "Updating Vault Size");
|
||||||
player->RetroactiveVaultSize();
|
player->RetroactiveVaultSize();
|
||||||
levelComponent->SetCharacterVersion(eCharacterVersion::VAULT_SIZE);
|
levelComponent->SetCharacterVersion(eCharacterVersion::VAULT_SIZE);
|
||||||
case eCharacterVersion::VAULT_SIZE:
|
case eCharacterVersion::VAULT_SIZE:
|
||||||
Game::logger->Log("WorldServer", "Updaing Speedbase");
|
Game::logger->Log("WorldServer", "Updaing Speedbase");
|
||||||
levelComponent->SetRetroactiveBaseSpeed();
|
levelComponent->SetRetroactiveBaseSpeed();
|
||||||
levelComponent->SetCharacterVersion(eCharacterVersion::UP_TO_DATE);
|
levelComponent->SetCharacterVersion(eCharacterVersion::UP_TO_DATE);
|
||||||
case eCharacterVersion::UP_TO_DATE:
|
case eCharacterVersion::UP_TO_DATE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
player->GetCharacter()->SetTargetScene("");
|
player->GetCharacter()->SetTargetScene("");
|
||||||
|
Loading…
Reference in New Issue
Block a user