Changed the "IRC_AddClientMessage" function so the newline marker \n was automatically appended to anything passed to it.
Added /whois and also a clean whois output result. Commented/fixed out some lingering code which executed on connect like trying to set a password when no password is given. Added default quit message "FTE Quakeworld IRC-Plugin http://fteqw.sf.net" Filtering out some junk raw messages, like motd, "end of /whois", current users Commented out some code in the /nick command so it acted like normal while connected. example; msg = "Jack in the gray hat" var1 will be "Jack in the gray hat" var2 will be "in the gray hat" var3 will be "the gray hat" etc git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1169 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
f75b31bd6d
commit
5f7f5e662e
1 changed files with 148 additions and 47 deletions
|
@ -1,6 +1,7 @@
|
||||||
//Released under the terms of the gpl as this file uses a bit of quake derived code. All sections of the like are marked as such
|
//Released under the terms of the gpl as this file uses a bit of quake derived code. All sections of the like are marked as such
|
||||||
|
|
||||||
#include "../plugin.h"
|
#include "../plugin.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#define Q_strncpyz(o, i, l) do {strncpy(o, i, l-1);o[l-1]='\0';}while(0)
|
#define Q_strncpyz(o, i, l) do {strncpy(o, i, l-1);o[l-1]='\0';}while(0)
|
||||||
|
|
||||||
|
@ -28,6 +29,10 @@ void Con_SubPrintf(char *subname, char *format, ...)
|
||||||
|
|
||||||
#define COLOURGREEN "^2"
|
#define COLOURGREEN "^2"
|
||||||
#define COLORWHITE "^7"
|
#define COLORWHITE "^7"
|
||||||
|
#define COLOURWHITE "^7" // word
|
||||||
|
#define COLOURRED "^1"
|
||||||
|
#define COLOURYELLOW "^3"
|
||||||
|
#define COLOURPURPLE "^5"
|
||||||
#define COMMANDPREFIX "irc "
|
#define COMMANDPREFIX "irc "
|
||||||
#define playsound(s)
|
#define playsound(s)
|
||||||
|
|
||||||
|
@ -200,7 +205,13 @@ int IRC_ConExecuteCommand(int *args)
|
||||||
|
|
||||||
void IRC_AddClientMessage(ircclient_t *irc, char *msg)
|
void IRC_AddClientMessage(ircclient_t *irc, char *msg)
|
||||||
{
|
{
|
||||||
Net_Send(irc->socket, msg, strlen(msg)); //FIXME: This needs rewriting to cope with errors.
|
char output[4096];
|
||||||
|
|
||||||
|
strcpy(output, msg);
|
||||||
|
strcat(output, "\n");
|
||||||
|
|
||||||
|
Net_Send(irc->socket, output, strlen(output)); //FIXME: This needs rewriting to cope with errors.
|
||||||
|
Con_SubPrintf("irc",COLOURYELLOW "<< %s \n",msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
ircclient_t *IRC_Connect(char *server, int defport)
|
ircclient_t *IRC_Connect(char *server, int defport)
|
||||||
|
@ -241,18 +252,18 @@ ircclient_t *IRC_Connect(char *server, int defport)
|
||||||
}
|
}
|
||||||
void IRC_SetPass(ircclient_t *irc, char *pass)
|
void IRC_SetPass(ircclient_t *irc, char *pass)
|
||||||
{
|
{
|
||||||
IRC_AddClientMessage(irc, va("PASS %s\r\n", pass));
|
if (pass != "") { IRC_AddClientMessage(irc, va("PASS %s", pass)); }
|
||||||
}
|
}
|
||||||
void IRC_SetNick(ircclient_t *irc, char *nick)
|
void IRC_SetNick(ircclient_t *irc, char *nick)
|
||||||
{
|
{
|
||||||
strncpy(irc->nick, nick, sizeof(irc->nick));
|
//strncpy(irc->nick, nick, sizeof(irc->nick)); // broken
|
||||||
irc->nick[sizeof(irc->nick)-1] = '\0';
|
//irc->nick[sizeof(irc->nick)-1] = '\0'; // broken, lets just allow "anonymous" on.
|
||||||
IRC_AddClientMessage(irc, va("NICK %s\r\n", irc->nick));
|
IRC_AddClientMessage(irc, va("NICK %s", irc->nick));
|
||||||
irc->nickcycle=0;
|
irc->nickcycle=0;
|
||||||
}
|
}
|
||||||
void IRC_SetUser(ircclient_t *irc, char *user)
|
void IRC_SetUser(ircclient_t *irc, char *user)
|
||||||
{
|
{
|
||||||
IRC_AddClientMessage(irc, va("USER %s %s %s :%s\r\n", user, irc->hostname, irc->server, "Something"));
|
IRC_AddClientMessage(irc, va("USER %s %s %s :%s", user, irc->hostname, irc->server, "Something"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRC_FilterMircColours(char *msg)
|
void IRC_FilterMircColours(char *msg)
|
||||||
|
@ -347,6 +358,11 @@ int IRC_ClientFrame(ircclient_t *irc)
|
||||||
char prefix[64];
|
char prefix[64];
|
||||||
int ret;
|
int ret;
|
||||||
char *nextmsg, *msg;
|
char *nextmsg, *msg;
|
||||||
|
|
||||||
|
char var[9][1000];
|
||||||
|
char *temp;
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
ret = Net_Recv(irc->socket, irc->bufferedinmessage+irc->bufferedinammount, sizeof(irc->bufferedinmessage)-1 - irc->bufferedinammount);
|
ret = Net_Recv(irc->socket, irc->bufferedinmessage+irc->bufferedinammount, sizeof(irc->bufferedinmessage)-1 - irc->bufferedinammount);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
return IRC_KILL;
|
return IRC_KILL;
|
||||||
|
@ -373,6 +389,27 @@ int IRC_ClientFrame(ircclient_t *irc)
|
||||||
|
|
||||||
msg = irc->bufferedinmessage;
|
msg = irc->bufferedinmessage;
|
||||||
|
|
||||||
|
strcpy(var[1],msg);
|
||||||
|
|
||||||
|
temp = strchr(var[1], ' ');
|
||||||
|
|
||||||
|
while (i < 8)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (temp != NULL)
|
||||||
|
{
|
||||||
|
strcpy(var[i],temp+1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcpy(var[i], "");
|
||||||
|
}
|
||||||
|
|
||||||
|
temp=strchr(var[i], ' ');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (*msg == ':') //we need to strip off the prefix
|
if (*msg == ':') //we need to strip off the prefix
|
||||||
{
|
{
|
||||||
char *sp = strchr(msg, ' ');
|
char *sp = strchr(msg, ' ');
|
||||||
|
@ -396,11 +433,11 @@ int IRC_ClientFrame(ircclient_t *irc)
|
||||||
else
|
else
|
||||||
strcpy(prefix, irc->server);
|
strcpy(prefix, irc->server);
|
||||||
|
|
||||||
if (!strncmp(msg, "PING ", 5))
|
if (!strncmp(var[1], "PING ", 5))
|
||||||
{
|
{
|
||||||
IRC_AddClientMessage(irc, va("PONG %s\r\n", msg+5));
|
IRC_AddClientMessage(irc, va("PONG %s", var[2]));
|
||||||
}
|
}
|
||||||
else if (!strncmp(msg, "PRIVMSG ", 7) || !strncmp(msg, "NOTICE ", 6)) //no autoresponses to notice please, and any autoresponses should be in the form of a notice
|
else if (!strncmp(var[2], "PRIVMSG ", 7) || !strncmp(var[2], "NOTICE ", 6)) //no autoresponses to notice please, and any autoresponses should be in the form of a notice
|
||||||
{
|
{
|
||||||
char *exc = strchr(prefix, '!');
|
char *exc = strchr(prefix, '!');
|
||||||
char *col = strchr(msg+6, ':');
|
char *col = strchr(msg+6, ':');
|
||||||
|
@ -411,6 +448,16 @@ int IRC_ClientFrame(ircclient_t *irc)
|
||||||
|
|
||||||
playsound ("misc/talk.wav");
|
playsound ("misc/talk.wav");
|
||||||
|
|
||||||
|
if (!stricmp(var[4]+1, "\1VERSION\1"))
|
||||||
|
{
|
||||||
|
char *username;
|
||||||
|
char delimiters[] = "!";
|
||||||
|
|
||||||
|
username = strtok(var[1]+1, delimiters);
|
||||||
|
|
||||||
|
IRC_AddClientMessage(irc, va("NOTICE %s :\1VERSION FTEQW-IRC-Plugin Build ?\1", username));
|
||||||
|
}
|
||||||
|
|
||||||
if (exc && col)
|
if (exc && col)
|
||||||
{
|
{
|
||||||
*col = '\0';
|
*col = '\0';
|
||||||
|
@ -501,14 +548,61 @@ int IRC_ClientFrame(ircclient_t *irc)
|
||||||
}
|
}
|
||||||
else Con_SubPrintf("irc", COLOURGREEN ":%sJOIN %s\n", prefix, msg+5);
|
else Con_SubPrintf("irc", COLOURGREEN ":%sJOIN %s\n", prefix, msg+5);
|
||||||
}
|
}
|
||||||
|
else if ((!strncmp(msg, "001 ", 4)) || (!strncmp(msg, "002 ", 4)) || (!strncmp(msg, "003 ", 4)) || (!strncmp(msg, "004 ", 4)) || (!strncmp(msg, "005 ", 4))) // useless info on connect
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if ((!strncmp(msg, "251 ", 4)) || (!strncmp(msg, "252 ", 4)) || (!strncmp(msg, "254 ", 4)) || (!strncmp(msg, "255 ", 4)) || (!strncmp(msg, "265 ", 4)) || (!strncmp(msg, "266 ", 4)) || (!strncmp(msg, "422 ", 4))) //useless info about local users, server users, connected servers, motd missing
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (!strncmp(msg, "311 ", 4)) // Whois
|
||||||
|
{
|
||||||
|
char *username = strtok(var[4], " ");
|
||||||
|
char *ident = strtok(var[5], " ");
|
||||||
|
char *address = strtok(var[6], " ");
|
||||||
|
char *realname = var[8]+1;
|
||||||
|
|
||||||
|
Con_SubPrintf("irc","WHOIS: <%s> (Ident: %s) (Address: %s) (Realname: %s) \n", username, ident, address, realname);
|
||||||
|
}
|
||||||
|
else if (!strncmp(msg, "312 ", 4))
|
||||||
|
{
|
||||||
|
char *username = strtok(var[4], " ");
|
||||||
|
char *serverhostname = strtok(var[5], " ");
|
||||||
|
char *servername = var[6]+1;
|
||||||
|
|
||||||
|
Con_SubPrintf("irc","WHOIS: <%s> (Server: %s) (Server Name: %s) \n", username, serverhostname, servername);
|
||||||
|
}
|
||||||
|
else if (!strncmp(msg, "317 ", 4)) // seconds idle etc
|
||||||
|
{
|
||||||
|
char *username = strtok(var[4], " ");
|
||||||
|
char *secondsidle = strtok(var[5], " ");
|
||||||
|
char *signontime = strtok(var[6], " ");
|
||||||
|
time_t t;
|
||||||
|
const struct tm *tm;
|
||||||
|
|
||||||
|
t=strtoul(signontime, 0, 0);
|
||||||
|
tm=localtime(&t);
|
||||||
|
|
||||||
|
//if (tm[strlen-2] = '\n') { tm[strlen-2] = '\0'; } // strip new line
|
||||||
|
|
||||||
|
Con_SubPrintf("irc","WHOIS: <%s> (Idle Time: %s seconds) (Signon Time: %s) \n", username, secondsidle, asctime(tm));
|
||||||
|
}
|
||||||
|
else if (!strncmp(msg, "318 ", 4)) //end of whois
|
||||||
|
{
|
||||||
|
}
|
||||||
else if (!strncmp(msg, "322 ", 4)) //channel listing
|
else if (!strncmp(msg, "322 ", 4)) //channel listing
|
||||||
{
|
{
|
||||||
Con_SubPrintf("irc", "%s\n", msg);
|
Con_SubPrintf("irc", "%s\n", msg);
|
||||||
}
|
}
|
||||||
|
else if ((!strncmp(msg, "372 ", 4)) || (!strncmp(msg, "375 ", 4)) || (!strncmp(msg, "376 ", 4)))
|
||||||
|
{
|
||||||
|
}
|
||||||
else if (!strncmp(msg, "375 ", 4))
|
else if (!strncmp(msg, "375 ", 4))
|
||||||
{
|
{
|
||||||
Con_SubPrintf("irc", "%s\n", msg);
|
Con_SubPrintf("irc", "%s\n", msg);
|
||||||
}
|
}
|
||||||
|
else if (!strncmp(msg, "378 ", 4)) //kinda useless whois info
|
||||||
|
{
|
||||||
|
}
|
||||||
else if (!strncmp(msg, "431 ", 4) || //nick not set
|
else if (!strncmp(msg, "431 ", 4) || //nick not set
|
||||||
!strncmp(msg, "433 ", 4) || //nick already in use
|
!strncmp(msg, "433 ", 4) || //nick already in use
|
||||||
!strncmp(msg, "436 ", 4)) //nick collision
|
!strncmp(msg, "436 ", 4)) //nick collision
|
||||||
|
@ -1261,9 +1355,11 @@ void IRC_Command(void)
|
||||||
else if (!strcmp(com_token+1, "nick"))
|
else if (!strcmp(com_token+1, "nick"))
|
||||||
{
|
{
|
||||||
msg = COM_Parse(msg);
|
msg = COM_Parse(msg);
|
||||||
Q_strncpyz(defaultnick, com_token, sizeof(defaultnick));
|
//Q_strncpyz(defaultnick, com_token, sizeof(defaultnick));
|
||||||
if (ircclient)
|
//if (ircclient)
|
||||||
IRC_SetNick(ircclient, defaultnick);
|
//IRC_SetNick(ircclient, defaultnick);
|
||||||
|
// the above 3 lines, don't work too well :(
|
||||||
|
IRC_AddClientMessage(ircclient, va("nick %s", com_token));
|
||||||
}
|
}
|
||||||
else if (!strcmp(com_token+1, "user"))
|
else if (!strcmp(com_token+1, "user"))
|
||||||
{
|
{
|
||||||
|
@ -1280,34 +1376,39 @@ void IRC_Command(void)
|
||||||
//ALL other commands require you to be connected.
|
//ALL other commands require you to be connected.
|
||||||
else if (!strcmp(com_token+1, "list"))
|
else if (!strcmp(com_token+1, "list"))
|
||||||
{
|
{
|
||||||
IRC_AddClientMessage(ircclient, "LIST\r\n");
|
IRC_AddClientMessage(ircclient, "LIST");
|
||||||
}
|
}
|
||||||
else if (!strcmp(com_token+1, "join"))
|
else if (!strcmp(com_token+1, "join"))
|
||||||
{
|
{
|
||||||
msg = COM_Parse(msg);
|
msg = COM_Parse(msg);
|
||||||
IRC_AddClientMessage(ircclient, va("JOIN %s\r\n", com_token));
|
IRC_AddClientMessage(ircclient, va("JOIN %s", com_token));
|
||||||
}
|
}
|
||||||
else if (!strcmp(com_token+1, "part") || !strcmp(com_token+1, "leave"))
|
else if (!strcmp(com_token+1, "part") || !strcmp(com_token+1, "leave"))
|
||||||
{
|
{
|
||||||
msg = COM_Parse(msg);
|
msg = COM_Parse(msg);
|
||||||
if (!*com_token)
|
if (!*com_token)
|
||||||
IRC_AddClientMessage(ircclient, va("PART %s\r\n", ircclient->defaultdest));
|
IRC_AddClientMessage(ircclient, va("PART %s", ircclient->defaultdest));
|
||||||
else
|
else
|
||||||
IRC_AddClientMessage(ircclient, va("PART %s\r\n", com_token));
|
IRC_AddClientMessage(ircclient, va("PART %s", com_token));
|
||||||
}
|
}
|
||||||
else if (!strcmp(com_token+1, "msg"))
|
else if (!strcmp(com_token+1, "msg"))
|
||||||
{
|
{
|
||||||
msg = COM_Parse(msg);
|
msg = COM_Parse(msg);
|
||||||
IRC_AddClientMessage(ircclient, va("PRIVMSG %s :%s\r\n", com_token, msg));
|
IRC_AddClientMessage(ircclient, va("PRIVMSG %s :%s", com_token, msg));
|
||||||
Con_SubPrintf(com_token, "%s: %s\n", ircclient->nick, msg);
|
Con_SubPrintf(com_token, "%s: %s\n", ircclient->nick, msg);
|
||||||
}
|
}
|
||||||
else if (!strcmp(com_token+1, "quote"))
|
else if (!strcmp(com_token+1, "quote"))
|
||||||
{
|
{
|
||||||
IRC_AddClientMessage(ircclient, va("%s\r\n", msg));
|
IRC_AddClientMessage(ircclient, va("%s", msg));
|
||||||
}
|
}
|
||||||
else if (!strcmp(com_token+1, "quit"))
|
else if (!strcmp(com_token+1, "quit"))
|
||||||
{
|
{
|
||||||
IRC_AddClientMessage(ircclient, va("QUIT\r\n"));
|
IRC_AddClientMessage(ircclient, va("QUIT :FTE QuakeWorld IRC-Plugin http://fteqw.sf.net"));
|
||||||
|
}
|
||||||
|
else if (!strcmp(com_token+1, "whois"))
|
||||||
|
{
|
||||||
|
msg = COM_Parse(msg);
|
||||||
|
IRC_AddClientMessage(ircclient, va("WHOIS :%s",com_token));
|
||||||
}
|
}
|
||||||
else if (!strcmp(com_token+1, "dest"))
|
else if (!strcmp(com_token+1, "dest"))
|
||||||
{
|
{
|
||||||
|
@ -1316,13 +1417,13 @@ void IRC_Command(void)
|
||||||
}
|
}
|
||||||
else if (!strcmp(com_token+1, "ping"))
|
else if (!strcmp(com_token+1, "ping"))
|
||||||
{
|
{
|
||||||
IRC_AddClientMessage(ircclient, va("PRIVMSG %s :\001PING%s\001\r\n", ircclient->defaultdest, msg));
|
IRC_AddClientMessage(ircclient, va("PRIVMSG %s :\001PING%s\001", ircclient->defaultdest, msg));
|
||||||
}
|
}
|
||||||
else if (!strcmp(com_token+1, "me"))
|
else if (!strcmp(com_token+1, "me"))
|
||||||
{
|
{
|
||||||
if(*msg <= ' ' && *msg)
|
if(*msg <= ' ' && *msg)
|
||||||
msg++;
|
msg++;
|
||||||
IRC_AddClientMessage(ircclient, va("PRIVMSG %s :\001ACTION %s\001\r\n", ircclient->defaultdest, msg));
|
IRC_AddClientMessage(ircclient, va("PRIVMSG %s :\001ACTION %s\001", ircclient->defaultdest, msg));
|
||||||
Con_SubPrintf(ircclient->defaultdest, "***%s %s\n", ircclient->nick, msg);
|
Con_SubPrintf(ircclient->defaultdest, "***%s %s\n", ircclient->nick, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1331,7 +1432,7 @@ void IRC_Command(void)
|
||||||
if (ircclient)
|
if (ircclient)
|
||||||
{
|
{
|
||||||
msg = imsg;
|
msg = imsg;
|
||||||
IRC_AddClientMessage(ircclient, va("PRIVMSG %s :%s\r\n", ircclient->defaultdest, msg));
|
IRC_AddClientMessage(ircclient, va("PRIVMSG %s :%s", ircclient->defaultdest, msg));
|
||||||
Con_SubPrintf(ircclient->defaultdest, "%s: %s\n", ircclient->nick, msg);
|
Con_SubPrintf(ircclient->defaultdest, "%s: %s\n", ircclient->nick, msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue