2 6e07fb41 2001-12-21 alex * ngIRCd -- The Next Generation IRC Daemon
3 b6254bbb 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
5 490f28ff 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 490f28ff 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 490f28ff 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 490f28ff 2002-12-12 alex * (at your option) any later version.
9 490f28ff 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
11 490f28ff 2002-12-12 alex * IRC command parser and validator
15 ca33cbda 2002-03-12 alex #include "portab.h"
17 57c7e236 2004-01-17 alex static char UNUSED id[] = "$Id: parse.c,v 1.60 2004/01/17 03:17:49 alex Exp $";
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 6e07fb41 2001-12-21 alex #include <assert.h>
21 1c8c92af 2002-01-05 alex #include <stdlib.h>
22 6e07fb41 2001-12-21 alex #include <stdio.h>
23 6e07fb41 2001-12-21 alex #include <string.h>
24 57c7e236 2004-01-17 alex #include <strings.h>
26 d79a7d28 2002-01-18 alex #include "ngircd.h"
27 ca33cbda 2002-03-12 alex #include "defines.h"
28 b8d7dcec 2002-12-30 alex #include "conn-func.h"
29 c2f60abe 2002-05-27 alex #include "client.h"
30 c2f60abe 2002-05-27 alex #include "channel.h"
31 c2f60abe 2002-05-27 alex #include "log.h"
32 c2f60abe 2002-05-27 alex #include "messages.h"
33 c2f60abe 2002-05-27 alex #include "tool.h"
35 c2f60abe 2002-05-27 alex #include "exp.h"
36 c2f60abe 2002-05-27 alex #include "parse.h"
38 c2f60abe 2002-05-27 alex #include "imp.h"
39 76c4f066 2001-12-23 alex #include "irc.h"
40 14aba7c1 2002-03-03 alex #include "irc-channel.h"
41 0c471b84 2002-11-30 alex #include "irc-info.h"
42 b56eb4d8 2002-02-27 alex #include "irc-login.h"
43 b56eb4d8 2002-02-27 alex #include "irc-mode.h"
44 c2f60abe 2002-05-27 alex #include "irc-op.h"
45 14aba7c1 2002-03-03 alex #include "irc-oper.h"
46 14aba7c1 2002-03-03 alex #include "irc-server.h"
47 b56eb4d8 2002-02-27 alex #include "irc-write.h"
49 ca33cbda 2002-03-12 alex #include "exp.h"
52 1e59617d 2002-11-30 alex COMMAND My_Commands[] =
54 17f7c6d3 2002-12-18 alex { "ADMIN", IRC_ADMIN, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
55 17f7c6d3 2002-12-18 alex { "AWAY", IRC_AWAY, CLIENT_USER, 0, 0, 0 },
56 17f7c6d3 2002-12-18 alex { "CONNECT", IRC_CONNECT, CLIENT_USER, 0, 0, 0 },
57 17f7c6d3 2002-12-18 alex { "DIE", IRC_DIE, CLIENT_USER, 0, 0, 0 },
58 a7956f33 2002-12-31 alex { "DISCONNECT", IRC_DISCONNECT, CLIENT_USER, 0, 0, 0 },
59 17f7c6d3 2002-12-18 alex { "ERROR", IRC_ERROR, 0xFFFF, 0, 0, 0 },
60 2152e377 2003-01-15 alex { "HELP", IRC_HELP, CLIENT_USER, 0, 0, 0 },
61 17f7c6d3 2002-12-18 alex { "INVITE", IRC_INVITE, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
62 17f7c6d3 2002-12-18 alex { "ISON", IRC_ISON, CLIENT_USER, 0, 0, 0 },
63 17f7c6d3 2002-12-18 alex { "JOIN", IRC_JOIN, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
64 17f7c6d3 2002-12-18 alex { "KICK", IRC_KICK, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
65 17f7c6d3 2002-12-18 alex { "KILL", IRC_KILL, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
66 17f7c6d3 2002-12-18 alex { "LINKS", IRC_LINKS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
67 17f7c6d3 2002-12-18 alex { "LIST", IRC_LIST, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
68 17f7c6d3 2002-12-18 alex { "LUSERS", IRC_LUSERS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
69 17f7c6d3 2002-12-18 alex { "MODE", IRC_MODE, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
70 17f7c6d3 2002-12-18 alex { "MOTD", IRC_MOTD, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
71 17f7c6d3 2002-12-18 alex { "NAMES", IRC_NAMES, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
72 17f7c6d3 2002-12-18 alex { "NICK", IRC_NICK, 0xFFFF, 0, 0, 0 },
73 17f7c6d3 2002-12-18 alex { "NJOIN", IRC_NJOIN, CLIENT_SERVER, 0, 0, 0 },
74 17f7c6d3 2002-12-18 alex { "NOTICE", IRC_NOTICE, 0xFFFF, 0, 0, 0 },
75 17f7c6d3 2002-12-18 alex { "OPER", IRC_OPER, CLIENT_USER, 0, 0, 0 },
76 17f7c6d3 2002-12-18 alex { "PART", IRC_PART, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
77 17f7c6d3 2002-12-18 alex { "PASS", IRC_PASS, 0xFFFF, 0, 0, 0 },
78 17f7c6d3 2002-12-18 alex { "PING", IRC_PING, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
79 17f7c6d3 2002-12-18 alex { "PONG", IRC_PONG, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
80 17f7c6d3 2002-12-18 alex { "PRIVMSG", IRC_PRIVMSG, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
81 17f7c6d3 2002-12-18 alex { "QUIT", IRC_QUIT, 0xFFFF, 0, 0, 0 },
82 17f7c6d3 2002-12-18 alex { "REHASH", IRC_REHASH, CLIENT_USER, 0, 0, 0 },
83 17f7c6d3 2002-12-18 alex { "RESTART", IRC_RESTART, CLIENT_USER, 0, 0, 0 },
84 17f7c6d3 2002-12-18 alex { "SERVER", IRC_SERVER, 0xFFFF, 0, 0, 0 },
85 17f7c6d3 2002-12-18 alex { "SQUIT", IRC_SQUIT, CLIENT_SERVER, 0, 0, 0 },
86 17f7c6d3 2002-12-18 alex { "STATS", IRC_STATS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
87 17f7c6d3 2002-12-18 alex { "TIME", IRC_TIME, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
88 17f7c6d3 2002-12-18 alex { "TOPIC", IRC_TOPIC, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
89 42c4e6c7 2003-01-13 alex { "TRACE", IRC_TRACE, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
90 17f7c6d3 2002-12-18 alex { "USER", IRC_USER, 0xFFFF, 0, 0, 0 },
91 17f7c6d3 2002-12-18 alex { "USERHOST", IRC_USERHOST, CLIENT_USER, 0, 0, 0 },
92 17f7c6d3 2002-12-18 alex { "VERSION", IRC_VERSION, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
93 17f7c6d3 2002-12-18 alex { "WHO", IRC_WHO, CLIENT_USER, 0, 0, 0 },
94 17f7c6d3 2002-12-18 alex { "WHOIS", IRC_WHOIS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
95 17f7c6d3 2002-12-18 alex { "WHOWAS", IRC_WHOWAS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
96 17f7c6d3 2002-12-18 alex #ifdef IRCPLUS
97 17f7c6d3 2002-12-18 alex { "CHANINFO", IRC_CHANINFO, CLIENT_SERVER, 0, 0, 0 },
99 17f7c6d3 2002-12-18 alex { NULL, NULL, 0x0, 0, 0, 0 } /* Ende-Marke */
103 c2f60abe 2002-05-27 alex LOCAL VOID Init_Request PARAMS(( REQUEST *Req ));
105 e0ed3aa1 2002-07-26 alex LOCAL BOOLEAN Validate_Prefix PARAMS(( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed ));
106 e0ed3aa1 2002-07-26 alex LOCAL BOOLEAN Validate_Command PARAMS(( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed ));
107 e0ed3aa1 2002-07-26 alex LOCAL BOOLEAN Validate_Args PARAMS(( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed ));
109 c2f60abe 2002-05-27 alex LOCAL BOOLEAN Handle_Request PARAMS(( CONN_ID Idx, REQUEST *Req ));
112 17f7c6d3 2002-12-18 alex GLOBAL COMMAND *
113 17f7c6d3 2002-12-18 alex Parse_GetCommandStruct( VOID )
115 17f7c6d3 2002-12-18 alex return My_Commands;
116 17f7c6d3 2002-12-18 alex } /* Parse_GetCommandStruct */
119 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
120 c2f60abe 2002-05-27 alex Parse_Request( CONN_ID Idx, CHAR *Request )
122 76c4f066 2001-12-23 alex /* Client-Request parsen. Bei einem schwerwiegenden Fehler wird
123 76c4f066 2001-12-23 alex * die Verbindung geschlossen und FALSE geliefert.
124 6e07fb41 2001-12-21 alex * Der Aufbau gueltiger Requests ist in RFC 2812, 2.3 definiert. */
126 6e07fb41 2001-12-21 alex REQUEST req;
127 6e07fb41 2001-12-21 alex CHAR *start, *ptr;
128 e0ed3aa1 2002-07-26 alex BOOLEAN closed;
130 6e07fb41 2001-12-21 alex assert( Idx >= 0 );
131 6e07fb41 2001-12-21 alex assert( Request != NULL );
133 d4a60bd4 2001-12-25 alex #ifdef SNIFFER
134 d79a7d28 2002-01-18 alex if( NGIRCd_Sniffer ) Log( LOG_DEBUG, " <- connection %d: '%s'.", Idx, Request );
137 6e07fb41 2001-12-21 alex Init_Request( &req );
139 363a03b8 2001-12-29 alex /* Fuehrendes und folgendes "Geraffel" verwerfen */
140 363a03b8 2001-12-29 alex ngt_TrimStr( Request );
142 6e07fb41 2001-12-21 alex /* gibt es ein Prefix? */
143 6e07fb41 2001-12-21 alex if( Request[0] == ':' )
145 6e07fb41 2001-12-21 alex /* Prefix vorhanden */
146 6e07fb41 2001-12-21 alex req.prefix = Request + 1;
147 6e07fb41 2001-12-21 alex ptr = strchr( Request, ' ' );
148 e0ed3aa1 2002-07-26 alex if( ! ptr )
150 e0ed3aa1 2002-07-26 alex Log( LOG_DEBUG, "Connection %d: Parse error: prefix without command!?", Idx );
151 e0ed3aa1 2002-07-26 alex return Conn_WriteStr( Idx, "ERROR :Prefix without command!?" );
153 6e07fb41 2001-12-21 alex *ptr = '\0';
154 3543c222 2002-01-09 alex #ifndef STRICT_RFC
155 3543c222 2002-01-09 alex /* multiple Leerzeichen als Trenner zwischen
156 3543c222 2002-01-09 alex * Prefix und Befehl ignorieren */
157 3543c222 2002-01-09 alex while( *(ptr + 1) == ' ' ) ptr++;
159 6e07fb41 2001-12-21 alex start = ptr + 1;
161 6e07fb41 2001-12-21 alex else start = Request;
163 6e07fb41 2001-12-21 alex /* Befehl */
164 6e07fb41 2001-12-21 alex ptr = strchr( start, ' ' );
167 3543c222 2002-01-09 alex *ptr = '\0';
168 3543c222 2002-01-09 alex #ifndef STRICT_RFC
169 3543c222 2002-01-09 alex /* multiple Leerzeichen als Trenner vor
170 fc1118cb 2003-01-12 alex * Parametern ignorieren */
171 3543c222 2002-01-09 alex while( *(ptr + 1) == ' ' ) ptr++;
174 6e07fb41 2001-12-21 alex req.command = start;
176 6e07fb41 2001-12-21 alex /* Argumente, Parameter */
179 6e07fb41 2001-12-21 alex /* Prinzipiell gibt es welche :-) */
180 6e07fb41 2001-12-21 alex start = ptr + 1;
181 6e07fb41 2001-12-21 alex while( start )
183 6e07fb41 2001-12-21 alex /* Parameter-String "zerlegen" */
184 76c4f066 2001-12-23 alex if( start[0] == ':' )
186 76c4f066 2001-12-23 alex req.argv[req.argc] = start + 1;
187 76c4f066 2001-12-23 alex ptr = NULL;
191 76c4f066 2001-12-23 alex req.argv[req.argc] = start;
192 76c4f066 2001-12-23 alex ptr = strchr( start, ' ' );
195 3543c222 2002-01-09 alex *ptr = '\0';
196 3543c222 2002-01-09 alex #ifndef STRICT_RFC
197 3543c222 2002-01-09 alex /* multiple Leerzeichen als
198 3543c222 2002-01-09 alex * Parametertrenner ignorieren */
199 3543c222 2002-01-09 alex while( *(ptr + 1) == ' ' ) ptr++;
204 6e07fb41 2001-12-21 alex req.argc++;
206 6e07fb41 2001-12-21 alex if( start[0] == ':' ) break;
207 6e07fb41 2001-12-21 alex if( req.argc > 14 ) break;
209 6e07fb41 2001-12-21 alex if( ptr ) start = ptr + 1;
210 6e07fb41 2001-12-21 alex else start = NULL;
214 b0b797b3 2002-11-28 alex /* Daten validieren */
215 b0b797b3 2002-11-28 alex if( ! Validate_Prefix( Idx, &req, &closed )) return ! closed;
216 b0b797b3 2002-11-28 alex if( ! Validate_Command( Idx, &req, &closed )) return ! closed;
217 e0ed3aa1 2002-07-26 alex if( ! Validate_Args( Idx, &req, &closed )) return ! closed;
219 6e07fb41 2001-12-21 alex return Handle_Request( Idx, &req );
220 6e07fb41 2001-12-21 alex } /* Parse_Request */
224 c2f60abe 2002-05-27 alex Init_Request( REQUEST *Req )
226 6e07fb41 2001-12-21 alex /* Neue Request-Struktur initialisieren */
230 6e07fb41 2001-12-21 alex assert( Req != NULL );
232 6e07fb41 2001-12-21 alex Req->prefix = NULL;
233 6e07fb41 2001-12-21 alex Req->command = NULL;
234 6e07fb41 2001-12-21 alex for( i = 0; i < 15; Req->argv[i++] = NULL );
235 6e07fb41 2001-12-21 alex Req->argc = 0;
236 6e07fb41 2001-12-21 alex } /* Init_Request */
239 c2f60abe 2002-05-27 alex LOCAL BOOLEAN
240 e0ed3aa1 2002-07-26 alex Validate_Prefix( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed )
242 5063de59 2002-07-29 alex CLIENT *client, *c;
244 e0ed3aa1 2002-07-26 alex assert( Idx >= 0 );
245 e0ed3aa1 2002-07-26 alex assert( Req != NULL );
247 e0ed3aa1 2002-07-26 alex *Closed = FALSE;
249 e0ed3aa1 2002-07-26 alex /* ist ueberhaupt ein Prefix vorhanden? */
250 e0ed3aa1 2002-07-26 alex if( ! Req->prefix ) return TRUE;
252 5063de59 2002-07-29 alex /* Client-Struktur der Connection ermitteln */
253 5063de59 2002-07-29 alex client = Client_GetFromConn( Idx );
254 5063de59 2002-07-29 alex assert( client != NULL );
256 5063de59 2002-07-29 alex /* nur validieren, wenn bereits registrierte Verbindung */
257 5063de59 2002-07-29 alex if(( Client_Type( client ) != CLIENT_USER ) && ( Client_Type( client ) != CLIENT_SERVER ) && ( Client_Type( client ) != CLIENT_SERVICE ))
259 5063de59 2002-07-29 alex /* noch nicht registrierte Verbindung.
260 5063de59 2002-07-29 alex * Das Prefix wird ignoriert. */
261 5063de59 2002-07-29 alex Req->prefix = NULL;
262 5063de59 2002-07-29 alex return TRUE;
265 e0ed3aa1 2002-07-26 alex /* pruefen, ob der im Prefix angegebene Client bekannt ist */
266 e0ed3aa1 2002-07-26 alex c = Client_Search( Req->prefix );
269 e0ed3aa1 2002-07-26 alex /* im Prefix angegebener Client ist nicht bekannt */
270 b0b797b3 2002-11-28 alex Log( LOG_ERR, "Invalid prefix \"%s\", client not known (connection %d, command %s)!?", Req->prefix, Idx, Req->command );
271 dd09b17e 2002-11-20 alex if( ! Conn_WriteStr( Idx, "ERROR :Invalid prefix \"%s\", client not known!?", Req->prefix )) *Closed = TRUE;
272 e0ed3aa1 2002-07-26 alex return FALSE;
275 e0ed3aa1 2002-07-26 alex /* pruefen, ob der Client mit dem angegebenen Prefix in Richtung
276 e0ed3aa1 2002-07-26 alex * des Senders liegt, d.h. sicherstellen, dass das Prefix nicht
277 e0ed3aa1 2002-07-26 alex * gefaelscht ist */
278 5063de59 2002-07-29 alex if( Client_NextHop( c ) != client )
280 e0ed3aa1 2002-07-26 alex /* das angegebene Prefix ist aus dieser Richtung, also
281 e0ed3aa1 2002-07-26 alex * aus der gegebenen Connection, ungueltig! */
282 b0b797b3 2002-11-28 alex Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Client_GetFromConn( Idx )), Idx, Req->command );
283 e0ed3aa1 2002-07-26 alex Conn_Close( Idx, NULL, "Spoofed prefix", TRUE );
284 e0ed3aa1 2002-07-26 alex *Closed = TRUE;
285 e0ed3aa1 2002-07-26 alex return FALSE;
288 6e07fb41 2001-12-21 alex return TRUE;
289 6e07fb41 2001-12-21 alex } /* Validate_Prefix */
292 c2f60abe 2002-05-27 alex LOCAL BOOLEAN
293 e0ed3aa1 2002-07-26 alex Validate_Command( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed )
295 e0ed3aa1 2002-07-26 alex assert( Idx >= 0 );
296 6e07fb41 2001-12-21 alex assert( Req != NULL );
297 e0ed3aa1 2002-07-26 alex *Closed = FALSE;
299 6e07fb41 2001-12-21 alex return TRUE;
300 6e07fb41 2001-12-21 alex } /* Validate_Comman */
303 c2f60abe 2002-05-27 alex LOCAL BOOLEAN
304 e0ed3aa1 2002-07-26 alex Validate_Args( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed )
306 e0ed3aa1 2002-07-26 alex assert( Idx >= 0 );
307 6e07fb41 2001-12-21 alex assert( Req != NULL );
308 e0ed3aa1 2002-07-26 alex *Closed = FALSE;
310 6e07fb41 2001-12-21 alex return TRUE;
311 6e07fb41 2001-12-21 alex } /* Validate_Args */
314 c2f60abe 2002-05-27 alex LOCAL BOOLEAN
315 c2f60abe 2002-05-27 alex Handle_Request( CONN_ID Idx, REQUEST *Req )
317 76c4f066 2001-12-23 alex /* Client-Request verarbeiten. Bei einem schwerwiegenden Fehler
318 76c4f066 2001-12-23 alex * wird die Verbindung geschlossen und FALSE geliefert. */
320 1c8c92af 2002-01-05 alex CLIENT *client, *target, *prefix;
321 1c8c92af 2002-01-05 alex CHAR str[LINE_LEN];
322 17f7c6d3 2002-12-18 alex BOOLEAN result;
323 1e59617d 2002-11-30 alex COMMAND *cmd;
326 6e07fb41 2001-12-21 alex assert( Idx >= 0 );
327 6e07fb41 2001-12-21 alex assert( Req != NULL );
328 6e07fb41 2001-12-21 alex assert( Req->command != NULL );
330 76c4f066 2001-12-23 alex client = Client_GetFromConn( Idx );
331 76c4f066 2001-12-23 alex assert( client != NULL );
333 fc1118cb 2003-01-12 alex /* Statuscode? */
334 fc1118cb 2003-01-12 alex if(( Client_Type( client ) == CLIENT_SERVER ) && ( strlen( Req->command ) == 3 ) && ( atoi( Req->command ) > 100 ))
336 fc1118cb 2003-01-12 alex /* Command is a status code from an other server */
338 fc1118cb 2003-01-12 alex /* Determine target */
339 fc1118cb 2003-01-12 alex if( Req->argc > 0 ) target = Client_Search( Req->argv[0] );
340 1c8c92af 2002-01-05 alex else target = NULL;
341 9e18ec30 2002-01-07 alex if( ! target )
343 fc1118cb 2003-01-12 alex /* Status code without target!? */
344 dd09b17e 2002-11-20 alex if( Req->argc > 0 ) Log( LOG_WARNING, "Unknown target for status code %s: \"%s\"", Req->command, Req->argv[0] );
345 dd09b17e 2002-11-20 alex else Log( LOG_WARNING, "Unknown target for status code %s!", Req->command );
346 9e18ec30 2002-01-07 alex return TRUE;
348 9e18ec30 2002-01-07 alex if( target == Client_ThisServer( ))
350 fc1118cb 2003-01-12 alex /* This server is the target, ignore it */
351 9e18ec30 2002-01-07 alex Log( LOG_DEBUG, "Ignored status code %s from \"%s\".", Req->command, Client_ID( client ));
352 9e18ec30 2002-01-07 alex return TRUE;
355 fc1118cb 2003-01-12 alex /* Determine source */
356 9e18ec30 2002-01-07 alex if( ! Req->prefix[0] )
358 fc1118cb 2003-01-12 alex /* Oops, no prefix!? */
359 fc1118cb 2003-01-12 alex Log( LOG_WARNING, "Got status code %s from \"%s\" without prefix!?", Req->command, Client_ID( client ));
360 9e18ec30 2002-01-07 alex return TRUE;
362 bc4ed226 2002-03-25 alex else prefix = Client_Search( Req->prefix );
363 9e18ec30 2002-01-07 alex if( ! prefix )
365 fc1118cb 2003-01-12 alex /* Oops, unknown prefix!? */
366 fc1118cb 2003-01-12 alex Log( LOG_WARNING, "Got status code %s from unknown source: \"%s\"", Req->command, Req->prefix );
367 9e18ec30 2002-01-07 alex return TRUE;
370 fc1118cb 2003-01-12 alex /* Forward status code */
371 695631b2 2002-12-26 alex strlcpy( str, Req->command, sizeof( str ));
372 1c8c92af 2002-01-05 alex for( i = 0; i < Req->argc; i++ )
374 6626395c 2002-12-26 alex if( i < Req->argc - 1 ) strlcat( str, " ", sizeof( str ));
375 6626395c 2002-12-26 alex else strlcat( str, " :", sizeof( str ));
376 6626395c 2002-12-26 alex strlcat( str, Req->argv[i], sizeof( str ));
378 ec474a4b 2002-10-04 alex return IRC_WriteStrClientPrefix( target, prefix, "%s", str );
381 1e59617d 2002-11-30 alex cmd = My_Commands;
382 1e59617d 2002-11-30 alex while( cmd->name )
384 1e59617d 2002-11-30 alex /* Befehl suchen */
385 1e59617d 2002-11-30 alex if( strcasecmp( Req->command, cmd->name ) != 0 )
387 1e59617d 2002-11-30 alex cmd++; continue;
390 1e59617d 2002-11-30 alex if( Client_Type( client ) & cmd->type )
392 17f7c6d3 2002-12-18 alex /* Command is allowed for this client: call it and count produced bytes */
393 17f7c6d3 2002-12-18 alex Conn_ResetWCounter( );
394 17f7c6d3 2002-12-18 alex result = (cmd->function)( client, Req );
395 17f7c6d3 2002-12-18 alex cmd->bytes += Conn_WCounter( );
397 17f7c6d3 2002-12-18 alex /* Adjust counters */
398 17f7c6d3 2002-12-18 alex if( Client_Type( client ) != CLIENT_SERVER ) cmd->lcount++;
399 17f7c6d3 2002-12-18 alex else cmd->rcount++;
401 17f7c6d3 2002-12-18 alex return result;
405 1e59617d 2002-11-30 alex /* Befehl ist fuer diesen Client-Typ nicht erlaubt! */
406 1e59617d 2002-11-30 alex return IRC_WriteStrClient( client, ERR_NOTREGISTERED_MSG, Client_ID( client ));
410 76c4f066 2001-12-23 alex /* Unbekannter Befehl */
411 3d2e9448 2002-01-05 alex Log( LOG_DEBUG, "Connection %d: Unknown command \"%s\", %d %s,%s prefix.", Client_Conn( client ), Req->command, Req->argc, Req->argc == 1 ? "parameter" : "parameters", Req->prefix ? "" : " no" );
412 1e59617d 2002-11-30 alex if( Client_Type( client ) != CLIENT_SERVER ) return IRC_WriteStrClient( client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( client ), Req->command );
413 1e59617d 2002-11-30 alex else return TRUE;
414 6e07fb41 2001-12-21 alex } /* Handle_Request */
417 6e07fb41 2001-12-21 alex /* -eof- */