mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
added heartbeat cpp + h, needs functionality
This commit is contained in:
parent
996d96639c
commit
3ba8e55e59
@ -3,5 +3,5 @@ project(BeamNG-MP-Server)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
add_executable(BeamNG-MP-Server src/main.cpp src/logger.cpp src/config.cpp src/Network/Server.cpp src/Network/enet.h src/Network/DataParser.cpp)
|
||||
add_executable(BeamNG-MP-Server src/main.cpp src/logger.cpp src/config.cpp src/Network/Server.cpp src/Network/enet.h src/Network/DataParser.cpp src/heartbeat.cpp src/heartbeat.h)
|
||||
target_link_libraries(BeamNG-MP-Server winmm ws2_32)
|
36
src/heartbeat.cpp
Normal file
36
src/heartbeat.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// Created by Mitch on 04/02/2020.
|
||||
//
|
||||
|
||||
#include "heartbeat.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
const int NUM_SECONDS = 10;
|
||||
|
||||
void HeartbeatInit()
|
||||
{
|
||||
/// Make initial connection to backend services to get UUID, then call Heartbeat()
|
||||
}
|
||||
|
||||
void Heartbeat()
|
||||
{
|
||||
double time_counter = 0;
|
||||
|
||||
clock_t this_time = clock();
|
||||
clock_t last_time = this_time;
|
||||
|
||||
while(true)
|
||||
{
|
||||
this_time = clock();
|
||||
time_counter += (double)(this_time - last_time);
|
||||
last_time = this_time;
|
||||
|
||||
if(time_counter > (double)(NUM_SECONDS * CLOCKS_PER_SEC))
|
||||
{
|
||||
time_counter -= (double)(NUM_SECONDS * CLOCKS_PER_SEC);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
12
src/heartbeat.h
Normal file
12
src/heartbeat.h
Normal file
@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by Mitch on 04/02/2020.
|
||||
//
|
||||
|
||||
#ifndef BEAMNG_MP_SERVER_HEARTBEAT_H
|
||||
#define BEAMNG_MP_SERVER_HEARTBEAT_H
|
||||
|
||||
|
||||
void HeartbeatInit();
|
||||
|
||||
|
||||
#endif //BEAMNG_MP_SERVER_HEARTBEAT_H
|
@ -17,6 +17,7 @@ void ParseConfig();
|
||||
void ServerMain(int Port, int MaxClients);
|
||||
bool Debug = false;
|
||||
void addToLog(basic_string<char> Data);
|
||||
void HeartbeatInit();
|
||||
int Port = 30814;
|
||||
int MaxClients = 10;
|
||||
string MapName = "levels/gridmap/level.json";
|
||||
@ -25,6 +26,7 @@ string ServerName = "BeamNG-MP FTW";
|
||||
//Entry
|
||||
int main() {
|
||||
LogInit();
|
||||
HeartbeatInit();
|
||||
ParseConfig();
|
||||
if(Debug){ //checks if debug is on
|
||||
DebugData(); //Prints Debug Data
|
||||
|
Loading…
x
Reference in New Issue
Block a user