t8-mod/source/proxy-dll/demonware/servers/lobby_server.cpp
project-bo4 354d022967 Squashed commit of the following:
commit f44d146e4ac906ff898e8968c6857fd2280f6d20
Author: project-bo4 <127137346+project-bo4@users.noreply.github.com>
Date:   Thu May 11 13:39:29 2023 -0700

    remove lpc package from repository

commit 29fb0f63e50de468ab0b9db35f7e8fdadf58afc3
Author: project-bo4 <themanwithantidote@gmail.com>
Date:   Thu May 11 13:06:13 2023 -0700

    generic improvements

    + added identity configuration
    + objectstore improvements
    + added battlenet 'US' servers to blocklist
    + some other minor improvements

commit 5d5e31099ebcce5a637b9a02d4936a97fb0802a7
Author: project-bo4 <themanwithantidote@gmail.com>
Date:   Sat Mar 25 16:32:52 2023 -0700

    lpc improvements

    + fix lpc issue with foreign languages(non-english) not being considered in listing
    + check lpc files pre-start and warn user if missing any of core items

commit 2de1a54b6f4cc5c44dc906871021cfbc85057ca9
Author: project-bo4 <themanwithantidote@gmail.com>
Date:   Thu Mar 23 12:45:56 2023 -0700

    demonware improvements

    + handle object store uploadUserObject
    + silence bdUNK125

commit 710dcc3ec6178071d67c27e5bf6705f08cabe7e2
Author: project-bo4 <themanwithantidote@gmail.com>
Date:   Mon Mar 20 13:43:56 2023 -0700

    forgot to update names

commit 217682dfb07b35f7a09399fb2698924bb7fe8b77
Author: project-bo4 <themanwithantidote@gmail.com>
Date:   Mon Mar 20 11:09:18 2023 -0700

    upload lpc and update readme

commit 83f812b33b90791a8d13b9468f27da51e0a4f2b9
Author: project-bo4 <themanwithantidote@gmail.com>
Date:   Mon Mar 20 10:53:43 2023 -0700

    demonware emulator

    + demonware emulator
    + platform name and id
    + xxhash and picoproto
    - remove g_runframe hook
    -disable discovery(save time)
    + improvements to utils
    + add new resources
2023-05-11 13:50:11 -07:00

182 lines
4.6 KiB
C++

#include <std_include.hpp>
#include "lobby_server.hpp"
#include "../services.hpp"
#include "../keys.hpp"
#include <utils/cryptography.hpp>
namespace demonware
{
lobby_server::lobby_server(std::string name) : tcp_server(std::move(name))
{
this->register_service<bdStats>();
this->register_service<bdProfiles>();
this->register_service<bdTitleUtilities>();
this->register_service<bdKeyArchive>();
this->register_service<bdBandwidthTest>();
this->register_service<bdCounter>();
this->register_service<bdDML>();
this->register_service<bdGroup>();
this->register_service<bdAnticheat>();
this->register_service<bdTags>();
this->register_service<bdPooledStorage>();
this->register_service<bdEventLog>();
this->register_service<bdRichPresence>();
this->register_service<bdMarketplace>();
this->register_service<bdPublisherVariables>();
this->register_service<bdMarketingComms>();
this->register_service<bdUNK125>();
this->register_service<bdObjectStore>();
this->register_service<bdLootGeneration>();
};
void lobby_server::send_reply(reply* data)
{
if (!data) return;
this->send(data->data());
}
void lobby_server::handle(const std::string& packet)
{
byte_buffer buffer(packet);
buffer.set_use_data_types(false);
try
{
while (buffer.has_more_data())
{
int size;
buffer.read_int32(&size);
if (size <= 0)
{
const std::string zero("\x00\x00\x00\x00", 4);
raw_reply reply(zero);
this->send_reply(&reply);
return;
}
else if (size == 0xC8)
{
#ifndef NDEBUG
logger::write(logger::LOG_TYPE_DEBUG, "[DW]: [lobby]: received client_header_ack.");
#endif
int c8;
buffer.read_int32(&c8);
std::string packet_1 = buffer.get_remaining();
demonware::queue_packet_to_hash(packet_1);
/* msgType[BYTE] serverSelectedProto[DWORD] cypher210ConnID[QWORD] serverNonce[QWORD] */
/* 0x81(129) 0xD2(210) 0x3713371337133713 0x3713371337133713 */
const std::string packet_2(
"\x16\x00\x00\x00\xab\x81\xd2\x00\x00\x00\x13\x37\x13\x37\x13\x37\x13\x37\x13\x37\x13\x37\x13\x37\x13\x37",
26);
demonware::queue_packet_to_hash(packet_2);
raw_reply reply(packet_2);
this->send_reply(&reply);
#ifndef NDEBUG
logger::write(logger::LOG_TYPE_DEBUG, "[DW]: [lobby]: sending server_header_ack.");
#endif
return;
}
if (buffer.size() < size_t(size)) return;
uint8_t check_ab;
buffer.read_ubyte(&check_ab);
if (check_ab == 0xAB)
{
uint8_t type;
buffer.read_ubyte(&type);
if (type == 0x82)
{
#ifndef NDEBUG
logger::write(logger::LOG_TYPE_DEBUG, "[DW]: [lobby]: received client_auth.");
#endif
std::string packet_3(packet.data(), packet.size() - 8); // this 8 are client hash check?
demonware::queue_packet_to_hash(packet_3);
demonware::derive_keys_iw8();
char buff[14] = "\x0A\x00\x00\x00\xAB\x83";
std::memcpy(&buff[6], demonware::get_response_id().data(), 8);
std::string response(buff, 14);
raw_reply reply(response);
this->send_reply(&reply);
#ifndef NDEBUG
logger::write(logger::LOG_TYPE_DEBUG, "[DW]: [lobby]: sending server_auth_done.");
#endif
return;
}
else if (type == 0x85)
{
uint32_t msg_count;
buffer.read_uint32(&msg_count);
char seed[16];
buffer.read(16, &seed);
std::string enc = buffer.get_remaining();
char hash[8];
std::memcpy(hash, &(enc.data()[enc.size() - 8]), 8);
std::string dec = utils::cryptography::aes::decrypt(
std::string(enc.data(), enc.size() - 8), std::string(seed, 16),
demonware::get_decrypt_key());
byte_buffer serv(dec);
serv.set_use_data_types(false);
uint32_t serv_size;
serv.read_uint32(&serv_size);
uint8_t magic; // 0x86
serv.read_ubyte(&magic);
uint8_t service_id;
serv.read_ubyte(&service_id);
this->call_service(service_id, serv.get_remaining());
return;
}
}
logger::write(logger::LOG_TYPE_DEBUG, "[DW]: [lobby]: ERROR! received unk message.");
return;
}
}
catch (...)
{
}
}
void lobby_server::call_service(const uint8_t id, const std::string& data)
{
const auto& it = this->services_.find(id);
if (it != this->services_.end())
{
it->second->exec_task(this, data);
}
else
{
logger::write(logger::LOG_TYPE_DEBUG, "[DW]: [lobby]: missing service '%s'", utils::string::va("%d", id));
// return no error
byte_buffer buffer(data);
uint8_t task_id;
buffer.read_ubyte(&task_id);
this->create_reply(task_id)->send();
}
}
}