summaryrefslogtreecommitdiff
path: root/ratatox.c
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2014-09-15 13:54:44 +0100
committersin <sin@2f30.org>2014-09-15 13:54:44 +0100
commit5858379862a198bd918d1759479207508eee3a43 (patch)
tree67d4993df2415a64e39c9c8a71cc44da1b11af4f /ratatox.c
parentd96ce07d8528e51079dca4ae1de77b21f83a8b4f (diff)
Add <id>/online
0 when friend is offline, 1 otherwise.
Diffstat (limited to 'ratatox.c')
-rw-r--r--ratatox.c32
1 files 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);
}