TNT/include/chat_room.h
m1ngsama e10b43074c feat: consolidated improvements, manpage, and deployment prep
Bug fixes:
- Fix data race on client->width/height (now _Atomic int)
- Persist join/leave system messages via message_save()
- Make room_add_message static to enforce lock contract
- Fix execute_command mutating command_input directly
- Increase help_copy buffer from 4096 to 8192 for CJK safety

New features:
- Add :msg/:w whisper command for private messaging
- Add command history with UP/DOWN arrows in command mode
- Add Ctrl+D/U/F/B page scrolling in normal mode
- Add :q/:quit/:exit Vim-style disconnect

Unix community:
- Add tnt.1 manpage (roff format) with full documentation
- Add manpage install/uninstall to Makefile
2026-04-19 17:49:06 +08:00

51 lines
1.2 KiB
C

#ifndef CHAT_ROOM_H
#define CHAT_ROOM_H
#include "common.h"
#include "message.h"
/* Forward declaration */
struct client;
/* Chat room structure */
typedef struct {
pthread_rwlock_t lock;
struct client **clients;
int client_count;
int client_capacity;
message_t *messages;
int message_count;
uint64_t update_seq;
} chat_room_t;
/* Global chat room instance */
extern chat_room_t *g_room;
/* Initialize chat room */
chat_room_t* room_create(void);
/* Destroy chat room */
void room_destroy(chat_room_t *room);
/* Add client to room */
int room_add_client(chat_room_t *room, struct client *client);
/* Remove client from room */
void room_remove_client(chat_room_t *room, struct client *client);
/* Broadcast message to all clients */
void room_broadcast(chat_room_t *room, const message_t *msg);
/* Get message by index (thread-safe value copy) */
bool room_get_message(chat_room_t *room, int index, message_t *out);
/* Get total message count */
int room_get_message_count(chat_room_t *room);
/* Get online client count */
int room_get_client_count(chat_room_t *room);
/* Get room update sequence */
uint64_t room_get_update_seq(chat_room_t *room);
#endif /* CHAT_ROOM_H */