Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
aronwk-aaron committed Jan 6, 2024
1 parent ed251b4 commit 801e2aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
49 changes: 24 additions & 25 deletions dNet/AuthPackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@
#include "eMasterMessageType.h"
#include "eGameMasterLevel.h"
#include "StringifiedEnum.h"
namespace {
std::vector<uint32_t> claimCodes;
}

void Stamp::Serialize(RakNet::BitStream* outBitStream){
outBitStream->Write(type);
outBitStream->Write(value);
outBitStream->Write(timestamp);
};

namespace {
std::vector<uint32_t> claimCodes;
}

void AuthPackets::LoadClaimCodes() {
if(!claimCodes.empty()) return;
auto rcstring = Game::config->GetValue("rewardcodes");
Expand Down Expand Up @@ -95,7 +94,7 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
CINSTREAM_SKIP_HEADER;

std::vector<Stamp> stamps;
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_START, 0, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_START, 0));

LUWString usernameLUString(33);
inStream.Read(usernameLUString);
Expand All @@ -106,20 +105,20 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {

LanguageCodeID locale_id;
inStream.Read(locale_id);
LOG("Locale ID: %s", StringifiedEnum::ToString(locale_id).data());
LOG_DEBUG("Locale ID: %s", StringifiedEnum::ToString(locale_id).data());

ClientOS clientOS;
inStream.Read(clientOS);
LOG("Operating System: %s", StringifiedEnum::ToString(clientOS).data());
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_CLIENT_OS, 0, time(nullptr)));
LOG_DEBUG("Operating System: %s", StringifiedEnum::ToString(clientOS).data());
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_CLIENT_OS, 0));

LUWString memoryStats(256);
inStream.Read(memoryStats);
LOG("Memory Stats [%s]", memoryStats.GetAsString().c_str());
LOG_DEBUG("Memory Stats [%s]", memoryStats.GetAsString().c_str());

LUWString videoCard(128);
inStream.Read(videoCard);
LOG("VideoCard Info: [%s]", videoCard.GetAsString().c_str());
LOG_DEBUG("VideoCard Info: [%s]", videoCard.GetAsString().c_str());

// Processor/CPU info
uint32_t numOfProcessors;
Expand All @@ -130,7 +129,7 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
inStream.Read(processorLevel);
uint16_t processorRevision;
inStream.Read(processorRevision);
LOG("CPU Info: [#Processors: %i, Processor Type: %i, Processor Level: %i, Processor Revision: %i]", numOfProcessors, processorType, processorLevel, processorRevision);
LOG_DEBUG("CPU Info: [#Processors: %i, Processor Type: %i, Processor Level: %i, Processor Revision: %i]", numOfProcessors, processorType, processorLevel, processorRevision);

// OS Info
uint32_t osVersionInfoSize;
Expand All @@ -143,30 +142,30 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
inStream.Read(buildNumber);
uint32_t platformID;
inStream.Read(platformID);
LOG("OS Info: [Size: %i, Major: %i, Minor %i, Buid#: %i, platformID: %i]", osVersionInfoSize, majorVersion, minorVersion, buildNumber, platformID);
LOG_DEBUG("OS Info: [Size: %i, Major: %i, Minor %i, Buid#: %i, platformID: %i]", osVersionInfoSize, majorVersion, minorVersion, buildNumber, platformID);

// Fetch account details
auto accountInfo = Database::Get()->GetAccountInfo(username);

if (!accountInfo) {
LOG("No user by name %s found!", username.c_str());
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::INVALID_USER, "", "", 2001, username, stamps);
return;
}

//If we aren't running in live mode, then only GMs are allowed to enter:
const auto& closedToNonDevs = Game::config->GetValue("closed_to_non_devs");
if (closedToNonDevs.size() > 0 && bool(std::stoi(closedToNonDevs)) && accountInfo->maxGmLevel == eGameMasterLevel::CIVILIAN) {
stamps.push_back(Stamp(eStamps::GM_REQUIRED, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::GM_REQUIRED, 1));
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "The server is currently only open to developers.", "", 2001, username, stamps);
return;
}

