aboutsummaryrefslogtreecommitdiff
path: root/src/ramen/protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ramen/protocol.c')
-rw-r--r--src/ramen/protocol.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/ramen/protocol.c b/src/ramen/protocol.c
new file mode 100644
index 0000000..eea5da2
--- /dev/null
+++ b/src/ramen/protocol.c
@@ -0,0 +1,49 @@
+#include "../include/protocol.h"
+#include "../include/better_string.h"
+#include "../include/helpers.h"
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <time.h>
+
+extern int GUESTS;
+
+string_t *date_str() {
+ char dateStr[11];
+ time_t t = time(NULL);
+ struct tm *tm_info = localtime(&t);
+
+ strftime(dateStr, sizeof(dateStr), "%d-%m-%Y", tm_info);
+ return init_string(dateStr);
+}
+
+bool same_day(struct tm *date1, struct tm *date2) {
+ return (date1->tm_year == date2->tm_year && date1->tm_mon == date2->tm_mon &&
+ date1->tm_mday == date2->tm_mday);
+}
+
+user_t *init_user(int fd) {
+ char buf[20];
+ user_t *user = safe_calloc(1, sizeof(user_t));
+ string_t *nick = init_string("guest");
+ GUESTS++;
+ snprintf(buf, 20, "%d", GUESTS);
+ string_concat_const(nick, buf);
+ user->is_guest = true;
+ user->autojoin = NULL;
+ user->dms = NULL;
+ return user;
+}
+
+server_t *init_server(size_t size) {
+ server_t *s = safe_calloc(1, sizeof(server_t));
+ s->accmap = init_ht(size);
+ s->chanmap = init_ht(size);
+ s->fdmap = init_ht(size);
+ s->friendmap = init_ht(size);
+ s->opmap = init_ht(size);
+ s->usermap = init_ht(size);
+ s->fds = NULL;
+ s->nfds = 4096;
+ return s;
+}