Skip to content

Commit 6652c04

Browse files
committed
Add simple accelerator integration
1 parent 231cb71 commit 6652c04

5 files changed

Lines changed: 24931 additions & 6 deletions

File tree

extension.cpp

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@
44
#include "client/linux/handler/exception_handler.h"
55
#include "common/linux/linux_libc_support.h"
66
#include "third_party/lss/linux_syscall_support.h"
7+
#include "common/linux/http_upload.h"
78

89
#include <dirent.h>
910
#include <unistd.h>
1011
#else
1112
#include "client/windows/handler/exception_handler.h"
13+
#include "common/windows/http_upload.h"
1214
#endif
1315

16+
#include "vendor/nlohmann/json.hpp"
17+
1418
#include <sys/stat.h>
1519
#include <stdio.h>
1620
#include <stdlib.h>
1721
#include <signal.h>
1822
#include <limits>
1923
#include <filesystem>
2024
#include <codecvt>
25+
#include <thread>
26+
#include <fstream>
2127

2228
#include "common/path_helper.h"
2329
#include "common/using_std_string.h"
@@ -42,6 +48,8 @@ char crashMap[256];
4248
char crashGamePath[512];
4349
char crashCommandLine[1024];
4450
char dumpStoragePath[512];
51+
std::string g_serverId;
52+
std::string g_UserId;
4553

4654
CGameEntitySystem *GameEntitySystem()
4755
{
@@ -283,6 +291,137 @@ static bool dumpCallback(const wchar_t* dump_path,
283291
}
284292
#endif
285293

294+
#ifdef _LINUX
295+
void UploadThread()
296+
{
297+
for (const auto& entry : std::filesystem::directory_iterator(dumpStoragePath)) {
298+
if (entry.path().extension() == ".dmp") {
299+
std::filesystem::path uploadedPath = entry.path();
300+
301+
// is dump already uploaded
302+
if (entry.path().stem().string().find("_uploaded") != std::string::npos) {
303+
continue;
304+
}
305+
306+
ConMsg("Uploading minidump %s\n", entry.path().string().c_str());
307+
308+
std::map<std::string, std::string> params;
309+
310+
params["UserID"] = g_UserId.c_str();
311+
params["GameDirectory"] = "csgo";
312+
params["ExtensionVersion"] = std::string(g_AcceleratorCS2.GetVersion()) + " [AcceleratorCS2 Build]";
313+
params["ServerID"] = g_serverId.c_str();
314+
params["PresubmitToken"] = "";
315+
316+
std::filesystem::path metadataPath = entry.path();
317+
metadataPath.replace_extension(".dmp.txt");
318+
319+
std::map<std::string, std::string> files;
320+
files["upload_file_minidump"] = entry.path().string();
321+
files["upload_file_metadata"] = metadataPath.string();
322+
323+
std::string res;
324+
google_breakpad::HTTPUpload::SendRequest("http://crash.limetech.org/submit", params, files, "", "", "", &res, nullptr, nullptr);
325+
326+
ConMsg("Upload response: %s\n", res.c_str());
327+
328+
uploadedPath.replace_filename(uploadedPath.stem().string() + "_uploaded" + uploadedPath.extension().string());
329+
std::filesystem::rename(entry.path(), uploadedPath);
330+
}
331+
}
332+
};
333+
#else
334+
void UploadThread()
335+
{
336+
for (const auto& entry : std::filesystem::directory_iterator(dumpStoragePath)) {
337+
if (entry.path().extension() == ".dmp") {
338+
std::filesystem::path uploadedPath = entry.path();
339+
340+
341+
// is dump already uploaded
342+
if (entry.path().stem().string().find("_uploaded") != std::string::npos) {
343+
continue;
344+
}
345+
346+
ConMsg("Uploading minidump %s\n", entry.path().string().c_str());
347+
348+
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> strconverter;
349+
std::map<std::wstring, std::wstring> params;
350+
351+
params[L"UserID"] = strconverter.from_bytes(g_UserId).c_str();
352+
params[L"GameDirectory"] = L"csgo";
353+
params[L"ExtensionVersion"] = strconverter.from_bytes(g_AcceleratorCS2.GetVersion()) + L" [AcceleratorCS2 Build]";
354+
params[L"ServerID"] = strconverter.from_bytes(g_serverId).c_str();
355+
params[L"PresubmitToken"] = L"";
356+
357+
std::filesystem::path metadataPath = entry.path();
358+
metadataPath.replace_extension(".dmp.txt");
359+
360+
std::map<std::wstring, std::wstring> files;
361+
files[L"upload_file_minidump"] = entry.path().wstring();
362+
files[L"upload_file_metadata"] = metadataPath.wstring();
363+
364+
std::wstring res;
365+
google_breakpad::HTTPUpload::SendMultipartPostRequest(L"http://crash.limetech.org/submit", params, files, nullptr, &res, nullptr);
366+
367+
ConMsg("Upload response: %s\n", strconverter.to_bytes(res).c_str());
368+
369+
uploadedPath.replace_filename(uploadedPath.stem().string() + "_uploaded" + uploadedPath.extension().string());
370+
std::filesystem::rename(entry.path(), uploadedPath);
371+
}
372+
}
373+
};
374+
#endif
375+
376+
void LoadServerId()
377+
{
378+
std::string serverIdPath = std::string(crashGamePath) + "/addons/accelerator_local/serverid.txt";
379+
std::ifstream serverIdFile(serverIdPath);
380+
if (serverIdFile.is_open()) {
381+
serverIdFile >> g_serverId;
382+
serverIdFile.close();
383+
}
384+
else {
385+
char buffer[64];
386+
V_snprintf(buffer, sizeof(buffer), "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
387+
rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255, 0x40 | ((rand() % 255) & 0x0F), rand() % 255,
388+
0x80 | ((rand() % 255) & 0x3F), rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
389+
g_serverId = buffer;
390+
391+
std::ofstream serverIdFile(serverIdPath);
392+
if (serverIdFile.is_open()) {
393+
serverIdFile << g_serverId;
394+
serverIdFile.close();
395+
}
396+
}
397+
};
398+
399+
void LoadConfig()
400+
{
401+
// load json config
402+
std::string configPath = std::string(crashGamePath) + "/addons/accelerator_local/config.json";
403+
std::ifstream configFile(configPath);
404+
if (configFile.is_open()) {
405+
nlohmann::json config;
406+
configFile >> config;
407+
configFile.close();
408+
409+
if (config.contains("MinidumpAccountSteamId64")) {
410+
g_UserId = config["MinidumpAccountSteamId64"];
411+
}
412+
}
413+
else {
414+
nlohmann::json config;
415+
config["MinidumpAccountSteamId64"] = "";
416+
417+
std::ofstream configFile(configPath);
418+
if (configFile.is_open()) {
419+
configFile << config.dump(2);
420+
configFile.close();
421+
}
422+
}
423+
}
424+
286425
bool AcceleratorCS2::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool late)
287426
{
288427
PLUGIN_SAVEVARS();
@@ -324,6 +463,12 @@ bool AcceleratorCS2::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen
324463
if (late)
325464
StartupServer({}, nullptr, nullptr);
326465

466+
LoadServerId();
467+
LoadConfig();
468+
469+
ConMsg("Start accelerator uploader thread\n");
470+
new std::thread(UploadThread);
471+
327472
return true;
328473
}
329474

extension.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef _INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_
2-
#define _INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_
1+
#pragma once
32
#include <ISmmPlugin.h>
43
#include <igameevents.h>
54
#include <sh_vector.h>
@@ -22,5 +21,4 @@ class AcceleratorCS2 : public ISmmPlugin, public IMetamodListener
2221
private: // Hooks
2322
void GameFrame(bool simulating, bool bFirstTick, bool bLastTick);
2423
void StartupServer(const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*);
25-
};
26-
#endif //_INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_
24+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/src/common/windows/http_upload.cc b/src/common/windows/http_upload.cc
2+
index bd48a233..cd12a24e 100644
3+
--- a/src/common/windows/http_upload.cc
4+
+++ b/src/common/windows/http_upload.cc
5+
@@ -427,7 +427,7 @@ namespace {
6+
return false;
7+
}
8+
}
9+
- request_body->append("--" + boundary_str + "--\r\n");
10+
+ request_body->append("\r\n--" + boundary_str + "--\r\n");
11+
return true;
12+
}
13+
}

