]> jfr.im git - irc/gameservirc.git/blame - gameserv/boolean.cpp
Cleaned up the player.cpp source
[irc/gameservirc.git] / gameserv / boolean.cpp
CommitLineData
64ed4698 1#include "extern.h"
2#include "aClient.h"
3#include "player.h"
4#include "flags.h"
5
6bool is_playing(char *u); // True if the given nickname in the clients list is playing.
7bool is_playing(aClient *user);
8
9bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything.
10bool is_fighting(aClient *user);
11
12bool player_fight(char *u); // True if the player is fighting another player.
13bool player_fight(aClient *user);
14
15bool master_fight(char *u); // True if the player is fighting their master.
16bool master_fight(aClient *user);
17
18bool dragon_fight(char *u); // True if the player is fighting the dragon.
19bool dragon_fight(aClient *user);
20
21bool alphaNumeric(const char *str); // Returns true if all of the characters in str are alphanumeric non-special chars
22/********** GameServ Booleans **********/
23
24
25bool is_playing(char *u)
26{
b713cd3d 27 aClient *user;
28 if (!(user = find(u)))
29 return false;
30 else
31 return is_playing(user);
64ed4698 32}
33
34bool is_playing(aClient *user)
35{
b713cd3d 36 if (!user)
37 {
38 return false;
39 }
40 else if (!user->stats)
41 {
42 return false;
43 }
44 else if (!FL_is_playing(user))
45 {
46 return false;
47 }
48 else if (user->stats->getClient() != user)
49 {
50 return false;
51 }
52 else
53 return true;
64ed4698 54}
55
56bool is_fighting(char *u)
57{
b713cd3d 58 aClient *user;
59
60 if (!(user = find(u)))
61 return false;
62 else
63 return is_fighting(user);
64ed4698 64}
65
66bool is_fighting(aClient *user)
67{
b713cd3d 68 if (!is_playing(user))
69 return false;
70 else
71 return player_fight(user) || master_fight(user) ||
72 user->stats->getMonster() != NULL;
64ed4698 73}
74
75bool player_fight(char *u)
76{
b713cd3d 77 aClient *user;
78
79 if (!(user = find(u)))
80 return false;
81 else
82 return player_fight(user);
64ed4698 83}
84
85bool player_fight(aClient *user)
86{
b713cd3d 87 if (!is_playing(user))
88 return false;
89 else if (is_playing(user->stats->getBattle()))
90 {
91 return true;
92 }
93
94 return false;
64ed4698 95}
96
97bool master_fight(char *u)
98{
b713cd3d 99 aClient *user;
100
101 if (!(user = find(u)))
102 return false;
103 else
104 return master_fight(user);
64ed4698 105}
106
107bool master_fight(aClient *user)
108{
b713cd3d 109 if (!is_playing(user))
110 return false;
111 else
112 return user->stats->getMaster() != NULL;
64ed4698 113}
114
115bool dragon_fight(char *u)
116{
b713cd3d 117 aClient *user;
118 if (!(user = find(u)))
119 return false;
120 else
121 return dragon_fight(user);
64ed4698 122}
123
124bool dragon_fight(aClient *user)
125{
b713cd3d 126 if (!is_playing(user))
127 return false;
128 else
129 return (isDragonFight(user->stats));
64ed4698 130}
131
132bool alphaNumeric(const char *str)
133{
b713cd3d 134 int len = strlen(str);
135 for (int x = 0; x < len; x++)
136 {
137 if (!((int(str[x]) >= 65 && int(str[x]) <= 90) || (int(str[x]) >= 97 && int(str[x]) <= 122) || (int(str[x]) >= 48 && int(str[x]) <= 57) || int(str[x]) == 95))
138 return false;
139 }
140 return true;
64ed4698 141}
142
143bool passcmp(const char *encrypted, char *plaintext)
144{
b713cd3d 145 char salt[3];
146 char *plaintext2, *plainToencrypt;
147 bool same = false;
148
149 plaintext2 = new char[strlen(encrypted) + strlen(plaintext)]; // Extra
150 strcpy(plaintext2, plaintext);
151
152 salt[0] = encrypted[0];
153 salt[1] = encrypted[1];
154 salt[3] = '\0';
155
156 plainToencrypt = crypt(plaintext2, salt);
157
158 same = (strcmp((const char *)encrypted, plainToencrypt) == 0 ? true : false);
159
160 delete []plaintext2;
161
162 return same;
64ed4698 163}
164
165bool check_password(char *name, char *plaintext)
166{
b713cd3d 167 Player *p;
168
169 if (!(p = findplayer(name)))
170 return false;
171 else
172 {
64ed4698 173 return passcmp(p->getPassword().c_str(), plaintext);
b713cd3d 174 }
64ed4698 175}
176
177bool timedOut(Player *p)
178{
b713cd3d 179 if (!p)
180 return false;
181 else if (p->lastcommand == 0)
c4c55a46 182 return false;
b713cd3d 183 else
184 {
185 if ((time(NULL) - p->lastcommand) >= maxidletime)
186 return true;
187
188 return false;
189 }
64ed4698 190}