mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 16:25:35 +00:00
Vehicle ghost fix, player list fix
This commit is contained in:
parent
2021f0b461
commit
a08d29a0ae
@ -1,44 +0,0 @@
|
|||||||
///
|
|
||||||
/// Created by Anonymous275 on 8/25/2020
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <mutex>
|
|
||||||
#include "CustomAssert.h"
|
|
||||||
class Client;
|
|
||||||
void GParser(Client*c, const std::string&Packet);
|
|
||||||
class Buffer{
|
|
||||||
public:
|
|
||||||
void Handle(Client*c,const std::string& Data){
|
|
||||||
Assert(c);
|
|
||||||
Buf += Data;
|
|
||||||
Manage(c);
|
|
||||||
}
|
|
||||||
void clear(){
|
|
||||||
Buf.clear();
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
std::string Buf;
|
|
||||||
void Manage(Client*c){
|
|
||||||
Assert(c);
|
|
||||||
if(!Buf.empty()){
|
|
||||||
std::string::size_type p;
|
|
||||||
if (Buf.at(0) == '\n'){
|
|
||||||
p = Buf.find('\n',1);
|
|
||||||
if(p != std::string::npos){
|
|
||||||
std::string R = Buf.substr(1,p-1);
|
|
||||||
std::string_view B(R.c_str(),R.find(char(0)));
|
|
||||||
GParser(c, B.data());
|
|
||||||
Buf = Buf.substr(p+1);
|
|
||||||
Manage(c);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
p = Buf.find('\n');
|
|
||||||
if(p == std::string::npos)Buf.clear();
|
|
||||||
else{
|
|
||||||
Buf = Buf.substr(p);
|
|
||||||
Manage(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
@ -9,7 +9,6 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#define SOCKET int
|
#define SOCKET int
|
||||||
#endif
|
#endif
|
||||||
#include "Buffer.h"
|
|
||||||
#include "CustomAssert.h"
|
#include "CustomAssert.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -55,7 +54,6 @@ public:
|
|||||||
int GetCarCount();
|
int GetCarCount();
|
||||||
void ClearCars();
|
void ClearCars();
|
||||||
int GetStatus();
|
int GetStatus();
|
||||||
Buffer Handler;
|
|
||||||
int GetID();
|
int GetID();
|
||||||
};
|
};
|
||||||
struct ClientInterface{
|
struct ClientInterface{
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "Client.hpp"
|
#include "Client.hpp"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include <sstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <future>
|
#include <future>
|
||||||
@ -21,14 +22,16 @@ std::string GetPlayers(){
|
|||||||
return Return;
|
return Return;
|
||||||
}
|
}
|
||||||
std::string GenerateCall(){
|
std::string GenerateCall(){
|
||||||
std::string State = Private ? "true" : "false";
|
std::stringstream Ret;
|
||||||
std::string ret = "uuid=";
|
Ret << "uuid=" << Key << "&players=" << CI->Size()
|
||||||
ret += Key+"&players="+std::to_string(CI->Size())+"&maxplayers="+std::to_string(MaxPlayers)+"&port="
|
<< "&maxplayers=" << MaxPlayers << "&port=" << Port
|
||||||
+ std::to_string(Port) + "&map=" + MapName + "&private="+State+"&version="+GetSVer()+
|
<< "&map=" << MapName << "&private=" << (Private ? "true" : "false")
|
||||||
"&clientversion="+GetCVer()+"&name="+ServerName+"&pps="+StatReport+"&modlist="+FileList+
|
<< "&version=" << GetSVer() << "&clientversion=" << GetCVer()
|
||||||
"&modstotalsize="+std::to_string(MaxModSize)+"&modstotal="+std::to_string(ModsLoaded)
|
<< "&name=" << ServerName << "&pps=" << StatReport
|
||||||
+"&playerslist="+GetPlayers()+"&desc="+ServerDesc;
|
<< "&modlist=" << FileList << "&modstotalsize=" << MaxModSize
|
||||||
return ret;
|
<< "&modstotal=" << ModsLoaded << "&playerslist=" << GetPlayers()
|
||||||
|
<< "&desc=" << ServerDesc;
|
||||||
|
return Ret.str();
|
||||||
}
|
}
|
||||||
std::string RunPromise(const std::string& IP, const std::string& R) {
|
std::string RunPromise(const std::string& IP, const std::string& R) {
|
||||||
std::packaged_task<std::string()> task([&]() { return PostHTTP(IP,R); });
|
std::packaged_task<std::string()> task([&]() { return PostHTTP(IP,R); });
|
||||||
|
@ -30,16 +30,15 @@ void Respond(Client*c, const std::string& MSG, bool Rel){
|
|||||||
if(C == 'O' || C == 'T' || MSG.length() > 1000)SendLarge(c,MSG);
|
if(C == 'O' || C == 'T' || MSG.length() > 1000)SendLarge(c,MSG);
|
||||||
else TCPSend(c,MSG);
|
else TCPSend(c,MSG);
|
||||||
}else UDPSend(c,MSG);
|
}else UDPSend(c,MSG);
|
||||||
|
|
||||||
}
|
}
|
||||||
void SendToAll(Client*c, const std::string& Data, bool Self, bool Rel){
|
void SendToAll(Client*c, const std::string& Data, bool Self, bool Rel){
|
||||||
if (!Self) {
|
if (!Self)Assert(c);
|
||||||
Assert(c);
|
|
||||||
}
|
|
||||||
char C = Data.at(0);
|
char C = Data.at(0);
|
||||||
for(Client*client : CI->Clients){
|
for(Client*client : CI->Clients){
|
||||||
if(client != nullptr) {
|
if(client != nullptr) {
|
||||||
if (Self || client != c) {
|
if (Self || client != c) {
|
||||||
if (client->isSynced || (C == 'O' && Data.at(1) == 's')) {
|
if (client->isSynced) {
|
||||||
if (Rel || C == 'W' || C == 'Y' || C == 'V' || C == 'E') {
|
if (Rel || C == 'W' || C == 'Y' || C == 'V' || C == 'E') {
|
||||||
if (C == 'O' || C == 'T' ||
|
if (C == 'O' || C == 'T' ||
|
||||||
Data.length() > 1000)SendLarge(client, Data);
|
Data.length() > 1000)SendLarge(client, Data);
|
||||||
|
@ -2,67 +2,84 @@
|
|||||||
/// Created by Anonymous275 on 8/1/2020
|
/// Created by Anonymous275 on 8/1/2020
|
||||||
///
|
///
|
||||||
#include "Security/Enc.h"
|
#include "Security/Enc.h"
|
||||||
|
#include "UnixCompat.h"
|
||||||
|
#include "Compressor.h"
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "UnixCompat.h"
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
void TCPSend(Client*c,const std::string&Data){
|
void TCPSend(Client*c,const std::string&Data){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
if(c == nullptr)return;
|
if(c == nullptr)return;
|
||||||
std::string Send = "\n" + Data.substr(0,Data.find(char(0))) + "\n";
|
auto Size = int32_t(Data.size());
|
||||||
#ifdef WIN32
|
std::string Send(4,0);
|
||||||
int Sent;
|
memcpy(&Send[0],&Size,sizeof(Size));
|
||||||
int len = static_cast<int>(Send.size());
|
Send += Data;
|
||||||
#else
|
Size = int32_t(Send.size());
|
||||||
int64_t Sent;
|
int32_t Sent = 0,Temp;
|
||||||
size_t len = Send.size();
|
|
||||||
#endif // WIN32
|
do {
|
||||||
Sent = send(c->GetTCPSock(), Send.c_str(), len, 0);
|
Temp = send(c->GetTCPSock(), &Send[Sent], Size - Sent, 0);
|
||||||
if (Sent == 0){
|
if (Temp == 0) {
|
||||||
if(c->GetStatus() > -1)c->SetStatus(-1);
|
if (c->GetStatus() > -1)c->SetStatus(-1);
|
||||||
}else if (Sent < 0) {
|
return;
|
||||||
if(c->GetStatus() > -1)c->SetStatus(-1);
|
} else if (Sent < 0) {
|
||||||
|
if (c->GetStatus() > -1)c->SetStatus(-1);
|
||||||
closesocket(c->GetTCPSock());
|
closesocket(c->GetTCPSock());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
Sent += Temp;
|
||||||
|
}while(Sent < Size);
|
||||||
}
|
}
|
||||||
void TCPHandle(Client*c,const std::string& data){
|
|
||||||
|
bool CheckBytes(Client*c,int32_t BytesRcv){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
#ifdef WIN32
|
|
||||||
__try{
|
|
||||||
#endif // WIN32
|
|
||||||
c->Handler.Handle(c,data);
|
|
||||||
#ifdef WIN32
|
|
||||||
}__except(1){
|
|
||||||
c->Handler.clear();
|
|
||||||
}
|
|
||||||
#endif // WIN32
|
|
||||||
}
|
|
||||||
void TCPRcv(Client*c){
|
|
||||||
Assert(c);
|
|
||||||
if(c == nullptr || c->GetStatus() < 0)return;
|
|
||||||
#define len 4096
|
|
||||||
char buf[len];
|
|
||||||
ZeroMemory(buf, len);
|
|
||||||
int64_t BytesRcv = recv(c->GetTCPSock(), buf, len,0);
|
|
||||||
#undef len
|
|
||||||
if (BytesRcv == 0){
|
if (BytesRcv == 0){
|
||||||
debug(Sec("(TCP) Connection closing..."));
|
debug(Sec("(TCP) Connection closing..."));
|
||||||
if(c->GetStatus() > -1)c->SetStatus(-1);
|
if(c->GetStatus() > -1)c->SetStatus(-1);
|
||||||
return;
|
return false;
|
||||||
}else if (BytesRcv < 0) {
|
}else if (BytesRcv < 0) {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
debug(Sec("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
debug(Sec("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
||||||
#else // unix
|
#else // unix
|
||||||
debug(Sec("(TCP) recv failed with error: ") + std::string(strerror(errno)));
|
debug(Sec("(TCP) recv failed with error: ") + std::string(strerror(errno)));
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
if(c->GetStatus() > -1)c->SetStatus(-1);
|
if(c->GetStatus() > -1)c->SetStatus(-1);
|
||||||
closesocket(c->GetTCPSock());
|
closesocket(c->GetTCPSock());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TCPRcv(Client*c){
|
||||||
|
Assert(c);
|
||||||
|
static int32_t Header,BytesRcv,Temp;
|
||||||
|
if(c == nullptr || c->GetStatus() < 0)return;
|
||||||
|
#ifdef WIN32
|
||||||
|
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<char*>(&Header), sizeof(Header),0);
|
||||||
|
#else
|
||||||
|
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<void*>(&Header), sizeof(Header), 0);
|
||||||
|
#endif
|
||||||
|
if(!CheckBytes(c,BytesRcv))return;
|
||||||
|
char* Data = new char[Header];
|
||||||
|
BytesRcv = 0;
|
||||||
|
do{
|
||||||
|
Temp = recv(c->GetTCPSock(), Data+BytesRcv, Header-BytesRcv,0);
|
||||||
|
if(!CheckBytes(c,Temp)){
|
||||||
|
delete[] Data;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string Buf(buf,(size_t(BytesRcv)));
|
BytesRcv += Temp;
|
||||||
TCPHandle(c,Buf);
|
}while(BytesRcv < Header);
|
||||||
|
std::string Ret = std::string(Data,Header);
|
||||||
|
delete[] Data;
|
||||||
|
if (Ret.substr(0, 4) == "ABG:") {
|
||||||
|
Ret = DeComp(Ret.substr(4));
|
||||||
|
}
|
||||||
|
GParser(c,Ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPClient(Client*c){
|
void TCPClient(Client*c){
|
||||||
DebugPrintTID();
|
DebugPrintTID();
|
||||||
Assert(c);
|
Assert(c);
|
||||||
|
@ -101,28 +101,11 @@ int SplitID() {
|
|||||||
void SendLarge(Client* c, std::string Data) {
|
void SendLarge(Client* c, std::string Data) {
|
||||||
Assert(c);
|
Assert(c);
|
||||||
Data = Data.substr(0, Data.find(char(0)));
|
Data = Data.substr(0, Data.find(char(0)));
|
||||||
int ID = PacktID();
|
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);
|
|
||||||
DataAcks.insert(new PacketData { ID, c, Packet, 1 });
|
|
||||||
UDPSend(c, Packet);
|
|
||||||
pckt = pckt.substr(1000);
|
|
||||||
S++;
|
|
||||||
ID = PacktID();
|
|
||||||
}
|
|
||||||
Packet = "SC|" + std::to_string(S) + "|" + std::to_string(Split) + "|" + std::to_string(ID) + "|" + std::to_string(SID) + "|" + pckt;
|
|
||||||
DataAcks.insert(new PacketData { ID, c, Packet, 1 });
|
|
||||||
UDPSend(c, Packet);
|
|
||||||
} else {
|
|
||||||
Packet = "BD:" + std::to_string(ID) + ":" + Data;
|
|
||||||
DataAcks.insert(new PacketData { ID, c, Packet, 1 });
|
|
||||||
UDPSend(c, Packet);
|
|
||||||
}
|
}
|
||||||
|
TCPSend(c,Data);
|
||||||
}
|
}
|
||||||
struct HandledC {
|
struct HandledC {
|
||||||
size_t Pos = 0;
|
size_t Pos = 0;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#include "Startup.h"
|
|
||||||
#include "CustomAssert.h"
|
#include "CustomAssert.h"
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <thread>
|
#include "Startup.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
[[noreturn]] void loop(){
|
[[noreturn]] void loop(){
|
||||||
DebugPrintTID();
|
DebugPrintTID();
|
||||||
while(true){
|
while(true){
|
||||||
@ -10,6 +12,7 @@
|
|||||||
std::this_thread::sleep_for(std::chrono::milliseconds(600));
|
std::this_thread::sleep_for(std::chrono::milliseconds(600));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
DebugPrintTID();
|
DebugPrintTID();
|
||||||
// curl needs to be initialized to properly deallocate its resources later
|
// curl needs to be initialized to properly deallocate its resources later
|
||||||
|
Loading…
x
Reference in New Issue
Block a user