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
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Buffer.h"
|
|
||||||
void NetReset();
|
void NetReset();
|
||||||
extern long long ping;
|
extern long long ping;
|
||||||
extern bool Dev;
|
extern bool Dev;
|
||||||
void ClearAll();
|
void ClearAll();
|
||||||
extern int ClientID;
|
extern int ClientID;
|
||||||
extern Buffer Handler;
|
|
||||||
extern bool ModLoaded;
|
extern bool ModLoaded;
|
||||||
extern bool Terminate;
|
extern bool Terminate;
|
||||||
extern int DEFAULT_PORT;
|
extern int DEFAULT_PORT;
|
||||||
|
@ -21,7 +21,7 @@ std::string MStatus;
|
|||||||
bool once = false;
|
bool once = false;
|
||||||
bool ModLoaded;
|
bool ModLoaded;
|
||||||
long long ping = -1;
|
long long ping = -1;
|
||||||
Buffer Handler;
|
|
||||||
void StartSync(const std::string &Data){
|
void StartSync(const std::string &Data){
|
||||||
std::string IP = GetAddr(Data.substr(1,Data.find(':')-1));
|
std::string IP = GetAddr(Data.substr(1,Data.find(':')-1));
|
||||||
if(IP.find('.') == -1){
|
if(IP.find('.') == -1){
|
||||||
@ -35,7 +35,6 @@ void StartSync(const std::string &Data){
|
|||||||
TCPTerminate = false;
|
TCPTerminate = false;
|
||||||
Terminate = false;
|
Terminate = false;
|
||||||
ConfList->clear();
|
ConfList->clear();
|
||||||
Handler.clear();
|
|
||||||
ping = -1;
|
ping = -1;
|
||||||
std::thread GS(TCPGameServer,IP,std::stoi(Data.substr(Data.find(':')+1)));
|
std::thread GS(TCPGameServer,IP,std::stoi(Data.substr(Data.find(':')+1)));
|
||||||
GS.detach();
|
GS.detach();
|
||||||
|
@ -6,11 +6,16 @@
|
|||||||
#include "Security/Enc.h"
|
#include "Security/Enc.h"
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "Logger.h"
|
||||||
|
#include <mutex>
|
||||||
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){
|
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){
|
||||||
((std::string*)userp)->append((char*)contents, size * nmemb);
|
((std::string*)userp)->append((char*)contents, size * nmemb);
|
||||||
return size * nmemb;
|
return size * nmemb;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HTTP_REQUEST(const std::string& IP,int port){
|
std::string HTTP_REQUEST(const std::string& IP,int port){
|
||||||
|
static std::mutex Lock;
|
||||||
|
Lock.lock();
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
std::string readBuffer;
|
std::string readBuffer;
|
||||||
@ -27,6 +32,7 @@ std::string HTTP_REQUEST(const std::string& IP,int port){
|
|||||||
if(res != CURLE_OK)return "-1";
|
if(res != CURLE_OK)return "-1";
|
||||||
}
|
}
|
||||||
curl_global_cleanup();
|
curl_global_cleanup();
|
||||||
|
Lock.unlock();
|
||||||
return readBuffer;
|
return readBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,6 @@ void SyncResources(SOCKET Sock){
|
|||||||
LFS.write(File, Recv);
|
LFS.write(File, Recv);
|
||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
}
|
||||||
ZeroMemory(File,Size);
|
|
||||||
delete[] File;
|
delete[] File;
|
||||||
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate);
|
}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);
|
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){
|
void SendLarge(std::string Data){
|
||||||
Data = Data.substr(0,Data.find(char(0)));
|
Data = Data.substr(0,Data.find(char(0)));
|
||||||
int ID = PackID();
|
if(Data.length() > 400){
|
||||||
std::string Packet;
|
std::string CMP(Comp(Data));
|
||||||
if(Data.length() > 1000){
|
Data = "ABG:" + CMP;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
TCPSend(Data);
|
||||||
}
|
}
|
||||||
std::array<int, 100> HandledIDs = {-1};
|
std::array<int, 100> HandledIDs = {-1};
|
||||||
int APos = 0;
|
int APos = 0;
|
||||||
|
@ -6,52 +6,71 @@
|
|||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <WS2tcpip.h>
|
#include <WS2tcpip.h>
|
||||||
|
#include <Zlib/Compressor.h>
|
||||||
#include "Security/Enc.h"
|
#include "Security/Enc.h"
|
||||||
#include "Network/network.h"
|
#include "Network/network.h"
|
||||||
|
|
||||||
SOCKET TCPSock;
|
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){
|
void TCPSend(const std::string&Data){
|
||||||
if(TCPSock == -1){
|
if(TCPSock == -1){
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string Send = "\n" + Data.substr(0,Data.find(char(0))) + "\n";
|
auto Size = int32_t(Data.size());
|
||||||
size_t Sent = send(TCPSock, Send.c_str(), int(Send.size()), 0);
|
std::string Send(4,0);
|
||||||
if (Sent == 0){
|
memcpy(&Send[0],&Size,sizeof(Size));
|
||||||
debug(Sec("(TCP) Connection closing..."));
|
Send += Data;
|
||||||
Terminate = true;
|
Size = int32_t(Send.size());
|
||||||
return;
|
int32_t Sent = 0,Temp;
|
||||||
}
|
do{
|
||||||
else if (Sent < 0) {
|
Temp = send(TCPSock, &Send[Sent], Size - Sent, 0);
|
||||||
debug(Sec("(TCP) send failed with error: ") + std::to_string(WSAGetLastError()));
|
if(!CheckBytes(Temp))return;
|
||||||
closesocket(TCPSock);
|
Sent += Temp;
|
||||||
Terminate = true;
|
}while(Sent < Size);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPRcv(){
|
void TCPRcv(){
|
||||||
char buf[4096];
|
|
||||||
int len = 4096;
|
|
||||||
ZeroMemory(buf, len);
|
|
||||||
if(TCPSock == -1){
|
if(TCPSock == -1){
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int BytesRcv = recv(TCPSock, buf, len,0);
|
static int32_t Header,BytesRcv,Temp;
|
||||||
if (BytesRcv == 0){
|
BytesRcv = recv(TCPSock, reinterpret_cast<char*>(&Header), sizeof(Header),0);
|
||||||
debug(Sec("(TCP) Connection closing..."));
|
|
||||||
Terminate = true;
|
if(!CheckBytes(BytesRcv))return;
|
||||||
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) {
|
ServerParser(Ret);
|
||||||
debug(Sec("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
|
||||||
closesocket(TCPSock);
|
|
||||||
Terminate = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Handler.Handle(std::string(buf));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SyncResources(SOCKET TCPSock);
|
void SyncResources(SOCKET TCPSock);
|
||||||
void TCPClientMain(const std::string& IP,int Port){
|
void TCPClientMain(const std::string& IP,int Port){
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
@ -20,11 +20,11 @@ std::string GetEN(){
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
std::string GetVer(){
|
std::string GetVer(){
|
||||||
static std::string r = Sec("1.63");
|
static std::string r = Sec("1.70");
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
std::string GetPatch(){
|
std::string GetPatch(){
|
||||||
static std::string r = Sec(".7");
|
static std::string r = Sec("");
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
void ReLaunch(int argc,char*args[]){
|
void ReLaunch(int argc,char*args[]){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user