[NeoStats-Devel] [Commits] r67 - branches/3.0

[email protected]
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: DNB
Date: Thu Mar 31 10:35:36 2005
New Revision: 67

Modified:
   branches/3.0/ChangeLog
   branches/3.0/TriviaChan.c
   branches/3.0/TriviaCmds.c
   branches/3.0/TriviaServ.c
   branches/3.0/TriviaServ.h
   branches/3.0/TriviaServ_help.c
   branches/3.0/TriviaUser.c
Log:
add option to reset channel scores automatically at set periods
Change Main and Alt Nickname to keep in line with other pseudo clients


Modified: branches/3.0/ChangeLog
==============================================================================
--- branches/3.0/ChangeLog	(original)
+++ branches/3.0/ChangeLog	Thu Mar 31 10:35:36 2005
@@ -2,6 +2,8 @@
 Fish (F), Mark (M), DeadNotBuried (D)
 ==============================================================================
 3.0.a3-dev
+ - Change Main and Alt Nickname (D)
+ - add option to reset channel scores automatically at set periods (D)
  - add score tracking per channel (not saving yet though) (D)
  - add OPCHAN command for channel ops to set if Trivia gets Channel Op
    status on joining or not (D)

Modified: branches/3.0/TriviaChan.c
==============================================================================
--- branches/3.0/TriviaChan.c	(original)
+++ branches/3.0/TriviaChan.c	Thu Mar 31 10:35:36 2005
@@ -68,6 +68,8 @@
 	tc->scorepoints = TriviaServ.defaultpoints;
 	tc->questtime = 60;
 	tc->opchan = 1;
+	tc->resettype = 0;
+	tc->lastreset = me.now;
 	SetChannelModValue (c, tc);
 	tc->qfl = list_create(-1);
 	hnode_create_insert (tch, tc, tc->name);

