Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
etorth committed Jan 13, 2025
1 parent 60c14e9 commit a67fe24
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
27 changes: 27 additions & 0 deletions common/src/aesf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "aesf.hpp"
#include "strf.hpp"
#include "totype.hpp"
#include "base64f.hpp"

std::string aesf::encrypt(const char *orig, const char *password, uint64_t r)
{
fflassert(orig, to_cstr(orig));
fflassert(password, to_cstr(password));

std::string result;
result.append(orig);
result.append(password);
result.append(std::to_string(r));
result.append(str_printf("%04zu", to_sv(orig).size()));
return base64f::encode(result);
}

std::string aesf::decrypt(const char *encoded, const char *, uint64_t)
{
const auto s = base64f::decode(encoded, to_sv(encoded).size());
const size_t size = (s.rbegin()[3] - '0') * 1000
+ (s.rbegin()[2] - '0') * 100
+ (s.rbegin()[1] - '0') * 10
+ (s.rbegin()[0] - '0') * 1;
return s.substr(0, size);
}
9 changes: 9 additions & 0 deletions common/src/aesf.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <string>
#include <cstdint>

namespace aesf
{
std::string encrypt(const char *, const char *, uint64_t);
std::string decrypt(const char *, const char *, uint64_t);
}
11 changes: 4 additions & 7 deletions server/src/npchar.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cstdint>
#include "uidf.hpp"
#include "aesf.hpp"
#include "luaf.hpp"
#include "xmlf.hpp"
#include "dbpod.hpp"
Expand All @@ -14,10 +15,12 @@
#include "serdesmsg.hpp"
#include "friendtype.hpp"
#include "monoserver.hpp"
#include "serverpasswordwindow.hpp"
#include "serverconfigurewindow.hpp"

extern DBPod *g_dbPod;
extern MonoServer *g_monoServer;
extern ServerPasswordWindow *g_serverPasswordWindow;
extern ServerConfigureWindow *g_serverConfigureWindow;

NPChar::LuaThreadRunner::LuaThreadRunner(NPChar *npc)
Expand Down Expand Up @@ -449,24 +452,18 @@ void NPChar::postXMLLayout(uint64_t uid, std::string path, std::string xmlString
if(auto elem = node->ToElement()){
for(auto attr = elem->FirstAttribute(); attr; attr = attr->Next()){
if(str_tolower(attr->Name()) == "id"){
std::string val = attr->Value() + std::to_string(xmlSeqID);
const_cast<tinyxml2::XMLAttribute *>(attr)->SetAttribute(val.c_str());
const_cast<tinyxml2::XMLAttribute *>(attr)->SetAttribute(aesf::encrypt(attr->Value(), g_serverPasswordWindow->getPassword(), xmlSeqID).c_str());
break;
}
}
}

if(node->NoChildren()) {
return;
}

for(auto child = node->FirstChild(); child; child = child->NextSibling()){
self(child);
}
};

fnXMLTran(xmlDoc.RootElement());

forwardNetPackage(uid, SM_NPCXMLLAYOUT, cerealf::serialize(SDNPCXMLLayout
{
.npcUID = UID(),
Expand Down

0 comments on commit a67fe24

Please sign in to comment.