X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Firc-write.c;h=92e8cfe39047992bdaff2d700ec192bb24a58483;hp=93753564770f3dbdeb32f768d01c0c991959f237;hb=2924b3d52ac2ab89e3bc517a1f664ec056a45edd;hpb=0a3d8d60d3c3ac66d09346aa02c10c9649b62e99 diff --git a/src/ngircd/irc-write.c b/src/ngircd/irc-write.c index 93753564..92e8cfe3 100644 --- a/src/ngircd/irc-write.c +++ b/src/ngircd/irc-write.c @@ -1,6 +1,6 @@ /* * ngIRCd -- The Next Generation IRC Daemon - * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors. + * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,6 @@ * Sending IRC commands over the network */ -#include "imp.h" #include #ifdef PROTOTYPES # include @@ -24,13 +23,10 @@ # include #endif #include -#include -#include "defines.h" #include "conn-func.h" #include "channel.h" -#include "exp.h" #include "irc-write.h" #define SEND_TO_USER 1 @@ -41,6 +37,43 @@ static void cb_writeStrServersPrefixFlag PARAMS((CLIENT *Client, CLIENT *Prefix, void *Buffer)); static void Send_Marked_Connections PARAMS((CLIENT *Prefix, const char *Buffer)); +/** + * Send an error message to a client and enforce a penalty time. + * + * @param Client The target client. + * @param Format Format string. + * @return CONNECTED or DISCONNECTED. + */ +#ifdef PROTOTYPES +GLOBAL bool +IRC_WriteErrClient( CLIENT *Client, const char *Format, ... ) +#else +GLOBAL bool +IRC_WriteErrClient( Client, Format, va_alist ) +CLIENT *Client; +const char *Format; +va_dcl +#endif +{ + char buffer[1000]; + va_list ap; + + assert(Client != NULL); + assert(Format != NULL); + +#ifdef PROTOTYPES + va_start(ap, Format); +#else + va_start(ap); +#endif + vsnprintf(buffer, sizeof(buffer), Format, ap); + va_end(ap); + + IRC_SetPenalty(Client, 2); + return IRC_WriteStrClientPrefix(Client, Client_ThisServer(), + "%s", buffer); +} + /** * Send a message to a client. * @@ -70,7 +103,7 @@ va_dcl #else va_start(ap); #endif - vsnprintf(buffer, 1000, Format, ap); + vsnprintf(buffer, sizeof(buffer), Format, ap); va_end(ap); return IRC_WriteStrClientPrefix(Client, Client_ThisServer(), @@ -111,7 +144,7 @@ va_dcl #else va_start( ap ); #endif - vsnprintf( buffer, 1000, Format, ap ); + vsnprintf(buffer, sizeof(buffer), Format, ap); va_end( ap ); return Conn_WriteStr(Client_Conn(Client_NextHop(Client)), ":%s %s", @@ -153,7 +186,7 @@ va_dcl #else va_start( ap ); #endif - vsnprintf( buffer, 1000, Format, ap ); + vsnprintf(buffer, sizeof(buffer), Format, ap); va_end( ap ); IRC_WriteStrChannelPrefix(Client, Chan, Client_ThisServer(), @@ -202,7 +235,7 @@ va_dcl #else va_start( ap ); #endif - vsnprintf( buffer, 1000, Format, ap ); + vsnprintf(buffer, sizeof(buffer), Format, ap); va_end( ap ); Conn_ClearFlags( ); @@ -259,7 +292,7 @@ va_dcl #else va_start( ap ); #endif - vsnprintf( buffer, 1000, Format, ap ); + vsnprintf(buffer, sizeof(buffer), Format, ap); va_end( ap ); IRC_WriteStrServersPrefix(ExceptOf, Client_ThisServer(), "%s", buffer); @@ -296,7 +329,7 @@ va_dcl #else va_start( ap ); #endif - vsnprintf( buffer, 1000, Format, ap ); + vsnprintf(buffer, sizeof(buffer), Format, ap); va_end( ap ); IRC_WriteStrServersPrefixFlag( ExceptOf, Prefix, '\0', "%s", buffer ); @@ -336,7 +369,7 @@ va_dcl #else va_start( ap ); #endif - vsnprintf( buffer, 1000, Format, ap ); + vsnprintf(buffer, sizeof(buffer), Format, ap); va_end( ap ); IRC_WriteStrServersPrefixFlag_CB(ExceptOf, Prefix, Flag, @@ -414,7 +447,7 @@ va_dcl #else va_start( ap ); #endif - vsnprintf( buffer, 1000, Format, ap ); + vsnprintf(buffer, sizeof(buffer), Format, ap); va_end( ap ); Conn_ClearFlags( ); @@ -476,7 +509,7 @@ va_dcl #else va_start(ap); #endif - vsnprintf(msg, 1000, Format, ap); + vsnprintf(msg, sizeof(msg), Format, ap); va_end(ap); for (to=Client_First(); to != NULL; to=Client_Next(to)) { @@ -488,12 +521,12 @@ va_dcl if (Client_HasMode(to, 'w')) IRC_WriteStrClientPrefix(to, From, "WALLOPS :%s", msg); - break; + break; case CLIENT_SERVER: if (to != Client) IRC_WriteStrClientPrefix(to, From, "WALLOPS :%s", msg); - break; + break; } } } /* IRC_SendWallops */ @@ -501,24 +534,27 @@ va_dcl /** * Set a "penalty time" for an IRC client. * - * Note: penalty times are never set for server links! + * Note: penalty times are never set for server links or remote clients! * * @param Client The client. * @param Seconds The additional "penalty time" to enforce. */ GLOBAL void -IRC_SetPenalty( CLIENT *Client, time_t Seconds ) +IRC_SetPenalty(CLIENT *Client, time_t Seconds) { CONN_ID c; - assert( Client != NULL ); - assert( Seconds > 0 ); + assert(Client != NULL); + assert(Seconds > 0); + + if (Client_Type(Client) == CLIENT_SERVER) + return; - if( Client_Type( Client ) == CLIENT_SERVER ) return; + c = Client_Conn(Client); + if (c <= NONE) + return; - c = Client_Conn( Client ); - if (c > NONE) - Conn_SetPenalty(c, Seconds); + Conn_SetPenalty(c, Seconds); } /* IRC_SetPenalty */ static const char *