Modified: branches/3.0/TriviaCmds.c
==============================================================================
--- branches/3.0/TriviaCmds.c	(original)
+++ branches/3.0/TriviaCmds.c	Thu Mar 31 10:35:36 2005
@@ -274,6 +274,59 @@
 }
 
 /*
+ * Allows Chanops to configure Automatic Score Resetting
+*/
+int tvs_cmd_resetscores (CmdParams* cmdparams) {
+	TriviaChan *tc;
+
+	/* check command was from a channel. */
+	if (!cmdparams->channel) {
+		irc_prefmsg (tvs_bot, cmdparams->source, "RESETSCORES Command is used in Channel Only");
+		return NS_FAILURE;
+	}
+	/* find if its our channel. */
+	tc = (TriviaChan *)GetChannelModValue (cmdparams->channel);
+	if (!tc) {
+		return NS_FAILURE;
+	}
+	/* finally, these ones are restricted always */
+	if (!IsChanOp(cmdparams->channel->name, cmdparams->source->name)) {
+		/* nope, get lost */
+		return NS_FAILURE;
+	}
+	if ( atoi(cmdparams->av[0]) < 0 || atoi(cmdparams->av[0]) > 6) {
+		irc_prefmsg (tvs_bot, cmdparams->source, "RESETSCORES Value out of range (0 to 6 allowed only).");
+		return NS_FAILURE;
+	}
+	tc->resettype = atoi(cmdparams->av[0]);
+	SaveTChan(tc);
+	switch (tc->resettype) {
+		case 0:
+			irc_chanprivmsg (tvs_bot, cmdparams->channel->name, "Channel Trivia Scores will no longer reset automatically.");
+			break;
+		case 1:
+			irc_chanprivmsg (tvs_bot, cmdparams->channel->name, "Channel Trivia Scores will now be reset Daily.");
+			break;
+		case 2:
+			irc_chanprivmsg (tvs_bot, cmdparams->channel->name, "Channel Trivia Scores will now be reset Weekly.");
+			break;
+		case 3:
+			irc_chanprivmsg (tvs_bot, cmdparams->channel->name, "Channel Trivia Scores will now be reset Monthly.");
+			break;
+		case 4:
+			irc_chanprivmsg (tvs_bot, cmdparams->channel->name, "Channel Trivia Scores will now be reset Quarterly.");
+			break;
+		case 5:
+			irc_chanprivmsg (tvs_bot, cmdparams->channel->name, "Channel Trivia Scores will now be reset Bi-Anually.");
+			break;
+		case 6:
+			irc_chanprivmsg (tvs_bot, cmdparams->channel->name, "Channel Trivia Scores will now be reset Anually.");
+			break;
+	}
+	return NS_SUCCESS;
+}
+
+/*
  * Lists all Question Sets / Categories available on the network
 */
 int tvs_catlist(CmdParams* cmdparams) {
@@ -351,7 +404,8 @@
 		while ((hnode = hash_scan_next(&hs)) != NULL) {
 			tc = hnode_get(hnode);
 			i++;
-			irc_prefmsg (tvs_bot, cmdparams->source, "\2%d\2) %s (%s) - Public? %s - OpChan? %s - Points %d", i, tc->name, (TriviaChan *)GetChannelModValue (tc->c) ? "Open" : "Closed", tc->publiccontrol ? "Yes" : "No", tc->opchan ? "Yes" : "No", tc->scorepoints);
+			irc_prefmsg (tvs_bot, cmdparams->source, "\2%d\2) %s (%s) - Public? %s - OpChan? %s - Reset? %s - Points %d", i, tc->name, (TriviaChan *)GetChannelModValue (tc->c) ? "Open" : "Closed", tc->publiccontrol ? "Yes" : "No", tc->opchan ? "Yes" : "No",
+				(tc->resettype == 0) ? "None" : (tc->resettype == 1) ? "Daily" : (tc->resettype == 2) ? "Weekly" : (tc->resettype == 3) ? "Monthly" : (tc->resettype == 4) ? "Quarterly" : (tc->resettype == 5) ? "Bi-Anually" : "Anually", tc->scorepoints);
 		}
 		irc_prefmsg (tvs_bot, cmdparams->source, "End of list.");
 	} else {

Modified: branches/3.0/TriviaServ.c
==============================================================================
--- branches/3.0/TriviaServ.c	(original)
+++ branches/3.0/TriviaServ.c	Thu Mar 31 10:35:36 2005
@@ -50,6 +50,10 @@
 
 int tvs_get_settings();
 int tvs_processtimer (void);
+int tvs_dailytimer (void);
+int tvs_weeklytimer (void);
+int tvs_monthlytimer (void);
+int tvs_clearscoretimers (int ct);
 
 Bot *tvs_bot;
 
@@ -76,24 +80,25 @@
 
 static bot_cmd tvs_commands[]=
 {
-	{"CHANS",	tvs_chans,	1,	NS_ULEVEL_OPER, tvs_help_chans,		tvs_help_chans_oneline },
-	{"CATLIST",	tvs_catlist,	0, 	0,		tvs_help_catlist,	tvs_help_catlist_oneline },
-	{"SCORE",	tvs_cmd_score,	0, 	0,		NULL,			NULL},
-	{"HINT",	tvs_cmd_hint,	0, 	0,		NULL,			NULL},
-	{"START",	tvs_cmd_start,	0, 	0,		tvs_help_start,		tvs_help_start_oneline},
-	{"STOP",	tvs_cmd_stop,	0, 	0,		tvs_help_stop,		tvs_help_stop_oneline},
-	{"QS",		tvs_cmd_qs,	1, 	0,		tvs_help_qs,		tvs_help_qs_oneline},
-	{"SETPOINTS",	tvs_cmd_sp,	1, 	0,		tvs_help_sp,		tvs_help_sp_oneline},
-	{"PUBLIC",	tvs_cmd_pc,	1, 	0,		tvs_help_pc,		tvs_help_pc_oneline},
-	{"OPCHAN",	tvs_cmd_opchan,	1, 	0,		tvs_help_opchan,	tvs_help_opchan_oneline},
-	{NULL,		NULL,		0, 	0,		NULL, 			NULL}
+	{"CHANS",	tvs_chans,		1,	NS_ULEVEL_OPER, tvs_help_chans,		tvs_help_chans_oneline },
+	{"CATLIST",	tvs_catlist,		0, 	0,		tvs_help_catlist,	tvs_help_catlist_oneline },
+	{"SCORE",	tvs_cmd_score,		0, 	0,		NULL,			NULL},
+	{"HINT",	tvs_cmd_hint,		0, 	0,		NULL,			NULL},
+	{"START",	tvs_cmd_start,		0, 	0,		tvs_help_start,		tvs_help_start_oneline},
+	{"STOP",	tvs_cmd_stop,		0, 	0,		tvs_help_stop,		tvs_help_stop_oneline},
+	{"QS",		tvs_cmd_qs,		1, 	0,		tvs_help_qs,		tvs_help_qs_oneline},
+	{"SETPOINTS",	tvs_cmd_sp,		1, 	0,		tvs_help_sp,		tvs_help_sp_oneline},
+	{"PUBLIC",	tvs_cmd_pc,		1, 	0,		tvs_help_pc,		tvs_help_pc_oneline},
+	{"OPCHAN",	tvs_cmd_opchan,		1, 	0,		tvs_help_opchan,	tvs_help_opchan_oneline},
+	{"RESETSCORES",	tvs_cmd_resetscores,	1, 	0,		tvs_help_resetscores,	tvs_help_resetscores_oneline},
+	{NULL,		NULL,			0, 	0,		NULL, 			NULL}
 };
 
 static bot_setting tvs_settings[]=
 {
-	{"EXCLUSIONS", 	&TriviaServ.use_exc,		SET_TYPE_BOOLEAN,	0,	0, 		NS_ULEVEL_ADMIN,	NULL,	tvs_help_set_exclusions,	NULL,	NULL},
+	{"EXCLUSIONS", 		&TriviaServ.use_exc,		SET_TYPE_BOOLEAN,	0,	0, 		NS_ULEVEL_ADMIN,	NULL,	tvs_help_set_exclusions,	NULL,	NULL},
 	{"DEFAULTPOINTS", 	&TriviaServ.defaultpoints,	SET_TYPE_INT,		1,	25, 		NS_ULEVEL_ADMIN,	NULL,	tvs_help_set_defaultpoints,	NULL,	(void *)1 },
-	{NULL,			NULL,				0,			0,	0,		0,			NULL,			NULL,				NULL,	NULL},
+	{NULL,			NULL,				0,			0,	0,		0,			NULL,	NULL,				NULL,	NULL},
 };
 
 /*
@@ -122,8 +127,8 @@
 /** BotInfo */
 static BotInfo tvs_botinfo = 
 {
-	"Trivia", 
-	"Trivia1", 
+	"TriviaServ", 
+	"TriviaServ1", 
 	"TS", 
 	BOT_COMMON_HOST, 
 	"Trivia Bot", 	
@@ -163,6 +168,10 @@
 	}
 	/* kick of the question/answer timer */
 	AddTimer (TIMER_TYPE_INTERVAL, tvs_processtimer, "tvs_processtimer", 10);
+	/* kick of the reset scores timers */
+	AddTimer (TIMER_TYPE_DAILY, tvs_dailytimer, "tvs_dailytimer", 0);
+	AddTimer (TIMER_TYPE_WEEKLY, tvs_weeklytimer, "tvs_weeklytimer", 0);
+	AddTimer (TIMER_TYPE_MONTHLY, tvs_monthlytimer, "tvs_monthlytimer", 0);
 	return NS_SUCCESS;
 }
 
