#include "../include/protocol.h" #include "../include/better_string.h" #include "../include/helpers.h" #include #include #include 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; }