Skip to content

Commit

Permalink
no more Stamp(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
aronwk-aaron committed Jan 6, 2024
1 parent 801e2aa commit bf62b25
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions dNet/AuthPackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void AuthPackets::HandleHandshake(dServer* server, Packet* packet) {

inStream.IgnoreBytes(33);

LOG("Client Data [Version: %i, Service: %s, Process: %u, Port: %u, Sysaddr Port: %u]", clientVersion, StringifiedEnum::ToString(serviceId).data(), processID, port, packet->systemAddress.port);
LOG_DEBUG("Client Data [Version: %i, Service: %s, Process: %u, Port: %u, Sysaddr Port: %u]", clientVersion, StringifiedEnum::ToString(serviceId).data(), processID, port, packet->systemAddress.port);

SendHandshake(server, packet->systemAddress, server->GetIP(), server->GetPort(), server->GetServerType());
}
Expand Down Expand Up @@ -94,7 +94,7 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
CINSTREAM_SKIP_HEADER;

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

LUWString usernameLUString(33);
inStream.Read(usernameLUString);
Expand All @@ -110,7 +110,7 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
ClientOS clientOS;
inStream.Read(clientOS);
LOG_DEBUG("Operating System: %s", StringifiedEnum::ToString(clientOS).data());
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_CLIENT_OS, 0));
stamps.emplace_back(eStamps::PASSPORT_AUTH_CLIENT_OS, 0);

LUWString memoryStats(256);
inStream.Read(memoryStats);
Expand Down Expand Up @@ -149,23 +149,23 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {

if (!accountInfo) {
LOG("No user by name %s found!", username.c_str());
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
stamps.emplace_back(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.emplace_back(Stamp(eStamps::GM_REQUIRED, 1));
stamps.emplace_back(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.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
stamps.emplace_back(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 @@ -175,48 +175,48 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
auto playKeyStatus = Database::Get()->IsPlaykeyActive(accountInfo->playKeyId);

if (!playKeyStatus) {
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
stamps.emplace_back(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.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
stamps.emplace_back(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.emplace_back(Stamp(eStamps::PASSPORT_AUTH_BYPASS, 1));
stamps.emplace_back(eStamps::PASSPORT_AUTH_BYPASS, 1);
}

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

if (accountInfo->locked) {
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
stamps.emplace_back(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.emplace_back(Stamp(eStamps::PASSPORT_AUTH_ERROR, 1));
stamps.emplace_back(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.emplace_back(Stamp(eStamps::PASSPORT_AUTH_WORLD_DISCONNECT, 1));
stamps.emplace_back(eStamps::PASSPORT_AUTH_WORLD_DISCONNECT, 1);
AuthPackets::SendLoginResponse(server, system, eLoginResponse::GENERAL_FAILED, "", "", 0, username, stamps);
return;
}
stamps.emplace_back(Stamp(eStamps::PASSPORT_AUTH_WORLD_SESSION_CONFIRM_TO_AUTH, 1));
stamps.emplace_back(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 @@ -228,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.emplace_back(Stamp(eStamps::PASSPORT_AUTH_IM_LOGIN_START, 1));
stamps.emplace_back(eStamps::PASSPORT_AUTH_IM_LOGIN_START, 1);
RakNet::BitStream loginResponse;
BitStreamUtils::WriteHeader(loginResponse, eConnectionType::CLIENT, eClientMessageType::LOGIN_RESPONSE);

Expand Down Expand Up @@ -291,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.emplace_back(Stamp(eStamps::PASSPORT_AUTH_WORLD_COMMUNICATION_FINISH, 1));
stamps.emplace_back(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

0 comments on commit bf62b25

Please sign in to comment.