Network logging stuff

This commit is contained in:
momo5502 2016-09-03 15:52:40 +02:00
parent 64682a8ef6
commit 18d1e9daa1
7 changed files with 141 additions and 5 deletions

2
deps/mongoose vendored

@ -1 +1 @@
Subproject commit 4120f953c7e5a14fdce2445effb1158b0650f103
Subproject commit 36405545033489ccfeb6c139c6e609998efc3cf9

2
deps/protobuf vendored

@ -1 +1 @@
Subproject commit c0a6a6b4628a634f6a0529c9f7e9e1e0fe66d4d6
Subproject commit 96a9d97352436c7284e8194e103ca8d92649ad02

View File

@ -2,10 +2,18 @@
namespace Components
{
bool Loader::Pregame = true;
std::vector<Component*> Loader::Components;
bool Loader::IsPregame()
{
return Loader::Pregame;
}
void Loader::Initialize()
{
Loader::Pregame = true;
Loader::Register(new Flags());
Loader::Register(new Singleton());
@ -59,6 +67,8 @@ namespace Components
Loader::Register(new MusicalTalent());
Loader::Register(new StructuredData());
Loader::Register(new ConnectProtocol());
Loader::Pregame = false;
}
void Loader::Uninitialize()

View File

@ -22,7 +22,10 @@ namespace Components
static bool PerformingUnitTests();
static void Register(Component* component);
static bool IsPregame();
private:
static bool Pregame;
static std::vector<Component*> Components;
};
}
@ -38,7 +41,6 @@ namespace Components
#include "Modules\Toast.hpp"
#include "Modules\Colors.hpp"
#include "Modules\D3D9Ex.hpp"
#include "Modules\Logger.hpp"
#include "Modules\Script.hpp"
#include "Modules\Weapon.hpp"
#include "Modules\Window.hpp"
@ -49,9 +51,9 @@ namespace Components
#include "Modules\Network.hpp"
#include "Modules\Theatre.hpp"
#include "Modules\Node.hpp"
#include "Modules\BitMessage.hpp"
#include "Modules\RCon.hpp"
#include "Modules\Party.hpp" // Destroys the order, but requires network classes :D
#include "Modules\Logger.hpp"
#include "Modules\Download.hpp"
#include "Modules\Playlist.hpp"
#include "Modules\RawFiles.hpp"
@ -62,10 +64,10 @@ namespace Components
#include "Modules\Dedicated.hpp"
#include "Modules\Discovery.hpp"
#include "Modules\Exception.hpp"
#include "Modules\MinidumpUpload.hpp"
#include "Modules\FastFiles.hpp"
#include "Modules\Materials.hpp"
#include "Modules\Singleton.hpp"
#include "Modules\BitMessage.hpp"
#include "Modules\FileSystem.hpp"
#include "Modules\QuickPatch.hpp"
#include "Modules\ServerInfo.hpp"
@ -75,5 +77,6 @@ namespace Components
#include "Modules\AssetHandler.hpp"
#include "Modules\Localization.hpp"
#include "Modules\MusicalTalent.hpp"
#include "Modules\MinidumpUpload.hpp"
#include "Modules\StructuredData.hpp"
#include "Modules\ConnectProtocol.hpp"

View File

