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