@@ -416,3 +425,63 @@
 	}
 	return NS_SUCCESS;
 }
+
+/*
+ * Process Timers to clear channel scores
+*/
+int tvs_dailytimer(void) {
+	return tvs_clearscoretimers(1);
+}
+
+int tvs_weeklytimer(void) {
+	return tvs_clearscoretimers(2);
+}
+
+int tvs_monthlytimer(void) {
+	int i;
+
+	for (i = 4 ; i < 7 ; i++) {
+		tvs_clearscoretimers(i);
+	}
+	return tvs_clearscoretimers(3);
+}
+
+int tvs_clearscoretimers(int ct) {
+	TriviaChan *tc;
+	hscan_t hs;
+	hnode_t *hnodes;
+	time_t timediff;	
+
+	hash_scan_begin(&hs, tch);
+	while ((hnodes = hash_scan_next(&hs)) != NULL) {
+		tc = hnode_get(hnodes);
+		if (tc != NULL) {
+			/* for each channel check if to be cleared */
+			if (tc->resettype = ct) {
+				switch (ct) {
+					case 1:
+					case 2:
+					case 3:
+						tc->lastreset = me.now;
+						break;
+					case 4:
+						if (tc->lastreset < (me.now - (86 * 86400))) {
+							tc->lastreset = me.now;
+						}
+						break;
+					case 5:
+						if (tc->lastreset < (me.now - (177 * 86400))) {
+							tc->lastreset = me.now;
+						}
+						break;
+					case 6:
+						if (tc->lastreset < (me.now - (363 * 86400))) {
+							tc->lastreset = me.now;
+						}
+						break;
+				}
+			}
+		}
+	}
+	return NS_SUCCESS;
+}

