From 3d0d5e9e4c2b7db59a7c7e608f19036cc4cf12c4 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 31 Jul 2021 20:19:35 +0200 Subject: [PATCH] minor fixes, version bump --- include/Common.h | 2 +- include/TConfig.h | 4 ++-- src/TNetwork.cpp | 28 +++++++++++++++++++--------- src/TResourceManager.cpp | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/Common.h b/include/Common.h index a6267ffd..76d5012a 100644 --- a/include/Common.h +++ b/include/Common.h @@ -50,7 +50,7 @@ class Application final { // Causes all threads to finish up and exit gracefull gracefully static void GracefullyShutdown(); static TConsole& Console() { return *mConsole; } - static std::string ServerVersion() { return "2.1.4"; } + static std::string ServerVersion() { return "2.2.0"; } static std::string ClientVersion() { return "2.0"; } static std::string PPS() { return mPPS; } static void SetPPS(std::string NewPPS) { mPPS = NewPPS; } diff --git a/include/TConfig.h b/include/TConfig.h index 8d59fcc3..ffb2b53a 100644 --- a/include/TConfig.h +++ b/include/TConfig.h @@ -8,13 +8,13 @@ class TConfig { public: explicit TConfig(); - bool Failed() const { return mFailed; } + [[nodiscard]] bool Failed() const { return mFailed; } private: void CreateConfigFile(std::string_view name); void ParseFromFile(std::string_view name); void PrintDebug(); - + void ParseOldFormat(); bool mFailed { false }; diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index dc4dfd62..5dbb640d 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -702,19 +702,29 @@ void TNetwork::Parse(TClient& c, const std::string& Packet) { } } -void TNetwork::SendFile(TClient& c, const std::string& Name) { - info(c.GetName() + " requesting : " + Name.substr(Name.find_last_of('/'))); +void TNetwork::SendFile(TClient& c, const std::string& UnsafeName) { + info(c.GetName() + " requesting : " + UnsafeName.substr(UnsafeName.find_last_of('/'))); - if (!std::filesystem::exists(Name)) { + if (!fs::path(UnsafeName).has_filename()) { if (!TCPSend(c, "CO")) { // TODO: handle } - warn("File " + Name + " could not be accessed!"); + warn("File " + UnsafeName + " is not a file!"); return; - } else { - if (!TCPSend(c, "AG")) { + } + auto FileName = fs::path(UnsafeName).filename().string(); + FileName = Application::Settings.Resource + "/Client/" + FileName; + + if (!std::filesystem::exists(FileName)) { + if (!TCPSend(c, "CO")) { // TODO: handle } + warn("File " + UnsafeName + " could not be accessed!"); + return; + } + + if (!TCPSend(c, "AG")) { + // TODO: handle } ///Wait for connections @@ -731,14 +741,14 @@ void TNetwork::SendFile(TClient& c, const std::string& Name) { return; } - size_t Size = size_t(std::filesystem::file_size(Name)), MSize = Size / 2; + size_t Size = size_t(std::filesystem::file_size(FileName)), MSize = Size / 2; std::thread SplitThreads[2] { std::thread([&] { - SplitLoad(c, 0, MSize, false, Name); + SplitLoad(c, 0, MSize, false, FileName); }), std::thread([&] { - SplitLoad(c, MSize, Size, true, Name); + SplitLoad(c, MSize, Size, true, FileName); }) }; diff --git a/src/TResourceManager.cpp b/src/TResourceManager.cpp index 862c27aa..69665785 100644 --- a/src/TResourceManager.cpp +++ b/src/TResourceManager.cpp @@ -19,7 +19,7 @@ TResourceManager::TResourceManager() { ++i; File = File.substr(i,pos-i); } - mTrimmedList += File + ';'; + mTrimmedList += "/" + fs::path(File).filename().string() + ';'; mFileSizes += std::to_string(size_t(fs::file_size(entry.path()))) + ';'; mMaxModSize += size_t(fs::file_size(entry.path())); mModsLoaded++;