Fix download size int casting (#244)

Fixed an int casting issue that caused weird download failures, improve
error handling and added missing return statement which unintentionally
forwarded data to the game (without the socket even being there)

---

By creating this pull request, I understand that code that is AI
generated or otherwise automatically generated may be rejected without
further discussion.
I declare that I fully understand all code I pushed into this PR, and
wrote all this code myself and own the rights to this code.
This commit is contained in:
Tixx
2026-08-02 13:54:54 +02:00
committed by GitHub
2 changed files with 13 additions and 2 deletions
+1
View File
@@ -199,6 +199,7 @@ void ParserAsync(std::string_view Data) {
return; return;
case 'U': case 'U':
magic = Data.substr(1); magic = Data.substr(1);
return;
default: default:
break; break;
} }
+12 -2
View File
@@ -163,7 +163,12 @@ std::vector<char> TCPRcvRaw(SOCKET Sock, uint64_t& GRcv, uint64_t Size) {
int i = 0; int i = 0;
do { do {
// receive at most some MB at a time // receive at most some MB at a time
int Len = std::min(int(Size - Rcv), 1 * 1024 * 1024); uint64_t Len = std::min<uint64_t>((Size - Rcv), 1 * 1024 * 1024);
if (Len == 0) {
error("Download size miscalculation");
break;
}
int Temp = RecvWaitAll(Sock, &File[Rcv], Len); int Temp = RecvWaitAll(Sock, &File[Rcv], Len);
if (Temp == -1 || Temp == 0) { if (Temp == -1 || Temp == 0) {
debug("Recv returned: " + std::to_string(Temp)); debug("Recv returned: " + std::to_string(Temp));
@@ -579,7 +584,12 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
} }
#endif #endif
fs::copy_file(PathToSaveTo, std::filesystem::path(GetGamePath()) / "mods/multiplayer" / FName, fs::copy_options::overwrite_existing); std::error_code ec;
fs::copy_file(PathToSaveTo, std::filesystem::path(GetGamePath()) / "mods/multiplayer" / FName, fs::copy_options::overwrite_existing, ec);
if (ec) {
error(beammp_wide("Error in copy_file during download of ") + beammp_fs_string(PathToSaveTo) + beammp_wide(": ") + Utils::ToWString(ec.message()));
break;
}
UpdateModUsage(FName); UpdateModUsage(FName);
} }
WaitForConfirm(); WaitForConfirm();