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