add udpserver, tcpserver

This commit is contained in:
Lion Kortlepel
2021-02-16 15:54:50 +01:00
committed by Anonymous275
parent f19a012509
commit bf74b1ae32
18 changed files with 401 additions and 55 deletions

View File

@@ -1,28 +1,29 @@
#include "Client.h"
#include "CustomAssert.h"
#include <memory>
// FIXME: add debug prints
void TClient::DeleteCar(int Ident) {
for (auto& v : _VehicleData) {
for (auto& v : mVehicleData) {
if (v != nullptr && v->ID() == Ident) {
_VehicleData.erase(v);
mVehicleData.erase(v);
break;
}
}
}
void TClient::ClearCars() {
_VehicleData.clear();
mVehicleData.clear();
}
int TClient::GetOpenCarID() {
int TClient::GetOpenCarID() const {
int OpenID = 0;
bool found;
do {
found = true;
for (auto& v : _VehicleData) {
for (auto& v : mVehicleData) {
if (v != nullptr && v->ID() == OpenID) {
OpenID++;
found = false;
@@ -33,15 +34,15 @@ int TClient::GetOpenCarID() {
}
void TClient::AddNewCar(int Ident, const std::string& Data) {
_VehicleData.insert(std::make_unique<TVehicleData>(TVehicleData { Ident, Data }));
mVehicleData.insert(std::make_unique<TVehicleData>(TVehicleData { Ident, Data }));
}
TClient::TSetOfVehicleData& TClient::GetAllCars() {
return _VehicleData;
return mVehicleData;
}
std::string TClient::GetCarData(int Ident) {
for (auto& v : _VehicleData) {
for (auto& v : mVehicleData) {
if (v != nullptr && v->ID() == Ident) {
return v->Data();
}
@@ -51,7 +52,7 @@ std::string TClient::GetCarData(int Ident) {
}
void TClient::SetCarData(int Ident, const std::string& Data) {
for (auto& v : _VehicleData) {
for (auto& v : mVehicleData) {
if (v != nullptr && v->ID() == Ident) {
v->Data() = Data;
return;
@@ -59,6 +60,13 @@ void TClient::SetCarData(int Ident, const std::string& Data) {
}
DeleteCar(Ident);
}
int TClient::GetCarCount() {
return int(_VehicleData.size());
int TClient::GetCarCount() const {
return int(mVehicleData.size());
}
TServer& TClient::Server() const {
return mServer;
}
TClient::TClient(TServer& Server)
: mServer(Server) {
}