mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-05 07:16:18 +00:00
Functions and new Config
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user