/[cvs]/eggdrop1.9/src/scriptuser.c
ViewVC logotype

Contents of /eggdrop1.9/src/scriptuser.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Fri Oct 11 06:56:02 2002 UTC (17 years, 1 month ago) by stdarg
Branch: MAIN
Changes since 1.2: +11 -2 lines
File MIME type: text/x-chdr
* Made 'uset' bind to intercept user settings, and 'uflag' bind for user flags. Next comes 'uhost' I guess.

1 #include "main.h"
2 #include <eggdrop/flags.h>
3 #include <eggdrop/users.h>
4
5 static char *script_uid_to_handle(int uid)
6 {
7 user_t *u;
8
9 u = user_lookup_by_uid(uid);
10 if (u) return(u->handle);
11 return(NULL);
12 }
13
14 static int script_handle_to_uid(char *handle)
15 {
16 user_t *u;
17
18 u = user_lookup_by_handle(handle);
19 if (u) return(u->uid);
20 return(0);
21 }
22
23 static int script_validhandle(char *handle)
24 {
25 if (user_lookup_by_handle(handle)) return(1);
26 return(0);
27 }
28
29 static int script_validuid(int uid)
30 {
31 if (user_lookup_by_uid(uid)) return(1);
32 return(0);
33 }
34
35 static int script_adduser(char *handle)
36 {
37 user_t *u;
38
39 u = user_new(handle);
40 if (!u) return(-1);
41 return(0);
42 }
43
44 static int script_user_addmask(int uid, char *ircmask)
45 {
46 user_t *u = user_lookup_by_uid(uid);
47 if (!u) return(-1);
48 user_add_ircmask(u, ircmask);
49 return(0);
50 }
51
52 static char *script_user_find(char *irchost)
53 {
54 user_t *u;
55
56 u = user_lookup_by_irchost_nocache(irchost);
57 if (u) return(u->handle);
58 return(NULL);
59 }
60
61 static char *script_user_get(int nargs, int uid, char *chan, char *setting)
62 {
63 char *value;
64 user_t *u;
65
66 /* If there's a missing arg, it's the channel. */
67 if (nargs == 2) {
68 setting = chan;
69 chan = NULL;
70 }
71
72 u = user_lookup_by_uid(uid);
73 if (!u) return(NULL);
74
75 user_get_setting(u, chan, setting, &value);
76 return(value);
77 }
78
79 static int script_user_set(int nargs, int uid, char *chan, char *setting, char *value)
80 {
81 int i;
82 user_t *u;
83
84 /* If there's a missing arg, it's the channel. */
85 if (nargs == 3) {
86 value = setting;
87 setting = chan;
88 chan = NULL;
89 }
90
91 u = user_lookup_by_uid(uid);
92 if (!u) return(-1);
93 i = user_set_setting(u, chan, setting, value);
94 return(i);
95 }
96
97 static int script_user_save(char *fname)
98 {
99 if (!fname) fname = "_users.xml";
100 user_save(fname);
101 return(0);
102 }
103
104 static int script_setflags(int uid, char *chan, char *flags)
105 {
106 user_t *u;
107
108 u = user_lookup_by_uid(uid);
109 if (!u) return(-1);
110
111 if (!flags) {
112 flags = chan;
113 chan = NULL;
114 }
115
116 user_set_flag_str(u, chan, flags);
117 return(0);
118 }
119
120 static char *script_getflags(int uid, char *chan)
121 {
122 user_t *u;
123 flags_t flags;
124 char flagstr[64];
125
126 u = user_lookup_by_uid(uid);
127 if (!u) return(NULL);
128 if (user_get_flags(u, chan, &flags)) return(NULL);
129 flag_to_str(&flags, flagstr);
130 return strdup(flagstr);
131 }
132
133 script_command_t script_new_user_cmds[] = {
134 {"", "user_uid_to_handle", script_uid_to_handle, NULL, 1, "i", "uid", SCRIPT_STRING, 0},
135 {"", "user_handle_to_uid", script_handle_to_uid, NULL, 1, "s", "handle", SCRIPT_INTEGER, 0},
136 {"", "user_validhandle", script_validhandle, NULL, 1, "s", "handle", SCRIPT_INTEGER, 0},
137 {"", "user_validuid", script_validuid, NULL, 1, "i", "uid", SCRIPT_INTEGER, 0},
138 {"", "user_add", script_adduser, NULL, 1, "s", "handle", SCRIPT_INTEGER, 0},
139 {"", "user_addmask", script_user_addmask, NULL, 2, "is", "uid ircmask", SCRIPT_INTEGER, 0},
140 {"", "user_find", script_user_find, NULL, 1, "s", "irchost", SCRIPT_STRING, 0},
141 {"", "user_get", script_user_get, NULL, 2, "iss", "uid ?channel? setting", SCRIPT_STRING, SCRIPT_VAR_ARGS | SCRIPT_PASS_COUNT},
142 {"", "user_set", script_user_set, NULL, 3, "isss", "uid ?channel? setting value", SCRIPT_INTEGER, SCRIPT_VAR_ARGS | SCRIPT_PASS_COUNT},
143 {"", "user_getflags", script_getflags, NULL, 1, "is", "uid ?chan?", SCRIPT_STRING | SCRIPT_FREE, SCRIPT_VAR_ARGS},
144 {"", "user_setflags", script_setflags, NULL, 2, "iss", "uid ?chan? flags", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
145 {"", "user_load", user_save, NULL, 0, "s", "?fname?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
146 {"", "user_save", script_user_save, NULL, 0, "s", "?fname?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
147 {0}
148 };

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23