aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--irc.h1
-rw-r--r--irc_commands.c29
-rw-r--r--irc_user.c10
-rw-r--r--lib/misc.c45
-rw-r--r--lib/misc.h2
-rw-r--r--root_commands.c43
6 files changed, 85 insertions, 45 deletions
diff --git a/irc.h b/irc.h
index e981b918..450d3259 100644
--- a/irc.h
+++ b/irc.h
@@ -119,6 +119,7 @@ typedef struct irc_user
struct irc_user_funcs
{
gboolean (*privmsg)( irc_user_t *iu, const char *msg );
+ gboolean (*ctcp)( irc_user_t *iu, char * const* ctcp );
};
extern const struct irc_user_funcs irc_user_root_funcs;
diff --git a/irc_commands.c b/irc_commands.c
index bf55e2b8..5387fb4d 100644
--- a/irc_commands.c
+++ b/irc_commands.c
@@ -254,16 +254,39 @@ static void irc_cmd_privmsg( irc_t *irc, char **cmd )
if( !cmd[2] )
{
irc_send_num( irc, 412, ":No text to send" );
+ return;
}
- else if( irc_channel_name_ok( cmd[1] ) &&
- ( ic = irc_channel_by_name( irc, cmd[1] ) ) )
+
+ /* Don't treat CTCP actions as real CTCPs, just convert them right now. */
+ if( g_strncasecmp( cmd[2], "\001ACTION", 7 ) == 0 )
+ {
+ cmd[2] += 4;
+ strcpy( cmd[2], "/me" );
+ if( cmd[2][strlen(cmd[2])-1] == '\001' )
+ cmd[2][strlen(cmd[2])-1] = '\0';
+ }
+
+ if( irc_channel_name_ok( cmd[1] ) &&
+ ( ic = irc_channel_by_name( irc, cmd[1] ) ) )
{
if( ic->f->privmsg )
ic->f->privmsg( ic, cmd[2] );
}
else if( ( iu = irc_user_by_name( irc, cmd[1] ) ) )
{
- if( iu->f->privmsg )
+ if( cmd[2][0] == '\001' )
+ {
+ char **ctcp;
+
+ if( iu->f->ctcp == NULL )
+ return;
+ if( cmd[2][strlen(cmd[2])-1] == '\001' )
+ cmd[2][strlen(cmd[2])-1] = '\0';
+
+ ctcp = split_command_parts( cmd[2] + 1 );
+ iu->f->ctcp( iu, ctcp );
+ }
+ else if( iu->f->privmsg )
iu->f->privmsg( iu, cmd[2] );
}
else
diff --git a/irc_user.c b/irc_user.c
index b7629490..cf1d1e3e 100644
--- a/irc_user.c
+++ b/irc_user.c
@@ -146,8 +146,18 @@ static gboolean root_privmsg( irc_user_t *iu, const char *msg )
return TRUE;
}
+static gboolean root_ctcp( irc_user_t *iu, char * const *ctcp )
+{
+ if( g_strcasecmp( ctcp[0], "VERSION" ) == 0 )
+ {
+ }
+
+ return TRUE;
+}
+
const struct irc_user_funcs irc_user_root_funcs = {
root_privmsg,
+ root_ctcp,
};
/* Echo to yourself: */
diff --git a/lib/misc.c b/lib/misc.c
index fe2ff17c..2901704a 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -613,3 +613,48 @@ int md5_verify_password( char *password, char *hash )
return ret;
}
+
+char **split_command_parts( char *command )
+{
+ static char *cmd[IRC_MAX_ARGS+1];
+ char *s, q = 0;
+ int k;
+
+ memset( cmd, 0, sizeof( cmd ) );
+ cmd[0] = command;
+ k = 1;
+ for( s = command; *s && k < IRC_MAX_ARGS; s ++ )
+ if( *s == ' ' && !q )
+ {
+ *s = 0;
+ while( *++s == ' ' );
+ if( *s == '"' || *s == '\'' )
+ {
+ q = *s;
+ s ++;
+ }
+ if( *s )
+ {
+ cmd[k++] = s;
+ s --;
+ }
+ else
+ {
+ break;
+ }
+ }
+ else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) )
+ {
+ char *cpy;
+
+ for( cpy = s; *cpy; cpy ++ )
+ cpy[0] = cpy[1];
+ }
+ else if( *s == q )
+ {
+ q = *s = 0;
+ }
+ cmd[k] = NULL;
+
+ return cmd;
+}
diff --git a/lib/misc.h b/lib/misc.h
index ce36caf5..e0e08bf1 100644
--- a/lib/misc.h
+++ b/lib/misc.h
@@ -67,4 +67,6 @@ G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl );
G_MODULE_EXPORT int md5_verify_password( char *password, char *hash );
+G_MODULE_EXPORT char **split_command_parts( char *command );
+
#endif
diff --git a/root_commands.c b/root_commands.c
index 3853a73e..7a4c021e 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -33,48 +33,7 @@
void root_command_string( irc_t *irc, char *command )
{
- char *cmd[IRC_MAX_ARGS];
- char *s;
- int k;
- char q = 0;
-
- memset( cmd, 0, sizeof( cmd ) );
- cmd[0] = command;
- k = 1;
- for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ )
- if( *s == ' ' && !q )
- {
- *s = 0;
- while( *++s == ' ' );
- if( *s == '"' || *s == '\'' )
- {
- q = *s;
- s ++;
- }
- if( *s )
- {
- cmd[k++] = s;
- s --;
- }
- else
- {
- break;
- }
- }
- else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) )
- {
- char *cpy;
-
- for( cpy = s; *cpy; cpy ++ )
- cpy[0] = cpy[1];
- }
- else if( *s == q )
- {
- q = *s = 0;
- }
- cmd[k] = NULL;
-
- root_command( irc, cmd );
+ root_command( irc, split_command_parts( command ) );
}
#define MIN_ARGS( x, y... ) \