]>
Commit | Line | Data |
---|---|---|
1 | #include "extern.h" | |
2 | #include "aClient.h" | |
3 | #include "player.h" | |
4 | #include "flags.h" | |
5 | ||
6 | bool is_playing(char *u); // True if the given nickname in the clients list is playing. | |
7 | bool is_playing(aClient *user); | |
8 | ||
9 | bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything. | |
10 | bool is_fighting(aClient *user); | |
11 | ||
12 | bool player_fight(char *u); // True if the player is fighting another player. | |
13 | bool player_fight(aClient *user); | |
14 | ||
15 | bool master_fight(char *u); // True if the player is fighting their master. | |
16 | bool master_fight(aClient *user); | |
17 | ||
18 | bool dragon_fight(char *u); // True if the player is fighting the dragon. | |
19 | bool dragon_fight(aClient *user); | |
20 | ||
21 | bool alphaNumeric(const char *str); // Returns true if all of the characters in str are alphanumeric non-special chars | |
22 | /********** GameServ Booleans **********/ | |
23 | ||
24 | ||
25 | bool is_playing(char *u) | |
26 | { | |
27 | aClient *user; | |
28 | if (!(user = find(u))) | |
29 | return false; | |
30 | else | |
31 | return is_playing(user); | |
32 | } | |
33 | ||
34 | bool is_playing(aClient *user) | |
35 | { | |
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; | |
54 | } | |
55 | ||
56 | bool is_fighting(char *u) | |
57 | { | |
58 | aClient *user; | |
59 | ||
60 | if (!(user = find(u))) | |
61 | return false; | |
62 | else | |
63 | return is_fighting(user); | |
64 | } | |
65 | ||
66 | bool is_fighting(aClient *user) | |
67 | { | |
68 | if (!is_playing(user)) | |
69 | return false; | |
70 | else | |
71 | return player_fight(user) || master_fight(user) || | |
72 | user->stats->getMonster() != NULL; | |
73 | } | |
74 | ||
75 | bool player_fight(char *u) | |
76 | { | |
77 | aClient *user; | |
78 | ||
79 | if (!(user = find(u))) | |
80 | return false; | |
81 | else | |
82 | return player_fight(user); | |
83 | } | |
84 | ||
85 | bool player_fight(aClient *user) | |
86 | { | |
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; | |
95 | } | |
96 | ||
97 | bool master_fight(char *u) | |
98 | { | |
99 | aClient *user; | |
100 | ||
101 | if (!(user = find(u))) | |
102 | return false; | |
103 | else | |
104 | return master_fight(user); | |
105 | } | |
106 | ||
107 | bool master_fight(aClient *user) | |
108 | { | |
109 | if (!is_playing(user)) | |
110 | return false; | |
111 | else | |
112 | return user->stats->getMaster() != NULL; | |
113 | } | |
114 | ||
115 | bool dragon_fight(char *u) | |
116 | { | |
117 | aClient *user; | |
118 | if (!(user = find(u))) | |
119 | return false; | |
120 | else | |
121 | return dragon_fight(user); | |
122 | } | |
123 | ||
124 | bool dragon_fight(aClient *user) | |
125 | { | |
126 | if (!is_playing(user)) | |
127 | return false; | |
128 | else | |
129 | return (isDragonFight(user->stats)); | |
130 | } | |
131 | ||
132 | bool alphaNumeric(const char *str) | |
133 | { | |
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; | |
141 | } | |
142 | ||
143 | bool passcmp(const char *encrypted, char *plaintext) | |
144 | { | |
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; | |
163 | } | |
164 | ||
165 | bool check_password(char *name, char *plaintext) | |
166 | { | |
167 | Player *p; | |
168 | ||
169 | if (!(p = findplayer(name))) | |
170 | return false; | |
171 | else | |
172 | { | |
173 | return passcmp(p->getPassword().c_str(), plaintext); | |
174 | } | |
175 | } | |
176 | ||
177 | bool timedOut(Player *p) | |
178 | { | |
179 | if (!p) | |
180 | return false; | |
181 | else if (p->lastcommand == 0) | |
182 | return false; | |
183 | else | |
184 | { | |
185 | if ((time(NULL) - p->lastcommand) >= maxidletime) | |
186 | return true; | |
187 | ||
188 | return false; | |
189 | } | |
190 | } |