mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-02 07:45:26 +00:00
Statistic reports mainly packets per second
This commit is contained in:
parent
a05acee04f
commit
280e3a8daa
@ -90,7 +90,7 @@ void GrabRole(Client*c){
|
||||
std::thread t1(HTTP,c);
|
||||
t1.detach();
|
||||
}
|
||||
|
||||
extern int PPS;
|
||||
void GlobalParser(Client*c, const std::string&Packet){
|
||||
if(Packet.empty())return;
|
||||
if(Packet.find("TEST")!=std::string::npos)SyncVehicles(c);
|
||||
@ -131,10 +131,9 @@ void GlobalParser(Client*c, const std::string&Packet){
|
||||
break;
|
||||
}
|
||||
//V to Z
|
||||
if(Packet.length() > 1000){
|
||||
std::cout << "Received data from: " << c->GetName() << " Size: " << Packet.length() << std::endl;
|
||||
if(Code <= 90 && Code >= 86){
|
||||
PPS++;
|
||||
SendToAll(c,Packet,false,false);
|
||||
}
|
||||
|
||||
if(Code <= 90 && Code >= 86)SendToAll(c,Packet,false,false);
|
||||
if(Debug)debug("Data : " + Packet);
|
||||
if(Debug)debug("Vehicle Data Received from " + c->GetName());
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "Client.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
#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
|
||||
///
|
||||
|
||||
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 ClientVersion;
|
||||
extern std::string FileList;
|
||||
extern std::string ServerName;
|
||||
extern std::string StatReport;
|
||||
extern std::string FileSizes;
|
||||
extern std::string Key;
|
||||
extern std::string Resource;
|
||||
extern std::string FileList;
|
||||
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 "Settings.hpp"
|
||||
#include "Network 2.0/Client.hpp"
|
||||
|
||||
extern std::string StatReport;
|
||||
std::string HTTP_REQUEST(const std::string&,int);
|
||||
std::string PostHTTP(const std::string& IP,const std::string& Fields);
|
||||
std::string HTA(const std::string& hex)
|
||||
@ -31,19 +31,23 @@ void Heartbeat()
|
||||
State = Private ? "true" : "false";
|
||||
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+
|
||||
"&clientversion="+ClientVersion+"&name="+ServerName;
|
||||
"&clientversion="+ClientVersion+"&name="+ServerName+"&pps="+StatReport;
|
||||
if(!CustomIP.empty())R+="&ip="+CustomIP;
|
||||
// https://beamng-mp.com/heartbeatv2
|
||||
R = PostHTTP(HTA("68747470733a2f2f6265616d6e672d6d702e636f6d2f6865617274626561747632"),R);
|
||||
if(R.find_first_not_of("20") != std::string::npos){
|
||||
//Backend system refused server startup!
|
||||
error(HTA("4261636b656e642073797374656d20726566757365642073657276657221"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
exit(-1);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
R = PostHTTP(HTA("68747470733a2f2f6265616d6e672d6d702e636f6d2f6865617274626561747632"),R);
|
||||
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
|
||||
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 CustomIP;
|
||||
void HandleResources(std::string path);
|
||||
//void TCPMain(int Port);
|
||||
void StatInit();
|
||||
void NetMain();
|
||||
//Entry
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if(argc > 1){
|
||||
CustomIP = argv[1];
|
||||
@ -44,6 +44,7 @@ int main(int argc, char* argv[]) {
|
||||
/*std::thread TCPThread(TCPMain,Port);
|
||||
TCPThread.detach();*/
|
||||
//ServerMain(Port, MaxPlayers);
|
||||
StatInit();
|
||||
NetMain();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user