-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.c
66 lines (47 loc) · 1.23 KB
/
users.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/******************************************************************************
* eiwic - Extensible Ircbot Written In C
* Copyright (C) Hannes Gräuler <[email protected]>
*
* users.c: This file contains functions to manage users on IRC
*****************************************************************************/
#include "eiwic.h"
#include "plugins.h"
#include "users.h"
USER *user_add(STRING name)
{
USER *user;
if ((user = user_find(name)) != NULL)
return user;
user = malloc(sizeof(USER));
bzero(user, sizeof(USER));
user_nickset(user, name);
dlist_ins_next(&e_global->users, dlist_tail(&e_global->users), user);
#ifdef VV_DEBUG
log(LOG_VERBOSE_DEBUG, "User '%s' has been added.", user->nick);
#endif
return user;
}
void user_nickset(USER *user, STRING newnick)
{
strncpy(user->nick, newnick, sizeof(user->nick)- 1);
}
void user_remove(USER *user)
{
if (user)
dlist_remove_and_destroy(&e_global->users, user);
return;
}
void user_destroy(void *data)
{
USER *user = data;
free(user);
}
USER *user_find(STRING name)
{
DListElmt *el;
FOR_EACH(&e_global->users, el)
if (strcasecmp(((USER *)el->data)->nick, name) == 0)
return (USER *)el->data;
return NULL;
}
/*--- end of channel functions ---*/