262 lines
18 KiB
C++
262 lines
18 KiB
C++
// OctoReport.exe - player bug report window (owner 2026-11-25, task #62). Lives in the client root next to
|
|
// OctoUpdater.exe. The player writes what happened; the tool attaches the logs we need, removes the account name and
|
|
// the Windows user name from them, packs everything into one zstd-compressed report and sends it by HTTPS POST to
|
|
// <url>report/ (url from OctoUpdater.cfg). The server only stores it (ops/patchserver/reporter/report_inbox.py).
|
|
// "Save copy" writes the same report file to the Desktop for sending by hand.
|
|
//
|
|
// Report file: "OCTOREPORT 1\n" + zstd( "TEXT <n>\n" <n bytes UTF-8> then per file "FILE <n> <relative path>\n" <n bytes> ).
|
|
// Read it with ops/patchserver/reporter/read_report.py.
|
|
#define UNICODE
|
|
#define _UNICODE
|
|
#include <windows.h>
|
|
#include <winhttp.h>
|
|
#include <shlobj.h>
|
|
#include <zstd.h>
|
|
#include "../smart_app_control.hpp"
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <map>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
namespace fs = std::filesystem;
|
|
|
|
static fs::path g_root; // client root (folder holding _classic_beta_)
|
|
static std::map<std::string, std::string> g_cfg;
|
|
static const uint64_t kFileCap = 4u << 20, kTotalCap = 60u << 20, kUploadCap = 24u << 20;
|
|
|
|
static std::wstring widen(const std::string& s) {
|
|
int n = MultiByteToWideChar(CP_UTF8, 0, s.data(), int(s.size()), nullptr, 0); std::wstring w(n, 0);
|
|
MultiByteToWideChar(CP_UTF8, 0, s.data(), int(s.size()), w.data(), n); return w;
|
|
}
|
|
static std::string narrow(const std::wstring& w) {
|
|
int n = WideCharToMultiByte(CP_UTF8, 0, w.data(), int(w.size()), nullptr, 0, nullptr, nullptr); std::string s(n, 0);
|
|
WideCharToMultiByte(CP_UTF8, 0, w.data(), int(w.size()), s.data(), n, nullptr, nullptr); return s;
|
|
}
|
|
static std::string read_tail(const fs::path& p, uint64_t cap) {
|
|
std::ifstream f(p, std::ios::binary); if (!f) return {};
|
|
f.seekg(0, std::ios::end); uint64_t n = uint64_t(f.tellg()); uint64_t from = n > cap ? n - cap : 0;
|
|
f.seekg(std::streamoff(from)); std::string s(size_t(n - from), '\0'); f.read(s.data(), std::streamsize(s.size()));
|
|
if (from) s = "[... first " + std::to_string(from) + " bytes left out ...]\n" + s;
|
|
return s;
|
|
}
|
|
|
|
// ---- privacy: the account name (WTF/Config.wtf accountName / accountList) and the Windows user name never leave the PC
|
|
static std::vector<std::pair<std::string, std::string>> g_scrub;
|
|
static void add_scrub(std::string v, const char* as) {
|
|
while (!v.empty() && (v.back() == '"' || v.back() == '\r' || v.back() == ' ')) v.pop_back();
|
|
while (!v.empty() && (v.front() == '"' || v.front() == ' ')) v.erase(v.begin());
|
|
if (v.size() >= 3) g_scrub.push_back({v, as});
|
|
}
|
|
static void load_scrub() {
|
|
std::ifstream f(g_root / "_classic_beta_" / "WTF" / "Config.wtf"); std::string l;
|
|
while (std::getline(f, l)) {
|
|
for (const char* key : {"SET accountName ", "SET accountList ", "SET lastAccountName "})
|
|
if (l.rfind(key, 0) == 0) {
|
|
std::string v = l.substr(strlen(key)); std::string part; std::istringstream in(v);
|
|
while (std::getline(in, part, '|')) { if (!part.empty() && part[0] == '!') part.erase(0, 1); add_scrub(part, "<account>"); }
|
|
}
|
|
}
|
|
wchar_t u[256]; DWORD n = 256; if (GetUserNameW(u, &n) && n > 1) add_scrub(narrow(std::wstring(u, n - 1)), "<user>");
|
|
std::sort(g_scrub.begin(), g_scrub.end(), [](auto& a, auto& b) { return a.first.size() > b.first.size(); });
|
|
}
|
|
static std::string lower(std::string s) { for (auto& c : s) c = char(tolower((unsigned char)c)); return s; }
|
|
static void scrub(std::string& s) {
|
|
for (auto& [v, as] : g_scrub) {
|
|
std::string ls = lower(s), lv = lower(v); size_t at = 0;
|
|
while ((at = ls.find(lv, at)) != std::string::npos) { s.replace(at, v.size(), as); ls.replace(at, v.size(), as); at += as.size(); }
|
|
}
|
|
// e-mail style logins: anything@host.tld
|
|
for (size_t at = s.find('@'); at != std::string::npos; at = s.find('@', at + 1)) {
|
|
size_t a = at, b = at + 1;
|
|
while (a > 0 && (isalnum((unsigned char)s[a - 1]) || strchr("._+-", s[a - 1]))) --a;
|
|
while (b < s.size() && (isalnum((unsigned char)s[b]) || strchr(".-", s[b]))) ++b;
|
|
if (a < at && s.substr(at + 1, b - at - 1).find('.') != std::string::npos) { s.replace(a, b - a, "<email>"); at = a; }
|
|
}
|
|
}
|
|
|
|
// ---- what gets attached
|
|
struct Item { std::string rel; fs::path path; uint64_t size; };
|
|
static std::vector<Item> collect() {
|
|
std::vector<Item> out; std::error_code ec; fs::path cb = g_root / "_classic_beta_";
|
|
auto add = [&](const fs::path& p) {
|
|
if (!fs::is_regular_file(p, ec)) return;
|
|
out.push_back({fs::relative(p, g_root, ec).generic_string(), p, std::min<uint64_t>(fs::file_size(p, ec), kFileCap)});
|
|
};
|
|
for (const char* n : {"Gateway.log", "GatewayRequests.log", "Connection.log", "Client.log", "WowConnection.log", "Hotfix.log", "taint.log", "gx.log", "Tact.log"}) add(cb / "Logs" / n);
|
|
// newest gateway Diagnostics session
|
|
fs::path newest; fs::file_time_type t{};
|
|
if (fs::is_directory(cb / "Diagnostics", ec))
|
|
for (auto& d : fs::directory_iterator(cb / "Diagnostics", ec)) if (d.is_directory(ec) && d.last_write_time(ec) > t) { t = d.last_write_time(ec); newest = d.path(); }
|
|
if (!newest.empty()) for (auto& f : fs::directory_iterator(newest, ec)) add(f.path());
|
|
// newest client error reports (text only; crash dumps are too large)
|
|
std::vector<fs::directory_entry> errs;
|
|
if (fs::is_directory(cb / "Errors", ec)) for (auto& e : fs::directory_iterator(cb / "Errors", ec)) if (e.path().extension() == ".txt") errs.push_back(e);
|
|
std::sort(errs.begin(), errs.end(), [&](auto& a, auto& b) { return a.last_write_time(ec) > b.last_write_time(ec); });
|
|
for (size_t i = 0; i < errs.size() && i < 6; ++i) add(errs[i].path());
|
|
add(g_root / "_patch" / "updater.log"); add(g_root / "_patch" / "applied.txt");
|
|
uint64_t total = 0; std::vector<Item> kept;
|
|
for (auto& i : out) if (total + i.size <= kTotalCap) { total += i.size; kept.push_back(i); }
|
|
return kept;
|
|
}
|
|
|
|
static std::string build_report(const std::string& text, const std::vector<Item>& items) {
|
|
std::string raw = "TEXT " + std::to_string(text.size()) + "\n" + text;
|
|
for (auto& i : items) { std::string d = read_tail(i.path, kFileCap); scrub(d); raw += "FILE " + std::to_string(d.size()) + " " + i.rel + "\n" + d; }
|
|
std::string z(ZSTD_compressBound(raw.size()), '\0');
|
|
size_t n = ZSTD_compress(z.data(), z.size(), raw.data(), raw.size(), 12);
|
|
if (ZSTD_isError(n)) return {};
|
|
z.resize(n); return "OCTOREPORT 1\n" + z;
|
|
}
|
|
|
|
// ---- upload: POST <url>report/ ; the server answers with the report id
|
|
static std::string upload(const std::string& body, std::string& err) {
|
|
std::wstring u = widen(g_cfg.count("url") ? g_cfg["url"] : "https://dl.hybridgateway.eu/"); if (u.back() != L'/') u += L'/'; u += L"report/";
|
|
URL_COMPONENTS c{}; c.dwStructSize = sizeof c; wchar_t host[256], path[1024];
|
|
c.lpszHostName = host; c.dwHostNameLength = 256; c.lpszUrlPath = path; c.dwUrlPathLength = 1024;
|
|
if (!WinHttpCrackUrl(u.c_str(), 0, 0, &c)) { err = "bad report address"; return {}; }
|
|
HINTERNET s = WinHttpOpen(L"OctoReport/1", WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, nullptr, nullptr, 0);
|
|
if (!s) s = WinHttpOpen(L"OctoReport/1", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, nullptr, nullptr, 0);
|
|
HINTERNET k = s ? WinHttpConnect(s, std::wstring(host, c.dwHostNameLength).c_str(), c.nPort, 0) : nullptr;
|
|
HINTERNET r = k ? WinHttpOpenRequest(k, L"POST", std::wstring(path, c.dwUrlPathLength).c_str(), nullptr, nullptr, nullptr, c.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0) : nullptr;
|
|
std::string reply; DWORD code = 0, n = sizeof code;
|
|
if (r) WinHttpSetTimeouts(r, 30000, 30000, 120000, 120000);
|
|
const wchar_t* hdr = L"Content-Type: application/octet-stream";
|
|
if (r && WinHttpSendRequest(r, hdr, DWORD(-1L), (LPVOID)body.data(), DWORD(body.size()), DWORD(body.size()), 0) && WinHttpReceiveResponse(r, nullptr)) {
|
|
WinHttpQueryHeaders(r, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, nullptr, &code, &n, nullptr);
|
|
char b[512]; DWORD got = 0; while (WinHttpReadData(r, b, sizeof b, &got) && got && reply.size() < 4096) reply.append(b, got);
|
|
} else err = "cannot reach the report server (error " + std::to_string(GetLastError()) + ")";
|
|
if (r) WinHttpCloseHandle(r); if (k) WinHttpCloseHandle(k); if (s) WinHttpCloseHandle(s);
|
|
if (err.empty() && code != 200) err = code == 429 ? "too many reports from this connection - please try again in an hour" : "report server answered HTTP " + std::to_string(code);
|
|
while (!reply.empty() && (reply.back() == '\n' || reply.back() == '\r')) reply.pop_back();
|
|
return err.empty() ? reply : std::string();
|
|
}
|
|
|
|
// ---- window
|
|
enum { ID_CHAR = 101, ID_TEXT, ID_LIST, ID_SEND, ID_SAVE, ID_CLOSE, ID_SAC_HELP };
|
|
static HWND g_char, g_text, g_list, g_send, g_save, g_status;
|
|
static std::vector<Item> g_items;
|
|
static HFONT g_font;
|
|
static HWND g_sac_help;
|
|
static bool g_log_has_sac_error;
|
|
|
|
static bool attached_sac_error() {
|
|
for (const auto& file : g_items) {
|
|
if (file.rel.starts_with("_classic_beta_/Errors/") ||
|
|
file.rel == "_classic_beta_/Logs/Gateway.log" || file.rel == "_classic_beta_/Logs/Client.log" ||
|
|
file.rel == "_patch/updater.log") {
|
|
if (smart_app_control::mentions_error(lower(read_tail(file.path, kFileCap)))) return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static void update_error_hint() {
|
|
if (!g_sac_help) return;
|
|
std::wstring text(GetWindowTextLengthW(g_text) + 1, L'\0');
|
|
GetWindowTextW(g_text, text.data(), int(text.size()));
|
|
const bool show = g_log_has_sac_error || smart_app_control::mentions_error(lower(narrow(text)));
|
|
ShowWindow(g_sac_help, show ? SW_SHOW : SW_HIDE);
|
|
}
|
|
|
|
static std::string report_text() {
|
|
auto get = [](HWND h) { int n = GetWindowTextLengthW(h); std::wstring w(n, 0); GetWindowTextW(h, w.data(), n + 1); return narrow(w); };
|
|
std::string who = get(g_char), what = get(g_text);
|
|
SYSTEMTIME st; GetSystemTime(&st); char when[64];
|
|
snprintf(when, sizeof when, "%04d-%02d-%02d %02d:%02d:%02dZ", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
|
|
OSVERSIONINFOW v{}; v.dwOSVersionInfoSize = sizeof v;
|
|
using RtlGetVersion_t = LONG(WINAPI*)(OSVERSIONINFOW*);
|
|
if (auto f = (RtlGetVersion_t)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion")) f(&v);
|
|
bool wine = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "wine_get_version") != nullptr;
|
|
std::string s = "Character: " + who + "\nWritten: " + std::string(when) + "\nWindows: " + std::to_string(v.dwMajorVersion) + "." +
|
|
std::to_string(v.dwMinorVersion) + "." + std::to_string(v.dwBuildNumber) + (wine ? " (Wine/Proton)" : "") + "\n\n" + what + "\n";
|
|
scrub(s); return s;
|
|
}
|
|
static bool have_text() { return GetWindowTextLengthW(g_text) >= 10; }
|
|
static void set_status(const std::wstring& w) { SetWindowTextW(g_status, w.c_str()); }
|
|
|
|
static void on_send(HWND w, bool save_only) {
|
|
if (!save_only && !have_text()) { MessageBoxW(w, L"Please describe what happened (a few words at least).", L"OctoWoW bug report", MB_ICONINFORMATION); return; }
|
|
set_status(L"Packing logs..."); UpdateWindow(w);
|
|
std::string body = build_report(report_text(), g_items);
|
|
if (body.empty()) { set_status(L"Could not pack the report."); return; }
|
|
if (save_only || body.size() > kUploadCap) {
|
|
wchar_t* desk = nullptr; SHGetKnownFolderPath(FOLDERID_Desktop, 0, nullptr, &desk);
|
|
SYSTEMTIME st; GetLocalTime(&st); wchar_t name[64];
|
|
swprintf(name, 64, L"OctoWoW-report-%04d%02d%02d-%02d%02d.octoreport", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute);
|
|
fs::path p = fs::path(desk ? desk : g_root.wstring()) / name; CoTaskMemFree(desk);
|
|
std::ofstream(p, std::ios::binary).write(body.data(), std::streamsize(body.size()));
|
|
std::wstring m = (save_only ? L"Saved to " : L"The report is too large to send; saved to ") + p.wstring() + L"\nSend this file to the OctoWoW team.";
|
|
set_status(L"Saved."); MessageBoxW(w, m.c_str(), L"OctoWoW bug report", MB_ICONINFORMATION); return;
|
|
}
|
|
set_status(L"Sending (" + std::to_wstring(body.size() / 1024) + L" KB)..."); EnableWindow(g_send, FALSE); UpdateWindow(w);
|
|
std::string err, id = upload(body, err); EnableWindow(g_send, TRUE);
|
|
if (!err.empty()) { set_status(L"Not sent."); MessageBoxW(w, (widen(err) + L"\n\nYou can use \"Save copy\" and send the file by hand.").c_str(), L"OctoWoW bug report", MB_ICONWARNING); return; }
|
|
set_status(L"Sent. Report " + widen(id));
|
|
MessageBoxW(w, (L"Thank you! Your report was sent.\nReport number: " + widen(id) + L"\nMention this number if you talk to us about it.").c_str(), L"OctoWoW bug report", MB_ICONINFORMATION);
|
|
SetWindowTextW(g_text, L"");
|
|
}
|
|
|
|
static LRESULT CALLBACK proc(HWND w, UINT m, WPARAM wp, LPARAM lp) {
|
|
switch (m) {
|
|
case WM_CREATE: {
|
|
auto mk = [&](const wchar_t* cls, const wchar_t* txt, DWORD st, int x, int y, int cx, int cy, int id) {
|
|
HWND h = CreateWindowExW(cls == std::wstring(L"EDIT") || cls == std::wstring(L"LISTBOX") ? WS_EX_CLIENTEDGE : 0, cls, txt, WS_CHILD | WS_VISIBLE | st, x, y, cx, cy, w, (HMENU)(INT_PTR)id, nullptr, nullptr);
|
|
SendMessageW(h, WM_SETFONT, (WPARAM)g_font, TRUE); return h;
|
|
};
|
|
mk(L"STATIC", L"Character name (optional):", 0, 12, 12, 200, 20, 0);
|
|
g_char = mk(L"EDIT", L"", WS_TABSTOP | ES_AUTOHSCROLL, 215, 9, 203, 24, ID_CHAR);
|
|
g_sac_help = mk(L"BUTTON", L"0xC0E90002 help", WS_TABSTOP, 424, 8, 148, 26, ID_SAC_HELP);
|
|
mk(L"STATIC", L"What happened? Where were you, what did you do, what did you expect?", 0, 12, 44, 560, 20, 0);
|
|
g_text = mk(L"EDIT", L"", WS_TABSTOP | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN, 12, 66, 560, 170, ID_TEXT);
|
|
SendMessageW(g_text, EM_SETLIMITTEXT, 20000, 0);
|
|
mk(L"STATIC", L"Attached automatically (account and Windows user names are removed):", 0, 12, 246, 560, 20, 0);
|
|
g_list = mk(L"LISTBOX", L"", WS_VSCROLL | LBS_NOSEL, 12, 268, 560, 130, ID_LIST);
|
|
for (auto& i : g_items) SendMessageW(g_list, LB_ADDSTRING, 0, (LPARAM)(widen(i.rel) + L" (" + std::to_wstring(std::max<uint64_t>(1, i.size / 1024)) + L" KB)").c_str());
|
|
if (g_items.empty()) SendMessageW(g_list, LB_ADDSTRING, 0, (LPARAM)L"(no log files found)");
|
|
g_status = mk(L"STATIC", L"", 0, 12, 412, 260, 20, 0);
|
|
g_send = mk(L"BUTTON", L"Send report", WS_TABSTOP | BS_DEFPUSHBUTTON, 282, 406, 110, 30, ID_SEND);
|
|
g_save = mk(L"BUTTON", L"Save copy", WS_TABSTOP, 398, 406, 90, 30, ID_SAVE);
|
|
mk(L"BUTTON", L"Close", WS_TABSTOP, 494, 406, 78, 30, ID_CLOSE);
|
|
g_log_has_sac_error = attached_sac_error();
|
|
update_error_hint();
|
|
SetFocus(g_text); return 0;
|
|
}
|
|
case WM_COMMAND:
|
|
if (LOWORD(wp) == ID_TEXT && HIWORD(wp) == EN_CHANGE) update_error_hint();
|
|
else if (LOWORD(wp) == ID_SAC_HELP) smart_app_control::show_help(w, L"Launch error 0xC0E90002 was reported.");
|
|
else if (LOWORD(wp) == ID_SEND) on_send(w, false);
|
|
else if (LOWORD(wp) == ID_SAVE) on_send(w, true);
|
|
else if (LOWORD(wp) == ID_CLOSE) DestroyWindow(w);
|
|
return 0;
|
|
case WM_CTLCOLORSTATIC: SetBkMode((HDC)wp, TRANSPARENT); return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
|
|
case WM_DESTROY: PostQuitMessage(0); return 0;
|
|
}
|
|
return DefWindowProcW(w, m, wp, lp);
|
|
}
|
|
|
|
int WINAPI wWinMain(HINSTANCE inst, HINSTANCE, LPWSTR, int show) {
|
|
wchar_t self[MAX_PATH]; GetModuleFileNameW(nullptr, self, MAX_PATH); g_root = fs::path(self).parent_path();
|
|
{ std::ifstream f(g_root / "OctoUpdater.cfg"); std::string l; while (std::getline(f, l)) { auto e = l.find('='); if (e != std::string::npos) { std::string v = l.substr(e + 1); while (!v.empty() && (v.back() == '\r' || v.back() == ' ')) v.pop_back(); g_cfg[l.substr(0, e)] = v; } } }
|
|
if (!fs::exists(g_root / "_classic_beta_")) { MessageBoxW(nullptr, L"OctoReport.exe must be in the OctoWoW client folder (next to _classic_beta_).", L"OctoWoW bug report", MB_ICONERROR); return 1; }
|
|
CoInitialize(nullptr); load_scrub(); g_items = collect();
|
|
// Test mode (no window): OctoReport.exe --save-to <file> [--send] builds the report from a fixed text.
|
|
int argc = 0; wchar_t** argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
|
if (argc >= 3 && !wcscmp(argv[1], L"--save-to")) {
|
|
std::string body = build_report("Character: test\n\nOctoReport self-test\n", g_items);
|
|
std::ofstream(fs::path(argv[2]), std::ios::binary).write(body.data(), std::streamsize(body.size()));
|
|
if (argc >= 4 && !wcscmp(argv[3], L"--send")) { std::string err, id = upload(body, err); std::ofstream(fs::path(std::wstring(argv[2]) + L".result")) << (err.empty() ? "id " + id : "error " + err) << "\n"; }
|
|
return body.empty() ? 1 : 0;
|
|
}
|
|
NONCLIENTMETRICSW nm{}; nm.cbSize = sizeof nm; SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof nm, &nm, 0); g_font = CreateFontIndirectW(&nm.lfMessageFont);
|
|
WNDCLASSW wc{}; wc.lpfnWndProc = proc; wc.hInstance = inst; wc.lpszClassName = L"OctoReport"; wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
|
wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW); wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION); RegisterClassW(&wc);
|
|
RECT r{0, 0, 584, 448}; DWORD st = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; AdjustWindowRect(&r, st, FALSE);
|
|
HWND w = CreateWindowW(L"OctoReport", L"OctoWoW - Report a bug", st, CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, nullptr, nullptr, inst, nullptr);
|
|
ShowWindow(w, show); MSG msg;
|
|
while (GetMessageW(&msg, nullptr, 0, 0)) { if (!IsDialogMessageW(w, &msg)) { TranslateMessage(&msg); DispatchMessageW(&msg); } }
|
|
return 0;
|
|
}
|