Updated Module API for more Flexibility

Worked on Module_Events to pass data
Fixed up Spam Module crashing Server at nick change
This commit is contained in:
fishwaldo 2000-02-05 02:51:50 +00:00
parent 5e52341218
commit 22ad3680d4
7 changed files with 58 additions and 20 deletions

2
dl.c
View file

@ -344,7 +344,7 @@ int load_module(char *path1, User *u) {
if (me.onchan == 1) {
while (event_fn_ptr->cmd_name != NULL ) {
if (!strcasecmp(event_fn_ptr->cmd_name, "ONLINE")) {
event_fn_ptr->function();
event_fn_ptr->function(me.s);
break;
}
event_fn_ptr++;

2
dl.h
View file

@ -42,7 +42,7 @@ struct functions {
struct evtfunctions {
char *cmd_name;
int (*function)();
int (*function)(void *data);
};

View file

@ -4,7 +4,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: spam.c,v 1.2 2000/02/05 00:22:59 fishwaldo Exp $
** $Id: spam.c,v 1.3 2000/02/05 02:51:50 fishwaldo Exp $
*/
@ -81,7 +81,9 @@ int __Bot_Message(char *origin, char *coreLine, int type)
return 1;
}
int Online() {
int Online(Server *data) {
log("testing %s", data->name);
if (init_bot(s_Spam,"please",me.name,"Chat to me", "+xd", my_info[0].module_name) == -1 ) {
/* Nick was in use!!!! */
s_Spam = strcat(s_Spam, "_");

View file

@ -4,7 +4,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: statserv.c,v 1.2 2000/02/04 00:48:16 fishwaldo Exp $
** $Id: statserv.c,v 1.3 2000/02/05 02:51:50 fishwaldo Exp $
*/
#include "stats.h"
@ -18,7 +18,8 @@ static void ss_tld(User *u, char *tld);
static void ss_operlist(User *origuser, char *flags, char *server);
static void ss_botlist(User *origuser);
static void ss_version(User *u);
static int Online();
static int Online(Server *);
static int pong(char *);
static void ss_cb_Config(char *, int);
static int new_m_version(char *av, char *tmp);
@ -39,6 +40,7 @@ Functions StatServ_fn_list[] = {
EventFnList StatServ_Event_List[] = {
{"ONLINE", Online},
{"PONG", pong},
{ NULL, NULL}
};
@ -79,7 +81,11 @@ void _fini() {
}
int Online() {
int pong(char *coreLine) {
log("got pong %s", coreLine);
return 1;
}
int Online(Server *s) {
/* We should go the the existing server/user lists and add them to stats, cause its possible
that this has been called after the server already connected */

31
ircd.c
View file

@ -5,7 +5,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: ircd.c,v 1.2 2000/02/04 04:52:45 fishwaldo Exp $
** $Id: ircd.c,v 1.3 2000/02/05 02:51:50 fishwaldo Exp $
*/
#include "stats.h"
@ -151,7 +151,7 @@ int del_bot(char *nick, char *reason)
void Module_Event(char *event) {
void Module_Event(char *event, void *data) {
Module *module_ptr;
EventFnList *ev_list;
@ -167,7 +167,7 @@ void Module_Event(char *event) {
/* This goes through each Command */
if (!strcasecmp(ev_list->cmd_name, event)) {
segv_location = module_ptr->info->module_name;
ev_list->function();
ev_list->function(data);
break;
log("should never get here-Parse");
}
@ -286,14 +286,17 @@ void Usr_AddServer(char *origin, char *coreLine){
char *cmd;
cmd = strtok(coreLine, " ");
AddServer(cmd,1);
Module_Event("NEWSERVER", coreLine);
}
void Usr_DelServer(char *origin, char *coreLine){
char *cmd;
cmd = strtok(coreLine, " ");
DelServer(cmd);
Module_Event("DELSERVER", coreLine);
}
void Usr_DelUser(char *origin, char *coreLine) {
DelUser(origin);
Module_Event("SIGNOFF", coreLine);
}
void Usr_Mode(char *origin, char *coreLine) {
char *rest, *cmd;
@ -302,16 +305,19 @@ void Usr_Mode(char *origin, char *coreLine) {
log("Mode: UserMode: %s",cmd);
cmd = strtok(NULL, "");
UserMode(origin, cmd);
Module_Event("UMODE", coreLine);
} else {
log("Mode: ChanMode: %s",cmd);
rest = strtok(NULL, "");
ChanMode(cmd, rest);
}
Module_Event("CMODE", coreLine);
}
}
void Usr_Kill(char *origin, char *coreLine) {
char *cmd;
cmd = strtok(coreLine, " ");
DelUser(cmd);
Module_Event("SIGNOFF", coreLine);
}
void Usr_Pong(char *origin, char *coreLine) {
Server *s;
@ -327,6 +333,7 @@ void Usr_Pong(char *origin, char *coreLine) {
} else {
log("Received PONG from unknown server: %s", cmd);
}
Module_Event("PONG", coreLine);
}
void Usr_Away(char *origin, char *coreLine) {
User *u = finduser(origin);
@ -335,12 +342,14 @@ void Usr_Away(char *origin, char *coreLine) {
} else {
u->is_away = 1;
}
Module_Event("AWAY", u);
}
void Usr_Nick(char *origin, char *coreLine) {
char *cmd;
User *u = finduser(origin);
if (u) {
cmd = strtok(coreLine, " ");
Module_Event("NICK_CHANGE",coreLine);
Change_User(u, cmd);
}
}
@ -393,22 +402,26 @@ void Srv_Netinfo(char *origin, char *coreLine) {
#endif
if (!strcmp(cmd ,"2109")) {
me.usesmo = 1;
}
}
Module_Event("NETINFO", coreLine);
}
void Srv_Pass(char *origin, char *coreLine) {
}
void Srv_Server(char *origin, char *coreLine) {
Server *s;
Module_Event("ONLINE");
AddServer(strtok(coreLine, " "), 1);
s = findserver(coreLine);
me.s = s;
Module_Event("ONLINE", s);
}
void Srv_Squit(char *origin, char *coreLine) {
Server *s;
s = findserver(coreLine);
if (s)
if (s) {
Module_Event("SQUIT", s);
DelServer(coreLine);
}
}
void Srv_Nick(char *origin, char *coreLine) {
char *user, *host, *server, *cmd;
@ -420,6 +433,7 @@ void Srv_Nick(char *origin, char *coreLine) {
host = strtok(NULL, " ");
server = strtok(NULL, " ");
AddUser(cmd, user, host, server);
Module_Event("SIGNON", coreLine);
}
void Srv_Svsnick(char *origin, char *coreLine) {
char *nnick;
@ -429,11 +443,14 @@ void Srv_Svsnick(char *origin, char *coreLine) {
u = finduser(nnick);
nnick = strtok(NULL, " ");
Change_User(u, nnick);
Module_Event("NICK_CHANGE",coreLine);
}
void Srv_Kill(char *origin, char *coreLine) {
char *user, *rest;
user = strtok(coreLine, " ");
rest = strtok(NULL, " ");
}
void privmsg(char *to, const char *from, char *fmt, ...)

View file

@ -4,12 +4,14 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: services.c,v 1.3 2000/02/05 00:22:59 fishwaldo Exp $
** $Id: services.c,v 1.4 2000/02/05 02:51:50 fishwaldo Exp $
*/
#include "stats.h"
#include "dl.h"
extern const char version_date[], version_time[];
extern const char protocol_version[];
@ -146,8 +148,6 @@ void servicesbot(char *nick, char *line) {
}
list_module_timer(u);
} else if (!strcasecmp(cmd, "UPTIME")) {
notice(s_Services,"Broken atm :(");
return;
ns_uptime(u);
notice(s_Services,"%s Wanted to see %s's Uptime ",u->nick,me.name);
} else if (!strcasecmp(cmd, "SHUTDOWN")) {
@ -442,10 +442,21 @@ static void ns_chan_dump(User *u)
}
static void ns_uptime(User *u)
{
struct rusage *prog_stats;
segv_location = "ns_uptime";
if (getrusage(RUSAGE_SELF, prog_stats) == 1) {
log("GetRusage Failed");
}
log("time %d", me.t_start);
privmsg(u->nick, s_Services, "Statistics Information:");
privmsg(u->nick, s_Services, "%s", uptime(me.t_start));
/* Broken atm */
privmsg(u->nick, s_Services, "Kernel User Time: %ld",prog_stats->ru_utime);
privmsg(u->nick, s_Services, "Kernel System Time: %ld", prog_stats->ru_stime);
privmsg(u->nick, s_Services, "Signals Recieved: %ld", prog_stats->ru_nsignals);
/* privmsg(u->nick, s_Services, "%s", uptime(me.t_start)); */
privmsg(u->nick, s_Services, "Reconnect Time: %d", me.r_time);
privmsg(u->nick, s_Services, "Statistic Requests: %d", me.requests);
privmsg(u->nick, s_Services, "Spam Service: %s",

View file

@ -5,7 +5,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: stats.h,v 1.2 2000/02/04 04:52:45 fishwaldo Exp $
** $Id: stats.h,v 1.3 2000/02/05 02:51:50 fishwaldo Exp $
*/
#ifndef STATS_H
@ -25,6 +25,8 @@
#include <sys/time.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include "m_stats.h"
#include "Unreal.h"
@ -215,7 +217,7 @@ extern void globops(char *, char *, ...);
extern int flood(User *);
extern int init_bot(char *, char *, char *, char *, char *,char *);
extern int del_bot(char *, char *);
extern void Module_Event(char *);
extern void Module_Event(char *, void *);
extern int bot_nick_change(char *, char *);
/* timer.c */