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

Annotation of /eggdrop1.9/src/core_party.c

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


Revision 1.11 - (hide annotations) (download) (as text)
Mon Dec 15 05:10:59 2003 UTC (15 years, 4 months ago) by stdarg
Branch: MAIN
Changes since 1.10: +75 -0 lines
File MIME type: text/x-chdr
* Partyline .get and .set commands

1 stdarg 1.1 #include <eggdrop/eggdrop.h>
2 stdarg 1.11 #include <ctype.h>
3 stdarg 1.5 #include "core_config.h"
4 stdarg 1.1
5 stdarg 1.4 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
6     {
7     if (!text || !strlen(text)) {
8     partymember_write(p, "Syntax: join <channel>", -1);
9     return(0);
10     }
11     partychan_join_name(text, p);
12     return(0);
13     }
14    
15     static int party_part(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
16     {
17     partychan_t *chan;
18    
19     if (!text || !strlen(text)) chan = partychan_get_default(p);
20     else chan = partychan_lookup_name(text);
21     partychan_part(chan, p, "parting");
22     return(0);
23     }
24    
25 stdarg 1.3 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
26 stdarg 1.1 {
27 stdarg 1.3 if (!text) text = "Quit";
28     partymember_write(p, "goodbye!", -1);
29     partymember_delete(p, text);
30 stdarg 1.1 return(0);
31     }
32    
33 stdarg 1.6 static int party_msg(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
34 stdarg 1.1 {
35     return(0);
36     }
37    
38 stdarg 1.11 static void *lookup_and_check(partymember_t *p, const char *path)
39     {
40     void *root;
41     char *flags;
42     flags_t uflags, rflags;
43    
44     root = config_get_root("eggdrop");
45     root = config_exists(root, path, 0, NULL);
46     if (!root) {
47     partymember_printf(p, "That setting was not found.");
48     return(NULL);
49     }
50    
51     config_get_str(&flags, root, "flags", 0, NULL);
52     if (flags) {
53     flag_from_str(&rflags, flags);
54     if (!p->user) goto nope;
55     user_get_flags(p->user, NULL, &uflags);
56     if (!flag_match_partial(&uflags, &rflags)) goto nope;
57     }
58     return(root);
59     nope:
60     partymember_printf(p, "You cannot access that setting.");
61     return(NULL);
62     }
63    
64     static int party_get(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
65     {
66     void *root;
67     char *str = NULL;
68    
69     if (!text || !*text) {
70     partymember_printf(p, "Syntax: get <path>");
71     return(0);
72     }
73    
74     root = lookup_and_check(p, text);
75     if (!root) return(0);
76    
77     config_get_str(&str, root, NULL);
78     if (str) {
79     partymember_printf(p, "==> '%s'", str);
80     }
81     else {
82     partymember_printf(p, "Config setting not found.");
83     }
84     return(0);
85     }
86    
87 stdarg 1.6 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
88 stdarg 1.2 {
89 stdarg 1.11 void *root;
90     char *path, *str;
91     const char *next;
92    
93     egg_get_word(text, &next, &path);
94     if (next) while (isspace(*next)) next++;
95     if (!next || !path || !*path) {
96     partymember_printf(p, "Syntax: set <path> <new value>");
97     if (path) free(path);
98     return(0);
99     }
100     root = lookup_and_check(p, path);
101     free(path);
102     if (!root) return(0);
103    
104     config_get_str(&str, root, NULL);
105     partymember_printf(p, "old value: '%s'", str);
106     config_set_str(next, root, NULL);
107     config_get_str(&str, root, NULL);
108     partymember_printf(p, "new value: '%s'", str);
109 stdarg 1.2 return(0);
110     }
111    
112 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
113 stdarg 1.2 {
114 stdarg 1.11 putlog(LOG_MISC, "*", "Saving user file...");
115 stdarg 1.5 user_save(core_config.userfile);
116 stdarg 1.11 putlog(LOG_MISC, "*", "Saving config file...");
117 stdarg 1.2 core_config_save();
118     return(1);
119     }
120    
121 stdarg 1.5 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
122     {
123     if (!text || strlen(text) < 6) {
124     partymember_write(p, "Please use at least 6 characters.", -1);
125     return(0);
126     }
127     user_set_pass(p->user, text);
128     partymember_printf(p, "Changed password to '%s'", text);
129     return(0);
130     }
131    
132 stdarg 1.7 static int intsorter(const void *left, const void *right)
133     {
134     return(*(int *)left - *(int *)right);
135     }
136    
137     static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
138     {
139     partymember_t *who;
140     int *pids, len, i;
141    
142     partymember_printf(p, "Partyline members");
143     partymember_who(&pids, &len);
144     qsort(pids, len, sizeof(int), intsorter);
145     for (i = 0; i < len; i++) {
146     who = partymember_lookup_pid(pids[i]);
147 stdarg 1.8 partymember_printf(p, " [%5d] %s (%s@%s)", who->pid, who->nick, who->ident, who->host);
148 stdarg 1.7 }
149     free(pids);
150     return(0);
151     }
152    
153     static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
154     {
155     exit(0);
156     }
157    
158     static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
159     {
160     user_t *newuser;
161    
162     if (!text || !*text) {
163     partymember_printf(p, "Syntax: +user <handle>");
164     return(0);
165     }
166     if (user_lookup_by_handle(text)) {
167     partymember_printf(p, "User '%s' already exists!");
168     return(0);
169     }
170     newuser = user_new(text);
171     if (newuser) partymember_printf(p, "User '%s' created", text);
172     else partymember_printf(p, "Could not create user '%s'", text);
173     return(0);
174     }
175    
176     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
177     {
178     user_t *who;
179    
180     if (!text || !*text) {
181     partymember_printf(p, "Syntax: -user <handle>");
182     return(0);
183     }
184     who = user_lookup_by_handle(text);
185     if (!who) partymember_printf(p, "User '%s' not found");
186     else {
187     partymember_printf(p, "Deleting user '%s'", who->handle);
188     user_delete(who);
189     }
190     return(0);
191     }
192    
193     static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
194     {
195     return(0);
196     }
197    
198 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
199     {
200     return(0);
201     }
202    
203     static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
204     {
205     const char *next;
206     char *who, *flags, *chan;
207     user_t *dest;
208     flags_t flagstruct;
209     char flagstr[64];
210     int n;
211    
212     n = egg_get_words(text, &next, &who, &chan, &flags, NULL);
213     if (!chan) {
214 stdarg 1.10 if (who) free(who);
215 stdarg 1.9 partymember_printf(p, "Syntax: chattr <user> [channel] <+/-flags>");
216     return(0);
217     }
218     if (!flags) {
219     flags = chan;
220     chan = NULL;
221     }
222     dest = user_lookup_by_handle(who);
223     if (dest) {
224     user_set_flag_str(dest, chan, flags);
225     user_get_flags(dest, chan, &flagstruct);
226     flag_to_str(&flagstruct, flagstr);
227     partymember_printf(p, "Flags for %s are now '%s'", who, flagstr);
228     }
229     else {
230     partymember_printf(p, "'%s' is not a valid user", who);
231     }
232     free(who);
233     free(flags);
234     if (chan) free(chan);
235     return(0);
236     }
237    
238 stdarg 1.1 static bind_list_t core_party_binds[] = {
239 stdarg 1.6 {NULL, "join", party_join},
240     {NULL, "msg", party_msg},
241     {NULL, "newpass", party_newpass},
242     {NULL, "part", party_part},
243     {NULL, "quit", party_quit},
244 stdarg 1.7 {NULL, "who", party_who},
245 stdarg 1.11 {"n", "get", party_get},
246 stdarg 1.6 {"n", "set", party_set},
247     {"n", "save", party_save},
248 stdarg 1.7 {"n", "die", party_die},
249     {"n", "+user", party_plus_user},
250     {"n", "-user", party_minus_user},
251 stdarg 1.11 {"n", "+host", party_plus_host},
252     {"n", "-host", party_minus_host},
253 stdarg 1.9 {"n", "chattr", party_chattr},
254 stdarg 1.1 {0}
255     };
256    
257     void core_party_init()
258     {
259     bind_add_list("party", core_party_binds);
260     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23