blob: eea5da2ab3765682dc7f1fb9700ec17f9ecb2816 (
plain)
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
47
48
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;
}
|