From 06e7f86a42416065398827e635d2b55711fb736c Mon Sep 17 00:00:00 2001 From: Edo Date: Mon, 9 Jan 2023 08:37:56 +0000 Subject: [PATCH] [Download]: Poll every 1000 msec, fix bug (#707) --- src/Components/Modules/Bots.cpp | 8 +++++ src/Components/Modules/Download.cpp | 50 ++++++----------------------- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index 3eb92273..40d37b15 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -3,6 +3,10 @@ #include "GSC/Script.hpp" +// From Quake-III +#define ANGLE2SHORT(x) ((int)((x) * (USHRT_MAX + 1) / 360.0f) & USHRT_MAX) +#define SHORT2ANGLE(x) ((x)* (360.0f / (USHRT_MAX + 1))) + namespace Components { std::vector Bots::BotNames; @@ -280,6 +284,10 @@ namespace Components userCmd.rightmove = g_botai[entnum].right; userCmd.weapon = g_botai[entnum].weapon; + userCmd.angles[0] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[0] - cl->gentity->client->ps.delta_angles[0])); + userCmd.angles[1] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[1] - cl->gentity->client->ps.delta_angles[1])); + userCmd.angles[2] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[2] - cl->gentity->client->ps.delta_angles[2])); + Game::SV_ClientThink(cl, &userCmd); } diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index 4b70a727..d4e53ffb 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -604,44 +604,7 @@ namespace Components } } - static void HTMLHandler(mg_connection* c, mg_http_message* hm) - { - auto url = "html" + std::string(hm->uri.ptr, hm->uri.len); - FileSystem::File file; - - if (url.ends_with("/")) - { - url.append("index.html"); - file = FileSystem::File(url); - } - else - { - file = FileSystem::File(url); - if (!file.exists()) - { - url.append("/index.html"); - file = FileSystem::File(url); - } - } - - const auto mimeType = Utils::GetMimeType(url); - - if (file.exists()) - { - mg_printf(c, "%s", "HTTP/1.1 200 OK\r\n"); - mg_printf(c, "Content-Type: %s\r\n", mimeType.data()); - mg_printf(c, "Content-Length: %d\r\n", static_cast(file.getBuffer().size())); - mg_printf(c, "%s", "Connection: close\r\n"); - mg_printf(c, "%s", "\r\n"); - mg_send(c, file.getBuffer().data(), file.getBuffer().size()); - } - else - { - mg_http_reply(c, 404, "Content-Type: text/html\r\n", "404 - Not Found"); - } - } - - static void EventHandler(mg_connection* c, int ev, void* ev_data, [[maybe_unused]] void* fn_data) + static void EventHandler(mg_connection* c, const int ev, void* ev_data, [[maybe_unused]] void* fn_data) { if (ev != MG_EV_HTTP_MSG) { @@ -649,7 +612,7 @@ namespace Components } auto* hm = static_cast(ev_data); - std::string url(hm->uri.ptr, hm->uri.len); + const std::string url(hm->uri.ptr, hm->uri.len); if (url.starts_with("/info")) { @@ -672,8 +635,12 @@ namespace Components } else { - HTMLHandler(c, hm); + mg_http_serve_opts opts = { .root_dir = "iw4x/html" }; // Serve local dir + mg_http_serve_dir(c, hm, &opts); } + + c->is_resp = FALSE; // This is important, the lack of this line of code will make the server die (in-game) + c->is_draining = TRUE; } #pragma endregion @@ -694,6 +661,7 @@ namespace Components if (!nc) { Logger::PrintError(Game::CON_CHANNEL_ERROR, "Failed to bind TCP socket, mod download won't work!\n"); + Terminate = true; } }); @@ -705,7 +673,7 @@ namespace Components while (!Terminate) { - mg_mgr_poll(&Mgr, 100); + mg_mgr_poll(&Mgr, 1000); } }); }