feat(lobby): implement bounded WebSocket sessions and countdown

This commit is contained in:
2026-09-04 02:13:26 +03:00
parent b10c7f5972
commit 996bda9567
21 changed files with 2040 additions and 64 deletions
@@ -0,0 +1,57 @@
#ifndef MAZE32_GATEWAY_H
#define MAZE32_GATEWAY_H
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
#include "esp_http_server.h"
#include "esp_timer.h"
#include "maze32_lobby.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MAZE32_GATEWAY_CONNECTION_LIMIT MAZE32_SESSION_LIMIT
#define MAZE32_GATEWAY_QUEUE_LIMIT 12U
#define MAZE32_GATEWAY_OUTGOING_LIMIT 768U
#define MAZE32_GATEWAY_RATE_LIMIT_PER_SECOND 20U
typedef struct {
int active;
int socket_fd;
uint32_t last_client_sequence;
uint64_t rate_window_started_ms;
unsigned int messages_in_window;
} maze32_gateway_connection_t;
typedef struct {
int socket_fd;
size_t length;
char payload[MAZE32_GATEWAY_OUTGOING_LIMIT];
} maze32_gateway_outgoing_t;
typedef struct {
httpd_handle_t server;
maze32_lobby_t lobby;
maze32_gateway_connection_t connections[MAZE32_GATEWAY_CONNECTION_LIMIT];
maze32_gateway_outgoing_t outgoing[MAZE32_GATEWAY_QUEUE_LIMIT];
size_t outgoing_head;
size_t outgoing_count;
uint32_t server_sequence;
unsigned int suggestion_index;
esp_timer_handle_t countdown_timer;
} maze32_gateway_t;
esp_err_t maze32_gateway_init(maze32_gateway_t* gateway);
void maze32_gateway_set_server(maze32_gateway_t* gateway, httpd_handle_t server);
esp_err_t maze32_gateway_register(httpd_handle_t server, maze32_gateway_t* gateway);
void maze32_gateway_close_socket(httpd_handle_t server, int socket_fd);
int maze32_gateway_can_reconfigure(const maze32_gateway_t* gateway);
#ifdef __cplusplus
}
#endif
#endif
+3 -1
View File
@@ -3,13 +3,15 @@
#include "esp_err.h"
#include "esp_http_server.h"
#include "maze32_gateway.h"
#include "maze32_health.h"
#ifdef __cplusplus
extern "C" {
#endif
esp_err_t maze32_web_start(httpd_handle_t *server, maze32_health_t *health);
esp_err_t maze32_web_start(httpd_handle_t* server, maze32_health_t* health,
maze32_gateway_t* gateway);
#ifdef __cplusplus
}