if (Game::config->GetValue("dont_use_keys") != "1" && accountInfo->maxGmLevel == eGameMasterLevel::CIVILIAN) {
//Check to see if we have a play key:
if (accountInfo->playKeyId == 0) {
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "Your account doesn't have a play key associated with it!", "", 2001, username, stamps);
LOG("User %s tried to log in, but they don't have a play key.", username.c_str());
return;
Expand All @@ -176,48 +175,48 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
auto playKeyStatus = Database::Get()->IsPlaykeyActive(accountInfo->playKeyId);

if (!playKeyStatus) {
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "Your account doesn't have a valid play key associated with it!", "", 2001, username, stamps);
return;
}

if (!playKeyStatus.value()) {
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "Your play key has been disabled.", "", 2001, username, stamps);
LOG("User %s tried to log in, but their play key was disabled", username.c_str());
return;
}
} else if (Game::config->GetValue("dont_use_keys") == "1" || accountInfo->maxGmLevel > eGameMasterLevel::CIVILIAN){
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_BYPASS, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_BYPASS, 1));
}

if (accountInfo->banned) {
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::BANNED, "", "", 2001, username, stamps);
return;
}

if (accountInfo->locked) {
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::ACCOUNT_LOCKED, "", "", 2001, username, stamps);
return;
}

bool loginSuccess = ::bcrypt_checkpw(password.GetAsString().c_str(), accountInfo->bcryptPassword.c_str()) == 0;

if (!loginSuccess) {
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::WRONG_PASS, "", "", 2001, username, stamps);
LOG("Wrong password used");
} else {
SystemAddress system = packet->systemAddress; //Copy the sysAddr before the Packet gets destroyed from main

if (!server->GetIsConnectedToMaster()) {
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_WORLD_DISCONNECT, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_WORLD_DISCONNECT, 1));
AuthPackets::SendLoginResponse(server, system, eLoginResponse::GENERAL_FAILED, "", "", 0, username, stamps);
return;
}
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_WORLD_SESSION_CONFIRM_TO_AUTH, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_WORLD_SESSION_CONFIRM_TO_AUTH, 1));
ZoneInstanceManager::Instance()->RequestZoneTransfer(server, 0, 0, false, [system, server, username, stamps](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string zoneIP, uint16_t zonePort) mutable {
AuthPackets::SendLoginResponse(server, system, eLoginResponse::SUCCESS, "", zoneIP, zonePort, username, stamps);
});
Expand All @@ -229,7 +228,7 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
}

void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAddr, eLoginResponse responseCode, const std::string& errorMsg, const std::string& wServerIP, uint16_t wServerPort, std::string username, std::vector<Stamp>& stamps) {
stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_IM_LOGIN_START, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_IM_LOGIN_START, 1));
RakNet::BitStream loginResponse;
BitStreamUtils::WriteHeader(loginResponse, eConnectionType::CLIENT, eClientMessageType::LOGIN_RESPONSE);

Expand Down Expand Up @@ -292,7 +291,7 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd
loginResponse.Write<uint16_t>(errorMsg.length());
loginResponse.Write(LUWString(errorMsg, static_cast<uint32_t>(errorMsg.length())));

stamps.push_back(Stamp(eStamps::PASSPORT_AUTH_WORLD_COMMUNICATION_FINISH, 1, time(nullptr)));
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_WORLD_COMMUNICATION_FINISH, 1));

loginResponse.Write<uint32_t>((sizeof(Stamp) * stamps.size()) + sizeof(uint32_t));
for (auto& stamp : stamps) stamp.Serialize(&loginResponse);
Expand Down
2 changes: 1 addition & 1 deletion dNet/AuthPackets.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct Stamp {
uint32_t value;
uint64_t timestamp;

Stamp(eStamps type, uint32_t value, uint64_t timestamp){
Stamp(eStamps type, uint32_t value, uint64_t timestamp = time(nullptr)){
this->type = type;
this->value = value;
this->timestamp = timestamp;
Expand Down

0 comments on commit 801e2aa

Please sign in to comment.