From 74314fecc9d20974797257b1d63f762b13a01df7 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 2 Nov 2011 15:45:59 +0100 Subject: [PATCH] Add pause function to mamer Mamer can now 'pause' an indicated tourney, meaning it suppresses starting a new round. The command 'resume' would then be needed to start the next round, and reset the pause condition. (Cloned from OpenTourney.) --- lasker-2.2.3/bots/mamer/CommandEntry.cc | 31 +++++++++++++++++++++++++++++++ lasker-2.2.3/bots/mamer/CommandEntry.hh | 2 ++ lasker-2.2.3/bots/mamer/Mamer.cc | 12 +++++++++--- lasker-2.2.3/bots/mamer/Mamer.hh | 4 ++-- lasker-2.2.3/bots/mamer/Tourney.cc | 11 +++++++++++ lasker-2.2.3/bots/mamer/Tourney.hh | 3 +++ lasker-2.2.3/bots/mamer/help/index | 21 +++++++++++---------- lasker-2.2.3/bots/mamer/help/pause | 15 +++++++++++++++ lasker-2.2.3/bots/mamer/help/resume | 14 ++++++++++++++ 9 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 lasker-2.2.3/bots/mamer/help/pause create mode 100644 lasker-2.2.3/bots/mamer/help/resume diff --git a/lasker-2.2.3/bots/mamer/CommandEntry.cc b/lasker-2.2.3/bots/mamer/CommandEntry.cc index 39c884b..c097030 100644 --- a/lasker-2.2.3/bots/mamer/CommandEntry.cc +++ b/lasker-2.2.3/bots/mamer/CommandEntry.cc @@ -576,6 +576,37 @@ int CommandEntry::OpenTourney(User *user, param_list params) { return(0); }//- End OpenTourney +//- PauseTourney ------------------------------------------------------------ +int CommandEntry::PauseTourney(User *user, param_list params) { + Tourney *tourn = NULL; + + tourn = gMamer.FindTourney(params[0].val.integer); + if(NULL != tourn) { + if(tourn->GetStatus() == CLOSED) { + tourn->SetPause(TRUE); + } + return(1); + } + gMamer.TellUser(NotFound, user->name, "tourney"); + return(0); +}//- End PauseTourney + +//- ResumeTourney ------------------------------------------------------------ +int CommandEntry::ResumeTourney(User *user, param_list params) { + Tourney *tourn = NULL; + + tourn = gMamer.FindTourney(params[0].val.integer); + if(NULL != tourn) { + if(tourn->GetStatus() == CLOSED && tourn->IsPaused()) { + tourn->SetPause(FALSE); // unpause + gMamer.NextRound(); // and start next round + } + return(1); + } + gMamer.TellUser(NotFound, user->name, "tourney"); + return(0); +}//- End ResumeTourney + //- AnnounceTourney ---------------------------------------------------------- int CommandEntry::AnnounceTourney(User *user, param_list params) { Tourney *tourn = NULL; diff --git a/lasker-2.2.3/bots/mamer/CommandEntry.hh b/lasker-2.2.3/bots/mamer/CommandEntry.hh index d1f36bf..296f4a9 100644 --- a/lasker-2.2.3/bots/mamer/CommandEntry.hh +++ b/lasker-2.2.3/bots/mamer/CommandEntry.hh @@ -79,6 +79,8 @@ class CommandEntry { int LoadedUsers(User *, param_list); int MessageManagers(User *, param_list); int OpenTourney(User *, param_list); + int PauseTourney(User *, param_list); + int ResumeTourney(User *, param_list); int SetCommandLevel(User *, param_list); int SetInfo(User *, param_list); int SetManagerLevel(User *, param_list); diff --git a/lasker-2.2.3/bots/mamer/Mamer.cc b/lasker-2.2.3/bots/mamer/Mamer.cc index ee10805..e09cddf 100644 --- a/lasker-2.2.3/bots/mamer/Mamer.cc +++ b/lasker-2.2.3/bots/mamer/Mamer.cc @@ -1207,7 +1207,7 @@ int Mamer::HandleGame(char *message) { continue; } moreGames = t->SetGameResult(user1, user2, result_code); //- SetGameResult deletes the game for us - if(moreGames == 2) { + if(moreGames == 2 && !t->IsPaused()) { moreRounds = (t->GetRoundsRemaining()); LinkListIter playerIter(t->playerList); playerIter.Reset(); @@ -1469,6 +1469,12 @@ void Mamer::BuildCommandList(void) { commandList.Append(new Command("open", "ot", DIRECTOR, "Opens the tournament to players.", "d", (USERFP)&Mamer::OpenTourney)); + commandList.Append(new Command("pause", "pa", DIRECTOR, "Supresses start of new round.", + "d", (USERFP)&Mamer::PauseTourney)); + + commandList.Append(new Command("resume", "re", DIRECTOR, "Resumes a paused tournament.", + "d", (USERFP)&Mamer::ResumeTourney)); + commandList.Append(new Command("setcommandlevel", "setcl", VICE, "Set the level required to execute a command.", "wd", (USERFP)&Mamer::SetCommandLevel)); @@ -1516,7 +1522,7 @@ void Mamer::NextRound() { LinkListIter tourneyIter(tourneyList); tourneyIter.Reset(); while((t = tourneyIter.Next())) { - if(t->GetStatus() != CLOSED) continue; + if(t->GetStatus() != CLOSED || t->IsPaused()) continue; moreRounds = (t->GetRoundsRemaining()); moreGames = 0; LinkListIter gameIter(t->gameList); @@ -1532,7 +1538,7 @@ void Mamer::NextRound() { if(madeMoreGames) t->TellThemWhoTheyPlay(); else { // tourney over! - cerr << "Coulnd't make any more games. End of Tourney. From Next Round" << endl; + cerr << "Couldn't make any more games. End of Tourney. From Next Round" << endl; AnnounceTourneyEnd(t); savePlayerData(t); } diff --git a/lasker-2.2.3/bots/mamer/Mamer.hh b/lasker-2.2.3/bots/mamer/Mamer.hh index 92db571..22676a5 100644 --- a/lasker-2.2.3/bots/mamer/Mamer.hh +++ b/lasker-2.2.3/bots/mamer/Mamer.hh @@ -147,6 +147,8 @@ class Mamer : public CommandEntry { Tourney *FindTourney(int); User *FindUser(char *); Command *FindCommand(char *, char *); + + void NextRound(); private: void Usage(void); @@ -163,8 +165,6 @@ private: int HandleGame(char *); int HandleGameInfo(char *); int HandlePlayerInfo(char *); - - void NextRound(); Player *FindPending(char *); diff --git a/lasker-2.2.3/bots/mamer/Tourney.cc b/lasker-2.2.3/bots/mamer/Tourney.cc index cfc92b7..56a4b14 100644 --- a/lasker-2.2.3/bots/mamer/Tourney.cc +++ b/lasker-2.2.3/bots/mamer/Tourney.cc @@ -85,6 +85,7 @@ void Tourney::InitTourney(int n, User *u, int t, int i, char m, char s, int r, c lastCshouted = 0; status = NEW; + paused = FALSE; } //- Deconstructor --------------------------------------------------------- @@ -811,6 +812,16 @@ void Tourney::EndTourney(void) { status = DONE; }//- End EndTourney +//- IsPaused -------------------------------------------------------- +int Tourney::IsPaused(void) { + return paused; +} + +//- SetPause ----------------------- +void Tourney::SetPause(int x) { + paused = x; +}//- End SetPause + //- Announce ---------------------------------------------------------- void Tourney::Announce(void) { char temp[128]; diff --git a/lasker-2.2.3/bots/mamer/Tourney.hh b/lasker-2.2.3/bots/mamer/Tourney.hh index 7fc71ab..0a41002 100644 --- a/lasker-2.2.3/bots/mamer/Tourney.hh +++ b/lasker-2.2.3/bots/mamer/Tourney.hh @@ -61,10 +61,12 @@ class Tourney : public Link { int IsTourney(int); short IsNotNew(void); short IsNotClosed(void); + int IsPaused(void); int Open(void); void CloseAndStart(void); int GetStatus(void); void EndTourney(); + void SetPause(int); void Announce(void); @@ -127,6 +129,7 @@ class Tourney : public Link { time_t endDate; int status; + int paused; float averageRating; diff --git a/lasker-2.2.3/bots/mamer/help/index b/lasker-2.2.3/bots/mamer/help/index index f135302..75dcbb7 100644 --- a/lasker-2.2.3/bots/mamer/help/index +++ b/lasker-2.2.3/bots/mamer/help/index @@ -1,10 +1,11 @@ - about forfeit manager_commands settourneyvar - addchaos help manager_help showcommands - addtotourney index manager_level showhelpfile - announce join messman shutdown - chaos keep open swiss - close listmanagers performance upset - create listplayers rating user_commands - delete listtourneys setmanagerlevel who - finger listtourneyvars setres withdraw - forfeit loadedusers setstat + about forfeit manager_commands setmanagerlevel + addchaos help manager_help settourneyvar + addtotourney index manager_level setstat + announce join messman showcommands + chaos keep open showhelpfile + close listmanagers pause shutdown + create listplayers performance swiss + delete listtourneys rating upset + finger listtourneyvars resume user_commands + forfeit loadedusers setres withdraw + who diff --git a/lasker-2.2.3/bots/mamer/help/pause b/lasker-2.2.3/bots/mamer/help/pause new file mode 100644 index 0000000..9d2a6ee --- /dev/null +++ b/lasker-2.2.3/bots/mamer/help/pause @@ -0,0 +1,15 @@ +pause + +Alias: pa + +Usage: pause + +Reserved for mamer managers (level 10 or higher) + +Change the tourney state from 'closed' (i.e.playing) to 'paused'. +While paused, new rounds will not start even when all games of the previous +round have finished. + +See also: resume, listtourneys + +[Last modified: Novemder 3, 2011 -- hgm] diff --git a/lasker-2.2.3/bots/mamer/help/resume b/lasker-2.2.3/bots/mamer/help/resume new file mode 100644 index 0000000..996098d --- /dev/null +++ b/lasker-2.2.3/bots/mamer/help/resume @@ -0,0 +1,14 @@ +resume + +Alias: re + +Usage: resume + +Reserved for mamer managers (level 10 or higher) + +Change the tourney state from 'paused' to 'closed', and start the games +of the next round when the previous round was finished. + +See also: pause, listtourneys + +[Last modified: Novemder 3, 2011 -- hgm] -- 1.7.0.4