1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include "control_commands.h"
#include "servers.h"
#include <glib.h>
#include <string.h>
static void list_servers(GSocketConnection *connection, const gchar *cmd) {
GSocket *socket = g_socket_connection_get_socket(connection);
for(GSList *node = servers; node; node = g_slist_next(node)) {
struct server *s = node->data;
gchar *buffer = g_strdup_printf("%s:%d\n", s->host, s->port);
g_socket_send(socket, buffer, strlen(buffer), NULL, NULL);
}
}
void control_commands_handle(GSocketConnection *connection, const gchar *cmd) {
if(g_strcmp0(cmd, "servers") == 0) {
list_servers(connection, cmd);
} else {
g_debug("unknown command");
gchar *buf = g_strdup_printf("error: unknown command %s\n", cmd);
GSocket *socket = g_socket_connection_get_socket(connection);
g_socket_send(socket, buf, strlen(buf), NULL, NULL);
g_free(buf);
}
}
|