1 //--------------------------------------------------------------------------
2 // CommandEntry.cc - Source file for the CommandEntry
4 // Matthew E. Moses & Michael A. Long
7 // $Date: 1998/09/10 19:57:17 $
12 // $Log: CommandEntry.cc,v $
13 // Revision 1.13 1998/09/10 19:57:17 mlong
14 // lots of little bug fixes and a few new features
16 // Revision 1.12 1998/06/18 18:41:30 mlong
17 // prepairing for yet another move.
19 // Revision 1.11 1998/06/08 20:41:17 mlong
20 // changes to the list tournies function
22 // Revision 1.10 1998/04/29 15:23:19 mlong
23 // prepairing for the move to daimi
24 // new sorting routine.
26 // Revision 1.9 1998/04/18 18:46:04 mlong
28 // added delete tourney function
30 // Revision 1.5 1997/10/08 21:03:35 chess
31 // preparing for move to oracle machine at eworks.
33 // Revision 1.4 1997/05/15 18:27:53 chess
34 // added Player and TourneyPlayers support
35 // added HandleGetPlayerInfo & HandleGetGameInfo
37 // Revision 1.3 1997/04/13 03:14:35 chess
38 // commands to do user statistic manipulationn added:
39 // setinfo - sets a whole line of information
40 // setstat - sets a particular stat
41 // addabuse - adds (or deletes) abuse points.
43 // Revision 1.2 1997/03/21 15:32:36 moses
44 // added the shutdown command.
46 // Revision 1.1 1996/10/01 20:14:43 moses
49 //--------------------------------------------------------------------------
51 // static char RCSid[] = "$Id: CommandEntry.cc,v 1.13 1998/09/10 19:57:17 mlong Exp $";
53 #include "CommandEntry.hh"
58 //- AddAbuse -------------------------------------------------------
59 int CommandEntry::AddAbuse(User *user, param_list params) {
61 char name[MAX_WORD_SIZE];
64 if(params[0].type == TYPE_WORD) {
65 strcpy(name, params[0].val.word);
68 u = gMamer.FindUser(name);
71 u->LoadPlayer(gMamer.userFilePath, name); // Loads the player info into memory and saves current info to disk
75 if((u->GetManagerLevel() >= user->GetManagerLevel()) &&
76 (user->GetManagerLevel() != PRESIDENT)) {
77 if(needToDelete) delete u;
78 gMamer.TellUser(NoPermissions, user->name);
83 if(params[1].type == TYPE_INT) {
84 u->AddAbuse(params[1].val.integer);
88 u->SavePlayer(gMamer.userFilePath);
89 if(u->GetAbuse() >= MAX_CHAOS_POINTS)
90 gMamer.XServerCom("%s %s%s", "+ censor", u->name, "\n");
91 gMamer.TellUser(ChangedAbuse, user->name, u->name, u->GetAbuse());
93 gMamer.TellUser(NotFound, user->name, name);
95 if(needToDelete) delete u;
100 //- FingerUser -------------------------------------------------------
101 int CommandEntry::FingerUser(User *user, param_list params) {
106 memset(name, '\0', 32);
107 if(params[0].type == TYPE_WORD) {
108 strncpy(name, params[0].val.word, MIN(31, (int)strlen(params[0].val.word)));
110 strcpy(name, user->name);
113 u = gMamer.FindUser(name);
114 if(u != NULL) notFound = 0;
118 notFound = u->LoadPlayer(gMamer.userFilePath, name);
119 notFound = !notFound;
122 gMamer.XServerCom("%s %s %s%s%s", "qtell", user->name, "\\n", u->name, "'s Stats:\\n\\n");
123 gMamer.XServerCom("%-17s %5s %4s %4s %3s %3s %3s %3s %5s %6s%-17s %4s %3s %3s %3s %3s %3s %3s %5s %6s",
124 "Name", " Tnys", " W ", " L ", " D ", "1st", "2nd", "3rd", "Chaos", "Rating\\n",
125 "-----------------", "-----", "----", "----", "---", "---", "---", "---", "-----","------\\n");
126 gMamer.XServerCom("%-17s %5ld %4ld %4ld %3ld %3ld %3ld %3ld %5d %6.2f %s",
127 u->name, u->GetPlayedTourneys(), u->GetWins(), u->GetLosses(), u->GetDraws(),
128 u->GetFirsts(), u->GetSeconds(), u->GetThirds(), u->GetAbuse(), u->GetRating(), "\\n");
129 if(u->GetManagerLevel() > USER) {
130 gMamer.XServerCom("%s %d %s %d %s", "\\nManager Level:", u->GetManagerLevel(),
131 " Managed Tourneys:", u->GetManagedTourneys(), "\\n");
133 gMamer.XServerCom("%s", "\n");
135 gMamer.TellUser(NotFound, user->name, name);
137 if(notFound) delete u;
140 } //- End of FingerUser
142 //- ListRank ----------------------------------------------------------
143 int CommandEntry::ListRank(User *user, param_list params) {
145 int start=0, i=0, end=0, tourneys=0, counter=0;
146 char filename[128], name[32], name2[32];
149 memset(name, '\0', 32);
150 memset(name2, '\0', 32);
151 switch (params[0].type) {
153 strcpy(name, params[0].val.word);
156 start = params[0].val.integer;
157 if(start <= 0) {start = 1;}
160 strcpy(name, user->name);
164 sprintf(filename, "%s/rank", gMamer.dataFilePath);
165 if(params[0].type != TYPE_INT) {
166 if((theFile = fopen(filename, "r"))) {
167 while(fscanf(theFile, "%s %d %f", name2, &tourneys, &rating) > 0) {
168 if(!(strncasecmp(name2, name, strlen(name)))) {
176 gMamer.TellUser(NotFound, user->name, filename);
181 gMamer.TellUser(NotFound, user->name, name);
186 if(start <= 0) {start = 1; end = 21;}
187 gMamer.XServerCom("%s %s %s %s%s %-5s %-18s %5s %6s %5s %-18s %5s %6s", "qtell", user->name, "\\n", gMamer.username,
188 "'s Rankings:\\n\\n", "Rank", "Name", "Trnys", "Rating\\n",
189 "-----", "------------------", "-----", "------\n");
190 gMamer.XServerCom("%s %s %s", "qtell", user->name, "\\n");
191 if(!(theFile = fopen(filename, "r"))) { return(0); }
193 while(fscanf(theFile, "%s %d %f", name2, &tourneys, &rating) > 0) {
194 if((i >= start) && (i < end)) {
195 if(i == start) { counter = 1; }
196 gMamer.XServerCom(" %-5d %-18s %5d %6.2f\\n", i, name2, tourneys, rating);
197 if(((counter % 10) == 0) && (counter > 0)) {
198 gMamer.XServerCom("%s", "\n");
200 gMamer.XServerCom("%s %s %s", "qtell", user->name, "\\n");
204 if(i > end) { break; }
209 if(i <= end) { gMamer.XServerCom("%s", "\n"); }
214 //- ListManagers ------------------------------------------------------
215 int CommandEntry::ListManagers(User *user, param_list params) {
216 int i=1, needToDelete=0;
218 char filename[256], manager[NAMELEN], date[16];
219 User *u=NULL, *newUser = NULL;
223 i = params[0].type; // just to get rid of the compiler messages
224 sprintf(filename, "%s/managers", gMamer.dataFilePath);
225 if((theFile = fopen(filename, "r"))) {
226 gMamer.XServerCom("%s %s %s %s%s", "qtell", user->name, "\\n", gMamer.username, "'s Manager List:\\n\\n");
227 gMamer.XServerCom("%2s%-18s %3s %4s %-8s%2s%-18s %3s %4s %-8s%s",
228 "","Name","Lvl","Tnys","Last", "","Name","Lvl","Tnys","Last", "\\n");
229 gMamer.XServerCom(" %-18s %3s %4s %-8s%2s%-18s %3s %4s %-8s%s",
230 "-----------------", "---", "----", "--------", "",
231 "-----------------", "---", "----", "--------", "", "\\n");
233 memset(date, '\0', 16);
234 gMamer.XServerCom("\n%s %s ", "qtell", user->name);
235 while(fscanf(theFile, "%s", manager) > 0) {
237 u = gMamer.FindUser(manager);
240 newUser = new User();
243 if(0 != u->LoadPlayer(gMamer.userFilePath, manager)) {
246 tmpDate = localtime(&last);
247 sprintf(date, "%02d/%02d/%02d", tmpDate->tm_mon+1, tmpDate->tm_mday, tmpDate->tm_year);
249 sprintf(date, "none");
252 sprintf(date, "%s", "none");
254 gMamer.XServerCom("%2s%-18s %3d %4d %8s%s",
255 ((gMamer.UserIsLoaded(manager)) ? "+" : " "),
256 manager, u->GetManagerLevel(), u->GetManagedTourneys(), date, (i%2)==0 ? "\\n":"");
257 if(((i % 20) == 0) && (i > 0)) {
259 gMamer.XServerCom("%s %s %s %s", "\n", "qtell", user->name, "\\n");
268 gMamer.XServerCom("%s", "\n");
272 gMamer.TellUser(NotFound, user->name, filename);
276 //- LoadedUsers -------------------------------------------------------
277 int CommandEntry::LoadedUsers(User *user, param_list params) {
279 LinkListIter<User> userIter(gMamer.userList);
285 gMamer.XServerCom("qtell %s \\nLoaded Users:\\n\\n", user->name);
286 while((u = userIter.Next())) {
288 gMamer.XServerCom(" %18s%s", u->name, (i%3)==0 ? "\\n":"");
289 if(((i % 30) == 0) && (i > 0)) {
291 gMamer.XServerCom("%s %s %s %s", "\n", "qtell", user->name, "\\n");
295 gMamer.XServerCom("%sTotal: %i%s", "\\n", count, "\n");
298 } //- End of LoadedUser
300 //- SetCommandLevel ----------------------------------------------------
301 int CommandEntry::SetCommandLevel(User *user, param_list params) {
304 c = gMamer.FindCommand(params[0].val.word, user->name);
307 if((c->GetManagerLevel() <= user->GetManagerLevel()) &&
308 (params[1].val.integer <= user->GetManagerLevel())) {
309 c->SetManagerLevel((ranks)params[1].val.integer);
310 gMamer.TellUser(ChangedCommandLevel, user->name, params[0].val.word, params[1].val.integer);
312 gMamer.TellUser(NoPermissions, user->name);
319 //- SetInfo -------------------------------------------------------
320 int CommandEntry::SetInfo(User *user, param_list params) {
325 memset(name, '\0', 32);
326 if(params[0].type == TYPE_WORD) {
327 strncpy(name, params[0].val.word, MIN(31, (int)strlen(params[0].val.word)));
330 u = gMamer.FindUser(name);
331 if(u != NULL) notFound = 0;
335 u->LoadPlayer(gMamer.userFilePath, name);
339 if((u->GetManagerLevel() >= user->GetManagerLevel()) &&
340 (user->GetManagerLevel() != PRESIDENT)) {
341 if(notFound) delete u;
342 gMamer.TellUser(NoPermissions, user->name);
346 u->SetStatistic(i, params[i].val.integer);
347 u->SavePlayer(gMamer.userFilePath);
348 gMamer.TellUser(ChangedInfo, user->name, u->name);
350 gMamer.TellUser(NotFound, user->name, name);
352 if(notFound) delete u;
357 //- SetManagerLevel -------------------------------------------------------
358 int CommandEntry::SetManagerLevel(User *user, param_list params) {
360 int notFound=1, new_level=1, length=0, i=0;
363 if(params[0].type == TYPE_WORD) {
364 length = strlen(params[0].val.word);
365 memset(name, '\0', 32);
366 while((i < 31) && (i < length)) {
367 name[i] = tolower(params[0].val.word[i]);
371 new_level = params[1].val.integer;
373 u = gMamer.FindUser(name);
374 if(u != NULL) notFound = 0;
378 u->LoadPlayer(gMamer.userFilePath, name);
380 if(((u->GetManagerLevel() >= user->GetManagerLevel()) ||
381 (new_level >= user->GetManagerLevel())) &&
382 (user->GetManagerLevel() != PRESIDENT)) {
383 if(notFound) delete u;
384 gMamer.TellUser(NoPermissions, user->name);
389 u->ChangeManagerLevel(new_level);
390 u->SavePlayer(gMamer.userFilePath);
391 gMamer.TellUser(ChangedManagerLevel, user->name, u->name, new_level);
393 gMamer.TellUser(NotFound, user->name, name);
395 if(notFound) delete u;
401 } //- End of SetManagerLevel
404 //- SetStat -------------------------------------------------------
405 int CommandEntry::SetStat(User *user, param_list params) {
407 int notFound=1, new_value, i, ret=0, size=0, counter=0;
408 char which_stat[64], name[32];
409 strings statAliases[] = {
410 {"tourneys", 1}, {"tnys", 1},
412 {"losses", 3}, {"lose", 3},
414 {"firsts", 5}, {"1sts", 5},
415 {"seconds", 6}, {"2nds", 6},
416 {"thirds", 7}, {"3rds", 7},
419 {"managedtourneys", 10},
423 memset(which_stat, '\0', 64);
424 if(params[0].type == TYPE_WORD) { strcpy(name, params[0].val.word); }
425 if(params[1].type == TYPE_WORD) { strncpy(which_stat, params[1].val.word, MIN(63, strlen(params[1].val.word))); }
426 size = strlen(which_stat);
427 new_value = params[2].val.integer;
429 u = gMamer.FindUser(name);
430 if(u != NULL) notFound = 0;
434 u->LoadPlayer(gMamer.userFilePath, name);
437 if((u->GetManagerLevel() >= user->GetManagerLevel()) &&
438 (user->GetManagerLevel() != PRESIDENT)) {
439 if(notFound) delete u;
440 gMamer.TellUser(NoPermissions, user->name);
444 while(statAliases[i].string != NULL) {
445 if (!(strncasecmp(statAliases[i].string, which_stat, MIN(size, (int)strlen(statAliases[i].string))))) {
447 if(counter > 1) break;
452 gMamer.TellUser(CanNotChange, user->name, u->name, which_stat, new_value);
453 } else if(counter == 0) {
454 gMamer.TellUser(NotFound, user->name, which_stat);
457 while(statAliases[i].string != NULL) {
458 if (!(strncasecmp(statAliases[i].string, which_stat, MIN(size, (int)strlen(statAliases[i].string))))) {
459 ret = u->SetStatistic(statAliases[i].number, new_value);
460 memset(which_stat, '\0', 64);
461 strcpy(which_stat, statAliases[i].string);
466 u->SavePlayer(gMamer.userFilePath);
468 gMamer.TellUser(ChangedInfo, user->name, u->name, which_stat, new_value);
470 gMamer.TellUser(NotFound, user->name, which_stat);
473 gMamer.TellUser(NotFound, user->name, name);
475 if(notFound) delete u;
480 //- ShowCommands --------------------------------------------
481 int CommandEntry::ShowCommands(User *user, param_list params) {
483 LinkListIter<Command> commIter(gMamer.commandList);
487 if(params[0].type == TYPE_WORD) {
488 command = params[0].val.word;
489 while((c = commIter.Next())) if(1 == c->IsCommand(command)) break;
491 gMamer.TellUser(NotFound, user->name, command);
494 gMamer.XServerCom("qtell %s %s Notes: %-16s | %-5s | %3d | %s \n",
495 user->name, gMamer.username, c->GetCommandName(),
496 c->GetCommandAlias(), c->GetManagerLevel(), c->GetCommandDescription());
499 gMamer.XServerCom("qtell %s %s's Command List:\\n\\n", user->name, gMamer.username);
501 while((c = commIter.Next())) {
502 gMamer.XServerCom(" %-16s | %-5s | %3d | %s\\n",
503 c->GetCommandName(), c->GetCommandAlias(), c->GetManagerLevel(), c->GetCommandDescription());
504 if((!(i % 9)) && (i > 0)) {
506 gMamer.XServerCom("%s", "\n");
507 gMamer.XServerCom("qtell %s \\n", user->name);
511 gMamer.XServerCom("%s", "\n");
515 //- ShowHelp -----------------------------------------------
516 int CommandEntry::ShowHelp(User *user, param_list params) {
518 char tmpBuffer[1024], request[128], filename[256];
521 memset(request, '\0', 128);
522 if(params[0].type == TYPE_WORD) {
523 strcpy(request, params[0].val.word);
525 strcpy(request, "index");
527 sprintf(filename, "%s/%s", gMamer.helpFilePath, request);
528 if((theFile = fopen(filename, "r"))) {
529 gMamer.XServerCom("qtell %s \\nThe %s Help File:\\n\\n", user->name, request);
531 memset(filename, '\0', 256);
532 while(fgets(filename, 79, theFile)) { /* Just reusing the variable filename could be any char [] */
533 memset(tmpBuffer, '\0', 1024);
534 strcpy(tmpBuffer, gMamer.s_and_r(filename, "\n", "\\n"));
535 gMamer.XServerCom("%s", tmpBuffer);
536 if(((i % 10) == 0) && (i > 0)) {
538 gMamer.XServerCom("\nqtell %s \\n", user->name);
541 memset(filename, '\0', 256);
544 gMamer.XServerCom("\n");
548 gMamer.TellUser(NotFound, user->name, request);
552 //- CreateTourney ------------------------------------------------------------
553 int CommandEntry::CreateTourney(User *user, param_list params) {
555 int num = gMamer.GenerateTourneyNumber();
557 params[0].type = params[0].type; // Just to stop the annoying unused variable messages during compile.
558 t = new Tourney(num, user, &(gMamer.tourneyParams));
559 gMamer.tourneyList.Append(t);
560 gMamer.XServerCom("%s %s %s %d %s", "xtell", user->name, "Created tourney number: ", t->number, "\n");
562 }//- End CreateTourney
564 //- OpenTourney ------------------------------------------------------------
565 int CommandEntry::OpenTourney(User *user, param_list params) {
566 Tourney *tourn = NULL;
568 tourn = gMamer.FindTourney(params[0].val.integer);
575 gMamer.TellUser(NotFound, user->name, "tourney");
579 //- PauseTourney ------------------------------------------------------------
580 int CommandEntry::PauseTourney(User *user, param_list params) {
581 Tourney *tourn = NULL;
583 tourn = gMamer.FindTourney(params[0].val.integer);
585 if(tourn->GetStatus() == CLOSED) {
586 tourn->SetPause(TRUE);
590 gMamer.TellUser(NotFound, user->name, "tourney");
592 }//- End PauseTourney
594 //- ResumeTourney ------------------------------------------------------------
595 int CommandEntry::ResumeTourney(User *user, param_list params) {
596 Tourney *tourn = NULL;
598 tourn = gMamer.FindTourney(params[0].val.integer);
600 if(tourn->GetStatus() == CLOSED && tourn->IsPaused()) {
601 tourn->SetPause(FALSE); // unpause
602 gMamer.NextRound(); // and start next round
606 gMamer.TellUser(NotFound, user->name, "tourney");
608 }//- End ResumeTourney
610 //- AnnounceTourney ----------------------------------------------------------
611 int CommandEntry::AnnounceTourney(User *user, param_list params) {
612 Tourney *tourn = NULL;
614 tourn = gMamer.FindTourney(params[0].val.integer);
616 if(tourn->GetStatus() == OPEN) {
620 gMamer.TellUser(TourneyNotOpen, user->name, params[0].val.integer);
624 gMamer.TellUser(NotFound, user->name, "tourney");
627 }//- AnnounceTourney ---------------------------------------------------------
629 //- KeepTourney ------------------------------------------------------------
630 int CommandEntry::KeepTourney(User *user, param_list params) {
633 t = gMamer.FindTourney(params[0].val.integer);
635 if(params[1].type != TYPE_NULL)
636 if(params[1].type == TYPE_WORD) {
637 if(strncasecmp("y", params[1].val.word, 1) == 0) {
639 gMamer.TellUser(WillKeepTourney, user->name, params[0].val.integer);
642 gMamer.TellUser(NotKeepTourney, user->name, params[0].val.integer);
644 } else if(params[1].type == TYPE_INT) {
645 t->SetPersist(params[1].val.integer);
646 if(params[1].val.integer)
647 gMamer.TellUser(WillKeepTourney, user->name, params[0].val.integer);
649 gMamer.TellUser(NotKeepTourney, user->name, params[0].val.integer);
651 gMamer.TellUser(NotFound, user->name, "tourney");
657 gMamer.TellUser(NotFound, user->name, "tourney");
661 //- DeleteTourney ------------------------------------------------------------
662 int CommandEntry::DeleteTourney(User *user, param_list params) {
664 TourneyPlayers *tp = NULL;
666 t = gMamer.FindTourney(params[0].val.integer);
668 if(t->GetStatus() != DONE) {
669 LinkListIter<TourneyPlayers> playerIter(t->playerList);
671 while((tp = playerIter.Next())) {
672 gMamer.XServerCom("%s %s %d%s", "tournset", tp->name, 0, "\n");
673 gMamer.XServerCom("tell %s Tourney#%d has been deleted.%s", tp->name, t->number, "\n");
675 gMamer.XServerCom("%s %d %s%d %s", "tell", gMamer.channelNumber,
676 "Tourney #", params[0].val.integer, "has been deleted.\n");
678 gMamer.tourneyList.Delete(t); // delete the tourney
682 gMamer.TellUser(NotFound, user->name, "tourney");
684 }//- End DeleteTourney
686 //- CloseTourney ------------------------------------------------------------
687 int CommandEntry::CloseTourney(User *user, param_list params) {
688 Tourney *tourn = NULL;
690 tourn = gMamer.FindTourney(params[0].val.integer);
692 if(tourn->GetPlayerCount() >= MINIMUM_PLAYERS) {
693 if(tourn->GetStatus() == OPEN) {
694 tourn->CloseAndStart();
695 gMamer.XServerCom("qtell %s %s Notes: %s %d %s",
696 user->name,gMamer.username,"Tourney #",
697 tourn->number, " is now closed.\n");
700 gMamer.TellUser(TourneyNotOpen, user->name, tourn->number);
703 gMamer.TellUser(NotEnoughPlayers, user->name, tourn->number);
706 gMamer.TellUser(TourneyNotFound, user->name, params[0].val.integer);
710 }//- End CloseTourney
712 int CommandEntry::ListTourneys(User *user, param_list params) {
714 LinkListIter<Tourney> tournIter(gMamer.tourneyList);
715 int notourneys = 1, Tstatus=0, i=3;
716 long stDate, enDate, timeNow;
717 struct tm *start, *end;
718 char outStart[128], outEnd[128], outStatus[128];
720 params[0].type = params[0].type; // Just to stop the annoying unused var messages in compile.
721 while((t = tournIter.Next())) notourneys = 0;
723 if(notourneys == 0) {
724 gMamer.XServerCom("qtell %s %s Notes: \\n", user->name, gMamer.username);
725 gMamer.XServerCom(" %3s %3s %3s %4s %3s %2s %4s %9s %6s %-14s %-14s\\n",
726 "No.","Rds","Sty", "Time", "Inc", "Md", "Vrnt", "Rtng Rnge", "Status"," Started at ", " Ended at ");
727 gMamer.XServerCom(" %3s %3s %3s %4s %3s %2s %4s %9s %6s %-14s %-14s\\n",
728 "---","---","---", "----", "---", "--", "----", "---------", "------","--------------", "--------------");
730 while((t = tournIter.Next())) {
731 stDate = t->GetStartDate();
732 enDate = t->GetEndDate();
733 Tstatus = t->GetStatus();
734 if((Tstatus == DONE) && (t->GetPersist() == 0)){
736 if((timeNow - enDate) > KEEP_TOURNEY_TIME) {
737 gMamer.tourneyList.Delete(t);
742 start = localtime(&stDate);
743 sprintf(outStart, "%02d:%02d %02d/%02d/%02d",
744 start->tm_hour, start->tm_min, start->tm_mon+1, start->tm_mday, start->tm_year);
745 } else { strcpy(outStart, "n/a"); }
747 end = localtime(&enDate);
748 sprintf(outEnd, "%02d:%02d %02d/%02d/%02d",
749 end->tm_hour, end->tm_min, end->tm_mon+1, end->tm_mday, end->tm_year);
750 } else { strcpy(outEnd, "n/a"); }
752 sprintf(outStatus, "%s", "new");
753 else if(Tstatus == OPEN)
754 sprintf(outStatus, "%s", "open");
755 else if(Tstatus == CLOSED)
756 sprintf(outStatus, "%s", "closed");
757 else if(Tstatus == DONE)
758 sprintf(outStatus, "%s", "done");
760 memset(outStatus, '\0', 128);
762 gMamer.XServerCom(" %3d %3d %3c %4d %3d %2c %4c %4d-%4d %6s %-14s %-14s\\n",
763 t->number, t->params.rounds, t->params.style, t->params.time, t->params.inc,
764 t->params.mode, t->params.variant, t->params.ratingLow, t->params.ratingHigh,
765 outStatus, outStart, outEnd);
766 if(((i % 12) == 0) && (i > 0)) {
768 gMamer.XServerCom("%s %s %s %s", "\n", "qtell", user->name, "\\n");
772 gMamer.XServerCom("%s", "\n");
774 gMamer.XServerCom("qtell %s %s Notes: %s", user->name, gMamer.username, "No tourneys right now.\n");
780 //- JoinTourney ------------------------------------------------------------
781 int CommandEntry::JoinTourney(User *user, param_list params) {
782 Tourney *tourn = NULL;
783 Player *newEntry = NULL;
785 tourn = gMamer.FindTourney(params[0].val.integer);
788 newEntry = new Player(user->name, params[0].val.integer);
789 printf("entry=%d\n",newEntry);
790 gMamer.pendingList.Append(newEntry);
791 gMamer.XServerCom("getpi %s%s", user->name, "\n");
795 gMamer.TellUser(TourneyNotFound, user->name, params[0].val.integer);
799 //- AddToTourney ------------------------------------------------------------
800 int CommandEntry::AddToTourney(User *user, param_list params) {
801 Tourney *tourn = NULL;
802 Player *newEntry = NULL;
804 tourn = gMamer.FindTourney(params[1].val.integer);
807 newEntry = new Player(params[0].val.word, params[1].val.integer);
808 gMamer.pendingList.Append(newEntry);
809 gMamer.XServerCom("getpi %s%s", params[0].val.word, "\n");
813 gMamer.TellUser(TourneyNotFound, user->name, params[1].val.integer);
817 //- RemoveFromTourney ------------------------------------------------------------
818 int CommandEntry::RemoveFromTourney(User *user, param_list params) {
819 Tourney *tourn = NULL;
820 TourneyPlayers *tp=NULL;
821 char name[NAMELEN], reason[64];
824 int chaosPointsEarned=0, needToDelete=0;
826 memset(name, '\0', NAMELEN);
827 memset(reason, '\0', 64);
828 if(params[0].type == TYPE_INT) { // if we are withdrawing ourselves
829 tourn = gMamer.FindTourney(params[0].val.integer);
830 strcpy(name, user->name);
832 num = params[0].val.integer;
833 strcpy(reason, "withdrew");
834 } else { // if a manager is forfeiting us
835 tourn = gMamer.FindTourney(params[1].val.integer);
836 strcpy(name, params[0].val.word);
837 u = gMamer.FindUser(params[0].val.word);
838 num = params[1].val.integer;
839 strcpy(reason, "was forfeited");
843 gMamer.TellUser(TourneyNotFound, user->name, num);
846 if(tourn->GetStatus() == DONE) {
847 gMamer.TellUser(TourneyDone, user->name, num);
850 tp = tourn->GetPlayer(name); //Get the players info
852 gMamer.TellUser(NotFound, user->name, name, num);// Player is not found in this tourney
856 gMamer.XServerCom("%s %s %d%s", "tournset", name, 0, "\n");
857 if(tourn->IsNotClosed()) { //If we get past this check it will cost the user chaos points
858 tourn->playerList.Delete(tp);
859 tourn->CalculateAverage();
860 gMamer.TellUser(PlayerRemoved, user->name, name, num);
861 gMamer.XServerCom("%s %d %s %s %s%d %d%s\n","tell", gMamer.channelNumber, name, reason, "from tourney #",
862 tourn->number, tourn->GetPlayerCount(), " player(s) now");
864 } // otherwise tourney is closed and started
866 chaosPointsEarned = tourn->RemovePlayer(name); // RemovePlayer will return the number of rounds
867 if(chaosPointsEarned >= 0) { // that were disturbed
869 u = new User(gMamer.userFilePath, name); // Make a new user - this will create a file but there
870 needToDelete = 1; // should already be one cause they are in the tourney
872 u->AddAbuse(chaosPointsEarned * PENALTY_PER_ROUND); // add the choas points and save them
873 u->SavePlayer(gMamer.userFilePath);
874 if(u->GetAbuse() >= MAX_CHAOS_POINTS)
875 gMamer.XServerCom("%s %s%s", "+ censor", u->name, "\n");
876 if(needToDelete) delete(u); // we created a new user so we should delete him here
877 gMamer.TellUser(PlayerRemoved, user->name, name, num);
878 gMamer.XServerCom("%s %d %s %s %s%d\n","tell",gMamer.channelNumber,name, reason,
879 "from tourney #", tourn->number);
885 //- ListTourneyGames ------------------------------------------------------------
886 int CommandEntry::ListTourneyGames(User *user, param_list params) {
888 TourneyPlayers *white, *black;
892 t = gMamer.FindTourney(params[0].val.integer);
894 LinkListIter<Game> gameIter(t->gameList);
896 gMamer.XServerCom("%s %s %s %d %s", "qtell", user->name, "Tourney Games for Round #", t->GetRound(), "\\n\\n");
897 gMamer.XServerCom("%3s %18s %6s %6s %2s %-18s %6s %6s %s",
898 "", "White", "[SCR ]", "[Rtng]", "vs", "Black", "[SCR ]", "[Rtng]",
899 "\\n---------------------------------------------------------------------------\\n");
900 while((g = gameIter.Next())) {
901 if(!(i % 10) && (i>0)) {
902 gMamer.XServerCom("\nqtell %s %s", user->name, "\\n");
905 white = t->GetPlayer(g->whiteName);
906 black = t->GetPlayer(g->blackName);
908 if(g->gameNumber > 0) {
909 gMamer.XServerCom("%3d %18s [%4.1f] [%4i] vs %-18s [%4.1f] [%4i] %3i%s",
910 i+1, g->whiteName, white->score, white->rating,
911 g->blackName, black->score, black->rating, g->gameNumber, "\\n");
913 gMamer.XServerCom("%3d %18s [%4.1f] [%4i] vs %-18s [%4.1f] [%4i] none%s",
914 i+1, g->whiteName, white->score, white->rating,
915 g->blackName, black->score, black->rating, "\\n");
919 gMamer.XServerCom("%s", "\\n\n");
923 gMamer.TellUser(TourneyNotFound, user->name, params[0].val.integer);
925 }//- End of ListTourneyGames
927 //- ListTourneyPlayers ------------------------------------------------------------
928 int CommandEntry::ListTourneyPlayers(User *user, param_list params) {
930 Player *p = NULL, *opp=NULL;
931 TourneyPlayers *tp = NULL;
933 int i = 0, counter = 0;
935 t = gMamer.FindTourney(params[0].val.integer);
937 if(t->GetPlayerCount() == 0) {
938 gMamer.TellUser(NoPlayers, user->name, params[0].val.integer);
942 gMamer.XServerCom("%s %s %s %s %d %s %d %s %3s %-17s %6s %5s %6s %-6s %-7s %s %3s %-17s %6s %5s %6s %6s %-7s %s",
943 "qtell", user->name, "Tourney Players:", "Round", t->GetRound(), "of", t->params.rounds,
944 "\\n\\n", "", "Name", "Rating", "Score", "Perfrm", "Upset ", "Results", "\\n",
945 "", "-----------------", "------", "-----", "------", "------", "-------", "\\n");
946 LinkListIter<TourneyPlayers> playerIter(t->playerList);
948 while((tp = playerIter.Next())) { counter++; } // count the number of players
949 for(i=1; i<=counter; i++) {
950 p = t->GetSortPlayer(i);
951 tp = t->GetPlayer(p->name);
952 if(tp->activeFlag > 0)
953 gMamer.XServerCom("%3d %s%-17s [%4d] %3.1f [%4d] [%4d] ",
954 i, ((tp->location == ONLINE) ? "+" : "-"),
955 tp->name, tp->rating, tp->score, tp->perform, tp->upset);
957 gMamer.XServerCom("%3d %s%-17s [%4s] %3.1f [%4d] [%4d] ",
958 i, ((tp->location == ONLINE) ? "+" : "-"),
959 tp->name, "forf", tp->score, tp->perform, tp->upset);
960 LinkListIter<Player> opponentIter(tp->opponentList); // List of opponents this player has had
961 opponentIter.Reset();
962 while((opp = opponentIter.Next())) {
963 p = t->GetSortPlayer(opp->name);
964 if(opp->value) { color = 'w'; } else { color = 'b'; }
965 if(opp->floatValue == 1.0) {
967 } else if(opp->floatValue == 0.5) {
969 } else if(opp->floatValue == 0.0) {
974 gMamer.XServerCom("%c%-0.2d%c ", result, p->value, color);
976 if(((i % 9) == 0) && (i > 0)) {
977 gMamer.XServerCom("%s %s %s %s", "\n", "qtell", user->name, "\\n");
979 gMamer.XServerCom("%s", "\\n");
982 gMamer.XServerCom("%-24s %6.1f %s", "\\n Average Rating", t->GetAverageRating(), "\\n\n");
986 gMamer.TellUser(TourneyNotFound, user->name, params[0].val.integer);
988 }//- End of ListTourneyPlayers
990 //- ListTourneyVars -----------------------------------------------------
991 int CommandEntry::ListTourneyVars(User *user, param_list params) {
992 Tourney *tourn = NULL;
994 tourn = gMamer.FindTourney(params[0].val.integer);
997 gMamer.XServerCom("%s %s %s", "qtell", user->name, "\\n");
998 gMamer.XServerCom(" %18s %4d %s", "(T)ime: ", tourn->params.time, "\\n");
999 gMamer.XServerCom(" %18s %4d %s", "(I)ncrement: ", tourn->params.inc, "\\n");
1000 gMamer.XServerCom(" %18s %4d %s", "(R)ounds: ", tourn->params.rounds, "\\n");
1001 gMamer.XServerCom(" %18s %4d %s", "Max (P)layers: ", tourn->params.maxPlayers, "\\n");
1002 gMamer.XServerCom(" %18s %4c %s", "(M)ode: ", tourn->params.mode, "(r)ated or (u)nrated\\n");
1003 gMamer.XServerCom(" %18s %4c %s", "(S)tyle: ", tourn->params.style, "(s)wiss or (r)oundrobin\\n");
1004 gMamer.XServerCom(" %18s %4c %s","(V)ariant: ",tourn->params.variant, "(w)ild, (r)egular, (b)ug, or (s)uicide\\n");
1005 if(tourn->params.variant == 'w')
1006 gMamer.XServerCom(" %18s %4d %s",
1008 tourn->params.wild, "(0), (1), (2), (3), (4), (5), (8), (9)8a, (10)fr\\n");
1009 gMamer.XServerCom(" %18s %4d %s", "Rating (L)ow: ", tourn->params.ratingLow, "\\n");
1010 gMamer.XServerCom(" %18s %4d %s", "Rating (H)igh: ", tourn->params.ratingHigh, "\\n\\n");
1011 gMamer.XServerCom(" %18s %-18s %s", "Manager: ", tourn->manager, "\\n\n");
1013 gMamer.TellUser(NotFound, user->name, "tourney");
1017 }//- End ListTourneyVars
1019 //- MessageManagers -----------------------------------------------------
1020 int CommandEntry::MessageManagers(User *user, param_list params) {
1021 int i, level, tourneys;
1023 char filename[256], manager[NAMELEN];
1027 level = params[0].type;
1028 sprintf(filename, "%s/managers", gMamer.dataFilePath);
1029 if((theFile = fopen(filename, "r"))) {
1030 while(fscanf(theFile, "%s %d %d %ld", manager, &level, &tourneys, &last) > 0) {
1031 gMamer.XServerCom("%s %s %s %s", "message", manager, params[0].val.string, "\n");
1037 gMamer.TellUser(NotFound, user->name, "Manager List");
1039 }//- MessageManagers
1041 //- SetResult ------------------------------------------------------------
1042 int CommandEntry::SetResult(User *user, param_list params) {
1044 int result, return_val = 0;
1047 t = gMamer.FindTourney(params[0].val.integer);
1050 switch (params[3].type) { // try and set the result
1052 switch(params[3].val.integer) {
1053 case 1: result = 1; break;
1054 case 0: result = 0; break;
1059 if(!strcmp("=", params[3].val.word)) { result = 2;
1060 } else if(!strcmp("draw", params[3].val.word)) { result = 2;
1061 } else if(!strcmp("win", params[3].val.word)) { result = 1;
1062 } else if(!strcmp("white", params[3].val.word)) { result = 1;
1063 } else if(!strcmp("loss", params[3].val.word)) { result = 0;
1064 } else if(!strcmp("black", params[3].val.word)) { result = 0;
1066 gMamer.TellUser(GameResultNotFound, user->name, params[3].val.word);
1071 gMamer.TellUser(GameResultNotFound, user->name, params[3].val.string);
1075 return_val = t->SetGameResult(params[1].val.word, params[2].val.word, result);
1077 switch (return_val) {
1079 sprintf(answer, "a game with %s as white and %s as black", params[1].val.word, params[2].val.word);
1080 gMamer.TellUser(NotFound, user->name, answer);
1083 gMamer.TellUser(GameResultSet, user->name, params[1].val.word, params[2].val.word, result);
1086 sprintf(answer, "1-0");
1089 sprintf(answer, "0-1");
1092 sprintf(answer, "1/2-1/2");
1095 gMamer.XServerCom("%s %d The game %s vs. %s in tourney #%d has been set %s by %s\n", "tell", gMamer.channelNumber,
1096 params[1].val.word, params[2].val.word, t->number, answer, user->name);
1100 }//- End of SetResult
1102 //- SetTourneyVariable -----------------------------------------------------
1103 int CommandEntry::SetTourneyVariable(User *user, param_list params) {
1104 Tourney *tourn = NULL;
1107 strings varAliases[] = {
1108 {"time", 0}, {"t", 0}, {"inc", 1}, {"i", 1}, {"rounds", 2}, {"r", 2},
1109 {"style", 3}, {"s", 3}, {"variant", 4}, {"v", 4}, {"mode", 5}, {"m", 5},
1110 {"wild", 6}, {"w", 6},
1111 {"ratingLow", 7}, {"l", 7}, {"ratingHigh", 8}, {"h", 8}, {"maxplayers", 9}, {"p", 9}, {NULL} };
1113 tourn = gMamer.FindTourney(params[0].val.integer); // what tourney are we talking about
1115 gMamer.TellUser(NotFound, user->name, "tourney"); // wrong tourney number
1118 if(FALSE == tourn->IsNotClosed()) {
1119 gMamer.TellUser(TourneyClosed, user->name, params[0].val.integer);
1122 if(TRUE == tourn->IsNotNew()) {
1123 if((0 != strncasecmp(params[1].val.word, "rounds", strlen(params[1].val.word))) && // even if it is open
1124 (0 != strncasecmp(params[1].val.word, "r", strlen(params[1].val.word))) && // we can still change rounds
1125 (0 != strncasecmp(params[1].val.word, "maxplayers", strlen(params[1].val.word))) && // or max players
1126 (0 != strncasecmp(params[1].val.word, "p", strlen(params[1].val.word))) && //
1127 (0 != strncasecmp(params[1].val.word, "style", strlen(params[1].val.word))) && // or style (rr) to (ss)
1128 (0 != strncasecmp(params[1].val.word, "s", strlen(params[1].val.word)))) {
1129 gMamer.TellUser(TourneyNotNew, user->name, params[0].val.integer);
1133 if(strcasecmp(user->name, tourn->manager) != 0) {
1134 gMamer.TellUser(NoPermissions, user->name, params[0].val.integer);
1137 while(varAliases[i].string != NULL) {
1138 if (!(strcasecmp(varAliases[i].string, params[1].val.word))) { //lets check the vars
1139 if(strlen(varAliases[i].string) == 1)
1140 strcpy(which_var, varAliases[i-1].string);
1141 else //copy the whole word
1142 strcpy(which_var, varAliases[i].string);
1144 if((varAliases[i].number <= 2) || (varAliases[i].number >= 6))
1145 if(params[2].type == TYPE_INT) { // if var is one that should be int
1146 tourn->SetVariable(varAliases[i].number, params[2].val.integer);
1147 gMamer.TellUser(ChangedInfo, user->name, which_var, params[2].val.integer);
1150 gMamer.TellUser(CanNotChange, user->name, which_var, params[2].val.word);
1154 if(params[2].type == TYPE_WORD) {
1155 tourn->SetVariable(varAliases[i].number, params[2].val.word);
1156 gMamer.TellUser(ChangedInfo, user->name, which_var, params[2].val.word);
1159 gMamer.TellUser(CanNotChange, user->name, which_var, params[2].val.integer);
1166 gMamer.TellUser(NotFound, user->name, params[1].val.word); // Bad Variable
1170 //- ShutdownCommand ----------------------------------------------------------
1171 int CommandEntry::Shutdown(User *user, param_list params) {
1175 i = user->GetManagerLevel();
1181 } //- end of Shutdown