/[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.9 - (hide annotations) (download) (as text)
Tue Aug 19 18:20:04 2003 UTC (15 years, 8 months ago) by stdarg
Branch: MAIN
Changes since 1.8: +40 -0 lines
File MIME type: text/x-chdr
*** empty log message ***

1 stdarg 1.1 #include <eggdrop/eggdrop.h>
2 stdarg 1.5 #include "core_config.h"
3 stdarg 1.1
4 stdarg 1.4 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
5     {
6     if (!text || !strlen(text)) {
7     partymember_write(p, "Syntax: join <channel>", -1);
8     return(0);
9     }
10     partychan_join_name(text, p);
11     return(0);
12     }
13    
14     static int party_part(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
15     {
16     partychan_t *chan;
17    
18     if (!text || !strlen(text)) chan = partychan_get_default(p);
19     else chan = partychan_lookup_name(text);
20     partychan_part(chan, p, "parting");
21     return(0);
22     }
23    
24 stdarg 1.3 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
25 stdarg 1.1 {
26 stdarg 1.3 if (!text) text = "Quit";
27     partymember_write(p, "goodbye!", -1);
28     partymember_delete(p, text);
29 stdarg 1.1 return(0);
30     }
31    
32 stdarg 1.6 static int party_msg(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
33 stdarg 1.1 {
34     return(0);
35     }
36    
37 stdarg 1.6 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
38 stdarg 1.2 {
39     return(0);
40     }
41    
42 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
43 stdarg 1.2 {
44 stdarg 1.5 user_save(core_config.userfile);
45 stdarg 1.2 core_config_save();
46     return(1);
47     }
48    
49 stdarg 1.5 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
50     {
51     if (!text || strlen(text) < 6) {
52     partymember_write(p, "Please use at least 6 characters.", -1);
53     return(0);
54     }
55     user_set_pass(p->user, text);
56     partymember_printf(p, "Changed password to '%s'", text);
57     return(0);
58     }
59    
60 stdarg 1.7 static int intsorter(const void *left, const void *right)
61     {
62     return(*(int *)left - *(int *)right);
63     }
64    
65     static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
66     {
67     partymember_t *who;
68     int *pids, len, i;
69    
70     partymember_printf(p, "Partyline members");
71     partymember_who(&pids, &len);
72     qsort(pids, len, sizeof(int), intsorter);
73     for (i = 0; i < len; i++) {
74     who = partymember_lookup_pid(pids[i]);
75 stdarg 1.8 partymember_printf(p, " [%5d] %s (%s@%s)", who->pid, who->nick, who->ident, who->host);
76 stdarg 1.7 }
77     free(pids);
78     return(0);
79     }
80    
81     static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
82     {
83     exit(0);
84     }
85    
86     static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
87     {
88     user_t *newuser;
89    
90     if (!text || !*text) {
91     partymember_printf(p, "Syntax: +user <handle>");
92     return(0);
93     }
94     if (user_lookup_by_handle(text)) {
95     partymember_printf(p, "User '%s' already exists!");
96     return(0);
97     }
98     newuser = user_new(text);
99     if (newuser) partymember_printf(p, "User '%s' created", text);
100     else partymember_printf(p, "Could not create user '%s'", text);
101     return(0);
102     }
103    
104     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
105     {
106     user_t *who;
107    
108     if (!text || !*text) {
109     partymember_printf(p, "Syntax: -user <handle>");
110     return(0);
111     }
112     who = user_lookup_by_handle(text);
113     if (!who) partymember_printf(p, "User '%s' not found");
114     else {
115     partymember_printf(p, "Deleting user '%s'", who->handle);
116     user_delete(who);
117     }
118     return(0);
119     }
120    
121     static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
122     {
123     return(0);
124     }
125    
126 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
127     {
128     return(0);
129     }
130    
131     static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
132     {
133     const char *next;
134     char *who, *flags, *chan;
135     user_t *dest;
136     flags_t flagstruct;
137     char flagstr[64];
138     int n;
139    
140     n = egg_get_words(text, &next, &who, &chan, &flags, NULL);
141     if (!chan) {
142     partymember_printf(p, "Syntax: chattr <user> [channel] <+/-flags>");
143     return(0);
144     }
145     if (!flags) {
146     flags = chan;
147     chan = NULL;
148     }
149     dest = user_lookup_by_handle(who);
150     if (dest) {
151     user_set_flag_str(dest, chan, flags);
152     user_get_flags(dest, chan, &flagstruct);
153     flag_to_str(&flagstruct, flagstr);
154     partymember_printf(p, "Flags for %s are now '%s'", who, flagstr);
155     }
156     else {
157     partymember_printf(p, "'%s' is not a valid user", who);
158     }
159     free(who);
160     free(flags);
161     if (chan) free(chan);
162     return(0);
163     }
164    
165 stdarg 1.1 static bind_list_t core_party_binds[] = {
166 stdarg 1.6 {NULL, "join", party_join},
167     {NULL, "msg", party_msg},
168     {NULL, "newpass", party_newpass},
169     {NULL, "part", party_part},
170     {NULL, "quit", party_quit},
171 stdarg 1.7 {NULL, "who", party_who},
172 stdarg 1.6 {"n", "set", party_set},
173     {"n", "save", party_save},
174 stdarg 1.7 {"n", "die", party_die},
175     {"n", "+user", party_plus_user},
176     {"n", "-user", party_minus_user},
177 stdarg 1.9 {"n", "chattr", party_chattr},
178 stdarg 1.1 {0}
179     };
180    
181     void core_party_init()
182     {
183     bind_add_list("party", core_party_binds);
184     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23