SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | if(!defined('INITIALIZED')) | |
3 | exit; | |
4 | ||
5 | // DEFINE VARIABLES FOR SCRIPTS AND LAYOUTS (no more notices 'undefinied variable'!) | |
6 | if(!isset($_REQUEST['subtopic']) || empty($_REQUEST['subtopic']) || is_array($_REQUEST['subtopic'])) | |
7 | { | |
8 | $_REQUEST['subtopic'] = "latestnews"; | |
9 | } | |
10 | else | |
11 | $_REQUEST['subtopic'] = (string) $_REQUEST['subtopic']; | |
12 | ||
13 | if(Functions::isValidFolderName($_REQUEST['subtopic'])) | |
14 | { | |
15 | if(Website::fileExists("pages/" . $_REQUEST['subtopic'] . ".php")) | |
16 | { | |
17 | $subtopic = $_REQUEST['subtopic']; | |
18 | } | |
19 | else | |
20 | new Error_Critic('CRITICAL ERROR', 'Cannot load page <b>' . htmlspecialchars($_REQUEST['subtopic']) . '</b>, file does not exist.'); | |
21 | } | |
22 | else | |
23 | new Error_Critic('CRITICAL ERROR', 'Cannot load page <b>' . htmlspecialchars($_REQUEST['subtopic']) . '</b>, invalid file name [contains illegal characters].'); | |
24 | ||
25 | // action that page should execute | |
26 | if(isset($_REQUEST['action'])) | |
27 | $action = (string) $_REQUEST['action']; | |
28 | else | |
29 | $action = ''; | |
30 | ||
31 | $logged = false; | |
32 | $account_logged = new Account(); | |
33 | $group_id_of_acc_logged = 0; | |
34 | // with ONLY_PAGE option we want disable useless SQL queries | |
35 | if(!ONLY_PAGE) | |
36 | { | |
37 | // logged boolean value: true/false | |
38 | $logged = Visitor::isLogged(); | |
39 | // Account object with account of logged player or empty Account | |
40 | $account_logged = Visitor::getAccount(); | |
41 | // group of acc. logged | |
42 | if(Visitor::isLogged()) | |
43 | $group_id_of_acc_logged = Visitor::getAccount()->getPageAccess(); | |
44 | } | |
45 | $layout_name = './layouts/' . Website::getWebsiteConfig()->getValue('layout'); | |
46 | ||
47 | $title = ucwords($subtopic) . ' - ' . Website::getServerConfig()->getValue('serverName'); | |
48 | ||
49 | $topic = $subtopic; | |
50 | ||
51 | $passwordency = Website::getServerConfig()->getValue('encryptionType'); | |
52 | if($passwordency == 'plain') | |
53 | $passwordency = ''; | |
54 | ||
55 | $news_content = ''; | |
56 | $vocation_name = array(); | |
57 | foreach(Website::getVocations() as $vocation) | |
58 | { | |
59 | $vocation_name[$vocation->getPromotion()][$vocation->getBaseId()] = $vocation->getName(); | |
60 | } | |
61 | ||
62 | $layout_ini = parse_ini_file($layout_name.'/layout_config.ini'); | |
63 | foreach($layout_ini as $key => $value) | |
64 | $config['site'][$key] = $value; | |
65 | ||
66 | //###################### FUNCTIONS ###################### | |
67 | function microtime_float() | |
68 | { | |
69 | return microtime(true); | |
70 | } | |
71 | ||
72 | function isPremium($premdays, $lastday) | |
73 | { | |
74 | return Functions::isPremium($premdays, $lastday); | |
75 | } | |
76 | ||
77 | function saveconfig_ini($config) | |
78 | { | |
79 | new Error_Critic('', 'function <i>saveconfig_ini</i> is deprecated. Do not use it.'); | |
80 | } | |
81 | ||
82 | function password_ency($password, $account = null) | |
83 | { | |
84 | new Error_Critic('', 'function <i>password_ency</i> is deprecated. Do not use it.'); | |
85 | } | |
86 | ||
87 | function check_name($name) | |
88 | { | |
89 | $name = (string) $name; | |
90 | $temp = strspn("$name", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM- [ ] '"); | |
91 | if($temp != strlen($name)) | |
92 | return false; | |
93 | if(strlen($name) > 25) | |
94 | return false; | |
95 | ||
96 | return true; | |
97 | } | |
98 | ||
99 | function check_account_name($name) | |
100 | { | |
101 | $name = (string) $name; | |
102 | $temp = strspn("$name", "QWERTYUIOPASDFGHJKLZXCVBNM0123456789"); | |
103 | if ($temp != strlen($name)) | |
104 | return false; | |
105 | if(strlen($name) < 1) | |
106 | return false; | |
107 | if(strlen($name) > 32) | |
108 | return false; | |
109 | ||
110 | return true; | |
111 | } | |
112 | ||
113 | function check_name_new_char($name) | |
114 | { | |
115 | global $config; | |
116 | ||
117 | $name = (string) $name; | |
118 | $name_to_check = strtolower($name); | |
119 | //first word can't be: | |
120 | $first_words_blocked = array('gm ','cm ', 'god ','tutor ', "'", '-'); | |
121 | //names blocked: | |
122 | $names_blocked = array('gm','cm', 'god', 'tutor'); | |
123 | //name can't contain: | |
124 | $words_blocked = array('gamemaster', 'game master', 'game-master', "game'master", '--', "''","' ", " '", '- ', ' -', "-'", "'-", 'fuck', 'sux', 'suck', 'noob', 'tutor'); | |
125 | foreach($first_words_blocked as $word) | |
126 | if($word == substr($name_to_check, 0, strlen($word))) | |
127 | return false; | |
128 | if(substr($name_to_check, -1) == "'" || substr($name_to_check, -1) == "-") | |
129 | return false; | |
130 | if(substr($name_to_check, 1, 1) == ' ') | |
131 | return false; | |
132 | if(substr($name_to_check, -2, 1) == " ") | |
133 | return false; | |
134 | foreach($names_blocked as $word) | |
135 | if($word == $name_to_check) | |
136 | return false; | |
137 | for($i = 0; $i < strlen($name_to_check); $i++) | |
138 | if($name_to_check[$i-1] == ' ' && $name_to_check[$i+1] == ' ') | |
139 | return false; | |
140 | foreach($words_blocked as $word) | |
141 | if (!(strpos($name_to_check, $word) === false)) | |
142 | return false; | |
143 | for($i = 0; $i < strlen($name_to_check); $i++) | |
144 | if($name_to_check[$i] == $name_to_check[($i+1)] && $name_to_check[$i] == $name_to_check[($i+2)]) | |
145 | return false; | |
146 | for($i = 0; $i < strlen($name_to_check); $i++) | |
147 | if($name_to_check[$i-1] == ' ' && $name_to_check[$i+1] == ' ') | |
148 | return false; | |
149 | $temp = strspn("$name", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM- '"); | |
150 | if ($temp != strlen($name)) | |
151 | return false; | |
152 | ||
153 | ||
154 | $monsters_data = new SimpleXMLElement(file_get_contents($config['site']['serverPath'] . 'data/monster/monsters.xml')); | |
155 | foreach ($monsters_data->monster as $v) { | |
156 | if (strtolower($v['name']) == strtolower($name)) { | |
157 | return false; | |
158 | } | |
159 | } | |
160 | ||
161 | foreach (glob($config['site']['serverPath'] . 'data/npc/*.xml') as $npcFile) { | |
162 | if (strtolower(basename($npcFile, '.xml')) == $name_to_check) { | |
163 | return false; | |
164 | } | |
165 | } | |
166 | ||
167 | if(strlen($name) < 1) | |
168 | return false; | |
169 | if(strlen($name) > 25) | |
170 | return false; | |
171 | ||
172 | return true; | |
173 | } | |
174 | ||
175 | function check_rank_name($name) | |
176 | { | |
177 | $name = (string) $name; | |
178 | $temp = strspn("$name", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789-[ ] "); | |
179 | if($temp != strlen($name)) | |
180 | return false; | |
181 | if(strlen($name) < 1) | |
182 | return false; | |
183 | if(strlen($name) > 60) | |
184 | return false; | |
185 | ||
186 | return true; | |
187 | } | |
188 | ||
189 | function check_guild_name($name) | |
190 | { | |
191 | $name = (string) $name; | |
192 | $words_blocked = array('--', "''","' ", " '", '- ', ' -', "-'", "'-", ' '); | |
193 | $temp = strspn("$name", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789-' "); | |
194 | if($temp != strlen($name)) | |
195 | return false; | |
196 | if(strlen($name) < 1) | |
197 | return false; | |
198 | if(strlen($name) > 60) | |
199 | return false; | |
200 | ||
201 | foreach($words_blocked as $word) | |
202 | if (!(strpos($name, $word) === false)) | |
203 | return false; | |
204 | ||
205 | return true; | |
206 | } | |
207 | ||
208 | function check_password($pass) | |
209 | { | |
210 | $pass = (string) $pass; | |
211 | $temp = strspn("$pass", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890"); | |
212 | if($temp != strlen($pass)) | |
213 | return false; | |
214 | if(strlen($pass) > 40) | |
215 | return false; | |
216 | ||
217 | return true; | |
218 | } | |
219 | ||
220 | function check_mail($email) | |
221 | { | |
222 | $email = (string) $email; | |
223 | $ok = "/[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}/"; | |
224 | return (preg_match($ok, $email))? true: false; | |
225 | } | |
226 | ||
227 | function items_on_player($characterid, $pid) | |
228 | { | |
229 | new Error_Critic('', 'function <i>items_on_player</i> is deprecated. Do not use it. It used too many queries!'); | |
230 | } | |
231 | ||
232 | function getReason($reasonId) | |
233 | { | |
234 | return Functions::getBanReasonName($reasonId); | |
235 | } | |
236 | ||
237 | //################### DISPLAY FUNCTIONS ##################### | |
238 | //return shorter text (news ticker) | |
239 | function short_text($text, $chars_limit) | |
240 | { | |
241 | if(strlen($text) > $chars_limit) | |
242 | return substr($text, 0, strrpos(substr($text, 0, $chars_limit), " ")).'...'; | |
243 | else | |
244 | return $text; | |
245 | } | |
246 | //return text to news msg | |
247 | function news_place() | |
248 | { | |
249 | return ''; | |
250 | } | |
251 | //set monster of week | |
252 | function logo_monster() | |
253 | { | |
254 | new Error_Critic('', 'function <i>logo_monster</i> is deprecated. Do not use it!'); | |
255 | } | |
256 | ||
257 | // we don't want to count AJAX scripts/guild images as page views, we also don't need status | |
258 | if(!ONLY_PAGE) | |
259 | { | |
260 | // STATUS CHECKER | |
261 | $statustimeout = 1; | |
262 | foreach(explode("*", str_replace(" ", "", $config['server']['statusTimeout'])) as $status_var) | |
263 | if($status_var > 0) | |
264 | $statustimeout = $statustimeout * $status_var; | |
265 | $statustimeout = $statustimeout / 1000; | |
266 | $config['status'] = parse_ini_file('cache/DONT_EDIT_serverstatus.txt'); | |
267 | if($config['status']['serverStatus_lastCheck']+$statustimeout < time()) | |
268 | { | |
269 | $config['status']['serverStatus_checkInterval'] = $statustimeout+3; | |
270 | $config['status']['serverStatus_lastCheck'] = time(); | |
271 | $statusInfo = new ServerStatus($config['server']['ip'], $config['server']['statusPort'], 1); | |
272 | if($statusInfo->isOnline()) | |
273 | { | |
274 | $config['status']['serverStatus_online'] = 1; | |
275 | $config['status']['serverStatus_players'] = $statusInfo->getPlayersCount(); | |
276 | $config['status']['serverStatus_playersMax'] = $statusInfo->getPlayersMaxCount(); | |
277 | $h = floor($statusInfo->getUptime() / 3600); | |
278 | $m = floor(($statusInfo->getUptime() - $h*3600) / 60); | |
279 | $config['status']['serverStatus_uptime'] = $h.'h '.$m.'m'; | |
280 | $config['status']['serverStatus_monsters'] = $statusInfo->getMonsters(); | |
281 | } | |
282 | else | |
283 | { | |
284 | $config['status']['serverStatus_online'] = 0; | |
285 | $config['status']['serverStatus_players'] = 0; | |
286 | $config['status']['serverStatus_playersMax'] = 0; | |
287 | } | |
288 | $file = fopen("cache/DONT_EDIT_serverstatus.txt", "w"); | |
289 | $file_data = ''; | |
290 | foreach($config['status'] as $param => $data) | |
291 | { | |
292 | $file_data .= $param.' = "'.str_replace('"', '', $data).'" | |
293 | '; | |
294 | } | |
295 | rewind($file); | |
296 | fwrite($file, $file_data); | |
297 | fclose($file); | |
298 | } | |
299 | //PAGE VIEWS COUNTER | |
300 | $views_counter = "cache/DONT_EDIT_usercounter.txt"; | |
301 | // checking if the file exists | |
302 | if (file_exists($views_counter)) | |
303 | { | |
304 | $actie = fopen($views_counter, "r+"); | |
305 | $page_views = fgets($actie, 9); | |
306 | $page_views++; | |
307 | rewind($actie); | |
308 | fputs($actie, $page_views, 9); | |
309 | fclose($actie); | |
310 | } | |
311 | else | |
312 | { | |
313 | // the file doesn't exist, creating a new one with value 1 | |
314 | $actie = fopen($views_counter, "w"); | |
315 | $page_views = 1; | |
316 | fputs($actie, $page_views, 9); | |
317 | fclose($actie); | |
318 | } | |
319 | } |