premake/breakpad.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ project "breakpad-client"
133133
path.join(breakpadPath, "common", "linux", "guid_creator.cc"),
134134
path.join(breakpadPath, "common", "linux", "linux_libc_support.cc"),
135135
path.join(breakpadPath, "common", "linux", "memory_mapped_file.cc"),
136-
path.join(breakpadPath, "common", "linux", "safe_readlink.cc")
136+
path.join(breakpadPath, "common", "linux", "safe_readlink.cc"),
137+
path.join(breakpadPath, "common", "linux", "http_upload.cc")
137138
}
138139

139140
includedirs {
@@ -147,13 +148,16 @@ project "breakpad-client"
147148
path.join(breakpadPath, "client", "windows", "crash_generation", "crash_generation_server.cc"),
148149
path.join(breakpadPath, "client", "windows", "crash_generation", "minidump_generator.cc"),
149150
path.join(breakpadPath, "client", "windows", "handler", "exception_handler.cc"),
150-
path.join(breakpadPath, "common", "windows", "guid_string.cc")
151+
path.join(breakpadPath, "common", "windows", "guid_string.cc"),
152+
path.join(breakpadPath, "common", "windows", "http_upload.cc")
151153
}
152154

153155
includedirs {
154156
path.join(_MAIN_SCRIPT_DIR, "breakpad-config", "windows")
155157
}
156158

159+
links "wininet"
160+
157161
filter {}
158162

159163
project "libdisasm"

0 commit comments

Comments
 (0)