From: Jānis Rūcis Date: Tue, 30 Mar 2010 20:42:35 +0000 (+0300) Subject: IRC: move functions around X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=737b2c2fef4864012608903a5b29099929ec50c0;p=xonotic%2Fdarkplaces.git IRC: move functions around --- diff --git a/irc.c b/irc.c index 37f9f0cb..ceed28f9 100644 --- a/irc.c +++ b/irc.c @@ -3,11 +3,23 @@ #include "console.h" static lhnetsocket_t *irc_socket; + static char irc_incoming[1024]; static char irc_outgoing[1024]; static int irc_incoming_len; static int irc_outgoing_len; +#define IRC_MAX_ARGS 15 + +typedef struct ircmessage_s +{ + char *prefix; + char *command; + char *args[IRC_MAX_ARGS]; + int args_num; +} +ircmessage_t; + static void IRC_Disconnect(void) { if (irc_socket) @@ -64,68 +76,6 @@ static void IRC_AddMessage(const char *message) Con_Printf("[IRC] %d bytes waiting to be written\n", irc_outgoing_len); } -static const char *IRC_NickFromPlayerName(void) -{ - const char prefix[] = "[DP]"; - const int prefix_len = sizeof (prefix) - 1; - char *nick; - - nick = Z_Malloc(prefix_len + strlen(cl_name.string) + 1); - memcpy(nick, prefix, prefix_len + 1); - SanitizeString(cl_name.string, nick + prefix_len); - - return nick; -} - -static void IRC_Connect_f(void) -{ - if (Cmd_Argc() != 2) - { - Con_Print("ircconnect
: connect to an IRC server\n"); - return; - } - - if (IRC_Connect(Cmd_Argv(1))) - { - const char *nick = IRC_NickFromPlayerName(); - - IRC_AddMessage(va("NICK %s", nick)); - IRC_AddMessage(va("USER %s %s %s :%s", nick, nick, Cmd_Argv(1), nick)); - - Z_Free((void *) nick); - } -} - -static void IRC_Disconnect_f(void) -{ - IRC_Disconnect(); -} - -static void IRC_IRC_f(void) -{ - if (Cmd_Argc() < 2) - { - Con_Print("irc \n"); - return; - } - - if (irc_socket) - IRC_AddMessage(Cmd_Args()); - else - Con_Print("[IRC] Not connected to a server.\n"); -} - -#define IRC_MAX_ARGS 15 - -typedef struct ircmessage_s -{ - char *prefix; - char *command; - char *args[IRC_MAX_ARGS]; - int args_num; -} -ircmessage_t; - static ircmessage_t *IRC_AllocMessage(void) { ircmessage_t *msg; @@ -354,6 +304,57 @@ void IRC_Frame(void) } } +static const char *IRC_NickFromPlayerName(void) +{ + const char prefix[] = "[DP]"; + const int prefix_len = sizeof (prefix) - 1; + char *nick; + + nick = Z_Malloc(prefix_len + strlen(cl_name.string) + 1); + memcpy(nick, prefix, prefix_len + 1); + SanitizeString(cl_name.string, nick + prefix_len); + + return nick; +} + +static void IRC_Connect_f(void) +{ + if (Cmd_Argc() != 2) + { + Con_Print("ircconnect
: connect to an IRC server\n"); + return; + } + + if (IRC_Connect(Cmd_Argv(1))) + { + const char *nick = IRC_NickFromPlayerName(); + + IRC_AddMessage(va("NICK %s", nick)); + IRC_AddMessage(va("USER %s %s %s :%s", nick, nick, Cmd_Argv(1), nick)); + + Z_Free((void *) nick); + } +} + +static void IRC_Disconnect_f(void) +{ + IRC_Disconnect(); +} + +static void IRC_IRC_f(void) +{ + if (Cmd_Argc() < 2) + { + Con_Print("irc \n"); + return; + } + + if (irc_socket) + IRC_AddMessage(Cmd_Args()); + else + Con_Print("[IRC] Not connected to a server.\n"); +} + void IRC_Init(void) { Cmd_AddCommand("ircconnect", IRC_Connect_f, "connect to an IRC server");