forked from status-im/nimbus-eth1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapper_example.c
46 lines (34 loc) · 1.04 KB
/
wrapper_example.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include "libnimbus.h"
void NimMain();
void print_msg(received_message* msg, void* udata) {
// Note: early null chars will terminate string early
printf("received message %.*s\n", (int)msg->decodedLen, msg->decoded);
}
const char* channel = "status-test-c";
const char* msg = "testing message";
int main(int argc, char* argv[]) {
time_t lastmsg;
NimMain();
nimbus_start(30303, true, false, 0.002, NULL, false);
nimbus_join_public_chat(channel, print_msg);
lastmsg = time(NULL);
while(1) {
usleep(1);
if (lastmsg + 1 <= time(NULL)) {
lastmsg = time(NULL);
char buf[4096];
snprintf(buf, 4095,
"[\"~#c4\",[\"%s\",\"text/plain\",\"~:public-group-user-message\",%ld,%ld,[\"^ \",\"~:chat-id\",\"%s\",\"~:text\",\"%s\"]]]",
msg, lastmsg * 1000 * 100, lastmsg * 1000, channel, msg);
printf("Posting %s\n", buf);
nimbus_post_public(channel, buf);
}
nimbus_poll();
}
}