This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.php
931 lines (839 loc) · 42.6 KB
/
game.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
<script>
<?php
include('conn.php');
session_start();
$townID = $_SESSION["townID"];
$userID = $_SESSION["userID"];
$town = $_SESSION["town"];
$mob = $_SESSION["mob"];
$name = $_SESSION["name"];
?>
var town = <?php echo json_encode($town); ?>;
var townID = <?php echo json_encode($townID); ?>;
</script>
<div id="header">
<table cellpadding="0" cellspacing="0" style="width: 100%; padding-left: 1%; padding-right: 1%;">
<td><img src="/assets/images/logo.png" style="height: 65px;"></img></td>
<td style="text-align: right; vertical-align: top; padding-top: 20px;">
<nav>
<input class="header link" style="padding-left: 10px; padding-right: 10px;" type="button" value="Privacy Policy" onclick="openPrivacy()"></input>
<input class="header link" style="padding-left: 10px; padding-right: 10px;" type="button" value="Report Bug" onclick="openBug()"></input>
<input class="header link" style="padding-left: 10px; padding-right: 10px;" type="button" value="About Us" onclick="openAbout()"></input>
</nav>
</td>
</table>
</div>
<div id="notification" class="alert"></div>
<div style="display: none;">
<?php
$query = "SELECT daily_index FROM town_details WHERE town_id = '$townID';";
$tempIndex = mysqli_fetch_assoc(mysqli_query($conn, $query))["daily_index"];
if($_SESSION["dailyIndex"] != $tempIndex) {
if($tempIndex%2 == 0) {
$_SESSION["dailyIndex"] = $tempIndex;
$_SESSION["revealed"] = '';
$prev = $tempIndex/2;
$query = "SELECT COUNT(name) FROM town_" . $townID . " WHERE is_killed = 0 AND is_executed = 0;";
$dayVoteMajority = mysqli_fetch_assoc(mysqli_query($conn, $query))["COUNT(name)"] / 2;
$executed = '';
$query = "SELECT COUNT(day_" . $prev . "), day_" . $prev . " FROM town_" . $townID . " WHERE day_" . $prev . " <> 0 GROUP BY day_" . $prev . " ORDER BY COUNT(day_" . $prev . ") DESC;";
$row = mysqli_fetch_assoc(mysqli_query($conn, $query));
if($row["COUNT(day_" . $prev . ")"] > $dayVoteMajority) {
$query = "SELECT name FROM town_" . $townID . " WHERE user_id = " . $row["day_" . $prev] . ";";
$executed = mysqli_fetch_assoc(mysqli_query($conn, $query))["name"];
$query = "SELECT is_mafia, is_poser, is_medic, is_sherrif FROM town_" . $townID . " WHERE name = '$executed';";
if(mysqli_fetch_assoc(mysqli_query($conn, $query))["is_mafia"])
$role = 'a *Mafia* member';
else if(mysqli_fetch_assoc(mysqli_query($conn, $query))["is_poser"])
$role = 'the *Poser*';
else if(mysqli_fetch_assoc(mysqli_query($conn, $query))["is_sherrif"])
$role = 'the towns *Sheriff*';
else if(mysqli_fetch_assoc(mysqli_query($conn, $query))["is_medic"])
$role = 'the towns *Medic*';
else
$role = 'just a *Citizen*';
}
$message = '<p id="news-update">You are in the underworld. There is no way to contact anyone from here. Maybe make a deal with Lucifer?</p>';
$postMessage = 'The citizens of *' . $town . '* are sleeping. Zzz</p>';
$flag = 1;
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_mafia = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$query = "SELECT name FROM town_" . $townID . " WHERE is_mafia = 1 AND is_killed = 0 AND is_executed = 0;";
$killer = mysqli_fetch_assoc(mysqli_query($conn, $query))["name"];
$postMessage = 'Discuss below with the other mafia members on who is to be killed, after that *' . $killer . '* has to click the *Kill* button to choose the next victim.</p>';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_medic = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$postMessage = 'Click the *Heal* button to choose who you\'d like to heal tonight.</p>';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_sherrif = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$postMessage = 'Click the *Reveal* button to find out more about the citizens of *' . $town . '* before the night ends.</p>';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)))
if($executed != '')
$message = '<p id="news-update">Citizens of *' . $town . '*, after the execution it was discovered that *' . $executed . '* was ' . $role . '. ' . $postMessage;
else
$message = '<p id="news-update">Citizens of *' . $town . '*, yesterday no one was executed. ' . $postMessage;
$message .= "<script>
clearInterval(indexTimeout);
indexTimeout = setInterval(function() {
var timer = document.getElementById('timer');
var timerMobile = document.getElementById('timer-mobile');
if (timer.innerHTML == '0') {
clearInterval(indexTimeout)
} else {
timer.innerHTML -= 1;
timerMobile.innerHTML -= 1;
if (timer.innerHTML == '0') {
timeUp();
clearInterval(indexTimeout)
}
}
}, 1000);
</script>";
$_SESSION["message"] = $message;
}
else {
$_SESSION["dailyIndex"] = $tempIndex;
$prev = $tempIndex/2 - 0.5;
$query = "SELECT name FROM town_" . $townID . " WHERE night_" . $prev . " <> 0;";
$killed = mysqli_fetch_assoc(mysqli_query($conn, $query))["name"];
$query = "SELECT name FROM town_" . $townID . " WHERE medic_" . $prev . " <> 0;";
$healed = mysqli_fetch_assoc(mysqli_query($conn, $query))["name"];
$message = '<p id="news-update">You are in the underworld. There is no way to contact anyone from here. Maybe make a deal with Lucifer?</p>';
$query = "SELECT name FROM town_" . $townID . " WHERE is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query))) {
if($killed != $healed)
$message = '<p id="news-update">Citizens of *' . $town . '*, I\'m afraid I have some bad news. Last night *' . $mob . '* struck again and murdered *' . $killed . '*. Discuss with other citizens on who you think should be executed for the henious crime, after that click the *Vote* button below.</p>';
else
$message = '<p id="news-update">Citizens of *' . $town . '*, Last night our medic saved the day, there were no casualities. However, this town is still not free from the mafia. Discuss with other citizens on who you think the mafia members might be, after that click the *Vote* button below.</p>';
}
$message .= "<script>
clearInterval(indexTimeout);
indexTimeout = setInterval(function() {
var timer = document.getElementById('timer');
var timerMobile = document.getElementById('timer-mobile');
if (timer.innerHTML == '0') {
clearInterval(indexTimeout)
} else {
timer.innerHTML -= 1;
timerMobile.innerHTML -= 1;
if (timer.innerHTML == '0') {
timeUp();
clearInterval(indexTimeout)
}
}
}, 1000);
</script>";
$_SESSION["message"] = $message;
}
}
echo $_SESSION["message"];
if($_SESSION["dailyIndex"] == 0) {
$message = '<p id="news-update">The citizens of *' . $town . '* are sleeping. Zzz</p>';
$flag = 1;
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_mafia = 1 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$query = "SELECT name FROM town_" . $townID . " WHERE is_mafia = 1;";
$killer = mysqli_fetch_assoc(mysqli_query($conn, $query))["name"];
$message = '<p id="news-update">Welcome members of *' . $mob . '*, discuss below on who you would like to kill, after that *' . $killer . '* has to click the *Kill* button to choose the first victim.</p>';
$query = "SELECT medic_0 FROM town_" . $townID . " WHERE night_0 <> 0;";
if($name == $killer && !mysqli_fetch_assoc(mysqli_query($conn, $query)))
$message = $message . '<script>
let notification = document.getElementById("notification");
notification.innerHTML = "We are waiting for you to choose your victim.";
notification.classList.remove("hide-alert");
notification.classList.add("show-alert");
</script>';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_poser = 1 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$message = '<p id="news-update">Hello there! You probably already know this but, you are the poser. The mafia members are marked in red for you, you have to try and make sure they don\'t get caught.</p>';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_medic = 1 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$message = '<p id="news-update">Hello there! You probably already know this but, you are the towns medic. Click the *Heal* button below to use your amazing abilities. :)</p>';
$query = "SELECT medic_0 FROM town_" . $townID . " WHERE medic_0 <> 0;";
if(!mysqli_fetch_assoc(mysqli_query($conn, $query)))
$message = $message . '<script>
let notification = document.getElementById("notification");
notification.innerHTML = "We are waiting for you to save a citizen.";
notification.classList.remove("hide-alert");
notification.classList.add("show-alert");
</script>';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_sherrif = 1 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$message = '<p id="news-update">Hello there! You probably already know this but, you are the towns sheriff. Click the *Reveal* button below to check whether a citizen is a mafia member. Remember, you only have this ability while the night lasts.</p>';
if($_SESSION["revealed"] == '')
$message = $message . '<script>
let notification = document.getElementById("notification");
notification.innerHTML = "Hurry up! You\'re running out of time!!";
notification.classList.remove("hide-alert");
notification.classList.add("show-alert");
</script>';
$flag = 0;
}
$message .= "<script>
clearInterval(indexTimeout);
indexTimeout = setInterval(function() {
var timer = document.getElementById('timer');
var timerMobile = document.getElementById('timer-mobile');
if (timer.innerHTML == '0') {
clearInterval(indexTimeout)
} else {
timer.innerHTML -= 1;
timerMobile.innerHTML -= 1;
if (timer.innerHTML == '0') {
timeUp();
clearInterval(indexTimeout)
}
}
}, 1000);
</script>";
echo $message;
}
?>
</div>
<div id="header-mobile">
<i id="menu-mobile" class="fas fa-bars" onclick="openMenu();"></i>
<div id="logo-mobile"><h3>
<?php
if($_SESSION["dailyIndex"] == 0) {
echo 'The First Night - <span id="timer-mobile" style="font-size: inherit;">60</span>s';
}
else if($_SESSION["dailyIndex"]%2 == 0) {
$night = $_SESSION["dailyIndex"] / 2;
echo 'Night ' . $night . ' - <span id="timer-mobile" style="font-size: inherit;">60</span>s';
}
else {
$day = $_SESSION["dailyIndex"]/2 + 0.5;
echo 'Day ' . $day . ' - <span id="timer-mobile" style="font-size: inherit;">150</span>s';
}
?>
</h3></div>
<nav id="nav-mobile" class="nav">
<table cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 20px;">
<td class="header2" style="text-align: left;"><img src="/assets/images/logo.png" style="height: 40px;"></img></td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeMenu()"></i></td>
</table>
<input class="header link" style="padding: 10px 20px 10px 20px;" type="button" value="Privacy Policy" onclick="openPrivacy()"></input>
</br>
<input class="header link" style="padding: 10px 20px 10px 20px;" type="button" value="Report Bug" onclick="openBug()"></input>
</br>
<input class="header link" style="padding: 10px 20px 10px 20px;" type="button" value="About Us" onclick="openAbout()"></input>
</nav>
</div>
<div id="game">
<table id="game-content">
<tr>
<th id="game-index" style="vertical-align: center;"><h3>
<?php
if($_SESSION["dailyIndex"] == 0) {
echo '<span id="index" style="font-size: inherit;">The First Night</span> - <span id="timer" style="font-size: inherit;">60</span>s';
}
else if($_SESSION["dailyIndex"]%2 == 0) {
$night = $_SESSION["dailyIndex"] / 2;
echo '<span id="index" style="font-size: inherit;">Night ' . $night . '</span> - <span id="timer" style="font-size: inherit;">60</span>s';
}
else {
$day = $_SESSION["dailyIndex"]/2 + 0.5;
echo '<span id="index" style="font-size: inherit;">Day ' . $day . '</span> - <span id="timer" style="font-size: inherit;">150</span>s';
}
?>
</h3></th>
<th id="role-button" style="vertical-align: center;"><input id="my-role" class="btn" type="button" value="My Role" onclick="openRole()"></input></th>
</tr>
<tr id="mobile-game-nav">
<td colspan="2"><table id="mobile-game-nav-content" style="width: 100%; vertical-align: middle;">
<th><i id="button-l" class="fas fa-comment-alt fa-2x mobile-game-nav" onclick="loadL();" style="color: #c80000;"></i></th>
<th><i id="button-r" class="fas fa-info-circle fa-2x mobile-game-nav" onclick="loadR();" style="color: #936c6c;"></i></th>
</table></td>
</tr>
<tr>
<td id="game-content-l" style="width: 80%; padding: 0;">
<div id="content">
<div id="news-bar">
<p id="news">News from <b><?php echo $_SESSION["town"] ?></b> will show up here.</p>
</div>
<div id="game-display">
<?php
if($_SESSION["dailyIndex"]%2 == 0) {
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_mafia = 1;";
if($result = mysqli_query($conn, $query)) {
while($row = mysqli_fetch_assoc($result)) {
if($row["user_id"] == $userID) {
$query = "SELECT * FROM chat_" . $townID . ";";
if($result = mysqli_query($conn, $query)) {
while($row = mysqli_fetch_assoc($result)) {
if($row["name"] == $name)
echo '<div style="100%; text-align: right;"><div class="message" style="background: #fff; color: #000;">' . $row["message"] . '</div></div>';
else
echo '<div style="100%; text-align: left;"><div class="message" style="background: #000; color: #fff;"><b>' . $row["name"] . ':</b> ' . $row["message"] . '</div></div>';
}
}
break;
}
}
}
}
else {
$query = "SELECT * FROM chat_" . $townID . ";";
if($result = mysqli_query($conn, $query)) {
while($row = mysqli_fetch_assoc($result)) {
if($row["name"] == $name)
echo '<div style="100%; text-align: right;"><div class="message" style="background: #fff; color: #000;"><b>' . $row["message"] . '</div></div>';
else
echo '<div style="100%; text-align: left;"><div class="message" style="background: #000; color: #fff;"><b>' . $row["name"] . ':</b> ' . $row["message"] . '</div></div>';
}
}
}
?>
</div>
<table id="game-footer" style="width: 100%;">
<td style="width: 100%;"><input id="chat-box" placeholder="Write a message..." autocomplete="off" onkeyup="enterMessage(event)"></input></td>
<td id="send" style="padding: 0;">
<input class="btn" type="button" style="border-radius: 10px;" onclick="sendMessage()" value="Send" <?php
$ability = 'disabled';
if($_SESSION["dailyIndex"]%2 == 0) {
$query = "SELECT name FROM town_" . $townID . " WHERE is_mafia = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)))
$ability = '';
}
else {
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)))
$ability = '';
}
echo $ability;
?>></input>
</td>
<td id="vote">
<input class="btn" type="button" style="border-radius: 10px;" onclick="openVote()" value="<?php
$value = 'Vote';
if($_SESSION["dailyIndex"]%2 == 0) {
$flag = 1;
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_mafia = 1 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$value = 'Kill';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_medic = 1 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$value = 'Heal';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_sherrif = 1 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$value = 'Reveal';
$flag = 0;
}
}
echo $value;
?>" <?php
$ability = 'disabled';
if($_SESSION["dailyIndex"]%2 == 0) {
$flag = 1;
$query = "SELECT name FROM town_" . $townID . " WHERE is_mafia = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$ability = '';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_medic = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$ability = '';
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_sherrif = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$ability = '';
$flag = 0;
}
}
else {
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)))
$ability = '';
}
echo $ability;
?>></input>
</td>
</table>
</div>
</td>
<td id="game-content-r" style="width: 20%;">
<div id="role-mobile">
<hr class="divider" style="width: 40%; margin-top: 0; margin-bottom: 10px;">
<input class="btn" type="button" value="My Role" style="margin-left: 50%; transform: translate(-50%, 0%);" onclick="openRole()"></input>
<hr class="divider" style="width: 40%; margin-top: 10px;">
</div>
<div id="game-details">
<div id="players">
<?php
$query = "SELECT user_id, name, is_mafia, is_poser, is_medic, is_sherrif, is_executed, is_killed FROM town_" . $townID . ";";
if($result = mysqli_query($conn, $query)) {
while($row = mysqli_fetch_assoc($result)) {
$name = $row["name"];
if($userID == $row["user_id"])
$name = $name . " <b>(You)</b>";
$span = '<span style="font-weight: normal;">';
if($row["is_mafia"] && $row["is_executed"])
$span = '<span style="font-weight: normal; color: #c80000; text-decoration: line-through;">';
else if($row["is_poser"] && $row["is_executed"])
$span = '<span style="font-weight: normal; color: #ffd300; text-decoration: line-through;">';
else if($row["is_medic"] && $row["is_executed"])
$span = '<span style="font-weight: normal; color: #fa691d; text-decoration: line-through;">';
else if($row["is_sherrif"] && $row["is_executed"])
$span = '<span style="font-weight: normal; color: #3895d3; text-decoration: line-through;">';
else if($row["is_executed"])
$span = '<span style="font-weight: normal; text-decoration: line-through;">';
else if($row["is_killed"])
$span = '<span style="font-weight: normal; text-decoration: line-through;">';
else if($row["is_mafia"]) {
$query = "SELECT name FROM town_" . $townID . " WHERE (is_mafia = 1 OR is_poser = 1) AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)))
$span = '<span style="font-weight: normal; color: #c80000">';
}
echo $span . $name . '</span><br>';
}
}
?>
</div>
<div id="town-details">
<?php
if($result = mysqli_query($conn, $query)) {
echo '<hr class="divider">';
echo '<span>Population: ' . mysqli_fetch_assoc(mysqli_query($conn, "SELECT COUNT(user_id) FROM town_" . $_SESSION["townID"] . ";"))["COUNT(user_id)"] . '</span><br>';
echo '<span style="color: #c80000;">Mafia: ' . mysqli_fetch_assoc(mysqli_query($conn, "SELECT COUNT(user_id) FROM town_" . $_SESSION["townID"] . " WHERE is_mafia = 1;"))["COUNT(user_id)"] . '</span><br>';
echo '<span style="color: #ffd300;">Poser: ' . mysqli_fetch_assoc(mysqli_query($conn, "SELECT COUNT(user_id) FROM town_" . $_SESSION["townID"] . " WHERE is_poser = 1;"))["COUNT(user_id)"] . '</span><br>';
echo '<span style="color: #fa691d;">Medic: ' . mysqli_fetch_assoc(mysqli_query($conn, "SELECT COUNT(user_id) FROM town_" . $_SESSION["townID"] . " WHERE is_medic = 1;"))["COUNT(user_id)"] . '</span><br>';
echo '<span style="color: #3895d3;">Sheriff: ' . mysqli_fetch_assoc(mysqli_query($conn, "SELECT COUNT(user_id) FROM town_" . $_SESSION["townID"] . " WHERE is_sherrif = 1;"))["COUNT(user_id)"] . '</span><br>';
}
?>
</div>
</div>
</td>
</td>
</table>
</div>
<div id="menu-background" onclick="closeMenu()"></div>
<div id="modal-background" onclick="closeAll()"></div>
<div id="privacy-modal" class="modal" style="text-align: left;">
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Privacy Policy</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<p>We use cookies to store your name and the avatar you selected.</p>
<p>Details necessary to set up the game environment are stored in our database. All data stored is deleted shortly after the game ends.</p>
</div>
<div id="bug-modal" class="modal">
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Report Bug</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<div id="bug-report" style="margin: 10px;">
<textArea id="report" class="text-box" placeholder="Write a bug report..."></textArea>
<p id="success-bug" style="margin: 10px; margin-top: 0; margin-bottom: 0; color: #c80000; display: none;">Success! Your report has been submitted.</p>
<p id="error-bug" style="margin: 10px; margin-top: 0; margin-bottom: 0; color: #c80000; display: none;">Error! Please try again later.</p>
<input id="submit-report" class="btn" type="button" style="margin-top: 10px;" value="Submit Bug Report"></input>
</div>
</div>
<div id="about-modal" class="modal" style="text-align: left;">
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">About Us</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<p>Made with love by a team of talented people from <b>BinaryStack</b>.</p>
<p>Credits: <b><a class="link2" href="https://instagram.com/abishek.stuff/" target="_blank">@AbishekDevendran</a></b> & <b><a class="link2" href="https://therealsuji.tk" target="_blank">@therealsujitk</a></b>.</p>
<div id="version"><span>v3.1.0</span></div>
</div>
<div id="error-modal" class="modal">
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Error!</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td style="width: 50px;"><img src="/assets/images/error.png" style="height: 50px;"></img></td>
<td><p id="error-message" style="padding: 0; margin: 0;"></p></td>
</table>
</div>
<div id="role-modal" class="modal" style="text-align: left;">
<?php
$query = "SELECT is_mafia, is_poser, is_medic, is_sherrif FROM town_" . $townID . " WHERE user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query))["is_mafia"]) {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Your Role</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td><img src="/assets/cards/mafia.png" style="height: 150px;"></img></td>
<td><h3>Mafia</h3><br><p style="padding: 0; margin: 0;">Your job is to take over <b>' . $town . '</b> with the help of the other mafia members by killing citizens every night.</p></td>
</table>';
}
else if(mysqli_fetch_assoc(mysqli_query($conn, $query))["is_poser"]) {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Your Role</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td><img src="/assets/cards/poser.png" style="height: 150px;"></img></td>
<td><h3>Poser</h3><br><p style="padding: 0; margin: 0;">Your job is to help ' . $mob . ' take over <b>' . $town . '</b> by moving the suspicion away from the mafia. You can even make the citizens think you are a mafia member.</p></td>
</table>';
}
else if(mysqli_fetch_assoc(mysqli_query($conn, $query))["is_medic"]) {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Your Role</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td><img src="/assets/cards/medic.png" style="height: 150px;"></img></td>
<td><h3>Medic</h3><br><p style="padding: 0; margin: 0;">You have the ability to heal anyone you want, you can even heal yourself. Note that you <b>can not</b> heal the same person more than once in a game.</p></td>
</table>';
}
else if(mysqli_fetch_assoc(mysqli_query($conn, $query))["is_sherrif"]) {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Your Role</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td><img src="/assets/cards/sheriff.png" style="height: 150px;"></img></td>
<td><h3>Sheriff</h3><br><p style="padding: 0; margin: 0;">You have the ability to find out whether a citizen is a mafia member or not. You can use this knowledge by convincing citizens to execute mafia members.</p></td>
</table>';
}
else {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Your Role</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td><img src="/assets/cards/citizen.png" style="height: 150px;"></img></td>
<td><h3>Citizen</h3><br><p style="padding: 0; margin: 0;">Your job is to vote on who is to be executed every day, make sure you vote on mafia members or you may lose.</p></td>
</table>';
}
?>
</div>
<div id="vote-modal" class="modal">
<?php
if($_SESSION["dailyIndex"]%2 == 0) {
$flag = 1;
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_mafia = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_mafia = 1 AND is_killed = 0 AND is_executed = 0;";
$killer = mysqli_fetch_assoc(mysqli_query($conn, $query))["user_id"];
if($killer == $userID) {
$night = $_SESSION["dailyIndex"] / 2;
$query = "SELECT name, avatar FROM town_" . $townID . " WHERE night_" . $night . " = 1;";
if(!mysqli_fetch_assoc(mysqli_query($conn, $query))) {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Choose a victim</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>';
echo '<div id="candidates-box"><div id="candidates">';
$query = "SELECT user_id, name, avatar, is_mafia FROM town_" . $townID . " WHERE is_killed = 0 AND is_executed = 0;";
if($result = mysqli_query($conn, $query))
while($row = mysqli_fetch_assoc($result)) {
$name = $row["name"];
if($userID == $row["user_id"])
$name = $name . ' <b>(You)</b>';
if($row["is_mafia"])
$color = '#c80000';
else
$color = '#fff';
echo '<figure style="margin: 10px 20px 10px 0px; display: inline-block;"><img class="candidate candidate-mafia" style="height: 100px;" src="'. $row["avatar"] .'" onclick="registerVote(`mafia`, `' . $row["user_id"] . '`);"></img><figcaption style="color: ' . $color . ';">' . $name . '</figcaption></figure>';
}
echo '</div></div>';
echo '<span id="alert" style="display: none;">We are waiting for you to choose your victim.</span>';
}
else {
$name = mysqli_fetch_assoc(mysqli_query($conn, $query))["name"];
$avatar = mysqli_fetch_assoc(mysqli_query($conn, $query))["avatar"];
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Victim chosen</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td><img src="' . $avatar . '" style="height: 150px;"></img></td>
<td><h3>' . $name . '</h3><br><p style="padding: 0; margin: 0;">You have already selected <b>' . $name . '</b> as your victim. You can only kill <b>one</b> citizen per night.</p></td>
</table>';
}
}
else {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Choose a victim</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td><img src="/assets/images/warning.png" style="height: 50px;"></img></td>
<td><p style="padding: 0; margin: 0;">Your accomplice will be taking care of the dirty work for tonight.</p></td>
</table>';
}
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_medic = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
$night = $_SESSION["dailyIndex"] / 2;
$query = "SELECT name, avatar FROM town_" . $townID . " WHERE medic_" . $night . " = 1;";
if(!mysqli_fetch_assoc(mysqli_query($conn, $query))) {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Select a citizen</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>';
echo '<div id="candidates-box"><div id="candidates">';
$prev = $_SESSION["dailyIndex"]/2 - 1;
if($prev < 0)
$prev = 0;
$query = "SELECT user_id, name, avatar FROM town_" . $townID . " WHERE medic_" . $prev . " = 0 AND is_killed = 0 AND is_executed = 0;";
if($result = mysqli_query($conn, $query))
while($row = mysqli_fetch_assoc($result)) {
$name = $row["name"];
if($userID == $row["user_id"])
$name = $name . ' <b>(You)</b>';
echo '<figure style="margin: 10px 20px 10px 0px; display: inline-block;"><img class="candidate candidate-medic" style="height: 100px;" src="'. $row["avatar"] .'" onclick="registerVote(`medic`, `' . $row["user_id"] . '`);"></img><figcaption>' . $name . '</figcaption></figure>';
}
echo '</div></div>';
echo '<span id="alert" style="display: none;">We are waiting for you to save a citizen.</span>';
}
else {
$name = mysqli_fetch_assoc(mysqli_query($conn, $query))["name"];
$avatar = mysqli_fetch_assoc(mysqli_query($conn, $query))["avatar"];
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Citizen saved</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td><img src="' . $avatar . '" style="height: 150px;"></img></td>
<td><h3>' . $name . '</h3><br><p style="padding: 0; margin: 0;">You have already saved <b>' . $name . '</b> tonight. You can only save <b>one</b> citizen per night.</p></td>
</table>';
}
$flag = 0;
}
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_sherrif = 1 AND is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query)) && $flag) {
if($_SESSION["revealed"] == '') {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Select a citizen</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>';
echo '<div id="candidates-box"><div id="candidates">';
$query = "SELECT user_id, name, avatar FROM town_" . $townID . " WHERE is_killed = 0 AND is_executed = 0;";
if($result = mysqli_query($conn, $query))
while($row = mysqli_fetch_assoc($result)) {
$name = $row["name"];
if($userID == $row["user_id"])
continue;
echo '<figure style="margin: 10px 20px 10px 0px; display: inline-block;"><img class="candidate candidate-sherrif" style="height: 100px;" src="'. $row["avatar"] .'" onclick="registerVote(`sheriff`, `' . $row["user_id"] . '`);"></img><figcaption>' . $name . '</figcaption></figure>';
}
echo '</div></div>';
echo '<span id="alert" style="display: none;">Hurry up! You\'re running out of time!!</span>';
}
else {
echo $_SESSION["revealed"];
}
$flag = 0;
}
}
else {
$query = "SELECT user_id FROM town_" . $townID . " WHERE is_killed = 0 AND is_executed = 0 AND user_id = " . $userID . ";";
if(mysqli_fetch_assoc(mysqli_query($conn, $query))) {
$day = $_SESSION["dailyIndex"]/2 + 0.5;
$query = "SELECT day_" . $day . " FROM town_" . $townID . " WHERE user_id = " . $userID . " AND day_" . $day . " <> 0;";
if(!mysqli_fetch_assoc(mysqli_query($conn, $query))) {
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Vote for execution</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>';
echo '<div id="candidates-box"><div id="candidates">';
$query = "SELECT user_id, name, avatar, is_mafia FROM town_" . $townID . " WHERE is_killed = 0 AND is_executed = 0;";
if($result = mysqli_query($conn, $query))
while($row = mysqli_fetch_assoc($result)) {
$name = $row["name"];
if($userID == $row["user_id"])
$name = $name . ' <b>(You)</b>';
$query2 = "SELECT user_id FROM town_" . $townID . " WHERE user_id = " . $userID . " AND is_mafia = 1;";
$color = "#fff";
if(mysqli_fetch_assoc(mysqli_query($conn, $query2)))
if($row["is_mafia"])
$color = "#c80000";
echo '<figure style="margin: 10px 20px 10px 0px; display: inline-block;"><img class="candidate" style="height: 100px;" src="'. $row["avatar"] .'" onclick="registerVote(`citizen`, `' . $row["user_id"] . '`);"></img><figcaption style="color: ' . $color . ';">' . $name . '</figcaption></figure>';
}
echo '</div></div>';
echo '<span id="alert" style="display: none;">We are awaiting your vote.</span>';
}
else {
$vote = mysqli_fetch_assoc(mysqli_query($conn, $query))["day_" . $day];
$query = "SELECT name, avatar FROM town_" . $townID . " WHERE user_id = " . $vote . ";";
$name = mysqli_fetch_assoc(mysqli_query($conn, $query))["name"];
$avatar = mysqli_fetch_assoc(mysqli_query($conn, $query))["avatar"];
echo '<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td class="header2" style="text-align: left;">Your vote</td>
<td style="text-align: right;"><i class="header link fas fa-times" onclick="closeAll()"></i></td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td><img src="' . $avatar . '" style="height: 150px;"></img></td>
<td><h3>' . $name . '</h3><br><p style="padding: 0; margin: 0;">You have already voted for <b>' . $name . '</b> today. You can only vote for <b>one</b> citizen per day.</p></td>
</table>';
}
}
}
?>
</div>
<div id="modal-background2"></div>
<div id="win-modal" class="modal">
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td id="results-header" class="header2" style="text-align: center;">Game Over</td>
</table>
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<td id="results" style="text-align: center; padding: 0; padding-bottom: 10px;"><p>
<?php
$query = "SELECT COUNT(user_id) FROM town_" . $townID . " WHERE is_mafia = 1 AND is_killed = 0 AND is_executed = 0";
$mafiaPopulation = mysqli_fetch_assoc(mysqli_query($conn, $query))["COUNT(user_id)"];
$query = "SELECT COUNT(user_id) FROM town_" . $townID . " WHERE is_mafia = 0 AND is_killed = 0 AND is_executed = 0";
$nonMafiaPopulation = mysqli_fetch_assoc(mysqli_query($conn, $query))["COUNT(user_id)"];
$flag = 0;
if($mafiaPopulation == 0) {
echo 'Our town is free from the members of <b>' . $mob . '</b>. All of them are dead.';
echo '<script>document.getElementById("results-header").innerHTML = "Citizens Wins!"</script>';
$flag = 1;
}
else if(($mafiaPopulation == $nonMafiaPopulation)) {
echo '<b>' . $mob . '</b> has taken over our town. The Mafia now has the majority members.';
echo '<script>document.getElementById("results-header").innerHTML = "Mafia Wins!"</script>';
$flag = 1;
}
if($flag) {
echo '</br><input id="restart-game" class="btn" style="margin-top: 10px;" type="button" value="Back to Lobby" onclick="restartGame();"></input>';
echo "<script>
if(indexTimeout) {
clearTimeout(indexTimeout);
indexTimeout = null;
}
</script>";
}
?>
</p></td>
</table>
</div>
<div id="has-started" style="display: none;">
<?php
$query = "SELECT has_started FROM town_details WHERE town_id = '$townID';";
if(mysqli_fetch_assoc(mysqli_query($conn, $query))["has_started"] == '0')
echo "<script>
$('body').load('lobby.php', function(response, status) {
if(status != 'success') {
closeAll();
setTimeout(function() {
document.getElementById('error-message').innerHTML = 'Sorry, we are having some trouble communicating with our servers. Please try refreshing this page.';
document.getElementById('error-modal').classList.add('show-modal');
document.getElementById('modal-background').style.display = 'block';
}, 500);
}
});
</script>";
mysqli_close($conn);
?>
</div>
<script>
gameSpaceCalc();
clientUpdate();
window.addEventListener('resize', () => {
gameSpaceCalc();
});
<?php
if(!$_SESSION["dailyIndex"]) {
echo "
document.getElementById('role-modal').classList.add('show-modal');
document.getElementById('modal-background').style.display = 'block';
";
}
?>
document.getElementsByTagName('title')[0].innerHTML = document.getElementById('index').innerHTML + ' • ' + town + ' - Mafia';
wamp.topic(townID).subscribe((arr) => {
if(arr._args[0] === "new message") {
$("#game-display").load("game.php #game-display > *", function(response, status) {
if(status != "success") {
closeAll();
setTimeout(function() {
document.getElementById('error-message').innerHTML = 'Sorry, we are having some trouble communicating with our servers. Please try refreshing this page.';
document.getElementById('error-modal').classList.add("show-modal");
document.getElementById('modal-background').style.display = "block";
}, 500);
}
else {
$("#game-display").animate({ scrollTop: $('#game-display').prop("scrollHeight")}, 500);
}
});
}
else if(arr._args[0] === "update index") {
if(indexTimeout) {
clearTimeout(indexTimeout);
indexTimeout = null;
}
var messageValue = document.getElementById('chat-box').value;
closeAll();
$("body").load("game.php", function(response, status) {
if(status != "success") {
closeAll();
setTimeout(function() {
document.getElementById('error-message').innerHTML = 'Sorry, we are having some trouble communicating with our servers. Please try refreshing this page.';
document.getElementById('error-modal').classList.add("show-modal");
document.getElementById('modal-background').style.display = "block";
}, 500);
}
else {
document.getElementById('chat-box').value = messageValue;
}
});
}
else if(arr._args[0] === "restart game") {
if(restartTimeout) {
clearTimeout(restartTimeout);
restartTimeout = null;
}
$("body").load("lobby.php", function(response, status) {
if(status != "success") {
closeAll();
setTimeout(function() {
document.getElementById('error-message').innerHTML = 'Sorry, we are having some trouble communicating with our servers. Please try refreshing this page.';
document.getElementById('error-modal').classList.add("show-modal");
document.getElementById('modal-background').style.display = "block";
}, 500);
}
});
}
else if(arr._args[0] === "try restart") {
if(document.getElementById('restart-game')) {
var restart = document.getElementById('restart-game');
restart.disabled = true;
restart.value = "Please wait...";
restartTimeout = setTimeout(function() {
restart.disabled = false;
restart.value = "Back to Lobby";
let message = 'Sorry, timeout error. Please try refreshing this page.';
openError(message);
}, 30000);
}
}
else if(arr._args[0] === "restart failed") {
if(document.getElementById('restart-game')) {
var restart = document.getElementById('restart-game');
restart.disabled = false;
restart.value = "Back to Lobby";
if(restartTimeout) {
clearTimeout(restartTimeout);
restartTimeout = null;
}
}
}
});
window.onbeforeunload = function() {
return "Are you sure you want to leave? If your session ends, you won\'t be able to continue playing this game.";
}
</script>