00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef lint
00021 static const char rcsid[] = "$Id: partyline.c,v 1.30 2007-11-06 00:05:40 sven Exp $";
00022 #endif
00023
00024 #include <eggdrop/eggdrop.h>
00025
00026 static char *partyline_command_chars = NULL;
00027
00028 static bind_table_t *BT_cmd = NULL;
00029 static bind_table_t *BT_party_out = NULL;
00030
00031 static int on_putlog(int flags, const char *chan, const char *text, int len);
00032
00033 extern int partychan_init(void);
00034 extern int partychan_shutdown(void);
00035
00036 extern int partymember_init(void);
00037 extern int partymember_shutdown(void);
00038
00039 static bind_list_t log_binds[] = {
00040 {NULL, NULL, on_putlog},
00041 {0}
00042 };
00043
00044 int partyline_init(void)
00045 {
00046 partychan_init();
00047 partymember_init();
00048 str_redup(&partyline_command_chars, "./");
00049 BT_cmd = bind_table_add(BTN_PARTYLINE_CMD, 5, "PsUss", MATCH_PARTIAL | MATCH_FLAGS, 0);
00050 BT_party_out = bind_table_add(BTN_PARTYLINE_OUT, 5, "isUsi", MATCH_NONE, 0);
00051 bind_add_list(BTN_LOG, log_binds);
00052 return(0);
00053 }
00054
00055 int partyline_shutdown(void)
00056 {
00057 bind_rem_list(BTN_LOG, log_binds);
00058 bind_table_del(BT_party_out);
00059 bind_table_del(BT_cmd);
00060
00061 if (partyline_command_chars)
00062 free(partyline_command_chars);
00063 partyline_command_chars = NULL;
00064
00065 partymember_shutdown();
00066 partychan_shutdown();
00067
00068 return (0);
00069 }
00070
00071
00072 int partyline_is_command(const char *text)
00073 {
00074 return strchr(partyline_command_chars, *text) ? 1 : 0;
00075 }
00076
00077
00078
00079
00080 int partyline_on_input(partychan_t *chan, partymember_t *p, const char *text, int len)
00081 {
00082 if (!p || p->flags & PARTY_DELETED || !len) return(0);
00083 if (!chan) chan = partychan_get_default(p);
00084
00085
00086 if (strchr(partyline_command_chars, *text)) {
00087 text++;
00088 len--;
00089
00090
00091 if (*text != *(text-1)) {
00092 const char *space;
00093
00094 space = strchr(text, ' ');
00095 if (space) {
00096 char *cmd;
00097
00098 len = space-text;
00099 cmd = malloc(len+1);
00100 memcpy(cmd, text, len);
00101 cmd[len] = 0;
00102 while (isspace(*space)) space++;
00103 partyline_on_command(p, cmd, space);
00104 free(cmd);
00105 }
00106 else {
00107 partyline_on_command(p, text, NULL);
00108 }
00109 return(0);
00110 }
00111 }
00112
00113 botnet_entity_t src = user_entity(p);
00114 partychan_msg(chan, &src, text, len);
00115 return(0);
00116 }
00117
00118
00119
00120 int partyline_on_command(partymember_t *p, const char *cmd, const char *text)
00121 {
00122 int r, hits;
00123
00124 if (!p) return(-1);
00125
00126 r = bind_check_hits(BT_cmd, &p->user->settings[0].flags, cmd, &hits, p, p->nick, p->user, cmd, text);
00127
00128
00129 if (hits == 0)
00130 partymember_printf (p, _("Unknown command '%s', perhaps you need '.help'?"),
00131 cmd);
00132 else {
00133 switch (r) {
00134
00135 case (BIND_RET_LOG):
00136 putlog(LOG_MISC, "*", "#%s# %s %s", p->nick, cmd, (text) ? text : "");
00137 break;
00138
00139 case (BIND_RET_LOG_COMMAND):
00140 putlog(LOG_MISC, "*", "#%s# %s ...", p->nick, cmd);
00141 break;
00142
00143 case (BIND_RET_BREAK):
00144 break;
00145 }
00146
00147 }
00148
00149 return(r);
00150 }
00151
00152 int partyline_update_info(partymember_t *p, const char *ident, const char *host)
00153 {
00154 if (!p) return(-1);
00155 if (ident) str_redup(&p->ident, ident);
00156 if (host) str_redup(&p->host, host);
00157 return(0);
00158 }
00159
00160 #if 0
00161 int partyline_write_all_but(int pid, const char *text, int len)
00162 {
00163 partymember_t *p;
00164
00165 if (len < 0) len = strlen(text);
00166 for (p = partyhead; p; p = p->next) {
00167 if (p->pid != pid) partyline_write_internal(p, text, len);
00168 }
00169 return(0);
00170 }
00171
00172 int partyline_printf(int pid, const char *fmt, ...)
00173 {
00174 va_list args;
00175 char *ptr, buf[1024];
00176 int len;
00177
00178 va_start(args, fmt);
00179 ptr = egg_mvsprintf(buf, sizeof(buf), &len, fmt, args);
00180 va_end(args);
00181
00182 partyline_write(pid, ptr, len);
00183
00184 if (ptr != buf) free(ptr);
00185 return(0);
00186 }
00187
00188 int partyline_printf_chan_but(int cid, int pid, const char *fmt, ...)
00189 {
00190 va_list args;
00191 char *ptr, buf[1024];
00192 int len;
00193
00194 va_start(args, fmt);
00195 ptr = egg_mvsprintf(buf, sizeof(buf), &len, fmt, args);
00196 va_end(args);
00197
00198 partyline_write_chan_but(cid, pid, ptr, len);
00199
00200 if (ptr != buf) free(ptr);
00201 return(0);
00202 }
00203
00204 int partyline_printf_all_but(int pid, const char *fmt, ...)
00205 {
00206 va_list args;
00207 char *ptr, buf[1024];
00208 int len;
00209
00210 va_start(args, fmt);
00211 ptr = egg_mvsprintf(buf, sizeof(buf), &len, fmt, args);
00212 va_end(args);
00213
00214 partyline_write_all_but(pid, ptr, len);
00215
00216 if (ptr != buf) free(ptr);
00217 return(0);
00218 }
00219 #endif
00220
00221
00222 static int on_putlog(int flags, const char *chan, const char *text, int len)
00223 {
00224 partychan_t *chanptr;
00225 botnet_entity_t me = bot_entity(NULL);
00226
00227 chanptr = partychan_lookup_name(chan);
00228 if (!chanptr)
00229 return(0);
00230
00231 localchan_msg(chanptr, &me, text, len);
00232 return(0);
00233 }
00234
00235 int partyline_idx_privmsg(int idx, partymember_t *dest, botnet_entity_t *src, const char *text, int len)
00236 {
00237 char *ts;
00238
00239 ts = timer_get_timestamp();
00240
00241 if (src) {
00242 if (len >= 9 && !strncasecmp(text, "\1ACTION ", 8) && text[len - 1] == 1) {
00243 egg_iprintf(idx, "%s* %s %.*s\r\n", ts, entity_common_name(src), len - 9, text + 8);
00244 } else {
00245 egg_iprintf(idx, "%s[%s] %s\r\n", ts, entity_common_name(src), text);
00246 }
00247 } else {
00248 egg_iprintf(idx, "%s\r\n", text);
00249 }
00250 return 0;
00251 }
00252
00253 int partyline_idx_nick(int idx, partymember_t *src, const char *oldnick, const char *newnick)
00254 {
00255 if (src->bot) egg_iprintf(idx, "* %s*** %s@%s is now known as %s@%s.\n", timer_get_timestamp(), oldnick, src->bot->name, newnick, src->bot->name);
00256 else egg_iprintf(idx, "* %s*** %s is now known as %s.\n", timer_get_timestamp(), oldnick, newnick);
00257 return 0;
00258 }
00259
00260 int partyline_idx_quit(int idx, partymember_t *src, const char *text, int len)
00261 {
00262 egg_iprintf(idx, "* %s*** %s (%s@%s) has quit: %s\n", timer_get_timestamp(), src->common_name, src->ident, src->host, text);
00263 return 0;
00264 }
00265
00266 int partyline_idx_chanmsg(int idx, partychan_t *chan, botnet_entity_t *src, const char *text, int len)
00267 {
00268 char *ts;
00269
00270 ts = timer_get_timestamp();
00271
00272 if (src) {
00273 if (len >= 9 && !strncasecmp(text, "\1ACTION ", 8) && text[len - 1] == 1) {
00274 egg_iprintf(idx, "%s %s* %s %.*s\r\n", chan->name, ts, entity_common_name(src), len - 9, text + 8);
00275 } else {
00276 egg_iprintf(idx, "%s %s<%s> %s\r\n", chan->name, ts, entity_common_name(src), text);
00277 }
00278 } else {
00279 egg_iprintf(idx, "%s %s%s\r\n", chan->name, ts, text);
00280 }
00281 return 0;
00282 }
00283
00284 int partyline_idx_join(int idx, partychan_t *chan, partymember_t *src)
00285 {
00286 egg_iprintf(idx, "%s %s*** %s (%s@%s) has joined the channel.\r\n", chan->name, timer_get_timestamp(), src->common_name, src->ident, src->host);
00287 return 0;
00288 }
00289
00290 int partyline_idx_part(int idx, partychan_t *chan, partymember_t *src, const char *text, int len)
00291 {
00292 egg_iprintf(idx, "%s %s*** %s (%s@%s) has left %s: %s\r\n", chan->name, timer_get_timestamp(), src->common_name, src->ident, src->host, chan->name, text);
00293 return 0;
00294 }
00295