mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-20 07:00:30 +00:00
Statistic reports mainly packets per second
This commit is contained in:
@@ -90,7 +90,7 @@ void GrabRole(Client*c){
|
|||||||
std::thread t1(HTTP,c);
|
std::thread t1(HTTP,c);
|
||||||
t1.detach();
|
t1.detach();
|
||||||
}
|
}
|
||||||
|
extern int PPS;
|
||||||
void GlobalParser(Client*c, const std::string&Packet){
|
void GlobalParser(Client*c, const std::string&Packet){
|
||||||
if(Packet.empty())return;
|
if(Packet.empty())return;
|
||||||
if(Packet.find("TEST")!=std::string::npos)SyncVehicles(c);
|
if(Packet.find("TEST")!=std::string::npos)SyncVehicles(c);
|
||||||
@@ -131,10 +131,9 @@ void GlobalParser(Client*c, const std::string&Packet){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//V to Z
|
//V to Z
|
||||||
if(Packet.length() > 1000){
|
if(Code <= 90 && Code >= 86){
|
||||||
std::cout << "Received data from: " << c->GetName() << " Size: " << Packet.length() << std::endl;
|
PPS++;
|
||||||
|
SendToAll(c,Packet,false,false);
|
||||||
}
|
}
|
||||||
|
if(Debug)debug("Vehicle Data Received from " + c->GetName());
|
||||||
if(Code <= 90 && Code >= 86)SendToAll(c,Packet,false,false);
|
|
||||||
if(Debug)debug("Data : " + Packet);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include "Client.hpp"
|
#include "Client.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <thread>
|
|
||||||
#include <any>
|
#include <any>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
33
src/Network 2.0/StatMonitor.cpp
Normal file
33
src/Network 2.0/StatMonitor.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
///
|
||||||
|
/// Created by Anonymous275 on 6/18/2020
|
||||||
|
///
|
||||||
|
#include "Client.hpp"
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
std::string StatReport = "-";
|
||||||
|
int PPS = 0;
|
||||||
|
[[noreturn]] void Monitor(){
|
||||||
|
int R,C;
|
||||||
|
while(true){
|
||||||
|
if(Clients.empty()){
|
||||||
|
StatReport = "-";
|
||||||
|
}else{
|
||||||
|
C = 0;
|
||||||
|
for(Client *c : Clients){
|
||||||
|
if(c->GetCarCount() > 0)C++;
|
||||||
|
}
|
||||||
|
if(C == 0 || PPS == 0){
|
||||||
|
StatReport = "-";
|
||||||
|
}else{
|
||||||
|
R = PPS/C;
|
||||||
|
StatReport = std::to_string(R);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StatInit(){
|
||||||
|
std::thread Init(Monitor);
|
||||||
|
Init.detach();
|
||||||
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
///
|
///
|
||||||
/// Created by Anonymous275 on 4/10/2020
|
/// Created by Anonymous275 on 4/10/2020
|
||||||
///
|
///
|
||||||
|
|
||||||
extern bool Private;
|
|
||||||
extern bool Debug;
|
|
||||||
extern int MaxPlayers;
|
|
||||||
extern int Port;
|
|
||||||
extern int MaxCars;
|
|
||||||
extern std::string MapName;
|
|
||||||
extern std::string ServerName;
|
|
||||||
extern std::string Resource;
|
|
||||||
extern std::string ServerVersion;
|
extern std::string ServerVersion;
|
||||||
extern std::string ClientVersion;
|
extern std::string ClientVersion;
|
||||||
extern std::string FileList;
|
extern std::string ServerName;
|
||||||
|
extern std::string StatReport;
|
||||||
extern std::string FileSizes;
|
extern std::string FileSizes;
|
||||||
extern std::string Key;
|
extern std::string Resource;
|
||||||
|
extern std::string FileList;
|
||||||
extern std::string CustomIP;
|
extern std::string CustomIP;
|
||||||
|
extern std::string MapName;
|
||||||
|
extern std::string Key;
|
||||||
|
extern int MaxPlayers;
|
||||||
|
extern bool Private;
|
||||||
|
extern int MaxCars;
|
||||||
|
extern bool Debug;
|
||||||
|
extern int Port;
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "Settings.hpp"
|
#include "Settings.hpp"
|
||||||
#include "Network 2.0/Client.hpp"
|
#include "Network 2.0/Client.hpp"
|
||||||
|
extern std::string StatReport;
|
||||||
std::string HTTP_REQUEST(const std::string&,int);
|
std::string HTTP_REQUEST(const std::string&,int);
|
||||||
std::string PostHTTP(const std::string& IP,const std::string& Fields);
|
std::string PostHTTP(const std::string& IP,const std::string& Fields);
|
||||||
std::string HTA(const std::string& hex)
|
std::string HTA(const std::string& hex)
|
||||||
@@ -31,19 +31,23 @@ void Heartbeat()
|
|||||||
State = Private ? "true" : "false";
|
State = Private ? "true" : "false";
|
||||||
R = "uuid="+Key+"&players="+std::to_string(Clients.size())+"&maxplayers="+std::to_string(MaxPlayers)+"&port="
|
R = "uuid="+Key+"&players="+std::to_string(Clients.size())+"&maxplayers="+std::to_string(MaxPlayers)+"&port="
|
||||||
+ std::to_string(Port) + "&map=" + MapName + "&private="+State+"&version="+ServerVersion+
|
+ std::to_string(Port) + "&map=" + MapName + "&private="+State+"&version="+ServerVersion+
|
||||||
"&clientversion="+ClientVersion+"&name="+ServerName;
|
"&clientversion="+ClientVersion+"&name="+ServerName+"&pps="+StatReport;
|
||||||
if(!CustomIP.empty())R+="&ip="+CustomIP;
|
if(!CustomIP.empty())R+="&ip="+CustomIP;
|
||||||
// https://beamng-mp.com/heartbeatv2
|
// https://beamng-mp.com/heartbeatv2
|
||||||
R = PostHTTP(HTA("68747470733a2f2f6265616d6e672d6d702e636f6d2f6865617274626561747632"),R);
|
R = PostHTTP(HTA("68747470733a2f2f6265616d6e672d6d702e636f6d2f6865617274626561747632"),R);
|
||||||
if(R.find_first_not_of("20") != std::string::npos){
|
if(R.find_first_not_of("20") != std::string::npos){
|
||||||
//Backend system refused server startup!
|
//Backend system refused server startup!
|
||||||
error(HTA("4261636b656e642073797374656d20726566757365642073657276657221"));
|
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
R = PostHTTP(HTA("68747470733a2f2f6265616d6e672d6d702e636f6d2f6865617274626561747632"),R);
|
||||||
exit(-1);
|
if(R.find_first_not_of("20") != std::string::npos){
|
||||||
|
error(HTA("4261636b656e642073797374656d20726566757365642073657276657221"));
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Server Authenticated
|
//Server Authenticated
|
||||||
if(R.length() == 4)info(HTA("5365727665722061757468656e746963617465642077697468206261636b656e64"));
|
if(R.length() == 4)info(HTA("5365727665722061757468656e746963617465642077697468206261636b656e64"));
|
||||||
std::this_thread::sleep_for (std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ std::string ServerVersion = "0.3";
|
|||||||
std::string ClientVersion = "1.3+";
|
std::string ClientVersion = "1.3+";
|
||||||
std::string CustomIP;
|
std::string CustomIP;
|
||||||
void HandleResources(std::string path);
|
void HandleResources(std::string path);
|
||||||
//void TCPMain(int Port);
|
void StatInit();
|
||||||
void NetMain();
|
void NetMain();
|
||||||
//Entry
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if(argc > 1){
|
if(argc > 1){
|
||||||
CustomIP = argv[1];
|
CustomIP = argv[1];
|
||||||
@@ -44,6 +44,7 @@ int main(int argc, char* argv[]) {
|
|||||||
/*std::thread TCPThread(TCPMain,Port);
|
/*std::thread TCPThread(TCPMain,Port);
|
||||||
TCPThread.detach();*/
|
TCPThread.detach();*/
|
||||||
//ServerMain(Port, MaxPlayers);
|
//ServerMain(Port, MaxPlayers);
|
||||||
|
StatInit();
|
||||||
NetMain();
|
NetMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user