/[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.1 - (show annotations) (download) (as text)
Mon Oct 7 22:37:27 2002 UTC (17 years, 1 month ago) by stdarg
Branch: MAIN
File MIME type: text/x-chdr
* Script interface to new user functions.

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23