mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
Functions and new Config
This commit is contained in:
parent
3c244c7e7f
commit
640a9c2e54
@ -1,6 +1,7 @@
|
||||
//
|
||||
// Created by Anonymous275 on 4/2/2020.
|
||||
//
|
||||
///
|
||||
/// Created by Anonymous275 on 4/2/2020
|
||||
///
|
||||
|
||||
#include "enet.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -8,7 +9,6 @@
|
||||
#include "../logger.h"
|
||||
|
||||
std::vector<std::string> Split(const std::string& String,const std::string& delimiter);
|
||||
void OnConnect(ENetPeer*peer,const std::string& data);
|
||||
|
||||
void ParseData(ENetPacket*packet,ENetPeer*peer){ //here we will parse the data
|
||||
std::string Packet = (char*)packet->data;
|
||||
@ -21,12 +21,7 @@ void ParseData(ENetPacket*packet,ENetPeer*peer){ //here we will parse the data
|
||||
split = Split(header, ":"); //1st is reliable - 2nd is Code - 3rd is VehID
|
||||
}
|
||||
if(!data.empty()){
|
||||
switch (stoi(split.at(1))){
|
||||
case 2000:
|
||||
OnConnect(peer,data);
|
||||
break;
|
||||
}
|
||||
//std::cout << data << std::endl;
|
||||
std::cout << data << std::endl;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// Created by Anonymous275 on 4/2/2020.
|
||||
//
|
||||
///
|
||||
/// Created by Anonymous275 on 4/2/2020
|
||||
///
|
||||
|
||||
#define ENET_IMPLEMENTATION
|
||||
#include "enet.h"
|
||||
@ -9,6 +9,7 @@
|
||||
#include "../logger.h"
|
||||
|
||||
void ParseData(ENetPacket*packet,ENetPeer*peer); //Data Parser
|
||||
void OnConnect(ENetPeer*peer);
|
||||
|
||||
ENetPacket* packet;
|
||||
|
||||
@ -18,16 +19,18 @@ void host_server(ENetHost *server) {
|
||||
while (enet_host_service(server, &event, 2) > 0) {
|
||||
switch (event.type) {
|
||||
case ENET_EVENT_TYPE_CONNECT:
|
||||
printf("A new client connected from %x:%u.\n", event.peer->address.host, event.peer->address.port); //Help xD
|
||||
printf("A new client connected from %x:%u.\n", event.peer->address.host, event.peer->address.port);
|
||||
//the data should be the client info could be name for now it's Client information
|
||||
event.peer->Name = (void *)"Client information";
|
||||
event.peer->gameVehicleID[0] = 15;
|
||||
event.peer->serverVehicleID = 17;
|
||||
|
||||
OnConnect(event.peer);
|
||||
break;
|
||||
|
||||
case ENET_EVENT_TYPE_RECEIVE:
|
||||
|
||||
ParseData(event.packet,event.peer/*->dataLength,event.packet->data, (char *)event.peer->data, event.channelID*/); //We grab and Parse the Data
|
||||
ParseData(event.packet,event.peer);
|
||||
/*->dataLength,event.packet->data, (char *)event.peer->data, event.channelID*/ //We grab and Parse the Data
|
||||
/* Clean up the packet now that we're done using it. */
|
||||
enet_packet_destroy (event.packet);
|
||||
break;
|
||||
|
@ -18,13 +18,9 @@ std::vector<std::string> Split(const std::string& String,const std::string& deli
|
||||
return Val;
|
||||
}
|
||||
|
||||
void OnConnect(ENetPeer*peer,const std::string& data){
|
||||
std::vector<std::string> Data = Split(data,":");
|
||||
if(strcmp((char*)peer->Name,"Client information")==0){ //Checks if the Client has no name
|
||||
peer->Name = (void *)Data.at(0).c_str();
|
||||
char Info[100];
|
||||
info("Client Name is " + Data.at(0) + " ID : " + std::to_string(peer->connectID)); //ID System //Logs the data
|
||||
peer->serverVehicleID = (int)peer->connectID; //test to see if it works
|
||||
info(Data.at(0)+" ServerVehicleID : "+std::to_string(peer->serverVehicleID)+" GameVehicleID : " + std::to_string(peer->gameVehicleID[0]));
|
||||
}
|
||||
void OnConnect(ENetPeer*peer){
|
||||
ENetPacket* packet = enet_packet_create ("NameRequest", //Send A Name Request to the Client
|
||||
strlen ("NameRequest") + 1,
|
||||
ENET_PACKET_FLAG_RELIABLE); //Create A reliable packet using the data
|
||||
enet_peer_send(peer, 0, packet);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// Created by Anonymous275 on 1/28/2020.
|
||||
//
|
||||
///
|
||||
/// Created by Anonymous275 on 1/28/2020
|
||||
///
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@ -8,15 +8,16 @@
|
||||
#include "logger.h"
|
||||
using namespace std; //nameSpace STD
|
||||
void GenerateConfig();
|
||||
string RemoveComments(string Line);
|
||||
string RemoveComments(const string& Line);
|
||||
string convertToString(char* a, int size);
|
||||
void SetValues(string Line, int Index);
|
||||
void SetMainValues(bool D,int P,int MP,string Name,string serverName);
|
||||
void SetValues(const string& Line, int Index);
|
||||
void SetMainValues(bool,int,int,string,string,string);
|
||||
bool D;
|
||||
int P;
|
||||
int MP;
|
||||
string M;
|
||||
string S;
|
||||
string F;
|
||||
|
||||
|
||||
//Generates or Reads Config
|
||||
@ -34,7 +35,7 @@ void ParseConfig(){
|
||||
index++;
|
||||
}
|
||||
}
|
||||
SetMainValues(D,P,MP,M,S); //gives the values to Main
|
||||
SetMainValues(D,P,MP,M,S,F); //gives the values to Main
|
||||
}else{
|
||||
info("Config Not Found Generating A new One");
|
||||
GenerateConfig();
|
||||
@ -44,12 +45,12 @@ void ParseConfig(){
|
||||
|
||||
|
||||
|
||||
void SetValues(string Line, int Index) {
|
||||
void SetValues(const string& Line, int Index) {
|
||||
int i = 0, state = 0;
|
||||
char Data[50] = "";
|
||||
bool Switch = false;
|
||||
if (Index > 3) { Switch = true; }
|
||||
for (char &c : Line) {
|
||||
for (char c : Line) {
|
||||
if (Switch) {
|
||||
if (c == '\"') { state++; }
|
||||
if (state > 0 && state < 2) {
|
||||
@ -71,7 +72,7 @@ void SetValues(string Line, int Index) {
|
||||
bool Boolean = (convertToString(Data,i-1).find("true") != string::npos);//searches for "true"
|
||||
switch (Index){
|
||||
case 1 :
|
||||
if(Boolean){D = true;}else{D = false;}//checks and sets the Debug Value
|
||||
D = Boolean;//checks and sets the Debug Value
|
||||
break;
|
||||
case 2 : P = stoi(Data, &sz);//sets the Port
|
||||
break;
|
||||
@ -80,6 +81,7 @@ void SetValues(string Line, int Index) {
|
||||
case 4 : M = Data; //Map
|
||||
break;
|
||||
case 5 : S = Data; //Name
|
||||
case 6 : F = Data; //File name
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,15 +96,16 @@ void GenerateConfig(){
|
||||
"Port = 30814 # Port to run the server on\n"
|
||||
"MaxPlayers = 10 # Maximum Amount of Clients\n"
|
||||
"Map = \"levels/gridmap/level.json\"\n"
|
||||
"Name = \"BeamNG-MP FTW\"";
|
||||
"Name = \"BeamNG-MP FTW\"\n"
|
||||
"use = \"/Resources\"";
|
||||
FileStream.close();
|
||||
}
|
||||
|
||||
|
||||
string RemoveComments(string Line){
|
||||
string RemoveComments(const string& Line){
|
||||
int i = 0;
|
||||
char Data[50] = "";
|
||||
for(char& c : Line) {
|
||||
for(char c : Line) {
|
||||
if(c == '#'){break;} //when it finds the # it will stop
|
||||
Data[i] = c;
|
||||
i++;
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// Created by Mitch on 04/02/2020.
|
||||
//
|
||||
///
|
||||
/// Created by Mitch on 04/02/2020
|
||||
///
|
||||
|
||||
#include "heartbeat.h"
|
||||
#include <stdio.h>
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// Created by jojos38 on 28.01.2020.
|
||||
//
|
||||
///
|
||||
/// Created by jojos38 on 28/01/2020
|
||||
///
|
||||
|
||||
|
||||
#include <fstream>
|
||||
@ -32,7 +32,7 @@ void setLoggerLevel(char level_string[]) {
|
||||
|
||||
stringstream getDate() {
|
||||
// current date/time based on current system
|
||||
time_t now = time(0);
|
||||
time_t now = time(nullptr);
|
||||
tm* ltm = localtime(&now);
|
||||
|
||||
int month = 1 + ltm->tm_mon;
|
||||
|
11
src/main.cpp
11
src/main.cpp
@ -1,6 +1,6 @@
|
||||
//
|
||||
// Created by Anonymous275 on 28.01.2020.
|
||||
//
|
||||
///
|
||||
/// Created by Anonymous275 on 28/01/2020
|
||||
///
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -21,6 +21,7 @@ int Port = 30814;
|
||||
int MaxPlayers = 10;
|
||||
string MapName = "levels/gridmap/level.json";
|
||||
string ServerName = "BeamNG-MP FTW";
|
||||
string Resource = "/Resources";
|
||||
|
||||
//Entry
|
||||
int main() {
|
||||
@ -41,14 +42,16 @@ void DebugData(){
|
||||
cout << "MaxPlayers : " << MaxPlayers << "\n";
|
||||
cout << "MapName : " << MapName << "\n";
|
||||
cout << "ServerName : " << ServerName << "\n";
|
||||
cout << "File : " << Resource << "\n";
|
||||
}
|
||||
|
||||
void SetMainValues(bool D, int P,int MP,string Name,string serverName){
|
||||
void SetMainValues(bool D, int P,int MP,string Name,string serverName,string filename){
|
||||
Debug = D;
|
||||
Port = P;
|
||||
MapName = Name;
|
||||
ServerName = serverName;
|
||||
MaxPlayers = MP;
|
||||
Resource = filename;
|
||||
}
|
||||
|
||||
void LogInit(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user