mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-17 00:35:55 +00:00
Vehicle ghost fix, server list fix
This commit is contained in:
parent
7c2871f1b3
commit
a2b6b29ea1
@ -1,40 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 8/25/2020
|
||||
///
|
||||
#pragma once
|
||||
void ServerParser(const std::string& Data);
|
||||
class Buffer{
|
||||
public:
|
||||
void Handle(const std::string& Data){
|
||||
Buf += Data;
|
||||
Manage();
|
||||
}
|
||||
void clear(){
|
||||
Buf.clear();
|
||||
}
|
||||
private:
|
||||
std::string Buf;
|
||||
void Manage(){
|
||||
if(!Buf.empty()){
|
||||
std::string::size_type p;
|
||||
if (Buf.at(0) == '\n'){
|
||||
p = Buf.find('\n',1);
|
||||
if(p != -1){
|
||||
std::string R = Buf.substr(1,p-1);
|
||||
std::string_view B(R.c_str(),R.find(char(0)));
|
||||
ServerParser(B.data());
|
||||
Buf = Buf.substr(p+1);
|
||||
Manage();
|
||||
}
|
||||
}else{
|
||||
p = Buf.find('\n');
|
||||
if(p == -1)Buf.clear();
|
||||
else{
|
||||
Buf = Buf.substr(p);
|
||||
Manage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -3,13 +3,11 @@
|
||||
///
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "Buffer.h"
|
||||
void NetReset();
|
||||
extern long long ping;
|
||||
extern bool Dev;
|
||||
void ClearAll();
|
||||
extern int ClientID;
|
||||
extern Buffer Handler;
|
||||
extern bool ModLoaded;
|
||||
extern bool Terminate;
|
||||
extern int DEFAULT_PORT;
|
||||
|
@ -21,7 +21,7 @@ std::string MStatus;
|
||||
bool once = false;
|
||||
bool ModLoaded;
|
||||
long long ping = -1;
|
||||
Buffer Handler;
|
||||
|
||||
void StartSync(const std::string &Data){
|
||||
std::string IP = GetAddr(Data.substr(1,Data.find(':')-1));
|
||||
if(IP.find('.') == -1){
|
||||
@ -35,7 +35,6 @@ void StartSync(const std::string &Data){
|
||||
TCPTerminate = false;
|
||||
Terminate = false;
|
||||
ConfList->clear();
|
||||
Handler.clear();
|
||||
ping = -1;
|
||||
std::thread GS(TCPGameServer,IP,std::stoi(Data.substr(Data.find(':')+1)));
|
||||
GS.detach();
|
||||
|
@ -6,11 +6,16 @@
|
||||
#include "Security/Enc.h"
|
||||
#include <curl/curl.h>
|
||||
#include <iostream>
|
||||
#include "Logger.h"
|
||||
#include <mutex>
|
||||
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){
|
||||
((std::string*)userp)->append((char*)contents, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
std::string HTTP_REQUEST(const std::string& IP,int port){
|
||||
static std::mutex Lock;
|
||||
Lock.lock();
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
std::string readBuffer;
|
||||
@ -27,6 +32,7 @@ std::string HTTP_REQUEST(const std::string& IP,int port){
|
||||
if(res != CURLE_OK)return "-1";
|
||||
}
|
||||
curl_global_cleanup();
|
||||
Lock.unlock();
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,6 @@ void SyncResources(SOCKET Sock){
|
||||
LFS.write(File, Recv);
|
||||
LFS.close();
|
||||
}
|
||||
ZeroMemory(File,Size);
|
||||
delete[] File;
|
||||
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate);
|
||||
if(!Terminate)fs::copy_file(a,Sec("BeamNG/mods")+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing);
|
||||
|
@ -106,30 +106,11 @@ int SplitID(){
|
||||
}
|
||||
void SendLarge(std::string Data){
|
||||
Data = Data.substr(0,Data.find(char(0)));
|
||||
int ID = PackID();
|
||||
std::string Packet;
|
||||
if(Data.length() > 1000){
|
||||
std::string pckt = Data;
|
||||
int S = 1,Split = int(ceil(float(pckt.length()) / 1000));
|
||||
int SID = SplitID();
|
||||
while(pckt.length() > 1000){
|
||||
Packet = "SC|"+std::to_string(S)+"|"+std::to_string(Split)+"|"+std::to_string(ID)+"|"+
|
||||
std::to_string(SID)+"|"+pckt.substr(0,1000);
|
||||
BigDataAcks.insert(new PacketData{ID,Packet,1});
|
||||
UDPSend(Packet);
|
||||
pckt = pckt.substr(1000);
|
||||
S++;
|
||||
ID = PackID();
|
||||
}
|
||||
Packet = "SC|"+std::to_string(S)+"|"+std::to_string(Split)+"|"+
|
||||
std::to_string(ID)+"|"+std::to_string(SID)+"|"+pckt;
|
||||
BigDataAcks.insert(new PacketData{ID,Packet,1});
|
||||
UDPSend(Packet);
|
||||
}else{
|
||||
Packet = "BD:" + std::to_string(ID) + ":" + Data;
|
||||
BigDataAcks.insert(new PacketData{ID,Packet,1});
|
||||
UDPSend(Packet);
|
||||
if(Data.length() > 400){
|
||||
std::string CMP(Comp(Data));
|
||||
Data = "ABG:" + CMP;
|
||||
}
|
||||
TCPSend(Data);
|
||||
}
|
||||
std::array<int, 100> HandledIDs = {-1};
|
||||
int APos = 0;
|
||||
|
@ -6,52 +6,71 @@
|
||||
#include "Logger.h"
|
||||
#include <iostream>
|
||||
#include <WS2tcpip.h>
|
||||
#include <Zlib/Compressor.h>
|
||||
#include "Security/Enc.h"
|
||||
#include "Network/network.h"
|
||||
|
||||
SOCKET TCPSock;
|
||||
bool CheckBytes(int32_t Bytes){
|
||||
if (Bytes == 0){
|
||||
debug(Sec("(TCP) Connection closing..."));
|
||||
Terminate = true;
|
||||
return false;
|
||||
}else if (Bytes < 0) {
|
||||
debug(Sec("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
closesocket(TCPSock);
|
||||
Terminate = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void TCPSend(const std::string&Data){
|
||||
if(TCPSock == -1){
|
||||
Terminate = true;
|
||||
return;
|
||||
}
|
||||
std::string Send = "\n" + Data.substr(0,Data.find(char(0))) + "\n";
|
||||
size_t Sent = send(TCPSock, Send.c_str(), int(Send.size()), 0);
|
||||
if (Sent == 0){
|
||||
debug(Sec("(TCP) Connection closing..."));
|
||||
Terminate = true;
|
||||
return;
|
||||
}
|
||||
else if (Sent < 0) {
|
||||
debug(Sec("(TCP) send failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
closesocket(TCPSock);
|
||||
Terminate = true;
|
||||
return;
|
||||
}
|
||||
auto Size = int32_t(Data.size());
|
||||
std::string Send(4,0);
|
||||
memcpy(&Send[0],&Size,sizeof(Size));
|
||||
Send += Data;
|
||||
Size = int32_t(Send.size());
|
||||
int32_t Sent = 0,Temp;
|
||||
do{
|
||||
Temp = send(TCPSock, &Send[Sent], Size - Sent, 0);
|
||||
if(!CheckBytes(Temp))return;
|
||||
Sent += Temp;
|
||||
}while(Sent < Size);
|
||||
|
||||
}
|
||||
|
||||
void TCPRcv(){
|
||||
char buf[4096];
|
||||
int len = 4096;
|
||||
ZeroMemory(buf, len);
|
||||
if(TCPSock == -1){
|
||||
Terminate = true;
|
||||
return;
|
||||
}
|
||||
int BytesRcv = recv(TCPSock, buf, len,0);
|
||||
if (BytesRcv == 0){
|
||||
debug(Sec("(TCP) Connection closing..."));
|
||||
Terminate = true;
|
||||
return;
|
||||
static int32_t Header,BytesRcv,Temp;
|
||||
BytesRcv = recv(TCPSock, reinterpret_cast<char*>(&Header), sizeof(Header),0);
|
||||
|
||||
if(!CheckBytes(BytesRcv))return;
|
||||
char* Data = new char[Header];
|
||||
BytesRcv = 0;
|
||||
do{
|
||||
Temp = recv(TCPSock,Data+BytesRcv,Header-BytesRcv,0);
|
||||
if(!CheckBytes(Temp)){
|
||||
delete[] Data;
|
||||
return;
|
||||
}
|
||||
BytesRcv += Temp;
|
||||
}while(BytesRcv < Header);
|
||||
std::string Ret = std::string(Data,Header);
|
||||
delete[] Data;
|
||||
if (Ret.substr(0, 4) == "ABG:") {
|
||||
Ret = DeComp(Ret.substr(4));
|
||||
}
|
||||
else if (BytesRcv < 0) {
|
||||
debug(Sec("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
||||
closesocket(TCPSock);
|
||||
Terminate = true;
|
||||
return;
|
||||
}
|
||||
Handler.Handle(std::string(buf));
|
||||
ServerParser(Ret);
|
||||
}
|
||||
|
||||
|
||||
void SyncResources(SOCKET TCPSock);
|
||||
void TCPClientMain(const std::string& IP,int Port){
|
||||
WSADATA wsaData;
|
||||
|
@ -20,11 +20,11 @@ std::string GetEN(){
|
||||
return r;
|
||||
}
|
||||
std::string GetVer(){
|
||||
static std::string r = Sec("1.63");
|
||||
static std::string r = Sec("1.70");
|
||||
return r;
|
||||
}
|
||||
std::string GetPatch(){
|
||||
static std::string r = Sec(".7");
|
||||
static std::string r = Sec("");
|
||||
return r;
|
||||
}
|
||||
void ReLaunch(int argc,char*args[]){
|
||||
|
Loading…
x
Reference in New Issue
Block a user