#include "control_commands.h" #include "servers.h" #include #include 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); } }