a few fixes to NickServ and the start of MemoServ`

This commit is contained in:
fishwaldo 2002-06-05 15:41:10 +00:00
parent 07282abebb
commit f429d2fd8c
13 changed files with 144 additions and 106 deletions

View file

@ -8,8 +8,8 @@ INSTALL_DATA = @INSTALL_DATA@
DIRECTORY=@DIRINST@/dl/
INCLUDES=-I@DIRINST@/include/ -I.
SOURCES= match.c hash.c servicescore.c nickserv.c language.c svc_help.c
OBJECTS= match.o hash.o servicescore.o nickserv.o language.o svc_help.o
SOURCES= match.c hash.c servicescore.c nickserv.c language.c svc_help.c memoserv.c
OBJECTS= match.o hash.o servicescore.o nickserv.o language.o svc_help.o memoserv.o
TARGET= services.so
DOCS=README.services
DATA= lang/en_us
@ -45,3 +45,4 @@ hash.o: hash.c services.h
servicescore.o: hash.c match.c language.c nickserv.c services.h
nickserv.o: match.c hash.c servicescore.c services.h
langauges.o: servicescore.c nickserv.c services.h
memoserv.o: hash.c servicescore.c services.h

15
hash.c
View file

@ -5,7 +5,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: hash.c,v 1.3 2002/03/31 08:37:14 fishwaldo Exp $
** $Id: hash.c,v 1.4 2002/06/05 15:41:10 fishwaldo Exp $
*/
@ -157,8 +157,8 @@ NS_User *lookup_regnick(char *name)
NS_User *ns2;
DBT key, data;
int i;
ns2 = smalloc(sizeof(NS_User));
ns2 = malloc(sizeof(NS_User));
bzero(ns2, sizeof(NS_User));
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
@ -189,8 +189,8 @@ NS_User *new_regnick(char *name, int create)
DBT key, data;
int i;
ns = smalloc(sizeof(NS_User));
ns2 = smalloc(sizeof(NS_User));
ns = malloc(sizeof(NS_User));
ns2 = malloc(sizeof(NS_User));
bzero(ns, sizeof(NS_User));
bzero(ns2, sizeof(NS_User));
memset(&key, 0, sizeof(key));
@ -231,10 +231,10 @@ NS_User *new_regnick(char *name, int create)
/* free(ns2); */
}
memcpy(ns->nick, name, strlen(name)+1);
strncpy(ns->nick, name, strlen(name));
nsn = hnode_create(ns);
if (!hash_isfull(nsuserlist)) {
hash_insert(nsuserlist, nsn, name);
hash_insert(nsuserlist, nsn, ns->nick);
} else {
log("eeek, NickServ User list hash is full");
}
@ -270,6 +270,7 @@ void del_regnick(char *name)
return;
}
ns = hnode_get(nsn);
hash_delete(nsuserlist, nsn);
hnode_destroy(nsn);
free(ns);
}

Binary file not shown.

View file

@ -411,3 +411,8 @@ NICKSERV_HELP_ACCESS
/msg %S access del <num>
will delete the corrosponding entry out of your access list. You can
figure out what num is via /msg %S access list
MEMOSERV_HELP
%S allows a registered IRC user to send Memos to other
registered IRC users

View file

@ -43,3 +43,4 @@ NICKSERV_HELP_GETPASS
NICKSERV_HELP_SETPASS
NICKSERV_HELP_VHOST
NICKSERV_HELP_ACCESS
MEMOSERV_HELP

View file

@ -43,5 +43,6 @@
#define NICKSERV_HELP_SETPASS 42
#define NICKSERV_HELP_VHOST 43
#define NICKSERV_HELP_ACCESS 44
#define MEMOSERV_HELP 45
#define NUM_STRINGS 45
#define NUM_STRINGS 46

View file

@ -69,7 +69,7 @@ static void load_lang(int index, const char *filename)
log("Warning: Bad number of strings (%d, wanted %d) "
"for language %d (%s)", num, NUM_STRINGS, index, filename);
}
langtexts[index] = smalloc(sizeof(char *) * NUM_STRINGS);
langtexts[index] = malloc(sizeof(char *) * NUM_STRINGS);
if (num > NUM_STRINGS)
num = NUM_STRINGS;
for (i = 0; i < num; i++) {
@ -109,7 +109,7 @@ static void load_lang(int index, const char *filename)
langtexts[index] = NULL;
return;
} else {
langtexts[index][i] = smalloc(len+1);
langtexts[index][i] = malloc(len+1);
fseek(f, pos, SEEK_SET);
if (fread(langtexts[index][i], 1, len, f) != len) {
log("Failed to read string %d in language %d (%s)",

View file

@ -43,5 +43,6 @@
#define NICKSERV_HELP_SETPASS 42
#define NICKSERV_HELP_VHOST 43
#define NICKSERV_HELP_ACCESS 44
#define MEMOSERV_HELP 45
#define NUM_STRINGS 45
#define NUM_STRINGS 46

View file

@ -70,7 +70,7 @@ void lslog(char *, ...);
int guest_num = 1000;
int __Bot_Message(char *origin, char **av, int ac)
int NS_Bot_Message(char *origin, char **av, int ac)
{
char *buf;
User *u;
@ -82,9 +82,9 @@ int __Bot_Message(char *origin, char **av, int ac)
log("%s", av[1]);
if (!strcasecmp(av[1], "HELP")) {
if (ac > 2) {
send_help(u, av[2]);
send_nshelp(u, av[2]);
} else {
send_help(u, NULL);
send_nshelp(u, NULL);
}
return 1;
} else if (!strcasecmp(av[1], "REGISTER")) {
@ -379,8 +379,8 @@ static void ns_forbid(User *u, char *line) {
privmsg(u->nick, s_NickServ, "Syntax Error: \002/%s help forbid del\002 for help", s_NickServ);
return;
}
newlist = smalloc(1024);
tmp2 = smalloc(1024);
newlist = malloc(1024);
tmp2 = malloc(1024);
strcpy(tmp2, ns_forbid_list);
tmp = strtok(tmp2, " ");
while (tmp) {
@ -538,8 +538,8 @@ static void ns_accesslist(User *u, char *line) {
privmsg(u->nick, s_NickServ, "Syntax Error: \002/%s help access del\002 for help", s_NickServ);
return;
}
newacl = smalloc(1024);
tmp = smalloc(1024);
newacl = malloc(1024);
tmp = malloc(1024);
strcpy(tmp, ns->acl);
target = strtok(tmp, " ");
while (target) {
@ -884,7 +884,7 @@ int ns_bye_user(User *u) {
/* recbuf from the core contains the line that trigged this, in this
** case, we need to copy it and extract the quit message
*/
buffer = smalloc(255);
buffer = malloc(255);
strcpy(buffer, recbuf);
quitmsg = strtok(buffer, ":");
quitmsg = strtok(NULL, "");
@ -900,19 +900,44 @@ int ns_bye_user(User *u) {
int ns_nickchange_user(char *line) {
char *orignick, *targetnick;
NS_User *tmp_user;
char *tmpnick;
Svs_Timers *svc_timers;
hscan_t hs;
hnode_t *rn;
orignick = strtok(line, " ");
targetnick = strtok(NULL, " ");
if (findregnick(orignick)) {
sync_nick_to_db(findregnick(orignick));
del_regnick(orignick);
tmp_user = findregnick(orignick);
if (tmp_user) {
sync_nick_to_db(tmp_user);
if (tmp_user->onlineflags &= NSFL_IDENTTIMEOUT) {
/* its a svsnick change */
tmp_user->onlineflags = NSFL_ENFORCED;
#ifdef ULTIMATE3
snewnick_cmd(orignick, "enforcer", me.name, "Services Nickname Enforcer", 0);
#else
snewnick_cmd(orignick, "enforcer", me.name, "Services Nickname Enforcer");
#endif
// TODO: DON'T HARDCODE THIS (size)
tmpnick = malloc(37);
snprintf(tmpnick, 36, "QuitEnforcer-%s", orignick);
svc_timers = new_svs_timers(tmpnick);
svc_timers->interval = ENFORCER_HOLD_TIME;
svc_timers->lastrun = time(NULL);
strcpy(svc_timers->varibles, orignick);
svc_timers->function = dlsym((int *)get_dl_handle("Services"), "ns_quit_enforced_nick");
if (!svc_timers->function) {
log("Error: %s", dlerror());
}
free(tmpnick);
}
}
/* this function is called after NeoStats has updated the Internal Tables, so finduser will work */
ns_new_user(finduser(targetnick));
ssvsmode_cmd(targetnick, "-r");
return 1;
}
int ns_new_user( User *u) {
@ -1006,7 +1031,7 @@ int ns_new_user( User *u) {
** and if it is, returns 1, which forces the garbage collection to clean it up
*/
tmp = smalloc(37);
tmp = malloc(37);
snprintf(tmp, 36, "IdentTO-%s", u->nick);
svc_timers = new_svs_timers(tmp);
svc_timers->interval = NICK_IDENT_TIME;
@ -1025,7 +1050,6 @@ int ns_new_user( User *u) {
int ns_ident_timeout(char *nick) {
User *u;
char *tmpnick;
Svs_Timers *svc_timers, *svc_timers2;
NS_User *tmp_user;
u = finduser(nick);
@ -1038,79 +1062,20 @@ int ns_ident_timeout(char *nick) {
if (tmp_user->onlineflags == NSFL_IDENTIFED) return 1;
/* create a guest user nick, and make sure its not used */
tmpnick = smalloc(32);
tmpnick = malloc(32);
snprintf(tmpnick, 32, "Guest%i", guest_num++);
while (finduser(tmpnick))
snprintf(tmpnick, 32, "Guest%i", guest_num++);
privmsg(u->nick, s_NickServ, "Your Nickname has been changed to \002%s\002 as you did not identify", tmpnick);
ssvsnick_cmd(u->nick, tmpnick);
free(tmpnick);
/* now we need to signon a new user to take this nick, so that if the clients script
** tries to regain the nick, it wont work.
** one problem with NeoStats at the moment, is that if someone messages's this
** enforced nick, NeoStats is going to Generate a Error message
** so thats a TODO for NeoStats, find some way to fix that
** currently Modules can only have 1 Bot... will fix that when I start writting CommServ (as it will be two Bots in the same
** Module, and its needed to fix)
*/
/* TODO: this is hardcoded stuff, change it when the config interface is available */
/* add a timer to delete this nick again, hard coded*/
tmpnick = smalloc(37);
snprintf(tmpnick, 36, "QuitEnforcer-%s", u->nick);
svc_timers = new_svs_timers(tmpnick);
svc_timers->interval = ENFORCER_HOLD_TIME;
svc_timers->lastrun = time(NULL);
strcpy(svc_timers->varibles, u->nick);
svc_timers->function = dlsym((int *)get_dl_handle("Services"), "ns_quit_enforced_nick");
if (!svc_timers->function) {
log("Error: %s", dlerror());
}
free(tmpnick);
tmpnick = smalloc(254);
snprintf(tmpnick, 254, "SignonEnforcer-%s", u->nick);
svc_timers2 = new_svs_timers(tmpnick);
/* when we get the nickchange event for this nick, we will see their nick is ident timeout so we sign on a new user */
tmp_user->onlineflags = NSFL_IDENTTIMEOUT;
/* run it straight away */
/* Straight away is NOT 0, as this would run it straight after this function, which deletes the purpose of a delay */
svc_timers2->interval = 2;
svc_timers2->lastrun = time(NULL);
snprintf(svc_timers2->varibles, 254, "NICK %s 1 %d enforcer %s %s 0 :Nickname Enforcer", u->nick, (int)time(NULL), me.name, me.name);
svc_timers2->function = dlsym((int *)get_dl_handle("Services"), "ns_signon_enforced_nick");
if (!svc_timers2->function) {
log("Error: %s", dlerror());
}
free(tmpnick);
return 1;
}
int ns_signon_enforced_nick(char *vars) {
NS_User *temp_user;
char *nick, *user;
sts("%s", vars);
nick = strtok(vars, " ");
nick = strtok(NULL, " ");
user = strtok(NULL, " ");
user = strtok(NULL, " ");
user = strtok(NULL, " ");
/* this is bad... NeoStats wont know how to handle this user... See the comments in ns_ident_timeout */
AddUser(nick, user, me.name, me.name);
/* have to add this user to the regnicks list, so recover can work */
temp_user = new_regnick(nick, 1);
temp_user->onlineflags = NSFL_ENFORCED;
return 1;
}
int ns_quit_enforced_nick(char *nick) {
NS_User *temp_user;
@ -1124,7 +1089,7 @@ int ns_quit_enforced_nick(char *nick) {
/* TODO: its this user is added to any list, then remove it */
DelUser(nick);
// DelUser(nick);
/* remove it from the Registered Nicks List
** we don't have to check if its in the list, as its a Enforcer Nick
@ -1190,7 +1155,7 @@ static void ns_recover(User *u, char *nick, char *pass) {
return;
}
tmp = smalloc(10);
tmp = malloc(10);
snprintf(tmp, 10, "Guest%i", guest_num++);
/* make sure that the nickname isn't used, and if it is, keep trying till we find a nick not being used! */
@ -1234,7 +1199,7 @@ static void ns_ghost(User *u, char *nick, char *pass) {
privmsg(u->nick, s_NickServ, "Success. the Nickname %s has been killed", target->nick);
ssvskill_cmd(target->nick, ":KILLED: Ghost Command Used by %s(%s@%s)");
notice(s_NickServ, "%s(%s@%s) Used Ghost Comand on %s(%s@%s)", u->nick, u->username, u->hostname, target->nick, target->username, target->hostname);
tmp = smalloc(255);
tmp = malloc(255);
snprintf(tmp, 255, "%s", target->nick);
free(tmp);
free(temp_user);

View file

@ -5,7 +5,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: options.h,v 1.2 2002/03/28 08:58:16 fishwaldo Exp $
** $Id: options.h,v 1.3 2002/06/05 15:41:10 fishwaldo Exp $
*/
@ -53,7 +53,7 @@
*/
#define NSDBASE "data/nsdata.db"
#define MSDBASE "data/msdata.db"
/* how long do users have to ident to nickserv before their nick is changed.
** this is set if kill is active for that nick (kill isn't a good word, read the online help about set kill.

View file

@ -5,7 +5,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: services.h,v 1.3 2002/03/31 08:37:14 fishwaldo Exp $
** $Id: services.h,v 1.4 2002/06/05 15:41:10 fishwaldo Exp $
*/
#ifndef M_SERVICES
@ -32,9 +32,13 @@
#include <hash.h>
#include "options.h"
/* nickserv database */
DB *dbp;
/* memoserv database */
DB *mdbp;
char *s_NickServ;
char *s_MemoServ;
/* used to determine which nicks have changed, and need sync'ing */
int last_db_sync;
@ -155,7 +159,7 @@ int get_dl_handle(char *);
#define NSFL_ACCESSMATCH 0x0004 /* user has been matched against the accesslist */
#define NSFL_ENFORCED 0x0008 /* this is a Enforcer.. ie, not a real user */
#define NSFL_SUSPEND 0x0010 /* nickname is suspended */
#define NSFL_IDENTTIMEOUT 0x0020 /* nickname has ident timeout */
#define NUM_LANGS 10

View file

@ -40,6 +40,19 @@ Functions my_fn_list[] = {
};
int __Bot_Message(char *origin, char **av, int ac)
{
if (!strcasecmp(av[0], s_NickServ)) {
NS_Bot_Message(origin, av, ac);
}
if (!strcasecmp(av[0], s_MemoServ)) {
MS_Bot_Message(origin, av, ac);
}
}
int Online(Server *data) {
if (init_bot(s_NickServ,"nick",me.name,"Network Nick Service", "+xd", my_info[0].module_name) == -1 ) {
@ -47,6 +60,12 @@ int Online(Server *data) {
s_NickServ = strcat(s_NickServ, "_");
init_bot(s_NickServ,"nick",me.name,"Network Nick Service", "+xd", my_info[0].module_name);
}
if (init_bot(s_MemoServ, "memo", me.name, "Network Memo Service", "+xd", my_info[0].module_name) == -1) {
/* Nick was in use!!!! */
s_MemoServ = strcat(s_MemoServ, "_");
init_bot(s_MemoServ,"memo",me.name,"Network Memo Service", "+xd", my_info[0].module_name);
}
/* TODO: don't use constants here */
add_mod_timer("runsvstimers", "Services", "Services", 1);
add_mod_timer("sync_changed_nicks_to_db", "DB_Sync", "Services", DB_SYNC_TIME);
@ -63,7 +82,6 @@ EventFnList my_event_list[] = {
};
Module_Info *__module_get_info() {
return my_info;
};
@ -80,24 +98,40 @@ void _init() {
int ret;
s_NickServ = "NS";
s_MemoServ = "MS";
ret = db_create(&dbp, NULL,0);
if (ret != 0) {
log("nickserv dbcreate error");
return;
}
ret = dbp->open(dbp, NSDBASE, NULL, DB_HASH, 0, 0644);
ret = db_create(&mdbp, NULL,0);
if (ret != 0) {
log("memoserv dbcreate error");
return;
}
ret = dbp->open(dbp, NSDBASE, "NICKSERV", DB_HASH, 0, 0644);
if (ret == ENOENT) {
/* db doesn't exist */
log("nickserv Database Doesn't Exist, Creating it!");
ret = dbp->open(dbp, NSDBASE, NULL, DB_HASH, DB_CREATE, 0644);
ret = dbp->open(dbp, NSDBASE, "NICKSERV", DB_HASH, DB_CREATE, 0644);
}
if (ret != 0) {
log("nickserv dbopen error %s", db_strerror(ret));
return;
}
ret = mdbp->open(mdbp, NSDBASE, "MEMOSERV", DB_HASH, 0, 0644);
if (ret == ENOENT) {
/* db doesn't exist */
log("memoserv Database Doesn't Exist, Creating it!");
ret = mdbp->open(mdbp, NSDBASE, "MEMOSERV", DB_HASH, DB_CREATE, 0644);
}
if (ret != 0) {
log("memoserv dbopen error %s", db_strerror(ret));
return;
}
log("NickServ Loaded");
log("MemoServ Loaded");
init_regnick_hash();
/* load the nickserv forbidden list */
init_nick_forbid_list();
@ -112,6 +146,11 @@ void _fini() {
globops("NickServ DB Close Error: %s", db_strerror(ret));
};
}
if (mdbp != NULL) {
if ((ret = mdbp->close(mdbp, 0) != 0)) {
globops("MemoServ DB Close Error: %s", db_strerror(ret));
}
}
log("NickServ Unloaded");
};

View file

@ -56,14 +56,19 @@ const SVC_help_ns svc_ns_help_index[] = {
{NULL, NULL, 0}
};
extern void send_help(User *u, char *line) {
const SVC_help_ns svc_ms_help_index[] = {
/* help, help function, level */
{"HELP", MEMOSERV_HELP, 0},
{NULL, NULL, 0}
};
extern void send_nshelp(User *u, char *line) {
int i;
if (!line) {
line = smalloc(5);
line = malloc(5);
strcpy(line, "HELP");
}
for (i = 0; i < ((sizeof(svc_ns_help_index) / sizeof(svc_ns_help_index[0])) -1); i++) {
log("%s - %s %d", svc_ns_help_index[i].name, line, strcasecmp(svc_ns_help_index[i].name, line));
if (!strcasecmp(svc_ns_help_index[i].name, line)) {
if (UserLevel(u) >= svc_ns_help_index[i].level) {
notice_help(s_NickServ, u->nick, svc_ns_help_index[i].function);
@ -71,3 +76,18 @@ extern void send_help(User *u, char *line) {
}
}
}
extern void send_mshelp(User *u, char *line) {
int i;
if (!line) {
line = malloc(5);
strcpy(line, "HELP");
}
for (i = 0; i < ((sizeof(svc_ms_help_index) / sizeof(svc_ms_help_index[0])) -1); i++) {
if (!strcasecmp(svc_ms_help_index[i].name, line)) {
if (UserLevel(u) >= svc_ms_help_index[i].level) {
notice_help(s_MemoServ, u->nick, svc_ms_help_index[i].function);
}
}
}
}