Modified: branches/3.0/TriviaServ.h
==============================================================================
--- branches/3.0/TriviaServ.h	(original)
+++ branches/3.0/TriviaServ.h	Thu Mar 31 10:35:36 2005
@@ -75,6 +75,8 @@
 	time_t lastquest;
 	long questtime;
 	int opchan;
+	int resettype;
+	int lastreset;
 	Questions *curquest;
 	list_t *qfl;
 } TriviaChan;
@@ -120,6 +122,8 @@
 extern const char tvs_help_pc_oneline[];
 extern const char *tvs_help_opchan[];
 extern const char tvs_help_opchan_oneline[];
+extern const char *tvs_help_resetscores[];
+extern const char tvs_help_resetscores_oneline[];
 
 /* TriviaUser.c */
 void tvs_addpoints(Client *u, TriviaChan *tc);
@@ -136,6 +140,7 @@
 int tvs_cmd_sp (CmdParams* cmdparams);
 int tvs_cmd_pc (CmdParams* cmdparams);
 int tvs_cmd_opchan (CmdParams* cmdparams);
+int tvs_cmd_resetscores (CmdParams* cmdparams);
 int tvs_catlist(CmdParams* cmdparams);
 int tvs_chans(CmdParams* cmdparams);
 

Modified: branches/3.0/TriviaServ_help.c
==============================================================================
--- branches/3.0/TriviaServ_help.c	(original)
+++ branches/3.0/TriviaServ_help.c	Thu Mar 31 10:35:36 2005
@@ -129,3 +129,22 @@
 	NULL
 };
 const char tvs_help_opchan_oneline[] = "Set CHANOP level";
+
+const char *tvs_help_resetscores[] = {
+	"Syntax: (in Channel only)",
+	"        \2!RESETSCORES <#>\2",
+	"",
+	"This command Sets the period that the channel scores",
+	"will be automatically reset to 0.",
+	"",
+	"Valid options are :",
+	"0 -> Never Reset Scores",
+	"1 -> Reset Scores Daily",
+	"2 -> Reset Scores Weekly",
+	"3 -> Reset Scores Monthly",
+	"4 -> Reset Scores Quarterly",
+	"5 -> Reset Scores Bi-Anually",
+	"6 -> Reset Scores Anually",
+	NULL
+};
+const char tvs_help_resetscores_oneline[] = "Set time duration to reset Channel scores";

Modified: branches/3.0/TriviaUser.c
==============================================================================
--- branches/3.0/TriviaUser.c	(original)
+++ branches/3.0/TriviaUser.c	Thu Mar 31 10:35:36 2005
@@ -88,6 +88,9 @@
 	tu->networkscore += TriviaServ.defaultpoints;
 	tu->lastused = me.now;
 	qe = tc->curquest;
+	if (ts->lastused < tc->lastreset) {
+		ts->score = 0;
+	}
 	ts->score += qe->points;
 	ts->lastused = me.now;
 	irc_chanprivmsg (tvs_bot, tc->name, "%s now has %d Points in %s, and %d points network wide", u->name, ts->score, tc->c->name, tu->networkscore);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.