feat: add UUID generation for session identification and update connection logic
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
// OverteClient.cpp
|
|
||||||
#include "OverteClient.hpp"
|
#include "OverteClient.hpp"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <random>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -15,7 +17,26 @@
|
|||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
// Generate a simple UUID-like string for session identification
|
||||||
|
static std::string generateUUID() {
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
std::uniform_int_distribution<> dis(0, 255);
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::hex << std::setfill('0');
|
||||||
|
for (int i = 0; i < 16; ++i) {
|
||||||
|
if (i == 4 || i == 6 || i == 8 || i == 10) ss << '-';
|
||||||
|
ss << std::setw(2) << dis(gen);
|
||||||
|
}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
bool OverteClient::connect() {
|
bool OverteClient::connect() {
|
||||||
|
// Generate session UUID
|
||||||
|
m_sessionUUID = generateUUID();
|
||||||
|
std::cout << "[OverteClient] Session UUID: " << m_sessionUUID << std::endl;
|
||||||
|
|
||||||
// Parse ws://host:port
|
// Parse ws://host:port
|
||||||
std::string url = m_domainUrl;
|
std::string url = m_domainUrl;
|
||||||
if (url.empty()) url = "ws://127.0.0.1:40102";
|
if (url.empty()) url = "ws://127.0.0.1:40102";
|
||||||
@@ -77,6 +98,9 @@ bool OverteClient::connect() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send domain connect request to initiate handshake
|
||||||
|
sendDomainConnectRequest();
|
||||||
|
|
||||||
m_useSimulation = (std::getenv("STARWORLD_SIMULATE") != nullptr);
|
m_useSimulation = (std::getenv("STARWORLD_SIMULATE") != nullptr);
|
||||||
if (m_useSimulation) {
|
if (m_useSimulation) {
|
||||||
// Seed a couple of demo entities.
|
// Seed a couple of demo entities.
|
||||||
|
|||||||
@@ -49,9 +49,13 @@ public:
|
|||||||
private:
|
private:
|
||||||
void parseNetworkPackets(); // standards-aligned parsing (scaffold)
|
void parseNetworkPackets(); // standards-aligned parsing (scaffold)
|
||||||
void parseEntityPacket(const char* data, size_t len);
|
void parseEntityPacket(const char* data, size_t len);
|
||||||
|
void parseDomainPacket(const char* data, size_t len);
|
||||||
void handleDomainListReply(const char* data, size_t len);
|
void handleDomainListReply(const char* data, size_t len);
|
||||||
|
void handleDomainConnectionDenied(const char* data, size_t len);
|
||||||
void sendDomainListRequest();
|
void sendDomainListRequest();
|
||||||
|
void sendDomainConnectRequest();
|
||||||
void sendEntityQuery();
|
void sendEntityQuery();
|
||||||
|
void sendPing(int fd, const sockaddr_storage& addr, socklen_t addrLen);
|
||||||
|
|
||||||
std::string m_domainUrl;
|
std::string m_domainUrl;
|
||||||
std::string m_host{"127.0.0.1"};
|
std::string m_host{"127.0.0.1"};
|
||||||
@@ -61,6 +65,8 @@ private:
|
|||||||
bool m_entityServer{false};
|
bool m_entityServer{false};
|
||||||
bool m_audioMixer{false};
|
bool m_audioMixer{false};
|
||||||
bool m_useSimulation{false};
|
bool m_useSimulation{false};
|
||||||
|
bool m_domainConnected{false};
|
||||||
|
std::string m_sessionUUID; // Our client session UUID
|
||||||
|
|
||||||
// Very small in-process world state for testing
|
// Very small in-process world state for testing
|
||||||
std::unordered_map<std::uint64_t, OverteEntity> m_entities;
|
std::unordered_map<std::uint64_t, OverteEntity> m_entities;
|
||||||
|
|||||||
Reference in New Issue
Block a user