]> jfr.im git - irc/gameservirc.git/blob - gameserv/do_list.cpp
Added code for the start of the DataLayer format as well as a basic FilePlayerDAO...
[irc/gameservirc.git] / gameserv / do_list.cpp
1 #include "extern.h"
2 #include "options.h"
3 #include "player.h"
4 #include "aClient.h"
5 #include "flags.h"
6 #include "toplist.h"
7
8 void do_list(char *u)
9 {
10 aClient *user;
11 Player *p;
12 char *cmd = strtok(NULL, " ");
13
14 if (!(user = find(u)))
15 {
16 log("Fatal Error: Couldn't find %s in the client list", u);
17 return;
18 }
19 else if (isIgnore(user))
20 {
21 #ifdef DEBUGMODE
22 log("Ignoring %s. Command LIST", user->getNick());
23 #endif
24 return;
25 }
26
27 if (cmd == NULL || stricmp(cmd, "TOP") == 0)
28 {
29 list<PlayerWrapper>::iterator iter;
30 bool header = false;
31
32 if (myToplist.empty())
33 {
34 notice(s_GameServ, u, "There are no players");
35 return;
36 }
37 myToplist.sort();
38 myToplist.reverse();
39
40 iter = myToplist.begin();
41
42 while (iter != myToplist.end())
43 {
44 if (!header)
45 {
46 notice(s_GameServ, u, "Top Players");
47 header = true;
48
49 }
50 notice(s_GameServ, u, "Level: %2d Exp: %-10d Name: %s",
51 (*iter).getLevel(), (*iter).getExp(), (*iter).getName().c_str());
52 iter++;
53 }
54 }
55 else
56 {
57
58 list<Player*>::iterator iter;
59 bool header = false;
60
61 for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
62 {
63 iter = players[x].begin();
64 if (!players[x].empty())
65 {
66 while(iter != players[x].end())
67 {
68 p = (*iter);
69 if (cmd || is_playing(p->getClient()))
70 {
71 if (!header)
72 {
73 notice(s_GameServ, u, "Players:");
74 header = true;
75 }
76 #ifdef P10
77 notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getRealNick() : "Not Playing"),
78 p->getName().c_str());
79 #else
80 notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getNick() : "Not Playing"),
81 p->getName().c_str());
82 #endif
83 }
84 iter++;
85 }
86 }
87 }
88 if (!header)
89 notice(s_GameServ, u, "No one is playing");
90 else
91 notice(s_GameServ, u, "End of List");
92 }
93 }