diff options
Diffstat (limited to 'vchat-commands.c')
-rwxr-xr-x | vchat-commands.c | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/vchat-commands.c b/vchat-commands.c index c81bf36..6380a44 100755 --- a/vchat-commands.c +++ b/vchat-commands.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * vchat-client - alpha version | 2 | * vchat-client - alpha version |
3 | * vchat-commands.c - handling of client commands | 3 | * vchat-commands.c - handling of client commands |
4 | * | 4 | * |
5 | * Copyright (C) 2001 Andreas Kotes <count@flatline.de> | 5 | * Copyright (C) 2003 Dirk Engling <erdgeist@erdgeist.org> |
6 | * | 6 | * |
7 | * This program is free software. It can be redistributed and/or modified, | 7 | * This program is free software. It can be redistributed and/or modified, |
8 | * provided that this copyright notice is kept intact. This program is | 8 | * provided that this copyright notice is kept intact. This program is |
@@ -38,6 +38,7 @@ COMMAND_HELP, | |||
38 | COMMAND_KEYS, | 38 | COMMAND_KEYS, |
39 | COMMAND_QUIT, | 39 | COMMAND_QUIT, |
40 | COMMAND_USER, | 40 | COMMAND_USER, |
41 | COMMAND_LOG, | ||
41 | COMMAND_FLT, | 42 | COMMAND_FLT, |
42 | COMMAND_PM, | 43 | COMMAND_PM, |
43 | COMMAND_ACTION, | 44 | COMMAND_ACTION, |
@@ -57,6 +58,7 @@ static void command_clflt ( unsigned char *tail); | |||
57 | static void command_rmflt ( unsigned char *tail); | 58 | static void command_rmflt ( unsigned char *tail); |
58 | void command_version ( unsigned char *tail); | 59 | void command_version ( unsigned char *tail); |
59 | static void command_none ( unsigned char *line); | 60 | static void command_none ( unsigned char *line); |
61 | static void command_log ( unsigned char *tail); | ||
60 | 62 | ||
61 | static void output_default ( unsigned char *tail); | 63 | static void output_default ( unsigned char *tail); |
62 | 64 | ||
@@ -74,6 +76,7 @@ commandtable[] = { | |||
74 | { COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT }, | 76 | { COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT }, |
75 | { COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER }, | 77 | { COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER }, |
76 | { COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT }, | 78 | { COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT }, |
79 | { COMMAND_LOG, "LOG", 3, command_log, NULL, NULL }, | ||
77 | { COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG }, | 80 | { COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG }, |
78 | { COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME }, | 81 | { COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME }, |
79 | { COMMAND_PMSHORT, "M", 1, command_pm, NULL, SHORT_HELPTEXT_MSG }, | 82 | { COMMAND_PMSHORT, "M", 1, command_pm, NULL, SHORT_HELPTEXT_MSG }, |
@@ -89,18 +92,26 @@ translatecommand( unsigned char **cmd) | |||
89 | int cut = 0; | 92 | int cut = 0; |
90 | int maxcut = 0; | 93 | int maxcut = 0; |
91 | 94 | ||
95 | /* We do only want to allow Command abbrevation to | ||
96 | the next newline, so that /VRES won't expand to /V RES */ | ||
97 | |||
92 | while( (*cmd)[maxcut] && ((*cmd)[maxcut] != 0x20) && ((*cmd)[maxcut] != '\n')) maxcut++; | 98 | while( (*cmd)[maxcut] && ((*cmd)[maxcut] != 0x20) && ((*cmd)[maxcut] != '\n')) maxcut++; |
93 | if( maxcut ) maxcut--; | 99 | if( maxcut ) maxcut--; |
94 | 100 | ||
101 | /* Repeatedly scan command table for command, with growing abbrevation cut off */ | ||
95 | do { | 102 | do { |
103 | /* Looks ugly, needs rewrite for better understanding */ | ||
96 | for( result = 0; | 104 | for( result = 0; |
97 | (result != COMMAND_NONE) && | 105 | (result != COMMAND_NONE) && |
98 | (strncasecmp(*cmd, commandtable[result].name, commandtable[result].len - | 106 | (strncasecmp(*cmd, commandtable[result].name, commandtable[result].len - |
99 | ((commandtable[result].len - maxcut - cut > 0) ? cut : 0))); | 107 | ((commandtable[result].len - maxcut - cut > 0) ? cut : 0))); |
100 | result++); | 108 | result++); |
101 | } while ((cut < commandtable[0].len) && (commandtable[result].number == COMMAND_NONE) && (++cut)); | 109 | } while ((cut < commandtable[0].len) && (commandtable[result].number == COMMAND_NONE) && (++cut)); |
102 | 110 | ||
111 | /* Just leave the tail... */ | ||
103 | (*cmd) += commandtable[result].len; | 112 | (*cmd) += commandtable[result].len; |
113 | |||
114 | /* ... whose start may be affected by abbrevation */ | ||
104 | if( commandtable[result].number != COMMAND_NONE ) | 115 | if( commandtable[result].number != COMMAND_NONE ) |
105 | (*cmd) -= cut; | 116 | (*cmd) -= cut; |
106 | 117 | ||
@@ -122,10 +133,8 @@ doaction( unsigned char *tail ) | |||
122 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBACTION), nick, tail); | 133 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBACTION), nick, tail); |
123 | writechan (tmpstr); | 134 | writechan (tmpstr); |
124 | } else { | 135 | } else { |
125 | |||
126 | /* missing action */ | 136 | /* missing action */ |
127 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_BGTXPUBACTION)); | 137 | msgout( " You do nothing. " ); |
128 | writechan (tmpstr); | ||
129 | } | 138 | } |
130 | } | 139 | } |
131 | 140 | ||
@@ -159,10 +168,8 @@ privatemessagetx ( unsigned char *tail ) { | |||
159 | ul_msgto(tail); | 168 | ul_msgto(tail); |
160 | 169 | ||
161 | } else { | 170 | } else { |
162 | 171 | /* Bump user to fill in missing parts */ | |
163 | /* missing nick or message body inform user */ | 172 | msgout( *tail ? " Won't send empty message. ":" Recipient missing. " ); |
164 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_BGPRIVMSG)); | ||
165 | writepriv (tmpstr); | ||
166 | } | 173 | } |
167 | } | 174 | } |
168 | 175 | ||
@@ -200,7 +207,6 @@ handleline (unsigned char *line) | |||
200 | } | 207 | } |
201 | break; | 208 | break; |
202 | default: | 209 | default: |
203 | |||
204 | /* generic server command, send to server, show to user */ | 210 | /* generic server command, send to server, show to user */ |
205 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_COMMAND), line); | 211 | snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_COMMAND), line); |
206 | networkoutput (line); | 212 | networkoutput (line); |
@@ -237,17 +243,17 @@ static void | |||
237 | command_user( unsigned char *tail) | 243 | command_user( unsigned char *tail) |
238 | { | 244 | { |
239 | while( *tail == ' ') tail++; | 245 | while( *tail == ' ') tail++; |
240 | if( strlen(tail) >= 3) { | 246 | if( *tail ) { |
241 | unsigned char * out = ul_matchuser( tail); | 247 | unsigned char * out = ul_matchuser( tail); |
242 | if( *out ) { | 248 | if( *out ) { |
243 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out); | 249 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out); |
244 | } else { | 250 | } else { |
245 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_ERR), "No user matched that substring"); | 251 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_ERR), " No user matched that regex. "); |
246 | } | 252 | } |
247 | } else { | 253 | } else { |
248 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_ERR), "Specify at least 3 characters to match users"); | 254 | snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_ERR), " Which user? "); |
249 | } | 255 | } |
250 | writechan( tmpstr ); | 256 | msgout( tmpstr ); |
251 | } | 257 | } |
252 | 258 | ||
253 | /* handle a "/msg " request */ | 259 | /* handle a "/msg " request */ |
@@ -296,10 +302,8 @@ command_help (unsigned char *line) { | |||
296 | /* handle an unknown command */ | 302 | /* handle an unknown command */ |
297 | static void | 303 | static void |
298 | command_none( unsigned char *line) { | 304 | command_none( unsigned char *line) { |
299 | flushout( ); | ||
300 | snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line); | 305 | snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line); |
301 | writeout(tmpstr); | 306 | msgout(tmpstr); |
302 | showout( ); | ||
303 | } | 307 | } |
304 | 308 | ||
305 | /* handle a "/flt " request */ | 309 | /* handle a "/flt " request */ |
@@ -366,3 +370,25 @@ command_version( unsigned char *tail) | |||
366 | writeout (vchat_cm_version); | 370 | writeout (vchat_cm_version); |
367 | showout(); | 371 | showout(); |
368 | } | 372 | } |
373 | |||
374 | /* Undocumented feature */ | ||
375 | void | ||
376 | command_log ( unsigned char *tail) | ||
377 | { | ||
378 | /* log to file */ | ||
379 | FILE *logfile = NULL; | ||
380 | while( *tail == ' ' ) | ||
381 | tail++; | ||
382 | if( (logfile = fopen( tail, "w")) ) { | ||
383 | if( *tail == '_' ) { | ||
384 | writelog_i(logfile); | ||
385 | } else { | ||
386 | writelog(logfile); | ||
387 | } | ||
388 | fclose( logfile ); | ||
389 | msgout(" Log written. "); | ||
390 | } else { | ||
391 | snprintf(tmpstr, TMPSTRSIZE, " Can't open file: %s ", tail); | ||
392 | msgout(tmpstr); | ||
393 | } | ||
394 | } | ||