· 7 years ago · Sep 10, 2018, 11:56 PM
1<?php
2define('DATABASE_NAME', 'ripple');
3define('DATABASE_USER', 'DB_USR');
4define('DATABASE_PASS', 'DB_PSW');
5define('DATABASE_HOST', 'localhost');
6define('DATABASE_WHAT', 'host');
7
8$db = new DBPDO();
9
10$q = <<<'ENDOFMYSQLQUERY'
11SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
12CREATE DATABASE IF NOT EXISTS `ripple` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
13USE `ripple`;
14
15CREATE TABLE IF NOT EXISTS `2fa` (
16 `userid` int(11) NOT NULL,
17 `ip` int(11) NOT NULL,
18 PRIMARY KEY (`userid`)
19) ENGINE=InnoDB DEFAULT CHARSET=latin1;
20
21CREATE TABLE IF NOT EXISTS `2fa_telegram` (
22 `id` int(11) NOT NULL AUTO_INCREMENT,
23 `userid` int(11) NOT NULL,
24 PRIMARY KEY (`id`)
25) ENGINE=InnoDB DEFAULT CHARSET=latin1;
26
27CREATE TABLE IF NOT EXISTS `2fa_totp` (
28 `enabled` tinyint(1) NOT NULL DEFAULT '0',
29 `userid` int(11) NOT NULL,
30 PRIMARY KEY (`userid`)
31) ENGINE=InnoDB DEFAULT CHARSET=latin1;
32
33CREATE TABLE IF NOT EXISTS `achievements` (
34 `id` int(11) NOT NULL AUTO_INCREMENT,
35 `name` varchar(64) NOT NULL,
36 `description` varchar(128) NOT NULL,
37 `icon` varchar(32) NOT NULL,
38 `version` int(11) NOT NULL DEFAULT '0',
39 PRIMARY KEY (`id`)
40) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
41
42CREATE TABLE IF NOT EXISTS `badges` (
43 `id` int(11) NOT NULL AUTO_INCREMENT,
44 `name` varchar(32) NOT NULL,
45 `icon` varchar(32) NOT NULL,
46 PRIMARY KEY (`id`)
47) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
48
49INSERT INTO `badges` (`id`, `name`, `icon`) VALUES
50(1, 'Beta tester 1.5', 'fa-gift'),
51(2, 'None', '');
52
53CREATE TABLE IF NOT EXISTS `bancho_channels` (
54 `id` int(11) NOT NULL AUTO_INCREMENT,
55 `name` varchar(32) NOT NULL,
56 `description` varchar(127) NOT NULL,
57 `public_read` tinyint(4) NOT NULL,
58 `public_write` tinyint(4) NOT NULL,
59 `status` tinyint(4) NOT NULL,
60 `temp` tinyint(1) NOT NULL DEFAULT '0',
61 `hidden` tinyint(1) NOT NULL DEFAULT '0',
62 PRIMARY KEY (`id`)
63) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
64
65INSERT INTO `bancho_channels` (`id`, `name`, `description`, `public_read`, `public_write`, `status`, `temp`, `hidden`) VALUES
66(1, '#osu', 'Main Ripple channel', 1, 1, 1, 0, 0),
67(2, '#announce', 'Announce channel', 1, 0, 1, 0, 0),
68(3, '#admin', 'Admin only channel', 0, 0, 1, 0, 0),
69(4, '#italian', 'Italian community channel', 1, 1, 1, 0, 0),
70(5, '#english', 'English speaking channel', 1, 1, 1, 0, 0);
71
72CREATE TABLE IF NOT EXISTS `bancho_messages` (
73 `id` int(11) NOT NULL AUTO_INCREMENT,
74 `msg_from_userid` int(11) NOT NULL,
75 `msg_from_username` varchar(30) NOT NULL,
76 `msg_to` varchar(32) NOT NULL,
77 `msg` varchar(127) NOT NULL,
78 `time` int(11) NOT NULL,
79 PRIMARY KEY (`id`)
80) ENGINE=InnoDB DEFAULT CHARSET=latin1;
81
82CREATE TABLE IF NOT EXISTS `bancho_private_messages` (
83 `id` int(11) NOT NULL AUTO_INCREMENT,
84 `msg_from_userid` int(11) NOT NULL,
85 `msg_from_username` varchar(30) NOT NULL,
86 `msg_to` varchar(32) NOT NULL,
87 `msg` varchar(127) NOT NULL,
88 `time` int(11) NOT NULL,
89 PRIMARY KEY (`id`)
90) ENGINE=InnoDB DEFAULT CHARSET=latin1;
91
92CREATE TABLE IF NOT EXISTS `bancho_settings` (
93 `id` int(11) NOT NULL AUTO_INCREMENT,
94 `name` varchar(32) NOT NULL,
95 `value_int` int(11) NOT NULL DEFAULT '0',
96 `value_string` varchar(512) NOT NULL,
97 PRIMARY KEY (`id`)
98) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
99
100INSERT INTO `bancho_settings` (`id`, `name`, `value_int`, `value_string`) VALUES
101(1, 'bancho_maintenance', 0, ''),
102(2, 'free_direct', 1, ''),
103(3, 'menu_icon', 0, 'https://i.imgur.com/L61sxgX.png|http://emily.steffen.sexy'),
104(4, 'login_messages', 0, ''),
105(5, 'restricted_joke', 0, ''),
106(6, 'login_notification', 0, 'Welcome to pep.py'),
107(7, 'osu_versions', 0, ''),
108(8, 'osu_md5s', 0, '');
109
110
111CREATE TABLE IF NOT EXISTS `bancho_tokens` (
112 `id` int(11) NOT NULL AUTO_INCREMENT,
113 `token` varchar(16) NOT NULL,
114 `osu_id` int(11) NOT NULL,
115 `latest_message_id` int(11) NOT NULL,
116 `latest_private_message_id` int(11) NOT NULL,
117 `latest_packet_time` int(11) NOT NULL,
118 `latest_heavy_packet_time` int(11) NOT NULL,
119 `joined_channels` varchar(512) NOT NULL,
120 `game_mode` tinyint(4) NOT NULL,
121 `action` int(11) NOT NULL,
122 `action_text` varchar(128) NOT NULL,
123 `kicked` tinyint(4) NOT NULL,
124 PRIMARY KEY (`id`)
125) ENGINE=InnoDB DEFAULT CHARSET=latin1;
126
127CREATE TABLE IF NOT EXISTS `beatmaps` (
128 `id` int(11) NOT NULL AUTO_INCREMENT,
129 `beatmap_id` int(11) NOT NULL DEFAULT '0',
130 `beatmapset_id` int(11) NOT NULL DEFAULT '0',
131 `beatmap_md5` varchar(32) NOT NULL DEFAULT '',
132 `song_name` varchar(128) NOT NULL DEFAULT '',
133 `ar` float NOT NULL DEFAULT '0',
134 `od` float NOT NULL DEFAULT '0',
135 `difficulty_std` float NOT NULL DEFAULT '0',
136 `difficulty_taiko` float NOT NULL DEFAULT '0',
137 `difficulty_ctb` float NOT NULL DEFAULT '0',
138 `difficulty_mania` float NOT NULL DEFAULT '0',
139 `max_combo` int(11) NOT NULL DEFAULT '0',
140 `hit_length` int(11) NOT NULL DEFAULT '0',
141 `bpm` int(11) NOT NULL DEFAULT '0',
142 `ranked` tinyint(4) NOT NULL DEFAULT '0',
143 `latest_update` int(11) NOT NULL DEFAULT '0',
144 `ranked_status_freezed` tinyint(1) NOT NULL DEFAULT '0',
145 `playcount` int(11) NOT NULL DEFAULT '0',
146 `passcount` int(11) NOT NULL DEFAULT '0',
147 `pp_100` int(11) NOT NULL DEFAULT '0',
148 `pp_99` int(11) NOT NULL DEFAULT '0',
149 `pp_98` int(11) NOT NULL DEFAULT '0',
150 `pp_95` int(11) NOT NULL DEFAULT '0',
151 PRIMARY KEY (`id`)
152) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
153
154CREATE TABLE IF NOT EXISTS `beatmaps_names` (
155 `id` int(11) NOT NULL AUTO_INCREMENT,
156 `beatmap_md5` varchar(32) NOT NULL DEFAULT '',
157 `beatmap_name` varchar(256) NOT NULL DEFAULT '',
158 PRIMARY KEY (`id`)
159) ENGINE=InnoDB DEFAULT CHARSET=latin1;
160
161CREATE TABLE IF NOT EXISTS `beta_keys` (
162 `id` int(11) NOT NULL AUTO_INCREMENT,
163 `key_md5` varchar(32) NOT NULL DEFAULT '',
164 `description` varchar(128) NOT NULL DEFAULT '',
165 `allowed` tinyint(4) NOT NULL DEFAULT '0',
166 `public` tinyint(4) NOT NULL DEFAULT '0',
167 PRIMARY KEY (`id`)
168) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
169
170INSERT INTO `beta_keys` (`id`, `key_md5`, `description`, `allowed`, `public`) VALUES
171(1, '110fe4a3830966be01d0b513fcdb4f66', 'betakey', 1, 1);
172
173CREATE TABLE IF NOT EXISTS `comments` (
174 `id` int(11) NOT NULL AUTO_INCREMENT,
175 `beatmap_id` int(11) DEFAULT NULL,
176 `beatmapset_id` int(11) DEFAULT NULL,
177 `score_id` int(11) DEFAULT NULL,
178 `mode` int(11) NOT NULL DEFAULT '0',
179 `user_id` int(11) NOT NULL,
180 `comment` varchar(128) NOT NULL,
181 `time` int(11) NOT NULL,
182 `who` enum('normal','player','admin','donor') DEFAULT NULL,
183 `special_format` varchar(8) DEFAULT NULL,
184 PRIMARY KEY (`id`)
185) ENGINE=InnoDB DEFAULT CHARSET=latin1;
186
187CREATE TABLE IF NOT EXISTS `cakes` (
188 `id` int(11) NOT NULL AUTO_INCREMENT,
189 `userid` int(11) NOT NULL,
190 `score_id` int(11) NOT NULL,
191 `processes` blob NOT NULL,
192 `detected` json NOT NULL,
193 `flags` int(11) NOT NULL DEFAULT '0',
194 PRIMARY KEY (`id`)
195) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
196
197CREATE TABLE IF NOT EXISTS `discord_roles` (
198 `id` int(11) NOT NULL AUTO_INCREMENT,
199 `userid` int(11) NOT NULL,
200 `discordid` int(11) NOT NULL,
201 `roleid` int(11) NOT NULL,
202 PRIMARY KEY (`id`)
203) ENGINE=InnoDB DEFAULT CHARSET=latin1;
204
205CREATE TABLE IF NOT EXISTS `docs` (
206 `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
207 `doc_name` varchar(255) NOT NULL DEFAULT 'New Documentation File',
208 `doc_contents` mediumtext NOT NULL,
209 `public` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
210 `old_name` varchar(200) DEFAULT NULL,
211 PRIMARY KEY (`id`)
212) ENGINE=MyISAM DEFAULT CHARSET=latin1;
213
214CREATE TABLE IF NOT EXISTS `eggs` (
215 `id` int(11) NOT NULL AUTO_INCREMENT,
216 `type` enum('hash','path','file','title') NOT NULL DEFAULT 'hash',
217 `value` varchar(128) NOT NULL,
218 `tag` varchar(128) NOT NULL,
219 `ban` tinyint(1) NOT NULL DEFAULT '0',
220 `is_regex` tinyint(1) NOT NULL DEFAULT '0',
221 PRIMARY KEY (`id`)
222) ENGINE=InnoDB DEFAULT CHARSET=latin1;
223
224CREATE TABLE IF NOT EXISTS `hw_user` (
225 `id` int(11) NOT NULL AUTO_INCREMENT,
226 `userid` int(11) NOT NULL,
227 `mac` varchar(32) NOT NULL,
228 `unique_id` varchar(32) NOT NULL,
229 `disk_id` varchar(32) NOT NULL,
230 `occurencies` int(11) NOT NULL DEFAULT '0',
231 `activated` tinyint(1) NOT NULL DEFAULT '0',
232 PRIMARY KEY (`id`),
233 UNIQUE KEY `userid` (`userid`)
234) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
235
236CREATE TABLE IF NOT EXISTS `identity_tokens` (
237 `userid` int(11) NOT NULL,
238 `token` varchar(64) NOT NULL,
239 UNIQUE KEY `userid` (`userid`)
240) ENGINE=InnoDB DEFAULT CHARSET=latin1;
241
242CREATE TABLE IF NOT EXISTS `ip_user` (
243 `userid` int(11) NOT NULL,
244 `ip` text NOT NULL,
245 `occurencies` int(11) NOT NULL,
246 UNIQUE KEY `userid` (`userid`)
247) ENGINE=InnoDB DEFAULT CHARSET=latin1;
248
249CREATE TABLE IF NOT EXISTS `irc_tokens` (
250 `userid` int(11) NOT NULL DEFAULT '0',
251 `token` varchar(32) NOT NULL DEFAULT '',
252 UNIQUE KEY `userid` (`userid`)
253) ENGINE=InnoDB DEFAULT CHARSET=latin1;
254
255CREATE TABLE IF NOT EXISTS `leaderboard_ctb` (
256 `position` int(10) UNSIGNED NOT NULL,
257 `user` int(11) NOT NULL,
258 `v` bigint(20) NOT NULL,
259 PRIMARY KEY (`position`)
260) ENGINE=InnoDB DEFAULT CHARSET=latin1;
261
262CREATE TABLE IF NOT EXISTS `leaderboard_mania` (
263 `position` int(10) UNSIGNED NOT NULL,
264 `user` int(11) NOT NULL,
265 `v` bigint(20) NOT NULL,
266 PRIMARY KEY (`position`)
267) ENGINE=InnoDB DEFAULT CHARSET=latin1;
268
269CREATE TABLE IF NOT EXISTS `leaderboard_std` (
270 `position` int(10) UNSIGNED NOT NULL,
271 `user` int(11) NOT NULL,
272 `v` bigint(20) NOT NULL,
273 PRIMARY KEY (`position`)
274) ENGINE=InnoDB DEFAULT CHARSET=latin1;
275
276CREATE TABLE IF NOT EXISTS `leaderboard_taiko` (
277 `position` int(10) UNSIGNED NOT NULL,
278 `user` int(11) NOT NULL,
279 `v` bigint(20) NOT NULL,
280 PRIMARY KEY (`position`)
281) ENGINE=InnoDB DEFAULT CHARSET=latin1;
282
283CREATE TABLE IF NOT EXISTS `main_menu_icons` (
284 `file_id` int(11) NOT NULL AUTO_INCREMENT,
285 `url` varchar(128) NOT NULL,
286 `is_current` tinyint(1) NOT NULL,
287 PRIMARY KEY (`file_id`)
288) ENGINE=InnoDB DEFAULT CHARSET=latin1;
289
290CREATE TABLE IF NOT EXISTS `osin_access` (
291 `scope` int(11) NOT NULL DEFAULT '0',
292 `created_at` int(11) NOT NULL DEFAULT '0',
293 `client` int(11) NOT NULL DEFAULT '0',
294 `extra` int(11) NOT NULL DEFAULT '0'
295) ENGINE=InnoDB DEFAULT CHARSET=latin1;
296
297CREATE TABLE IF NOT EXISTS `osin_client` (
298 `id` int(11) NOT NULL AUTO_INCREMENT,
299 `secret` varchar(64) NOT NULL DEFAULT '',
300 `extra` varchar(127) NOT NULL DEFAULT '',
301 `redirect_uri` varchar(127) NOT NULL DEFAULT '',
302 PRIMARY KEY (`id`)
303) ENGINE=InnoDB DEFAULT CHARSET=latin1;
304
305CREATE TABLE IF NOT EXISTS `osin_client_user` (
306 `client_id` int(11) NOT NULL DEFAULT '0',
307 `user` int(11) NOT NULL DEFAULT '0'
308) ENGINE=InnoDB DEFAULT CHARSET=latin1;
309
310CREATE TABLE IF NOT EXISTS `password_recovery` (
311 `id` int(11) NOT NULL AUTO_INCREMENT,
312 `k` varchar(80) NOT NULL,
313 `u` varchar(30) NOT NULL,
314 `t` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
315 PRIMARY KEY (`id`)
316) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
317
318CREATE TABLE IF NOT EXISTS `privileges_groups` (
319 `id` int(11) NOT NULL AUTO_INCREMENT,
320 `name` varchar(32) NOT NULL,
321 `privileges` int(11) NOT NULL,
322 `color` varchar(32) NOT NULL,
323 PRIMARY KEY (`id`),
324 UNIQUE KEY `name` (`name`)
325) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
326
327INSERT INTO `privileges_groups` (`id`, `name`, `privileges`, `color`) VALUES
328(1, 'Banned', 0, ''),
329(2, 'BAT', 267, ''),
330(3, 'Chat Moderators', 2883911, ''),
331(4, 'Community Manager ', 978427, ''),
332(5, 'Developer', 1043995, ''),
333(6, 'Donor', 7, ''),
334(7, 'God', 1048575, 'primary'),
335(8, 'Normal User', 3, ''),
336(9, 'Pending', 1048576, ''),
337(10, 'Restricted', 2, '');
338
339CREATE TABLE IF NOT EXISTS `profile_backgrounds` (
340 `uid` int(11) NOT NULL,
341 `time` int(11) NOT NULL,
342 `type` int(11) NOT NULL,
343 `value` text NOT NULL,
344 PRIMARY KEY (`uid`)
345) ENGINE=InnoDB DEFAULT CHARSET=latin1;
346
347CREATE TABLE IF NOT EXISTS `rank_requests` (
348 `id` int(11) NOT NULL AUTO_INCREMENT,
349 `userid` int(11) NOT NULL,
350 `bid` int(11) NOT NULL,
351 `type` varchar(8) NOT NULL,
352 `time` int(11) NOT NULL,
353 `blacklisted` tinyint(1) NOT NULL,
354 PRIMARY KEY (`id`),
355 UNIQUE KEY `bid` (`bid`)
356) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
357
358CREATE TABLE IF NOT EXISTS `rap_logs` (
359 `id` int(11) NOT NULL AUTO_INCREMENT,
360 `userid` int(11) NOT NULL,
361 `text` varchar(512) NOT NULL,
362 `datetime` int(11) NOT NULL,
363 `through` varchar(64) NOT NULL,
364 PRIMARY KEY (`id`)
365) ENGINE=InnoDB DEFAULT CHARSET=latin1;
366
367
368CREATE TABLE IF NOT EXISTS `remember` (
369 `id` int(11) NOT NULL AUTO_INCREMENT,
370 `userid` int(11) NOT NULL,
371 `series_identifier` int(11) DEFAULT NULL,
372 `token_sha` varchar(255) DEFAULT NULL,
373 PRIMARY KEY (`id`)
374) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
375
376CREATE TABLE IF NOT EXISTS `reports` (
377 `id` int(11) NOT NULL AUTO_INCREMENT,
378 `name` varchar(128) NOT NULL,
379 `from_username` varchar(32) NOT NULL,
380 `content` varchar(1024) NOT NULL,
381 `type` tinyint(4) NOT NULL,
382 `open_time` varchar(18) NOT NULL,
383 `update_time` varchar(18) NOT NULL,
384 `status` tinyint(4) NOT NULL,
385 `response` varchar(1024) NOT NULL,
386 PRIMARY KEY (`id`)
387) ENGINE=InnoDB DEFAULT CHARSET=latin1;
388
389CREATE TABLE IF NOT EXISTS `scores` (
390 `id` int(11) NOT NULL AUTO_INCREMENT,
391 `beatmap_md5` varchar(32) NOT NULL DEFAULT '',
392 `userid` int(11) NOT NULL,
393 `score` bigint(20) DEFAULT NULL,
394 `max_combo` int(11) NOT NULL DEFAULT '0',
395 `full_combo` tinyint(1) NOT NULL DEFAULT '0',
396 `mods` int(11) NOT NULL DEFAULT '0',
397 `300_count` int(11) NOT NULL DEFAULT '0',
398 `100_count` int(11) NOT NULL DEFAULT '0',
399 `50_count` int(11) NOT NULL DEFAULT '0',
400 `katus_count` int(11) NOT NULL DEFAULT '0',
401 `gekis_count` int(11) NOT NULL DEFAULT '0',
402 `misses_count` int(11) NOT NULL DEFAULT '0',
403 `time` varchar(18) NOT NULL DEFAULT '',
404 `play_mode` tinyint(4) NOT NULL DEFAULT '0',
405 `completed` tinyint(11) NOT NULL DEFAULT '0',
406 `accuracy` float(15,12) DEFAULT NULL,
407 `pp` float DEFAULT '0',
408 PRIMARY KEY (`id`)
409) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
410
411CREATE TABLE IF NOT EXISTS `system_settings` (
412 `id` int(11) NOT NULL AUTO_INCREMENT,
413 `name` varchar(32) NOT NULL,
414 `value_int` int(11) NOT NULL DEFAULT '0',
415 `value_string` varchar(512) NOT NULL,
416 PRIMARY KEY (`id`)
417) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
418
419INSERT INTO `system_settings` (`id`, `name`, `value_int`, `value_string`) VALUES
420(1, 'website_maintenance', 0, ''),
421(2, 'game_maintenance', 0, ''),
422(3, 'website_global_alert', 0, ''),
423(4, 'website_home_alert', 0, ''),
424(5, 'registrations_enabled', 1, '');
425
426CREATE TABLE IF NOT EXISTS `tokens` (
427 `id` int(11) NOT NULL AUTO_INCREMENT,
428 `user` varchar(31) NOT NULL,
429 `privileges` int(11) NOT NULL,
430 `description` varchar(255) NOT NULL,
431 `token` varchar(127) NOT NULL,
432 `private` tinyint(4) NOT NULL,
433 `last_updated` int(11) NOT NULL DEFAULT '0',
434 PRIMARY KEY (`id`)
435) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
436
437CREATE TABLE IF NOT EXISTS `users` (
438 `id` int(11) NOT NULL AUTO_INCREMENT,
439 `username` varchar(30) NOT NULL,
440 `username_safe` varchar(30) NOT NULL,
441 `password_md5` varchar(127) NOT NULL,
442 `salt` varchar(32) NOT NULL,
443 `email` varchar(254) NOT NULL,
444 `register_datetime` int(10) NOT NULL,
445 `rank` tinyint(1) NOT NULL DEFAULT '1',
446 `achievements_version` int(11) NOT NULL DEFAULT '0',
447 `allowed` tinyint(1) NOT NULL DEFAULT '1',
448 `latest_activity` int(10) NOT NULL DEFAULT '0',
449 `silence_end` int(11) NOT NULL DEFAULT '0',
450 `silence_reason` varchar(127) NOT NULL DEFAULT '',
451 `notes` varchar(127) NOT NULL DEFAULT '',
452 `ban_datetime` int(11) NOT NULL DEFAULT '0',
453 `password_version` tinyint(4) NOT NULL DEFAULT '1',
454 `privileges` int(11) NOT NULL,
455 `donor_expire` int(11) NOT NULL DEFAULT '0',
456 `flags` int(11) NOT NULL DEFAULT '0',
457 PRIMARY KEY (`id`)
458) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
459
460CREATE TABLE IF NOT EXISTS `users_achievements` (
461 `user_id` int(11) NOT NULL,
462 `achievement_id` int(11) NOT NULL,
463 `time` int(11) NOT NULL
464) ENGINE=InnoDB DEFAULT CHARSET=latin1;
465
466CREATE TABLE IF NOT EXISTS `users_relationships` (
467 `id` int(11) NOT NULL AUTO_INCREMENT,
468 `user1` int(11) NOT NULL,
469 `user2` int(11) NOT NULL,
470 PRIMARY KEY (`id`)
471) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
472
473CREATE TABLE IF NOT EXISTS `users_stats` (
474 `id` int(11) NOT NULL AUTO_INCREMENT,
475 `username` varchar(30) NOT NULL,
476 `username_aka` varchar(32) NOT NULL DEFAULT '',
477 `user_color` varchar(16) NOT NULL DEFAULT 'black',
478 `user_style` varchar(128) NOT NULL DEFAULT '',
479 `ranked_score_std` bigint(20) DEFAULT NULL,
480 `playcount_std` int(11) NOT NULL DEFAULT '0',
481 `total_score_std` bigint(20) DEFAULT NULL,
482 `replays_watched_std` int(11) UNSIGNED NOT NULL DEFAULT '0',
483 `ranked_score_taiko` bigint(20) DEFAULT NULL,
484 `playcount_taiko` int(11) NOT NULL DEFAULT '0',
485 `total_score_taiko` bigint(20) DEFAULT NULL,
486 `replays_watched_taiko` int(11) NOT NULL DEFAULT '0',
487 `ranked_score_ctb` bigint(20) DEFAULT NULL,
488 `playcount_ctb` int(11) NOT NULL DEFAULT '0',
489 `total_score_ctb` bigint(20) DEFAULT NULL,
490 `replays_watched_ctb` int(11) NOT NULL DEFAULT '0',
491 `ranked_score_mania` bigint(20) DEFAULT NULL,
492 `playcount_mania` int(11) NOT NULL DEFAULT '0',
493 `total_score_mania` bigint(20) DEFAULT NULL,
494 `replays_watched_mania` int(10) UNSIGNED NOT NULL DEFAULT '0',
495 `total_hits_std` int(11) NOT NULL DEFAULT '0',
496 `total_hits_taiko` int(11) NOT NULL DEFAULT '0',
497 `total_hits_ctb` int(11) NOT NULL DEFAULT '0',
498 `total_hits_mania` int(11) NOT NULL DEFAULT '0',
499 `country` char(2) NOT NULL DEFAULT 'XX',
500 `show_country` tinyint(4) NOT NULL DEFAULT '1',
501 `level_std` int(11) NOT NULL DEFAULT '1',
502 `level_taiko` int(11) NOT NULL DEFAULT '1',
503 `level_ctb` int(11) NOT NULL DEFAULT '1',
504 `level_mania` int(11) NOT NULL DEFAULT '1',
505 `avg_accuracy_std` float(15,12) NOT NULL DEFAULT '0.000000000000',
506 `avg_accuracy_taiko` float(15,12) NOT NULL DEFAULT '0.000000000000',
507 `avg_accuracy_ctb` float(15,12) NOT NULL DEFAULT '0.000000000000',
508 `avg_accuracy_mania` float(15,12) NOT NULL DEFAULT '0.000000000000',
509 `pp_std` int(11) NOT NULL DEFAULT '0',
510 `pp_taiko` int(11) NOT NULL DEFAULT '0',
511 `pp_ctb` int(11) NOT NULL DEFAULT '0',
512 `pp_mania` int(11) NOT NULL DEFAULT '0',
513 `badges_shown` varchar(24) NOT NULL DEFAULT '1,0,0,0,0,0',
514 `safe_title` tinyint(4) NOT NULL DEFAULT '0',
515 `userpage_content` mediumtext,
516 `play_style` smallint(6) NOT NULL DEFAULT '0',
517 `favourite_mode` tinyint(4) NOT NULL DEFAULT '0',
518 `custom_badge_icon` varchar(32) NOT NULL DEFAULT '',
519 `custom_badge_name` varchar(32) NOT NULL DEFAULT '',
520 `can_custom_badge` tinyint(1) NOT NULL DEFAULT '0',
521 `show_custom_badge` tinyint(1) NOT NULL DEFAULT '0',
522 PRIMARY KEY (`id`)
523) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
524
525CREATE TABLE IF NOT EXISTS `user_badges` (
526 `user` int(11) NOT NULL,
527 `badge` int(11) NOT NULL,
528 PRIMARY KEY (`user`)
529) ENGINE=InnoDB DEFAULT CHARSET=latin1;
530ENDOFMYSQLQUERY;
531
532$db->execute($q);
533
534function randomString($l) {
535 $c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
536 $res = '';
537 srand((float) microtime() * 1000000);
538 for ($i = 0; $i < $l; $i++) {
539 $res .= $c[rand() % strlen($c)];
540 }
541
542 return $res;
543}
544
545echo "Fokabot doesn't exist. Creating account...\n";
546$plainPassword = randomString(8);
547$options = ['cost' => 9, 'salt' => base64_decode(base64_encode(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)))];
548$md5Password = crypt(md5($plainPassword), '$2y$'.$options['salt']);
549$db->execute("INSERT INTO `users`(`id`, `username`, `username_safe`, `password_md5`, `salt`, `email`, `register_datetime`, `rank`, `allowed`, `latest_activity`, `silence_end`, `silence_reason`, `password_version`, `privileges`, `flags`) VALUES ('999', 'FokaBot', 'fokabot', ?, ?, 'fo@kab.ot', '1452544880', '4', '1', '0', '0', '', 1, 978427, 0);", [$md5Password, base64_encode($options['salt'])]);
550$db->execute("INSERT INTO `users_stats`(`id`, `username`, `username_aka`, `user_color`, `user_style`, `ranked_score_std`, `playcount_std`, `total_score_std`, `replays_watched_std`, `ranked_score_taiko`, `playcount_taiko`, `total_score_taiko`, `replays_watched_taiko`, `ranked_score_ctb`, `playcount_ctb`, `total_score_ctb`, `replays_watched_ctb`, `ranked_score_mania`, `playcount_mania`, `total_score_mania`, `replays_watched_mania`, `total_hits_std`, `total_hits_taiko`, `total_hits_ctb`, `total_hits_mania`, `country`, `show_country`, `level_std`, `level_taiko`, `level_ctb`, `level_mania`, `avg_accuracy_std`, `avg_accuracy_taiko`, `avg_accuracy_ctb`, `avg_accuracy_mania`, `pp_std`, `pp_taiko`, `pp_ctb`, `pp_mania`, `badges_shown`, `safe_title`, `userpage_content`, `play_style`, `favourite_mode`) VALUES ('999', 'FokaBot', '', 'black', '', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'XX', '1', '0', '0', '0', '0', '0.000000000000', '0.000000000000', '0.000000000000', '0.000000000000', '0', '0', '0', '0', '3,4,11,0,0,0', '0', '', 0, 0);");
551echo 'Fokabot account created! Password is: '.$plainPassword."\n";
552echo 'Yepp... thats all we got for now. Some stuff might be missing as not everything is tested and set up correctly.';
553
554class DBPDO {
555 public $pdo;
556 private $error;
557
558 public function __construct() {
559 $this->connect();
560 }
561
562 public function prep_query($query) {
563 return $this->pdo->prepare($query);
564 }
565
566 public function connect() {
567 if (!$this->pdo) {
568 $dsn = 'mysql:dbname='.DATABASE_NAME.';'.DATABASE_WHAT.'='.DATABASE_HOST;
569 $user = DATABASE_USER;
570 $password = DATABASE_PASS;
571 try {
572 $this->pdo = new PDO($dsn, $user, $password, [PDO::ATTR_PERSISTENT => true]);
573
574 return true;
575 }
576 catch(PDOException $e) {
577 $this->error = $e->getMessage();
578 die($this->error);
579
580 return false;
581 }
582 } else {
583 $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
584
585 return true;
586 }
587 }
588
589 public function table_exists($table_name) {
590 $stmt = $this->prep_query('SHOW TABLES LIKE ?');
591 $stmt->execute([$this->add_table_prefix($table_name)]);
592
593 return $stmt->rowCount() > 0;
594 }
595
596 public function execute($query, $values = null) {
597 if ($values === null) {
598 $values = [];
599 } elseif (!is_array($values)) {
600 $values = [$values];
601 }
602 $stmt = $this->prep_query($query);
603 $stmt->execute($values);
604
605 return $stmt;
606 }
607
608 public function fetch($query, $values = null) {
609 if ($values === null) {
610 $values = [];
611 } elseif (!is_array($values)) {
612 $values = [$values];
613 }
614 $stmt = $this->execute($query, $values);
615
616 return $stmt->fetch(PDO::FETCH_ASSOC);
617 }
618
619 public function fetchAll($query, $values = null, $key = null) {
620 if ($values === null) {
621 $values = [];
622 } elseif (!is_array($values)) {
623 $values = [$values];
624 }
625 $stmt = $this->execute($query, $values);
626 $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
627 // Allows the user to retrieve results using a
628 // column from the results as a key for the array
629 if ($key != null && $results[0][$key]) {
630 $keyed_results = [];
631 foreach ($results as $result) {
632 $keyed_results[$result[$key]] = $result;
633 }
634 $results = $keyed_results;
635 }
636
637 return $results;
638 }
639
640 public function lastInsertId() {
641 return $this->pdo->lastInsertId();
642 }
643}
644?>