summaryrefslogtreecommitdiff
path: root/vchat-commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'vchat-commands.c')
-rwxr-xr-xvchat-commands.c106
1 files changed, 52 insertions, 54 deletions
diff --git a/vchat-commands.c b/vchat-commands.c
index 5f54733..5dc7b4f 100755
--- a/vchat-commands.c
+++ b/vchat-commands.c
@@ -25,7 +25,7 @@
25#include "vchat-help.h" 25#include "vchat-help.h"
26 26
27/* version of this module */ 27/* version of this module */
28unsigned char *vchat_cm_version = "$Id$"; 28char *vchat_cm_version = "$Id$";
29 29
30/* our "/command " table */ 30/* our "/command " table */
31enum { 31enum {
@@ -38,29 +38,30 @@ COMMAND_HELP,
38COMMAND_KEYS, 38COMMAND_KEYS,
39COMMAND_QUIT, 39COMMAND_QUIT,
40COMMAND_USER, 40COMMAND_USER,
41COMMAND_LOG,
42COMMAND_FLT, 41COMMAND_FLT,
43COMMAND_PM, 42COMMAND_PM,
44COMMAND_ACTION, 43COMMAND_ACTION,
45COMMAND_PMSHORT, 44COMMAND_PMSHORT,
45COMMAND_QUERY,
46COMMAND_QUITSHORT,
46COMMAND_PLAIN, 47COMMAND_PLAIN,
47COMMAND_NONE 48COMMAND_NONE
48}; 49};
49 50
50static void command_quit ( unsigned char *tail); 51static void command_quit ( char *tail);
51static void command_user ( unsigned char *tail); 52static void command_user ( char *tail);
52static void command_pm ( unsigned char *tail); 53static void command_pm ( char *tail);
53static void command_action ( unsigned char *tail); 54static void command_action ( char *tail);
54static void command_help ( unsigned char *tail); 55static void command_help ( char *tail);
55static void command_flt ( unsigned char *tail); 56static void command_flt ( char *tail);
56static void command_lsflt ( unsigned char *tail); 57static void command_lsflt ( char *tail);
57static void command_clflt ( unsigned char *tail); 58static void command_clflt ( char *tail);
58static void command_rmflt ( unsigned char *tail); 59static void command_rmflt ( char *tail);
59 void command_version ( unsigned char *tail); 60 void command_version ( char *tail);
60static void command_none ( unsigned char *line); 61static void command_none ( char *line);
61static void command_log ( unsigned char *tail); 62static void command_query ( char *tail);
62 63
63static void output_default ( unsigned char *tail); 64static void output_default ( char *tail);
64 65
65/* commandentry defined in vchat.h */ 66/* commandentry defined in vchat.h */
66 67
@@ -73,20 +74,21 @@ commandtable[] = {
73{ COMMAND_HELP, "HELP", 4, command_help, SHORT_HELPTEXT_HELP, LONG_HELPTEXT_HELP }, 74{ COMMAND_HELP, "HELP", 4, command_help, SHORT_HELPTEXT_HELP, LONG_HELPTEXT_HELP },
74{ COMMAND_FILTERS, "FILTERS", 7, command_help, SHORT_HELPTEXT_FILTERS, LONG_HELPTEXT_FILTERS }, 75{ COMMAND_FILTERS, "FILTERS", 7, command_help, SHORT_HELPTEXT_FILTERS, LONG_HELPTEXT_FILTERS },
75{ COMMAND_KEYS, "KEYS", 4, command_help, SHORT_HELPTEXT_KEYS, LONG_HELPTEXT_KEYS }, 76{ COMMAND_KEYS, "KEYS", 4, command_help, SHORT_HELPTEXT_KEYS, LONG_HELPTEXT_KEYS },
77{ COMMAND_QUERY, "QUERY", 5, command_query, NULL, NULL },
76{ COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT }, 78{ COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT },
77{ COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER }, 79{ COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER },
78{ COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT }, 80{ COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT },
79{ COMMAND_LOG, "LOG", 3, command_log, NULL, NULL },
80{ COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG }, 81{ COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG },
81{ COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME }, 82{ COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME },
82{ COMMAND_PMSHORT, "M", 1, command_pm, NULL, SHORT_HELPTEXT_MSG }, 83{ COMMAND_PMSHORT, "M", 1, command_pm, NULL, SHORT_HELPTEXT_MSG },
84{ COMMAND_QUITSHORT,"Q", 1, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT },
83{ COMMAND_PLAIN, "/", 1, output_default, NULL, NULL }, 85{ COMMAND_PLAIN, "/", 1, output_default, NULL, NULL },
84{ COMMAND_NONE, "", 0, command_none, NULL, NULL } 86{ COMMAND_NONE, "", 0, command_none, NULL, NULL }
85}; 87};
86 88
87/* parse "/command" */ 89/* parse "/command" */
88static int 90static int
89translatecommand( unsigned char **cmd) 91translatecommand( char **cmd)
90{ 92{
91 int result; 93 int result;
92 int cut = 0; 94 int cut = 0;
@@ -120,7 +122,7 @@ translatecommand( unsigned char **cmd)
120 122
121/* handle thought */ 123/* handle thought */
122static void 124static void
123dothink( unsigned char *tail, char nice ) 125dothink( char *tail, char nice )
124{ 126{
125 while( *tail == ' ' ) tail++; 127 while( *tail == ' ' ) tail++;
126 128
@@ -136,7 +138,7 @@ dothink( unsigned char *tail, char nice )
136 138
137/* handle action */ 139/* handle action */
138static void 140static void
139doaction( unsigned char *tail ) 141doaction( char *tail )
140{ 142{
141 while( *tail == ' ' ) tail++; 143 while( *tail == ' ' ) tail++;
142 144
@@ -156,8 +158,8 @@ doaction( unsigned char *tail )
156 158
157/* handle private message outgoing */ 159/* handle private message outgoing */
158static void 160static void
159privatemessagetx ( unsigned char *tail ) { 161privatemessagetx ( char *tail ) {
160 unsigned char *mesg; 162 char *mesg;
161 163
162 /* find nick */ 164 /* find nick */
163 while( *tail==' ') tail++; 165 while( *tail==' ') tail++;
@@ -191,7 +193,7 @@ privatemessagetx ( unsigned char *tail ) {
191 193
192/* handle line entered by user */ 194/* handle line entered by user */
193void 195void
194handleline (unsigned char *line) 196handleline (char *line)
195{ 197{
196#ifdef DEBUG 198#ifdef DEBUG
197 /* debugging? log users input! */ 199 /* debugging? log users input! */
@@ -245,7 +247,7 @@ handleline (unsigned char *line)
245} 247}
246 248
247static void 249static void
248output_default( unsigned char *line ) { 250output_default(char *line ) {
249 /* prepare for output on display */ 251 /* prepare for output on display */
250 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBMSG), nick, line); 252 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBMSG), nick, line);
251 253
@@ -258,11 +260,11 @@ output_default( unsigned char *line ) {
258 260
259/* handle a "/user " request */ 261/* handle a "/user " request */
260static void 262static void
261command_user( unsigned char *tail) 263command_user(char *tail)
262{ 264{
263 while( *tail == ' ') tail++; 265 while( *tail == ' ') tail++;
264 if( *tail ) { 266 if( *tail ) {
265 unsigned char * out = ul_matchuser( tail); 267 char * out = ul_matchuser( tail);
266 if( *out ) { 268 if( *out ) {
267 snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out); 269 snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out);
268 } else { 270 } else {
@@ -276,14 +278,14 @@ command_user( unsigned char *tail)
276 278
277/* handle a "/msg " request */ 279/* handle a "/msg " request */
278static void 280static void
279command_pm (unsigned char *tail) 281command_pm (char *tail)
280{ 282{
281 privatemessagetx( tail ); 283 privatemessagetx( tail );
282} 284}
283 285
284/* handle a help request */ 286/* handle a help request */
285static void 287static void
286command_help (unsigned char *line) { 288command_help (char *line) {
287 flushout( ); 289 flushout( );
288 while( *line==' ') line++; 290 while( *line==' ') line++;
289 if( *line ) { /* Get help on command */ 291 if( *line ) { /* Get help on command */
@@ -297,7 +299,7 @@ command_help (unsigned char *line) {
297 line = commandtable[i].help; 299 line = commandtable[i].help;
298 if( line ) { 300 if( line ) {
299 while( *line ) { 301 while( *line ) {
300 unsigned char *tmp = tmpstr; 302 char *tmp = tmpstr;
301 while( *line && (*line != '\n') ) 303 while( *line && (*line != '\n') )
302 *tmp++ = *line++; 304 *tmp++ = *line++;
303 *tmp = '\0'; if( *line == '\n') line++; 305 *tmp = '\0'; if( *line == '\n') line++;
@@ -319,15 +321,15 @@ command_help (unsigned char *line) {
319 321
320/* handle an unknown command */ 322/* handle an unknown command */
321static void 323static void
322command_none( unsigned char *line) { 324command_none(char *line) {
323 snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line); 325 snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line);
324 msgout(tmpstr); 326 msgout(tmpstr);
325} 327}
326 328
327/* handle a "/flt " request */ 329/* handle a "/flt " request */
328static void 330static void
329command_flt( unsigned char *tail){ 331command_flt(char *tail){
330 unsigned char colour; 332 char colour;
331 while(*tail==' ') tail++; 333 while(*tail==' ') tail++;
332 colour = *tail++; 334 colour = *tail++;
333 while( colour && *tail == ' ') tail++; 335 while( colour && *tail == ' ') tail++;
@@ -338,34 +340,34 @@ command_flt( unsigned char *tail){
338 340
339/* handle a "/clflt " request */ 341/* handle a "/clflt " request */
340static void 342static void
341command_clflt ( unsigned char *tail) { 343command_clflt (char *tail) {
342 while( *tail == ' ') tail++; 344 while( *tail == ' ') tail++;
343 clearfilters( *tail ); 345 clearfilters( *tail );
344} 346}
345 347
346/* handle a "/rmflt " request */ 348/* handle a "/rmflt " request */
347static void 349static void
348command_rmflt ( unsigned char *tail) { 350command_rmflt (char *tail) {
349 while( *tail == ' ') tail++; 351 while( *tail == ' ') tail++;
350 removefilter( tail ); 352 removefilter( tail );
351} 353}
352 354
353/* list filters */ 355/* list filters */
354static void 356static void
355command_lsflt ( unsigned char *tail) { 357command_lsflt (char *tail) {
356 listfilters(); 358 listfilters();
357} 359}
358 360
359/* handle a "/me " action */ 361/* handle a "/me " action */
360static void 362static void
361command_action( unsigned char *tail) 363command_action(char *tail)
362{ 364{
363 doaction( tail); 365 doaction( tail);
364} 366}
365 367
366/* handle a "/quit " exit */ 368/* handle a "/quit " exit */
367static void 369static void
368command_quit ( unsigned char *tail) 370command_quit(char *tail)
369{ 371{
370 /* send users message to server */ 372 /* send users message to server */
371 snprintf (tmpstr, TMPSTRSIZE, ".x %s", tail); 373 snprintf (tmpstr, TMPSTRSIZE, ".x %s", tail);
@@ -377,7 +379,7 @@ command_quit ( unsigned char *tail)
377 379
378/* print out version */ 380/* print out version */
379void 381void
380command_version( unsigned char *tail) 382command_version(char *tail)
381{ 383{
382 /* output internal versions of all modules */ 384 /* output internal versions of all modules */
383 flushout(); 385 flushout();
@@ -389,24 +391,20 @@ command_version( unsigned char *tail)
389 showout(); 391 showout();
390} 392}
391 393
392/* Undocumented feature */ 394/* start or end a query */
393void 395void
394command_log ( unsigned char *tail) 396command_query(char *tail)
395{ 397{
396 /* log to file */ 398 char *msg;
397 FILE *logfile = NULL; 399 while( *tail == ' ') tail++;
398 while( *tail == ' ' ) 400
399 tail++; 401 // Check, if a message is to be sent in first query
400 if( (logfile = fopen( tail, "w")) ) { 402 // Note: this is safe, since readline chops trailing spaces
401 if( *tail == '_' ) { 403 if((msg = strchr(tail, ' '))) {
402 writelog_i(logfile); 404 privatemessagetx( tail );
403 } else { 405 *msg = 0;
404 writelog(logfile);
405 }
406 fclose( logfile );
407 msgout(" Log written. ");
408 } else {
409 snprintf(tmpstr, TMPSTRSIZE, " Can't open file: %s ", tail);
410 msgout(tmpstr);
411 } 406 }
407
408 // Do the ui stuff for query
409 handlequery( tail );
412} 410}