channel support updated. Bugfixes and RECVLOG, CODERHACK defined

This commit is contained in:
fishwaldo 2002-03-11 06:55:05 +00:00
parent bb636afc60
commit a2e6f4f244
11 changed files with 185 additions and 117 deletions

View file

@ -1,8 +1,14 @@
NeoStats ChangeLog - Anything we add/remove/fix/change is in here (even our rants)
* NeoStats * Fish * Version 2.5.0-Alpha4.7 (hu, what happened to 4.6?)
- Bug fixes (maybe) with channel support
- New option to userdump to specify a user to dump out particulars
- RECVLOG define, saves a copy of all incomming lines from the server. Defined in stats.h for testing only.
- CODERHACK define, allows coders (^Enigma^, Shmad, Fish full (200) access to NeoStats for Debuging. defined in stats.h
- Memleaks fixed in Chan support
* NeoStats * Fish * Version 2.5.0-Alpha4.5
- Added Channel Support.
* NeoStats * Fish * Version 2.5.0-Alpha4
- Fixed a bug with the hashs and when a user changes Nicks
- Moved all variable passing to arrays. Ms and statserv modules updated, but need more work.

110
chans.c
View file

@ -5,7 +5,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: chans.c,v 1.6 2002/03/08 14:18:08 fishwaldo Exp $
** $Id: chans.c,v 1.7 2002/03/11 06:55:04 fishwaldo Exp $
*/
#include <fnmatch.h>
@ -76,22 +76,26 @@ void ChanMode(char *origin, char **av, int ac) {
}
void ChangeChanUserMode(Chans *c, User *u, int add, long mode) {
hnode_t *cmn;
lnode_t *cmn;
Chanmem *cm;
cmn = hash_lookup(c->chanmembers, u->nick);
cmn = list_find(c->chanmembers, u->nick, comparef);
if (!cmn) {
log("ChangeChanUserMode() %s doesn't seem to be in the Chan %s", u->nick, c->name);
if (me.coder_debug) {
notice("ChangeChanUserMode() %s doesn't seem to be in the Chan %s", u->nick, c->name);
chandump(c->name);
UserDump(u->nick);
}
return;
}
cm = hnode_get(cmn);
cm = lnode_get(cmn);
if (add) {
#ifdef DEBUG
log("Adding mode %ld to Channel %s User %s\n", mode, c->name, u->nick);
log("Adding mode %ld to Channel %s User %s", mode, c->name, u->nick);
#endif
cm->flags |= mode;
} else {
#ifdef DEBUG
log("Deleting Mode %ld to Channel %s User %s\n", mode, c->name, u->nick);
log("Deleting Mode %ld to Channel %s User %s", mode, c->name, u->nick);
#endif
cm->flags &= ~mode;
}
@ -128,46 +132,66 @@ void del_chan(Chans *c) {
void part_chan(User *u, char *chan) {
Chans *c;
hnode_t *un;
lnode_t *un;
strcpy(segv_location, "part_chan");
if (!u) {
log("Ehh, Parting a Unknown User from Chan %s: %s", chan, recbuf);
log("Ehh, Parting a Unknown User %s from Chan %s: %s", u->nick, chan, recbuf);
if (me.coder_debug) {
notice("Ehh, Parting a Unknown User %s from Chan %s: %s", u->nick, chan, recbuf);
chandump(chan);
UserDump(u->nick);
}
return;
}
c = findchan(chan);
if (!c) {
log("Hu, Parting a Non existant Channel?");
log("Hu, Parting a Non existant Channel? %s", chan);
return;
} else {
un = hash_lookup(c->chanmembers, u->nick);
un = list_find(c->chanmembers, u->nick, comparef);
if (!un) {
log("hu, User %s isn't a member of this channel %s", u->nick, chan);
if (me.coder_debug) {
notice("hu, User %s isn't a member of this channel %s", u->nick, chan);
chandump(c->name);
UserDump(u->nick);
}
} else {
hash_delete(c->chanmembers, un);
lnode_destroy(list_delete(c->chanmembers, un));
c->cur_users--;
}
if (c->cur_users <= 0) {
del_chan(c);
}
un = hash_lookup(u->chans, chan);
un = list_find(u->chans, c->name, comparef);
if (!un) {
log("Hu, User %s claims not to be part of Chan %s", u->nick, chan);
if (me.coder_debug) {
notice("Hu, User %s claims not to be part of Chan %s", u->nick, chan);
chandump(c->name);
UserDump(u->nick);
}
return;
}
hash_delete(u->chans, un);
lnode_destroy(list_delete(u->chans, un));
}
}
void change_user_nick(Chans *c, char *newnick, char *oldnick) {
hnode_t *cm;
lnode_t *cm;
strcpy(segv_location, "change_user_nick");
cm = hash_lookup(c->chanmembers, oldnick);
cm = list_find(c->chanmembers, oldnick, comparef);
if (!cm) {
log("change_user_nick() %s isn't a member of %s", oldnick, c->name);
if (me.coder_debug) {
notice("change_user_nick() %s isn't a member of %s", oldnick, c->name);
chandump(c->name);
UserDump(oldnick);
}
return;
} else {
hash_delete(c->chanmembers, cm);
hash_insert(c->chanmembers, cm, newnick);
lnode_destroy(list_delete(c->chanmembers, cm));
list_append(c->chanmembers, lnode_create(newnick));
}
}
@ -176,7 +200,7 @@ void change_user_nick(Chans *c, char *newnick, char *oldnick) {
void join_chan(User *u, char *chan) {
Chans *c;
hnode_t *un;
lnode_t *un;
Chanmem *cm;
strcpy(segv_location, "join_chan");
if (!u) {
@ -191,30 +215,36 @@ void join_chan(User *u, char *chan) {
log("join_chan() -> New Channel %s", chan);
#endif
c = new_chan(chan);
c->chanmembers = hash_create(CHAN_MEM_SIZE, 0, 0);
c->chanmembers = list_create(CHAN_MEM_SIZE);
}
/* add this users details to the channel members hash */
cm = malloc(sizeof(Chanmem));
cm->u = u;
strcpy(cm->nick, u->nick);
cm->joint = time(NULL);
cm->flags = 0;
un = hnode_create(cm);
un = lnode_create(cm);
#ifdef DEBUG
log("adding usernode %s to Channel %s", u->nick, chan);
#endif
if (hash_lookup(c->chanmembers, u->nick)) {
if (list_find(c->chanmembers, u->nick, comparef)) {
log("Adding %s to Chan %s when he is already a member?", u->nick, chan);
if (me.coder_debug) {
notice("Adding %s to Chan %s when he is already a member?", u->nick, chan);
chandump(c->name);
UserDump(u->nick);
}
return;
}
hash_insert(c->chanmembers, un, u->nick);
list_prepend(c->chanmembers, un);
c->cur_users++;
un = hnode_create(c->name);
hash_insert(u->chans, un, c->name);
un = lnode_create(c->name);
list_prepend(u->chans, un);
}
void chandump(User *u, char *chan) {
hnode_t *cn, *cmn;
hscan_t sc, scm;
void chandump(char *chan) {
hnode_t *cn;
lnode_t *cmn;
hscan_t sc;
Chans *c;
Chanmem *cm;
char mode[10];
@ -233,17 +263,18 @@ void chandump(User *u, char *chan) {
sprintf(mode, "%s%c", mode, cFlagTab[i].flag);
}
}
sendcoders("Channel: %s Members: %d (Hash %d) Flags %s", c->name, c->cur_users, hash_count(c->chanmembers), mode);
hash_scan_begin(&scm, c->chanmembers);
while ((cmn = hash_scan_next(&scm)) != NULL) {
cm = hnode_get(cmn);
sendcoders("Channel: %s Members: %d (List %d) Flags %s", c->name, c->cur_users, list_count(c->chanmembers), mode);
cmn = list_first(c->chanmembers);
while (cmn) {
cm = lnode_get(cmn);
strcpy(mode, "+");
for (i = 0; i < ((sizeof(cFlagTab) / sizeof(cFlagTab[0])) - 1); i++) {
if (cm->flags & cFlagTab[i].mode) {
sprintf(mode, "%s%c", mode, cFlagTab[i].flag);
}
}
sendcoders("Members: %s Modes %s Joined %d", cm->u->nick, mode, cm->joint);
sendcoders("Members: %s Modes %s Joined %d", cm->nick, mode, cm->joint);
cmn = list_next(c->chanmembers, cmn);
}
}
} else {
@ -257,17 +288,18 @@ void chandump(User *u, char *chan) {
sprintf(mode, "%s%c", mode, cFlagTab[i].flag);
}
}
sendcoders("Channel: %s Members: %d (Hash %d) Flags %s", c->name, c->cur_users, hash_count(c->chanmembers), mode);
hash_scan_begin(&scm, c->chanmembers);
while ((cmn = hash_scan_next(&scm)) != NULL) {
cm = hnode_get(cmn);
sendcoders("Channel: %s Members: %d (List %d) Flags %s", c->name, c->cur_users, list_count(c->chanmembers), mode);
cmn = list_first(c->chanmembers);
while (cmn) {
cm = lnode_get(cmn);
strcpy(mode, "+");
for (i = 0; i < ((sizeof(cFlagTab) / sizeof(cFlagTab[0])) - 1); i++) {
if (cm->flags & cFlagTab[i].mode) {
sprintf(mode, "%s%c", mode, cFlagTab[i].flag);
}
}
sendcoders("Members: %s Modes %s Joined: %d", cm->u->nick, mode, cm->joint);
sendcoders("Members: %s Modes %s Joined: %d", cm->nick, mode, cm->joint);
cmn = list_next(c->chanmembers, cmn);
}
}
}

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.7 2002/03/07 08:42:17 fishwaldo Exp $
** $Id: spam.c,v 1.8 2002/03/11 06:55:05 fishwaldo Exp $
*/
@ -33,33 +33,6 @@ Functions my_fn_list[] = {
{ NULL, NULL, 0 }
};
void TimerSpam()
{
register char c;
register int i;
char temp[5];
srand(time(NULL));
bzero(temp, sizeof(temp));
for (i = 0; i < sizeof(temp)-1; i++) {
c = (((u_short)rand())%26)+97;
temp[i] = c;
}
/* if (servsock > 0) {
if (bot_nick_change(s_Spam, temp) == 1) {
s_Spam = sstrdup(temp);
notice(s_Spam, "Spam Users Nick is now: %s",temp);
} else { */
/* ToDo: Add routine if nick is in use, to find another nick */
/* return;
}
} */
return;
}
int __Bot_Message(char *origin, char **argv, int argc)
{
User *u;
@ -86,7 +59,6 @@ int Online(Server *data) {
s_Spam = strcat(s_Spam, "_");
init_bot(s_Spam,"Please",me.name,"Chat to me", "+xd", my_info[0].module_name);
}
add_mod_timer("TimerSpam","Spam_Nick",my_info[0].module_name, 300);
return 1;
};

1
ircd.c
View file

@ -575,7 +575,6 @@ void Usr_DelUser(char *origin, char **argv, int argc) {
DelUser(origin);
}
void Usr_Smode(char *origin, char **argv, int argc) {
log("svsmode nick %s Mode %s", argv[0], argv[1]);
UserMode(argv[0], argv[1]);
Module_Event("UMODE", finduser(argv[0]));
}

16
list.c
View file

@ -14,7 +14,7 @@
* into proprietary software; there is no requirement for such software to
* contain a copyright notice related to this source.
*
* $Id: list.c,v 1.1 2002/02/27 11:19:15 fishwaldo Exp $
* $Id: list.c,v 1.2 2002/03/11 06:55:04 fishwaldo Exp $
* $Name: $
*/
@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stddef.h>
#include <assert.h>
#include <string.h>
#define LIST_IMPLEMENTATION
#include "list.h"
@ -44,7 +45,7 @@
#define lnode_prev(N) ((N)->prev)
#ifdef KAZLIB_RCSID
static const char rcsid[] = "$Id: list.c,v 1.1 2002/02/27 11:19:15 fishwaldo Exp $";
static const char rcsid[] = "$Id: list.c,v 1.2 2002/03/11 06:55:04 fishwaldo Exp $";
#endif
/*
@ -771,6 +772,13 @@ int list_verify(list_t *list)
return 1;
}
int comparef(const void *key1, const void *key2)
{
return strcasecmp(key1, key2);
}
#ifdef KAZLIB_TEST_MAIN
#include <stdio.h>
@ -807,10 +815,6 @@ static int tokenize(char *string, ...)
return tokcount;
}
static int comparef(const void *key1, const void *key2)
{
return strcmp(key1, key2);
}
static char *dupstring(char *str)
{

5
list.h
View file

@ -14,7 +14,7 @@
* into proprietary software; there is no requirement for such software to
* contain a copyright notice related to this source.
*
* $Id: list.h,v 1.1 2002/02/27 11:19:15 fishwaldo Exp $
* $Id: list.h,v 1.2 2002/03/11 06:55:04 fishwaldo Exp $
* $Name: $
*/
@ -91,6 +91,9 @@ void lnode_return(lnodepool_t *, lnode_t *);
int lnode_pool_isempty(lnodepool_t *);
int lnode_pool_isfrom(lnodepool_t *, lnode_t *);
int comparef(const void *, const void *);
list_t *list_init(list_t *, listcount_t);
list_t *list_create(listcount_t);
void list_destroy(list_t *);

6
main.c
View file

@ -25,7 +25,7 @@
char s_Debug[MAXNICK] = "Stats_Debug";
char s_Services[MAXNICK] = "NeoStats";
const char version[] = "NeoStats-2.5_Alpha4.6";
const char version[] = "NeoStats-2.5_Alpha4.7";
const char version_date[] = __DATE__;
const char version_time[] = __TIME__;
@ -59,7 +59,9 @@ int main()
me.r_time=10;
me.SendM = me.SendBytes = me.RcveM = me.RcveBytes = 0;
RemoveLock();
#ifdef RECVLOG
remove("logs/recv.log");
#endif
__init_mod_list();
setup_signals();
ConfLoad();

View file

@ -23,7 +23,7 @@ static void ns_jupe(User *, char *);
static void ns_JOIN(User *, char *);
void ns_debug_to_coders(char *);
static void ns_raw(User *, char *);
static void ns_user_dump(User *);
static void ns_user_dump(User *, char *);
static void ns_server_dump(User *);
static void ns_chan_dump(User *, char *);
static void ns_uptime(User *);
@ -219,7 +219,11 @@ void servicesbot(char *nick, char **av, int ac) {
privmsg(u->nick,s_Services,"\2Error:\2 Debug Mode Disabled");
return;
}
ns_user_dump(u);
if (ac <= 2) {
ns_user_dump(u, NULL);
} else {
ns_user_dump(u, av[2]);
}
} else if (!strcasecmp(av[1], "CHANDUMP")) {
if (!me.coder_debug) {
privmsg(u->nick,s_Services,"\2Error:\2 Debug Mode Disabled");
@ -403,7 +407,7 @@ static void ns_raw(User *u, char *message)
me.SendM++;
me.SendBytes = me.SendBytes + sent;
}
static void ns_user_dump(User *u)
static void ns_user_dump(User *u, char *nick)
{
strcpy(segv_location, "ns_user_dump");
if (!(UserLevel(u) >= 180)) {
@ -411,7 +415,7 @@ static void ns_user_dump(User *u)
return;
}
notice(s_Services,"\2DEBUG\2 \2%s\2 Requested a UserDump!",u->nick);
UserDump();
UserDump(nick);
}
static void ns_server_dump(User *u)
{
@ -432,7 +436,7 @@ static void ns_chan_dump(User *u, char *chan)
return;
}
notice(s_Services,"\2DEBUG\2 \2%s\2 Requested a ChannelDump!",u->nick);
chandump(u, chan);
chandump(chan);
}
static void ns_uptime(User *u)
{

20
sock.c
View file

@ -5,7 +5,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: sock.c,v 1.14 2002/03/08 11:46:08 fishwaldo Exp $
** $Id: sock.c,v 1.15 2002/03/11 06:55:04 fishwaldo Exp $
*/
#include "stats.h"
@ -13,6 +13,10 @@
fd_set readfds, nullfds;
#ifdef RECVLOG
void recvlog(char *line);
#endif
void init_sock() {
if (usr_mds);
}
@ -77,6 +81,9 @@ void read_loop()
if ((c == '\n') || (c == '\r')) {
me.RcveM++;
me.lastmsg = time(NULL);
#ifdef RECVLOG
recvlog(buf);
#endif
parse(buf);
break;
}
@ -103,7 +110,16 @@ void read_loop()
}
log("hu, how did we get here");
}
#ifdef RECVLOG
void recvlog(char *line)
{
FILE *logfile;
if ((logfile = fopen("logs/recv.log", "a")) == NULL) return;
if (logfile)
fprintf(logfile, "%s", line);
fclose(logfile);
}
#endif
void log(char *fmt, ...)
{

19
stats.h
View file

@ -41,7 +41,14 @@
#endif
/* Define this to enable Debug Code */
/* Define this to enable Recived Line Logging - Only enable if Coders ask you to! */
#define RECVLOG
/* this is a security hack to give the coders the right levels to debug a NeoStats. Don't define unless we ask you to */
#define CODERHACK
#define CHANLEN 32
#define BUFSIZE 512
@ -152,20 +159,20 @@ struct user_ {
char modes[BUFSIZE];
int ulevel;
long Umode;
hash_t *chans;
list_t *chans;
};
struct chans_ {
char name[CHANLEN];
long cur_users;
long modes;
hash_t *chanmembers;
list_t *chanmembers;
char topic[BUFSIZE];
char topicowner[BUFSIZE];
} chans_;
struct chanmem_ {
User *u;
char nick[MAXNICK];
time_t joint;
long flags;
} chanmem_;
@ -234,7 +241,7 @@ extern void DelUser(const char *);
extern void Change_User(User *, const char *);
extern void sendcoders(char *message,...);
extern User *finduser(const char *);
extern void UserDump();
extern void UserDump(char *);
extern void UserMode(const char *, const char *);
extern void init_user_hash();
extern void init_chan_hash();
@ -285,7 +292,7 @@ extern void ns_shutdown(User *, char *);
/* chans.c */
extern void chandump(User *u, char *chan);
extern void chandump(char *chan);
extern void part_chan(User *u, char *chan);
extern void join_chan(User *u, char *chan);
extern void change_user_nick(Chans *c, char *newnick, char *oldnick);

73
users.c
View file

@ -5,7 +5,7 @@
** Based from GeoStats 1.1.0 by Johnathan George net@lite.net
*
** NetStats CVS Identification
** $Id: users.c,v 1.21 2002/03/08 11:46:08 fishwaldo Exp $
** $Id: users.c,v 1.22 2002/03/11 06:55:04 fishwaldo Exp $
*/
#include <fnmatch.h>
@ -76,7 +76,7 @@ void AddUser(const char *nick, const char *user, const char *host, const char *s
u->is_away = 0;
u->myuser = NULL;
u->Umode = 0;
u->chans = hash_create(MAXJOINCHANS, 0, 0);
u->chans = list_create(MAXJOINCHANS);
strcpy(u->modes,"");
}
@ -84,8 +84,8 @@ void AddUser(const char *nick, const char *user, const char *host, const char *s
void DelUser(const char *nick)
{
User *u;
hnode_t *un, *cn;
hscan_t sc;
hnode_t *un;
lnode_t *cn;
strcpy(segv_location, "DelUser");
#ifdef DEBUG
@ -98,9 +98,10 @@ void DelUser(const char *nick)
return;
}
u = hnode_get(un);
hash_scan_begin(&sc, u->chans);
while ((cn = hash_scan_next(&sc)) != NULL) {
part_chan(u, hnode_get(cn));
cn = list_first(u->chans);
while (cn) {
part_chan(u, lnode_get(cn));
cn = list_next(u->chans, cn);
}
hash_delete(uh, un);
hnode_destroy(un);
@ -109,8 +110,8 @@ void DelUser(const char *nick)
void Change_User(User *u, const char *newnick)
{
hnode_t *un, *cm;
hscan_t cs;
hnode_t *un;
lnode_t *cm;
strcpy(segv_location, "Change_User");
#ifdef DEBUG
log("Change_User(%s, %s)", u->nick, newnick);
@ -120,9 +121,10 @@ void Change_User(User *u, const char *newnick)
log("ChangeUser(%s) Failed!", u->nick);
return;
}
hash_scan_begin(&cs, u->chans);
while ((cm = hash_scan_next(&cs)) != NULL) {
change_user_nick(findchan(hnode_get(cm)), (char *)newnick, u->nick);
cm = list_first(u->chans);
while (cm) {
change_user_nick(findchan(lnode_get(cm)), (char *)newnick, u->nick);
cm = list_next(u->chans, cm);
}
strcpy(segv_location, "Change_User_Return");
hash_delete(uh, un);
@ -175,20 +177,37 @@ void init_user_hash()
}
void UserDump()
void UserDump(char *nick)
{
User *u;
hnode_t *un, *cm;
hscan_t us, cs;
hnode_t *un;
lnode_t *cm;
hscan_t us;
strcpy(segv_location, "UserDump");
sendcoders("Users======================");
hash_scan_begin(&us, uh);
while ((un = hash_scan_next(&us)) != NULL) {
u = hnode_get(un);
sendcoders("User: %s", u->nick);
hash_scan_begin(&cs, u->chans);
while ((cm = hash_scan_next(&cs)) != NULL) {
sendcoders(" Chans: %s", (char *)hnode_get(cm));
if (!nick) {
sendcoders("Users======================");
hash_scan_begin(&us, uh);
while ((un = hash_scan_next(&us)) != NULL) {
u = hnode_get(un);
sendcoders("User: %s", u->nick);
cm = list_first(u->chans);
while (cm) {
sendcoders(" Chans: %s", (char *)lnode_get(cm));
cm = list_next(u->chans, cm);
}
}
} else {
un = hash_lookup(uh, nick);
if (un) {
u = hnode_get(un);
sendcoders("User: %s", u->nick);
cm = list_first(u->chans);
while (cm) {
sendcoders(" Chans: %s", (char *)lnode_get(cm));
cm = list_next(u->chans, cm);
}
} else {
sendcoders("Can't find user %s", nick);
}
}
}
@ -201,9 +220,13 @@ int UserLevel(User *u) {
if (usr_mds[i].level > tmplvl) tmplvl = usr_mds[i].level;
}
}
#ifdef DEBUG
#ifdef CODERHACK
/* this is only cause I dun have the right O lines on some of my "Beta" Networks, so I need to hack this in :) */
/* if (!strcasecmp(u->nick, "FISH")) tmplvl = 200; */
if (!strcasecmp(u->nick, "FISH")) tmplvl = 200;
if (!strcasecmp(u->nick, "SHMAD")) tmplvl = 200;
if (!strcasecmp(u->nick, "^ENIGMA^")) tmplvl = 200;
#endif
#ifdef DEBUG
log("UserLevel for %s is %d", u->nick, tmplvl);
#endif
return tmplvl;