Add command menu for messages received from loopback.
[cascardo/f2fchat.git] / friend.c
index 03d306d..af5d5e3 100644 (file)
--- a/friend.c
+++ b/friend.c
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include "message.h"
+#include "menu.h"
 
 enum {
        STATE_OFFLINE,
@@ -81,12 +82,27 @@ void friend_timeout(struct friend *friend)
 void friend_got_message(struct friend *friend, char *buffer, size_t len)
 {
        if (len >= 4 && !strncmp(buffer, "PING", 4)) {
+               friend->state = STATE_ONLINE;
                pong(friend);
        } else if (len >= 4 && !strncmp(buffer, "PONG", 4)) {
                friend->state = STATE_ONLINE;
        }
 }
 
+void friend_cmd(gchar **args, GSocketAddress *address)
+{
+       printf("%s\n", args[1]);
+}
+
+void friend_init(void)
+{
+       struct menu_item *mi;
+       mi = g_malloc(sizeof(*mi));
+       mi->cmd = "friend";
+       mi->func = friend_cmd;
+       menu_add(mi);
+}
+
 struct cache {
        GList *friends;
 };