Author: DNB
Date: Thu Mar 31 10:33:10 2005
New Revision: 21
Modified:
Trunk/bomb.c
Trunk/common.c
Trunk/gamesserv.h
Trunk/hilo.c
Trunk/russian.c
Log:
code tidyups
Modified: Trunk/bomb.c
==============================================================================
--- Trunk/bomb.c (original)
+++ Trunk/bomb.c Thu Mar 31 10:33:10 2005
@@ -27,32 +27,11 @@
* Start Bomb Game
*/
int startbomb(CmdParams* cmdparams) {
- Channel *c;
-
- if (gamestatus[GS_GAME_BOMB] == GS_GAME_STOPPED) {
- c = FindChannel(cmdparams->av[0]);
- if (!c) {
- irc_prefmsg (gs_bot, cmdparams->source, "You must be in the Channel you wish to start the game in.");
- } else {
- if (IsChannelMember(c, cmdparams->source)) {
- if ( kickgameschanoponly && !IsChanOp(c->name, cmdparams->source->name) ) {
- irc_prefmsg (gs_bot, cmdparams->source, "You must be a Channel Operator to start the game.");
- } else {
- countdowntime[GS_GAME_BOMB] = 60;
- strlcpy (gameroom[GS_GAME_BOMB], cmdparams->av[0], MAXCHANLEN);
- strlcpy (gameplayernick[GS_GAME_BOMB], cmdparams->source->name, MAXNICK);
- gamestatus[GS_GAME_BOMB] = GS_GAME_PLAYING;
- irc_join (gs_bot, gameroom[GS_GAME_BOMB], "+o");
- irc_chanprivmsg (gs_bot, gameroom[GS_GAME_BOMB], "\0037A Bomb has been brought into the channel by %s. Don''t be the last one with it.", cmdparams->source->name);
- AddTimer (TIMER_TYPE_COUNTDOWN, timerupstopbomb, "bombcountdown", countdowntime[GS_GAME_BOMB]);
- }
- } else {
- irc_prefmsg (gs_bot, cmdparams->source, "You must be in the Channel you wish to start the game in.");
- }
- }
- } else {
- irc_prefmsg (gs_bot, cmdparams->source, "The Game is already active in %s , Try Again Later.", gameroom[GS_GAME_BOMB]);
+ if (CheckGameStart(cmdparams->source, cmdparams->av[0], GS_GAME_BOMB, 60, GS_GAME_KICK, GS_GAME_CHANNEL_JOIN) != NS_SUCCESS) {
+ return NS_SUCCESS;
}
+ irc_chanprivmsg (gs_bot, gameroom[GS_GAME_BOMB], "\0037A Bomb has been brought into the channel by %s. Don''t be the last one with it.", cmdparams->source->name);
+ AddTimer (TIMER_TYPE_COUNTDOWN, timerupstopbomb, "bombcountdown", countdowntime[GS_GAME_BOMB]);
return NS_SUCCESS;
}
@@ -117,11 +96,7 @@
}
}
irc_kick(gs_bot, gameroom[GS_GAME_BOMB], gameplayernick[GS_GAME_BOMB], "\0034BOOOOOM !!!!!!");
- irc_chanprivmsg (gs_bot, gameroom[GS_GAME_BOMB], "\0037GAME OVER");
CheckPartGameChannel(GS_GAME_BOMB);
- gameroom[GS_GAME_BOMB][0] = '\0';
- gameplayernick[GS_GAME_BOMB][0] = '\0';
- gamestatus[GS_GAME_BOMB] = GS_GAME_STOPPED;
}
/*
Modified: Trunk/common.c
==============================================================================
--- Trunk/common.c (original)
+++ Trunk/common.c Thu Mar 31 10:33:10 2005
@@ -44,12 +44,62 @@
void CheckPartGameChannel(int gr) {
int i;
- for (i = 0 ; i < GS_GAME_TOTAL ; i++)
+ irc_chanprivmsg (gs_bot, gameroom[gr], "\0037GAME OVER");
+ for (i = 0 ; i < GS_GAME_TOTAL ; i++) {
if (!ircstrcasecmp (gameroom[i], gameroom[gr]) && i != gr) {
i = -1;
break;
}
+ }
if (i != -1) {
irc_part (gs_bot, gameroom[gr], NULL);
}
+ gameroom[gr][0] = '\0';
+ gameplayernick[gr][0] = '\0';
+ gamestatus[gr] = GS_GAME_STOPPED;
+ return;
+}
+
+/*
+ * Check Game not already running,
+ * and channel allowed for game,
+ * and join channel if needed.
+*/
+int CheckGameStart(Client *u, char *cn, int gn, int ct, int kg, int cj) {
+ Channel *c;
+ int i;
+
+ if (gamestatus[gn] != GS_GAME_STOPPED) {
+ irc_prefmsg (gs_bot, u, "The Game is already active in %s , Try Again Later.", gameroom[gn]);
+ return NS_FAILURE;
+ }
+ c = FindChannel(cn);
+ if (!c) {
+ irc_prefmsg (gs_bot, u, "You must be in the Channel you wish to start the game in.");
+ return NS_FAILURE;
+ }
+ if (!IsChannelMember(c, u)) {
+ irc_prefmsg (gs_bot, u, "You must be in the Channel you wish to start the game in.");
+ return NS_FAILURE;
+ }
+ if (kickgameschanoponly && kg == GS_GAME_KICK && !IsChanOp(c->name, u->name)) {
+ irc_prefmsg (gs_bot, u, "You must be a Channel Operator to start the game.");
+ return NS_FAILURE;
+ }
+ if (cj == GS_GAME_CHANNEL_JOIN) {
+ for (i = 0 ; i < GS_GAME_TOTAL ; i++) {
+ if (!ircstrcasecmp (gameroom[i], gameroom[gn]) && i != gn) {
+ i = -1;
+ break;
+ }
+ }
+ if (i != -1) {
+ irc_join (gs_bot, gameroom[gn], "+o");
+ }
+ }
+ countdowntime[gn] = ct;
+ strlcpy (gameroom[gn], cn, MAXCHANLEN);
+ strlcpy (gameplayernick[gn], u->name, MAXNICK);
+ gamestatus[gn] = GS_GAME_PLAYING;
+ return NS_SUCCESS;
}
Modified: Trunk/gamesserv.h
==============================================================================
--- Trunk/gamesserv.h (original)
+++ Trunk/gamesserv.h Thu Mar 31 10:33:10 2005
@@ -84,6 +84,11 @@
#define GS_GAME_PLAYING 0x00000003 /* Game Running */
#define GS_GAME_STOPPING 0x00000004 /* Game Stopping */
+#define GS_GAME_CHANNEL_NOJOIN 0x00000000 /* Don't Join Game Channel */
+#define GS_GAME_CHANNEL_JOIN 0x00000001 /* Join Game Channel */
+#define GS_GAME_NOKICK 0x00000000 /* No Kicks From Channels */
+#define GS_GAME_KICK 0x00000001 /* Loser Kicked From Game Channel */
+
/*
* Game Variables
*/
@@ -107,3 +112,4 @@
*/
int PlayerNickChange (CmdParams* cmdparams);
void CheckPartGameChannel(int gr);
+int CheckGameStart(Client *u, char *cn, int gn, int ct, int kg, int cj);
Modified: Trunk/hilo.c
==============================================================================
--- Trunk/hilo.c (original)
+++ Trunk/hilo.c Thu Mar 31 10:33:10 2005
@@ -30,31 +30,14 @@
* Start HiLo Game
*/
int starthilo(CmdParams* cmdparams) {
- Channel *c;
-
- if (gamestatus[GS_GAME_HILO] == GS_GAME_STOPPED) {
- c = FindChannel(cmdparams->av[0]);
- if (!c) {
- irc_prefmsg (gs_bot, cmdparams->source, "You must be in the Channel you wish to start the game in.");
- } else {
- if (IsChannelMember(c, cmdparams->source)) {
- num_low = (rand() % 999000);
- num = (num_low + (rand() % 999) + 1);
- num_high = (num_low + 1000);
- countdowntime[GS_GAME_HILO] = 120;
- strlcpy (gameroom[GS_GAME_HILO], cmdparams->av[0], MAXCHANLEN);
- strlcpy (gameplayernick[GS_GAME_HILO], cmdparams->source->name, MAXNICK);
- gamestatus[GS_GAME_HILO] = GS_GAME_PLAYING;
- irc_join (gs_bot, gameroom[GS_GAME_HILO], "+o");
- irc_chanprivmsg (gs_bot, gameroom[GS_GAME_HILO], "\0037A game of HiLo has been started by %s. Can you guess the number between %d and %d.", cmdparams->source->name, num_low, num_high);
- AddTimer (TIMER_TYPE_COUNTDOWN, timerupstophilo, "hilocountdown", countdowntime[GS_GAME_HILO]);
- } else {
- irc_prefmsg (gs_bot, cmdparams->source, "You must be in the Channel you wish to start the game in.");
- }
- }
- } else {
- irc_prefmsg (gs_bot, cmdparams->source, "The Game is already active in %s , Try Again Later.", gameroom[GS_GAME_HILO]);
+ if (CheckGameStart(cmdparams->source, cmdparams->av[0], GS_GAME_HILO, 120, GS_GAME_NOKICK, GS_GAME_CHANNEL_JOIN) != NS_SUCCESS) {
+ return NS_SUCCESS;
}
+ num_low = (rand() % 999000);
+ num = (num_low + (rand() % 999) + 1);
+ num_high = (num_low + 1000);
+ irc_chanprivmsg (gs_bot, gameroom[GS_GAME_HILO], "\0037A game of HiLo has been started by %s. Can you guess the number between %d and %d.", cmdparams->source->name, num_low, num_high);
+ AddTimer (TIMER_TYPE_COUNTDOWN, timerupstophilo, "hilocountdown", countdowntime[GS_GAME_HILO]);
return NS_SUCCESS;
}
@@ -94,10 +77,7 @@
irc_chanprivmsg (gs_bot, gameroom[GS_GAME_HILO], "\0037%s is correct with %d and wins, the rest of you are just Losers :)", nic, hlg);
DelTimer ("hilocountdown");
}
- irc_chanprivmsg (gs_bot, gameroom[GS_GAME_HILO], "\0037GAME OVER");
CheckPartGameChannel(GS_GAME_HILO);
- gameroom[GS_GAME_HILO][0] = '\0';
- gamestatus[GS_GAME_HILO] = GS_GAME_STOPPED;
}
/*
Modified: Trunk/russian.c
==============================================================================
--- Trunk/russian.c (original)
+++ Trunk/russian.c Thu Mar 31 10:33:10 2005
@@ -27,32 +27,11 @@
* Start Russian Roulette Game
*/
int startruss(CmdParams* cmdparams) {
- Channel *c;
-
- if ( gamestatus[GS_GAME_RUSS] == GS_GAME_STOPPED ) {
- c = FindChannel(cmdparams->av[0]);
- if (!c) {
- irc_prefmsg (gs_bot, cmdparams->source, "You must be in the Channel you wish to start the game in.");
- } else {
- if (IsChannelMember(c, cmdparams->source)) {
- if ( kickgameschanoponly && !IsChanOp(c->name, cmdparams->source->name) ) {
- irc_prefmsg (gs_bot, cmdparams->source, "You must be a Channel Operator to start the game.");
- } else {
- countdowntime[GS_GAME_RUSS] = 60;
- strlcpy (gameroom[GS_GAME_RUSS], cmdparams->av[0], MAXCHANLEN);
- strlcpy (gameplayernick[GS_GAME_RUSS], cmdparams->source->name, MAXNICK);
- gamestatus[GS_GAME_RUSS] = GS_GAME_PLAYING;
- irc_join (gs_bot, gameroom[GS_GAME_RUSS], "+o");
- irc_chanprivmsg (gs_bot, gameroom[GS_GAME_RUSS], "\0037Russian Roulette has been started by %s. Who will die this time?", cmdparams->source->name);
- AddTimer (TIMER_TYPE_COUNTDOWN, timerupstopruss, "russcountdown", countdowntime[GS_GAME_RUSS]);
- }
- } else {
- irc_prefmsg (gs_bot, cmdparams->source, "You must be in the Channel you wish to start the game in.");
- }
- }
- } else {
- irc_prefmsg (gs_bot, cmdparams->source, "The Game is already active in %s , Try Again Later.", gameroom[GS_GAME_RUSS]);
+ if (CheckGameStart(cmdparams->source, cmdparams->av[0], GS_GAME_RUSS, 60, GS_GAME_KICK, GS_GAME_CHANNEL_JOIN) != NS_SUCCESS) {
+ return NS_SUCCESS;
}
+ irc_chanprivmsg (gs_bot, gameroom[GS_GAME_RUSS], "\0037Russian Roulette has been started by %s. Who will die this time?", cmdparams->source->name);
+ AddTimer (TIMER_TYPE_COUNTDOWN, timerupstopruss, "russcountdown", countdowntime[GS_GAME_RUSS]);
return NS_SUCCESS;
}
@@ -132,11 +111,7 @@
}
}
irc_kick(gs_bot, gameroom[GS_GAME_RUSS], gameplayernick[GS_GAME_RUSS], russdiereason);
- irc_chanprivmsg (gs_bot, gameroom[GS_GAME_RUSS], "\0037GAME OVER");
CheckPartGameChannel(GS_GAME_RUSS);
- gameroom[GS_GAME_RUSS][0] = '\0';
- gameplayernick[GS_GAME_RUSS][0] = '\0';
- gamestatus[GS_GAME_RUSS] = GS_GAME_STOPPED;
}
/*
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.