@ -46,6 +46,17 @@ namespace Components
void Command::AddSV(const char* name, Command::Callback* callback)
{
if (Loader::IsPregame())
{
MessageBoxA(0, "Registering server commands in pregamestate is illegal!", 0, MB_ICONERROR);
#ifdef DEBUG
__debugbreak();
#endif
return;
}
std::string command = Utils::String::ToLower(name);
if (Command::FunctionMapSV.find(command) == Command::FunctionMapSV.end())

View File

@ -4,6 +4,7 @@ namespace Components
{
std::mutex Logger::MessageMutex;
std::vector<std::string> Logger::MessageQueue;
std::vector<Network::Address> Logger::LoggingAddresses[2];
void(*Logger::PipeCallback)(std::string) = nullptr;
bool Logger::IsConsoleReady()
@ -108,6 +109,29 @@ namespace Components
}
}
void Logger::NetworkLog(const char* data, bool gLog)
{
std::string buffer(data);
for (auto& addr : Logger::LoggingAddresses[gLog & 1])
{
Network::SendCommand(addr, "print", buffer);
}
}
__declspec(naked) void Logger::GameLogStub()
{
__asm
{
push 1
push[esp + 4h]
call Logger::NetworkLog
add esp, 8h
mov eax, 4576C0h
jmp eax
}
}
__declspec(naked) void Logger::PrintMessageStub()
{
__asm
@ -122,6 +146,11 @@ namespace Components
retn
returnPrint:
push 0
push [esp + 8h]
call Logger::NetworkLog
add esp, 8h
push esi
mov esi, [esp + 0Ch]
@ -143,11 +172,90 @@ namespace Components
QuickPatch::OnFrame(Logger::Frame);
Utils::Hook(0x4B0218, Logger::GameLogStub, HOOK_CALL).Install()->Quick();
Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).Install()->Quick();
Dvar::OnInit([] ()
{
Command::AddSV("log_add", [] (Command::Params params)
{
if (params.Length() < 2) return;
Network::Address addr(params[1]);
if (std::find(Logger::LoggingAddresses[0].begin(), Logger::LoggingAddresses[0].end(), addr) == Logger::LoggingAddresses[0].end())
{
Logger::LoggingAddresses[0].push_back(addr);
}
});
Command::AddSV("log_del", [] (Command::Params params)
{
if (params.Length() < 2) return;
Network::Address addr(params[1]);
auto i = std::find(Logger::LoggingAddresses[0].begin(), Logger::LoggingAddresses[0].end(), addr);
if (i != Logger::LoggingAddresses[0].end())
{
Logger::LoggingAddresses[0].erase(i);
}
});
Command::AddSV("log_list", [] (Command::Params)
{
Logger::Print("# ID: Address\n");
Logger::Print("-------------\n");
for (unsigned int i = 0; i < Logger::LoggingAddresses[0].size(); ++i)
{
Logger::Print("#%03d: %5s\n", i, Logger::LoggingAddresses[0][i].GetCString());
}
});
Command::AddSV("glog_add", [] (Command::Params params)
{
if (params.Length() < 2) return;
Network::Address addr(params[1]);
if (std::find(Logger::LoggingAddresses[1].begin(), Logger::LoggingAddresses[1].end(), addr) == Logger::LoggingAddresses[1].end())
{
Logger::LoggingAddresses[1].push_back(addr);
}
});
Command::AddSV("glog_del", [] (Command::Params params)
{
if (params.Length() < 2) return;
Network::Address addr(params[1]);
auto i = std::find(Logger::LoggingAddresses[1].begin(), Logger::LoggingAddresses[1].end(), addr);
if (i != Logger::LoggingAddresses[1].end())
{
Logger::LoggingAddresses[1].erase(i);
}
});
Command::AddSV("glog_list", [] (Command::Params)
{
Logger::Print("# ID: Address\n");
Logger::Print("-------------\n");
for (unsigned int i = 0; i < Logger::LoggingAddresses[1].size(); ++i)
{
Logger::Print("#%03d: %5s\n", i, Logger::LoggingAddresses[1][i].GetCString());
}
});
});
}
Logger::~Logger()
{
Logger::LoggingAddresses[0].clear();
Logger::LoggingAddresses[1].clear();
Logger::MessageMutex.lock();
Logger::MessageQueue.clear();
Logger::MessageMutex.unlock();

View File

@ -24,13 +24,17 @@ namespace Components
private:
static std::mutex MessageMutex;
static std::vector<std::string> MessageQueue;
static std::vector<Network::Address> LoggingAddresses[2];
static void(*PipeCallback)(std::string);
static void Frame();
static void GameLogStub();
static void PrintMessageStub();
static void PrintMessagePipe(const char* data);
static void EnqueueMessage(std::string message);
static void NetworkLog(const char* data, bool gLog);
static std::string Format(const char** message);
};
}