From 62f319a90e8cee2ad0aaea48dfc5492d78e5afa1 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 20 Dec 2020 16:04:25 +0200 Subject: [PATCH] fixed mod download --- src/Logger.cpp | 6 ++++-- src/Network/Resources.cpp | 31 +++++++++++++++++-------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Logger.cpp b/src/Logger.cpp index 85cf932..4a5cbbd 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -1,5 +1,7 @@ -Copyright (c) 2020 BeamMP-Server & BeamMP-Launcher Developers. -BeamMP Server code is not in the public domain and is not free software. One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries. Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository. +// Copyright (c) 2019-present Anonymous275. +// BeamMP Launcher code is not in the public domain and is not free software. +// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries. +// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository. /// /// Created by Anonymous275 on 7/17/2020 /// diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index 711107c..b8b7082 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -118,11 +118,11 @@ void AsyncUpdate(uint64_t& Rcv,uint64_t Size,const std::string& Name){ }while(!Terminate && Rcv < Size); } -std::string TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){ +char* TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){ if(Sock == -1){ Terminate = true; UUl("Invalid Socket"); - return ""; + return nullptr; } char* File = new char[Size]; uint64_t Rcv = 0; @@ -137,14 +137,12 @@ std::string TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){ KillSocket(Sock); Terminate = true; delete[] File; - return ""; + return nullptr; } Rcv += Temp; GRcv += Temp; }while(Rcv < Size && !Terminate); - std::string Ret = std::string(File,Size); - delete[] File; - return Ret; + return File; } void MultiKill(SOCKET Sock,SOCKET Sock1){ KillSocket(Sock1); @@ -182,29 +180,34 @@ std::string MultiDownload(SOCKET MSock,SOCKET DSock, uint64_t Size, const std::s std::thread Au(AsyncUpdate,std::ref(GRcv),Size,Name); Au.detach(); - std::packaged_task task([&] { return TCPRcvRaw(MSock,GRcv,MSize); }); - std::future f1 = task.get_future(); + std::packaged_task task([&] { return TCPRcvRaw(MSock,GRcv,MSize); }); + std::future f1 = task.get_future(); std::thread Dt(std::move(task)); Dt.detach(); - std::string Ret = TCPRcvRaw(DSock,GRcv,DSize); + char* DData = TCPRcvRaw(DSock,GRcv,DSize); - if(Ret.empty()){ + if(!DData){ MultiKill(MSock,DSock); return ""; } f1.wait(); - std::string Temp = f1.get(); + char* MData = f1.get(); - if(Temp.empty()){ + if(!MData){ MultiKill(MSock,DSock); return ""; } if(Au.joinable())Au.join(); + std::string Ret(Size,0); + memcpy_s(&Ret[0],MSize,MData,MSize); + delete[]MData; + + memcpy_s(&Ret[MSize],DSize,DData,DSize); + delete[]DData; - Ret += Temp; return Ret; } @@ -286,7 +289,7 @@ void SyncResources(SOCKET Sock){ std::ofstream LFS; LFS.open(a.c_str(), std::ios_base::app | std::ios::binary); if (LFS.is_open()) { - LFS.write(Data.c_str(), Data.size()); + LFS.write(&Data[0], Data.size()); LFS.close(); }