serialization

This commit is contained in:
MarcEricMartel
2023-09-25 16:30:03 -04:00
parent 035436c639
commit 4c2e8a12ad
10 changed files with 239 additions and 59 deletions

View File

@@ -25,19 +25,19 @@ uint64_t Connection::GetTeamHash() const { return m_tid; }
std::string Connection::GetName() const { return m_name; }
void Connection::AddInput(Input in) {
m_input_manifest.insert({in.timestamp, in});
void Connection::AddInput(netprot::Input in) {
m_input_manifest.insert({ in.timestamp, in });
}
Output* Connection::getOutput(Timestamp time) {
netprot::Output* Connection::getOutput(Timestamp time) {
auto out = m_output_manifest.find(time);
if (out != m_output_manifest.end())
return &out->second;
return nullptr;
}
Sync Connection::getSync(Timestamp time) {
Sync sync;
netprot::Sync Connection::getSync(Timestamp time) {
netprot::Sync sync;
auto out = m_output_manifest.find(time);
if (out != m_output_manifest.end()) {
sync.timestamp = out->second.timestamp;

View File

@@ -4,7 +4,7 @@
#include <map>
#include "../SQCSim-common/player.h"
#include "../SQCSim-common/vector3.h"
#include "../SQCSim-common/serialization.h"
#include "../SQCSim-common/netprotocol.h"
#include "define.h"
class Connection {
@@ -24,14 +24,14 @@ public:
uint64_t GetTeamHash() const;
std::string GetName() const;
void AddInput(Input in);
Output* getOutput(Timestamp time);
Sync getSync(Timestamp time);
void AddInput(netprot::Input in);
netprot::Output* getOutput(Timestamp time);
netprot::Sync getSync(Timestamp time);
void CleanInputManifest(Timestamp time);
private:
std::map<Timestamp, Input> m_input_manifest;
std::map<Timestamp, Output> m_output_manifest;
std::map<Timestamp, netprot::Input> m_input_manifest;
std::map<Timestamp, netprot::Output> m_output_manifest;
in_addr m_addr;
uint64_t m_id,
m_sid,

View File

@@ -1,4 +1,3 @@
#include "define.h"
#include "server.h"
int main() {

View File

@@ -79,14 +79,16 @@ int Server::Ready() {
Log("<EFBFBD> l'<27>coute sur le port: " + std::to_string(SRV_PORT), false, false);
while (!readystart) {
Log("trololo", false, false);
// Listen/accept ici.
readystart = true;
}
return 0;
}
void Server::Run() {
Log("Partie en cours...", false, false);
}
@@ -131,6 +133,32 @@ void Server::Log(std::string str, bool is_error = false, bool is_fatal = false)
}
}
// Test serialize/deserialize:
/*
netprot::LoginInfo* log = new netprot::LoginInfo();
char nom[] = "Jean Dujardin";
memcpy(log->name, &nom, sizeof(nom));
log->sid = 12345;
char* buf = new char[150];
uint32_t buflen = 150;
netprot::Serialize(log, &buf, &buflen);
delete log;
log = new netprot::LoginInfo();
bool is_work = netprot::Deserialize(log, buf, buflen);
std::string str;
str.append(is_work ? "Y " : "N ").append(log->name).append(": ").append(std::to_string(log->sid));
Log(str, false, false);
*/
///* Recevoir paquet */
//while (true) {
// char buffer[2048];

View File

@@ -7,6 +7,7 @@
#include "../SQCSim-common/world.h"
#include "define.h"
#include "connection.h"
#include "../SQCSim-common/netprotocol.h"
class Server {
public: