void OnTcpServerEvent(int64_t server_handle, int64_t conn_id, int32_t event_type,
int64_t data, int32_t data_len, int64_t user_data) {
if (event_type == 1) {
const char* msg = (char*)data;
if (strncmp(msg, "quit", 4) == 0) {
printf("客户端请求断开[conn_id=%lld]\n", conn_id);
TcpServerDisconnect(instance, server_handle, conn_id);
}
} else if (event_type == 2) {
printf("连接已断开[conn_id=%lld]\n", conn_id);
}
}
void DisconnectAllClients(int64_t server) {
const char* connIds = TcpServerGetAllConnectionIds(instance, server);
if (connIds != NULL) {
char* ids = strdup(connIds);
char* token = strtok(ids, ",");
while (token != NULL) {
int64_t conn_id = atoll(token);
TcpServerDisconnect(instance, server, conn_id);
token = strtok(NULL, ",");
}
free(ids);
FreeStringPtr(instance, connIds);
}
}