Commit 9e9bb898 authored by Shu's avatar Shu 🍠
Browse files

Move server full check

parent 5d0009c7
......@@ -41,6 +41,26 @@
}
]
},
{
"name": "Run server (gdb)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/univerxel-server",
"args": ["server.toml"],
"preLaunchTask": "Build server",
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Run server (gdb debug)",
"type": "cppdbg",
......
......@@ -100,6 +100,12 @@
"dependsOrder": "sequence",
"dependsOn": ["cmake debug", "make"]
},
{
"label": "Build server",
"group": "build",
"dependsOrder": "sequence",
"dependsOn": ["cmake", "make server"]
},
{
"label": "Build debug server",
"group": "build",
......
......@@ -7,17 +7,16 @@ namespace net::server {
uint64_t stream_id, uint8_t* bytes, size_t length,
picoquic_call_back_event_t fin_or_event, void* callback_ctx, void* v_stream_ctx) {
if (fin_or_event == picoquic_callback_almost_ready)
return 0; //NOTE: only use full connections
auto server = (Server*)picoquic_get_default_callback_context(picoquic_get_quic_ctx(cnx));
auto peer = (Peer*)callback_ctx;
if (peer == nullptr || peer == (void*)server) {
assert(fin_or_event == picoquic_callback_ready);
peer = server->connect(cnx);
picoquic_set_callback(cnx, connection_callback, peer);
if (fin_or_event != picoquic_callback_almost_ready) {
if (peer == nullptr || peer == (void*)server) {
assert(fin_or_event == picoquic_callback_ready);
peer = server->connect(cnx);
picoquic_set_callback(cnx, connection_callback, peer);
}
assert(peer == nullptr || peer->contains(cnx) || fin_or_event == picoquic_callback_close);
}
assert(peer == nullptr || peer->contains(cnx) || fin_or_event == picoquic_callback_close);
assert(v_stream_ctx == nullptr || ((net::stream_ctx*)v_stream_ctx)->stream_id == stream_id);
return server->connectionCallback(peer, stream_id, bytes, length, fin_or_event, v_stream_ctx);
......@@ -163,8 +162,12 @@ int Server::connectionCallback(Peer* peer, uint64_t stream_id, uint8_t* bytes, s
break;
}
case picoquic_callback_almost_ready:
// NOTE: handled is static callback
assert(peer == nullptr);
// MAYBE: use pre-connect for server status
if (Connection::GetSize(peers) >= max_connections) {
LOG_W("Server is full");
return -1;
}
break;
case picoquic_callback_ready:
/* TODO: Check that the transport parameters are what the sample expects */
......
......@@ -50,7 +50,6 @@ public:
picoquic_call_back_event_t fin_or_event, void *v_stream_ctx);
bool isRunning() const { return true; }
constexpr bool isFull(uint32_t val) const { return val >= max_connections; }
template<typename C>
void iterPeers(C call) {
......
......@@ -449,10 +449,6 @@ std::optional<uint16_t> Universe::onConnect(net::server::Peer* peer) {
LOG_I("Client connect from " << peer->getAddress());
net_client* client = new net_client(entities.at(PLAYER_ENTITY_ID).instances.emplace(Entity::Instance{spawnPoint, glm::vec3(0)}));
peer->ctx = client;
if (host.isFull(client->instanceId.index)) {
LOG_W("Server is full");
return (uint16_t)net::disconnect_reason::FULL;
}
peer->send(net::PacketWriter::Of(net::server_packet_type::CAPABILITIES, loadDistance));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment