]> jfr.im git - irc/gameservirc.git/blob - gameserv/boolean.cpp
Removed GameServ.suo
[irc/gameservirc.git] / gameserv / boolean.cpp
1 #include "extern.h"
2 #include "aClient.h"
3 #include "player.h"
4 #include "flags.h"
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
17
18 bool is_playing(char *u); // True if the given nickname in the clients list is playing.
19 bool is_playing(aClient *user);
20
21 bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything.
22 bool is_fighting(aClient *user);
23
24 bool player_fight(char *u); // True if the player is fighting another player.
25 bool player_fight(aClient *user);
26
27 bool master_fight(char *u); // True if the player is fighting their master.
28 bool master_fight(aClient *user);
29
30 bool dragon_fight(char *u); // True if the player is fighting the dragon.
31 bool dragon_fight(aClient *user);
32
33 bool alphaNumeric(const char *str); // Returns true if all of the characters in str are alphanumeric non-special chars
34 /********** GameServ Booleans **********/
35
36
37 bool is_playing(char *u)
38 {
39 aClient *user;
40 if (!(user = find(u)))
41 return false;
42 else
43 return is_playing(user);
44 }
45
46 bool is_playing(aClient *user)
47 {
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;
66 }
67
68 bool is_fighting(char *u)
69 {
70 aClient *user;
71
72 if (!(user = find(u)))
73 return false;
74 else
75 return is_fighting(user);
76 }
77
78 bool is_fighting(aClient *user)
79 {
80 if (!is_playing(user))
81 return false;
82 else
83 return player_fight(user) || master_fight(user) ||
84 user->stats->getMonster() != NULL;
85 }
86
87 bool player_fight(char *u)
88 {
89 aClient *user;
90
91 if (!(user = find(u)))
92 return false;
93 else
94 return player_fight(user);
95 }
96
97 bool player_fight(aClient *user)
98 {
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;
107 }
108
109 bool master_fight(char *u)
110 {
111 aClient *user;
112
113 if (!(user = find(u)))
114 return false;
115 else
116 return master_fight(user);
117 }
118
119 bool master_fight(aClient *user)
120 {
121 if (!is_playing(user))
122 return false;
123 else
124 return user->stats->getMaster() != NULL;
125 }
126
127 bool dragon_fight(char *u)
128 {
129 aClient *user;
130 if (!(user = find(u)))
131 return false;
132 else
133 return dragon_fight(user);
134 }
135
136 bool dragon_fight(aClient *user)
137 {
138 if (!is_playing(user))
139 return false;
140 else
141 return (isDragonFight(user->stats));
142 }
143
144 bool alphaNumeric(const char *str)
145 {
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;
153 }
154
155 bool passcmp(const char *encrypted, char *plaintext)
156 {
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;
175 }
176
177 bool check_password(char *name, char *plaintext)
178 {
179 Player *p;
180
181 if (!(p = findplayer(name)))
182 return false;
183 else
184 {
185 return passcmp(p->getPassword().c_str(), plaintext);
186 }
187 }
188
189 bool timedOut(Player *p)
190 {
191 if (!p)
192 return false;
193 else if (p->lastcommand == 0)
194 return false;
195 else
196 {
197 if ((time(NULL) - p->lastcommand) >= maxidletime)
198 return true;
199
200 return false;
201 }
202 }