services ts support, new splitbuf and seperate parse/spltbuf for ircu

This commit is contained in:
Mark 2004-01-22 23:18:10 +00:00
parent 2b4e42e1c0
commit 6deffae15e
8 changed files with 171 additions and 82 deletions

View file

@ -30,6 +30,11 @@ NeoStats ChangeLog - Anything we add/remove/fix/change is in here (even our rant
the incoming text and let the NeoStats core process it (M)
- Added NICKV2 and UMODE2 support to Unreal (M)
- Set segv_module before calling bot chan messages (M)
- Added servicests support to Unreal and core (M)
- New style splif buffer function introduced to save splits and joins (M)
- Added system to overide the core parse and splitbuf functions for IRCu; will merge
back into core when IRCu support complete (M)
- Bug fix in NICKV2 for Unreal; realname was not parsed properly (M)
* NeoStats * Fish (F) * Version 2.5.14
- Fix a bug with HostServ unable to load the database

77
Ircu.c
View file

@ -420,3 +420,80 @@ static void
m_burst (char *origin, char **argv, int argc, int srv)
{
}
/* Override the core splitbuf and parse functions until
* IRCU support is complete
*/
int
splitbuf (char *buf, char ***argv, int colon_special)
{
int argvsize = 8;
int argc;
char *s;
SET_SEGV_LOCATION();
*argv = calloc (sizeof (char *) * argvsize, 1);
argc = 0;
while (*buf) {
if (argc == argvsize) {
argvsize += 8;
*argv = realloc (*argv, sizeof (char *) * argvsize);
}
s = strpbrk (buf, " ");
if (s) {
*s++ = 0;
while (isspace (*s))
s++;
} else {
s = buf + strnlen (buf, BUFSIZE);
}
if (*buf == 0) {
buf++;
}
(*argv)[argc++] = buf;
buf = s;
}
return argc;
}
void
parse (char *line)
{
char origin[64], cmd[64], *coreLine;
int cmdptr = 0;
int ac;
char **av;
SET_SEGV_LOCATION();
strip (line);
strlcpy (recbuf, line, BUFSIZE);
if (!(*line))
return;
nlog (LOG_DEBUG1, LOG_CORE, "R: %s", line);
if (!*line)
return;
coreLine = strpbrk (line, " ");
if (coreLine) {
*coreLine = 0;
while (isspace (*++coreLine));
} else
coreLine = line + strlen (line);
if ((!strcasecmp(line, "SERVER")) || (!strcasecmp(line, "PASS"))) {
strlcpy(cmd, line, sizeof(cmd));
ac = splitbuf(coreLine, &av, 1);
cmdptr = 0;
} else {
strlcpy(origin, line, sizeof(origin));
cmdptr = 1;
line = strpbrk (coreLine, " ");
if (line) {
*line = 0;
while (isspace (*++line));
} else
coreLine = line + strlen (line);
ac = splitbuf(line, &av, 0);
}
process_ircd_cmd (cmdptr, cmd, origin, av, ac);
free (av);
}

5
Ircu.h
View file

@ -58,6 +58,11 @@
/* we don't have automatic host cloaking support via Umode */
#undef GOTUMODECLOAKING
/* Override NeoStats core splitbuf function */
#define IRCD_SPLITBUF
/* Override NeoStats core parse function */
#define IRCD_PARSE
/* buffer sizes */
#define MAXHOST (63 + 1)
#define MAXPASS (32 + 1)

View file

@ -193,10 +193,11 @@ send_server (const char *name, const int numeric, const char *infoline)
void
send_server_connect (const char *name, const int numeric, const char *infoline, const char *pass)
{
#if 0
sts ("%s TOKEN SJOIN", (me.token ? TOK_PROTOCTL : MSG_PROTOCTL));
/* PROTOCTL NOQUIT TOKEN NICKv2 SJOIN SJOIN2 UMODE2 VL SJ3 NS SJB64 */
#ifdef SJOIN
sts ("%s TOKEN NICKv2 SJOIN SJOIN2 UMODE2", (me.token ? TOK_PROTOCTL : MSG_PROTOCTL));
#else
sts ("%s TOKEN UMODE2 NICKv2", (me.token ? TOK_PROTOCTL : MSG_PROTOCTL));
sts ("%s TOKEN NICKv2 UMODE2", (me.token ? TOK_PROTOCTL : MSG_PROTOCTL));
#endif
sts ("%s %s", (me.token ? TOK_PASS : MSG_PASS), pass);
sts ("%s %s %d :%s", (me.token ? TOK_SERVER : MSG_SERVER), name, numeric, infoline);
@ -471,10 +472,7 @@ m_server (char *origin, char **argv, int argc, int srv)
static void
m_squit (char *origin, char **argv, int argc, int srv)
{
char *tmpbuf;
tmpbuf = joinbuf(argv, argc, 1);
SquitServer (argv[0], tmpbuf);
free(tmpbuf);
SquitServer (argv[0], argv[1]);
}
/* m_quit
@ -483,10 +481,7 @@ m_squit (char *origin, char **argv, int argc, int srv)
static void
m_quit (char *origin, char **argv, int argc, int srv)
{
char *tmpbuf;
tmpbuf = joinbuf(argv, argc, 0);
UserQuit (origin, tmpbuf);
free(tmpbuf);
UserQuit (origin, argv[0]);
}
/* m_svsmode
@ -500,7 +495,11 @@ m_svsmode (char *origin, char **argv, int argc, int srv)
if (argv[0][0] == '#') {
ChanMode (origin, argv, argc);
} else {
UserMode (argv[0], argv[1]);
if (argv[2] && isdigit(*argv[2])) {
SetUserServicesTS(argv[0], argv[2]);
} else {
UserMode (argv[0], argv[1]);
}
}
}
@ -541,10 +540,7 @@ m_umode2 (char *origin, char **argv, int argc, int srv)
static void
m_kill (char *origin, char **argv, int argc, int srv)
{
char *tmpbuf;
tmpbuf = joinbuf(argv, argc, 1);
KillUser (argv[0], tmpbuf);
free(tmpbuf);
KillUser (argv[0], argv[1]);
}
static void
m_vhost (char *origin, char **argv, int argc, int srv)
@ -568,15 +564,7 @@ m_pong (char *origin, char **argv, int argc, int srv)
static void
m_away (char *origin, char **argv, int argc, int srv)
{
char *buf;
if (argc > 0) {
buf = joinbuf (argv, argc, 0);
UserAway (origin, buf);
free (buf);
} else {
UserAway (origin, NULL);
}
UserAway (origin, (argc > 0) ? argv[0] : NULL);
}
/* m_nick
@ -602,17 +590,12 @@ static void
m_nick (char *origin, char **argv, int argc, int srv)
{
if(!srv) {
char *realname;
#ifdef NICKV2
realname = joinbuf (argv, argc, 7);
AddUser (argv[0], argv[3], argv[4], realname, argv[5], NULL, argv[2]);
free (realname);
AddUser (argv[0], argv[3], argv[4], argv[9], argv[5], NULL, argv[2]);
UserMode (argv[0], argv[7]);
SetUserVhost(argv[0], argv[8]);
#else
realname = joinbuf (argv, argc, 7);
AddUser (argv[0], argv[3], argv[4], realname, argv[5], NULL, argv[2]);
free (realname);
AddUser (argv[0], argv[3], argv[4], argv[7], argv[5], NULL, argv[2]);
#endif
} else {
UserNick (origin, argv[0], NULL);
@ -631,11 +614,7 @@ m_nick (char *origin, char **argv, int argc, int srv)
static void
m_topic (char *origin, char **argv, int argc, int srv)
{
char *buf;
buf = joinbuf (argv, argc, 3);
ChanTopic (argv[1], argv[0], argv[2], buf);
free (buf);
ChanTopic (argv[1], argv[0], argv[2], argv[3]);
}
/* m_kick
@ -646,10 +625,7 @@ m_topic (char *origin, char **argv, int argc, int srv)
static void
m_kick (char *origin, char **argv, int argc, int srv)
{
char *tmpbuf;
tmpbuf = joinbuf(argv, argc, 2);
kick_chan(argv[0], argv[1], origin, tmpbuf);
free(tmpbuf);
kick_chan(argv[0], argv[1], origin, argv[2]);
}
/* m_join
@ -669,10 +645,7 @@ m_join (char *origin, char **argv, int argc, int srv)
static void
m_part (char *origin, char **argv, int argc, int srv)
{
char *tmpbuf;
tmpbuf = joinbuf(argv, argc, 1);
part_chan (finduser (origin), argv[0], tmpbuf);
free(tmpbuf);
part_chan (finduser (origin), argv[0], argv[1]);
}
/* m_ping
@ -698,12 +671,9 @@ m_ping (char *origin, char **argv, int argc, int srv)
static void
m_netinfo (char *origin, char **argv, int argc, int srv)
{
char *buf;
ircd_srv.uprot = atoi (argv[2]);
strlcpy (ircd_srv.cloak, argv[3], 10);
buf = joinbuf (argv, argc, 7);
strlcpy (me.netname, buf, MAXPASS);
free (buf);
strlcpy (me.netname, argv[7], MAXPASS);
send_netinfo ();
init_services_bot ();
globops (me.name, "Link with Network \2Complete!\2");

View file

@ -742,7 +742,8 @@
#define is_oper(x) ((x) && ((x->Umode & UMODE_OPER) || (x->Umode & UMODE_LOCOP)))
#define is_bot(x) ((x) && (x->Umode & UMODE_BOT))
//#define NEW_STYLE_SPLITBUF
#define NEW_STYLE_SPLITBUF
#define NICKV2
/*#define SJOIN*/
#endif /* UNREAL_H Define */

85
ircd.c
View file

@ -42,6 +42,11 @@ static char SmodeStringBuf[64];
#endif
static long services_bot_umode= 0;
/* Fully split buffer */
#ifdef NEW_STYLE_SPLITBUF
static char privmsgbuffer[BUFSIZE];
#endif
static int signon_newbot (const char *nick, const char *user, const char *host, const char *rname, long Umode);
/** @brief init_ircd
@ -232,7 +237,12 @@ signon_newbot (const char *nick, const char *user, const char *host, const char
sjoin_cmd (nick, me.chan);
schmode_cmd (me.name, me.chan, "+a", nick);
#elif defined(UNREAL)
#ifdef SJOIN
ssjoin_cmd(nick, me.chan, CMODE_CHANOP);
#else
sjoin_cmd (nick, me.chan);
schmode_cmd (me.name, me.chan, "+o", nick);
#endif
#endif
}
return NS_SUCCESS;
@ -376,29 +386,25 @@ CloakHost (ModUser *bot_ptr)
*
* @return
*/
#ifndef IRCD_SPLITBUF
#ifdef NEW_STYLE_SPLITBUF
int
split_buf (char *buf, char ***argv, int colon_special)
splitbuf (char *buf, char ***argv, int colon_special)
{
int argvsize = 8;
int argc;
char *s;
#ifndef IRCU
int colcount = 0;
#endif
SET_SEGV_LOCATION();
*argv = calloc (sizeof (char *) * argvsize, 1);
argc = 0;
#ifndef IRCU
if (*buf == ':')
buf++;
#endif
while (*buf) {
if (argc == argvsize) {
argvsize += 8;
*argv = realloc (*argv, sizeof (char *) * argvsize);
}
#ifndef IRCU
if ((*buf == ':') && (colcount < 1)) {
buf++;
colcount++;
@ -407,7 +413,6 @@ split_buf (char *buf, char ***argv, int colon_special)
break;
}
}
#endif
s = strpbrk (buf, " ");
if (s) {
*s++ = 0;
@ -425,6 +430,10 @@ split_buf (char *buf, char ***argv, int colon_special)
return argc;
}
#else
#define splitbuf split_buf
#endif
#endif
int
split_buf (char *buf, char ***argv, int colon_special)
{
@ -468,7 +477,6 @@ split_buf (char *buf, char ***argv, int colon_special)
}
return argc;
}
#endif
/** @brief joinbuf
*
@ -514,6 +522,10 @@ joinbuf (char **av, int ac, int from)
static void
m_privmsg (int cmdptr, char* origin, char **av, int ac)
{
#ifdef NEW_STYLE_SPLITBUF
int argc;
char **argv;
#endif
char target[64];
User *u;
ModUser *mod_usr;
@ -526,12 +538,19 @@ m_privmsg (int cmdptr, char* origin, char **av, int ac)
strlcpy (target, av[0], 64);
av[0] = strtok (target, "@");
}
if (!strcasecmp (s_Services, av[0])) {
if (flood (finduser (origin))) {
return;
}
/* its to the Internal Services Bot */
#ifdef NEW_STYLE_SPLITBUF
argc = split_buf (privmsgbuffer, &argv, 1);
servicesbot (origin, argv, argc);
free (argv);
#else
servicesbot (origin, av, ac);
#endif
return;
} else {
mod_usr = findbot (av[0]);
@ -553,21 +572,39 @@ m_privmsg (int cmdptr, char* origin, char **av, int ac)
SET_SEGV_INMODULE(mod_usr->modname);
if (setjmp (sigvbuf) == 0) {
if(mod_usr->function) {
#ifdef NEW_STYLE_SPLITBUF
argc = split_buf (privmsgbuffer, &argv, 1);
mod_usr->function (origin, argv, argc);
free (argv);
#else
mod_usr->function (origin, av, ac);
#endif
}
else {
u = finduser (origin);
if (!u) {
nlog (LOG_WARNING, LOG_CORE, "Unable to finduser %s (%s)", origin, mod_usr->nick);
return;
} else {
#ifdef NEW_STYLE_SPLITBUF
argc = split_buf (privmsgbuffer, &argv, 1);
run_bot_cmd(mod_usr, u, argv, argc);
free (argv);
#else
run_bot_cmd(mod_usr, u, av, ac);
#endif
}
run_bot_cmd(mod_usr, u, av, ac);
}
}
CLEAR_SEGV_INMODULE();
return;
} else {
#ifdef NEW_STYLE_SPLITBUF
argc = split_buf (privmsgbuffer, &argv, 1);
bot_chan_message (origin, argv, argc);
free (argv);
#else
bot_chan_message (origin, av, ac);
#endif
return;
}
}
@ -623,6 +660,7 @@ process_ircd_cmd (int cmdptr, char *cmd, char* origin, char **av, int ac)
*
* @return none
*/
#ifndef IRCD_PARSE
void
parse (char *line)
{
@ -637,7 +675,6 @@ parse (char *line)
if (!(*line))
return;
nlog (LOG_DEBUG1, LOG_CORE, "R: %s", line);
#ifndef IRCU
if (*line == ':') {
coreLine = strpbrk (line, " ");
if (!coreLine)
@ -651,40 +688,24 @@ parse (char *line)
cmdptr = 0;
*origin = 0;
}
#endif
if (!*line)
return;
coreLine = strpbrk (line, " ");
if (coreLine) {
*coreLine = 0;
while (isspace (*++coreLine));
} else
coreLine = line + strlen (line);
#ifdef IRCU
if ((!strcasecmp(line, "SERVER")) || (!strcasecmp(line, "PASS"))) {
strlcpy(cmd, line, sizeof(cmd));
ac = split_buf(coreLine, &av, 1);
cmdptr = 0;
} else {
strlcpy(origin, line, sizeof(origin));
cmdptr = 1;
line = strpbrk (coreLine, " ");
if (line) {
*line = 0;
while (isspace (*++line));
} else
coreLine = line + strlen (line);
ac = split_buf(line, &av, 0);
coreLine = line + strlen (line);
}
#else
strlcpy (cmd, line, sizeof (cmd));
ac = split_buf (coreLine, &av, 1);
#ifdef NEW_STYLE_SPLITBUF
strlcpy (privmsgbuffer, coreLine, BUFSIZE);
#endif
ac = splitbuf (coreLine, &av, 1);
process_ircd_cmd (cmdptr, cmd, origin, av, ac);
free (av);
}
#endif
/** @brief init_services_bot
*

View file

@ -367,6 +367,7 @@ typedef struct User {
list_t *chans;
struct in_addr ipaddr;
time_t TS;
time_t servicesstamp;
long Smode;
void *moddata[NUM_MODULES];
long flags;

View file

@ -702,3 +702,12 @@ UserSMode (const char *nick, const char *modes)
nlog (LOG_DEBUG1, LOG_CORE, "UserSMode: smode for %s is now %p", u->nick, (int *)u->Smode);
}
#endif
void SetUserServicesTS(char* nick, char* ts)
{
User* u;
u = finduser(nick);
if(u) {
u->servicesstamp = strtoul(ts, NULL, 10);
}
}