From 5858379862a198bd918d1759479207508eee3a43 Mon Sep 17 00:00:00 2001 From: sin Date: Mon, 15 Sep 2014 13:54:44 +0100 Subject: Add /online 0 when friend is offline, 1 otherwise. --- ratatox.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ratatox.c b/ratatox.c index 3a1c63a..4b5e1f5 100644 --- a/ratatox.c +++ b/ratatox.c @@ -199,9 +199,11 @@ tokenize(char *s, char **args, int maxargs) static void cb_conn_status(Tox *tox, int32_t fid, uint8_t status, void *udata) { + FILE *fp; struct friend *f; uint8_t name[TOX_MAX_NAME_LENGTH + 1]; uint8_t *nick; + char path[PATH_MAX]; int n; n = tox_get_name(tox, fid, name); @@ -211,17 +213,17 @@ cb_conn_status(Tox *tox, int32_t fid, uint8_t status, void *udata) } name[n] = '\0'; - if (n == 0) { - if (status == 0) - printf("Anonymous went offline\n"); - else - printf("Anonymous came online\n"); - } else { - if (status == 0) - printf("%s went offline\n", name); - else - printf("%s came online\n", name); + printf("%s %s\n", n == 0 ? (uint8_t *)"Anonymous" : name, + status == 0 ? "went offline" : "came online"); + + snprintf(path, sizeof(path), "%s/online", f->idstr); + fp = fopen(path, "w"); + if (!fp) { + perror("fopen"); + exit(1); } + fputs(status == 0 ? "0\n" : "1\n", fp); + fclose(fp); TAILQ_FOREACH(f, &friendhead, entry) if (f->fid == fid) @@ -553,6 +555,16 @@ friendcreate(int32_t fid) } fclose(fp); + snprintf(path, sizeof(path), "%s/online", f->idstr); + fp = fopen(path, "w"); + if (!fp) { + perror("fopen"); + exit(1); + } + /* friend is offline by default */ + fputs("0\n", fp); + fclose(fp); + TAILQ_INSERT_TAIL(&friendhead, f, entry); } -- cgit v1.2.3