-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.html
More file actions
3068 lines (2572 loc) · 105 KB
/
Copy pathclient.html
File metadata and controls
3068 lines (2572 loc) · 105 KB
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
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Client</title>
<style>
body {
font-family: 'Courier New', monospace;
background-color: #1e1e1e;
color: #e0e0e0;
margin: 0;
padding: 10px; /* Reduced padding to maximize space */
height: 100vh;
overflow: hidden; /* Prevent body scrolling */
}
.container {
display: flex;
flex-direction: column;
height: calc(100vh - 20px); /* Adjusted for reduced padding */
width: 100%;
margin: 0 auto;
}
.header {
margin-bottom: 10px; /* Reduced margin to give more space to the game */
display: flex;
justify-content: flex-end; /* Align to the right since no title */
align-items: center;
}
.player-info {
font-size: 0.7rem;
color: #e0e0e0;
display: flex;
gap: 15px; /* Space between the three elements */
align-items: center;
}
.player-name {
color: #4fc3f7;
font-weight: bold;
}
.player-name-input {
background-color: #3d3d3d;
border: 1px solid #555;
border-radius: 3px;
padding: 4px 8px;
color: #4fc3f7;
font-family: 'Courier New', monospace;
font-weight: bold;
font-size: 0.7rem;
width: 180px;
transition: border-color 0.2s;
}
.player-name-input:focus {
outline: none;
border-color: #4fc3f7;
box-shadow: 0 0 4px rgba(79, 195, 247, 0.3);
}
.player-name-input:disabled {
background-color: #2a2a2a;
border-color: #444;
color: #888;
cursor: not-allowed;
}
.clear-button {
background-color: #f44336;
border: none;
border-radius: 3px;
padding: 4px 8px;
color: white;
font-family: 'Courier New', monospace;
font-size: 0.7rem;
cursor: pointer;
transition: background-color 0.2s;
margin-right: 8px;
}
.clear-button:hover {
background-color: #d32f2f;
}
.clear-button:disabled {
background-color: #666;
cursor: not-allowed;
}
.player-address {
color: #ffeb3b;
font-family: monospace;
cursor: pointer;
text-decoration: underline;
transition: color 0.2s;
position: relative;
font-size: 0.7rem;
}
.player-address:hover {
color: #fff59d;
}
.copy-hint {
position: absolute;
top: -30px;
left: 50%;
transform: translateX(-50%);
background-color: #333;
color: #4caf50;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.6rem;
white-space: nowrap;
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
z-index: 1000;
}
.copy-hint.show {
opacity: 1;
}
.player-balance {
color: #4caf50;
font-weight: bold;
}
.main-content {
display: flex;
flex: 1;
height: calc(100vh - 70px); /* Adjusted for header and padding */
overflow: hidden; /* Prevent scroll on the main container */
}
.panel {
background-color: #2d2d2d;
border-radius: 5px;
padding: 15px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
.left-panel {
width: 250px; /* Increased from 200px to 250px */
min-width: 150px; /* Minimum width for usability */
max-width: 600px; /* Maximum width to prevent taking over */
flex-shrink: 0;
display: flex;
flex-direction: column;
position: relative;
overflow-y: auto;
max-height: 100%; /* Ensure it doesn't overflow the container */
font-size: 0.33em; /* Reduce all text by triple fold */
}
/* Scale down all elements in left panel */
.left-panel h2 {
font-size: 2.4em; /* Increased by 2x: was 1.2em, now 2.4em */
}
.left-panel button {
font-size: 2em; /* Increased by 2x: was 1em, now 2em */
/* Padding defined in the override below */
}
.left-panel input {
font-size: 1em; /* Keep input fields at normal size for readability */
padding: 4px 6px; /* Smaller padding */
}
.resizer {
width: 5px;
background-color: #444;
cursor: col-resize;
flex-shrink: 0;
transition: background-color 0.2s;
position: relative;
}
.resizer:hover {
background-color: #4fc3f7;
}
.resizer:active {
background-color: #2196f3;
}
.right-panels {
flex: 1;
display: flex;
flex-direction: column;
height: 100%;
max-height: 100%;
overflow: hidden;
}
.server-list {
height: 450px; /* Fixed height for server list */
overflow-y: auto;
margin-bottom: 15px;
}
.server-item {
background-color: #3d3d3d;
border: 2px solid #5d5d5d;
border-radius: 3px;
padding: 2px 4px; /* Smaller padding like other buttons */
margin-bottom: 4px; /* Reduced margin for tighter spacing */
cursor: pointer;
transition: background-color 0.2s, border-color 0.2s;
}
.server-item:hover {
background-color: #4d4d4d;
}
.server-item.selected {
background-color: rgba(33, 150, 243, 0.3);
border-color: #2196f3 !important;
box-shadow: 0 0 8px rgba(33, 150, 243, 0.5);
}
.server-item.malformed {
background-color: rgba(255, 68, 68, 0.15);
border: 2px solid #ff4444;
color: #ffffff;
}
.server-item.malformed:hover {
background-color: rgba(255, 68, 68, 0.25);
}
.server-item.not-running {
background-color: rgba(102, 102, 102, 0.15);
border: 2px solid #666666;
color: #cccccc;
}
.server-item.not-running:hover {
background-color: rgba(102, 102, 102, 0.25);
}
.server-item.starting {
background-color: rgba(255, 170, 0, 0.15);
border: 2px solid #ffaa00;
color: #ffffff;
}
.server-item.starting:hover {
background-color: rgba(255, 170, 0, 0.25);
}
.server-item.running {
background-color: rgba(76, 175, 80, 0.15);
border: 2px solid #4caf50;
color: #ffffff;
}
.server-item.running:hover {
background-color: rgba(76, 175, 80, 0.25);
}
.server-item.game-over {
background-color: rgba(255, 152, 0, 0.15);
border: 2px solid #ff9800;
color: #ffffff;
}
.server-item.game-over:hover {
background-color: rgba(255, 152, 0, 0.25);
}
.server-item.disabled {
opacity: 0.4;
cursor: not-allowed;
}
.server-item.disabled:hover {
background-color: inherit;
}
.server-status {
font-size: 0.8rem;
font-weight: bold;
margin-top: 2px;
}
.server-status.running {
color: #4caf50;
}
.server-status.starting {
color: #ffaa00;
}
.server-status.not-running {
color: #888888;
}
.server-status.game-over {
color: #ff9800;
}
.game-panel {
flex: 1;
display: flex;
flex-direction: column;
height: 100%; /* Fill available height */
}
.chat-panel {
margin-top: 15px;
display: flex;
flex-direction: column;
}
.token-panel {
margin-top: 15px;
}
.log {
flex: 1;
background-color: #252525;
border-radius: 3px;
padding: 10px;
overflow-y: auto;
font-size: 14px;
}
.chat-log {
flex: 0 0 auto; /* Don't grow, use fixed height */
height: 80px; /* Reduced from 150px to 80px to save space */
background-color: #252525;
border-radius: 3px;
padding: 10px;
overflow-y: auto;
font-size: 7px; /* Reduced by half: was 14px, now 7px */
margin-bottom: 10px;
}
/* Ensure all chat content uses the smaller font */
.chat-log * {
font-size: inherit !important;
}
.chat-input {
display: flex;
gap: 10px;
}
input, button {
background-color: #3d3d3d;
border: none;
border-radius: 3px;
padding: 8px 12px; /* Default padding for inputs and general buttons */
color: #e0e0e0;
font-family: 'Courier New', monospace;
}
/* Override for left panel buttons to be smaller */
.left-panel button {
padding: 2px 4px; /* Minimal padding for left panel buttons */
}
input {
flex: 1;
}
button {
background-color: #2196f3;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover {
background-color: #1976d2;
}
button:disabled {
background-color: #555;
cursor: not-allowed;
}
.button-row {
display: flex;
gap: 10px;
margin-top: 4px; /* Reduced from 10px to 4px for tighter spacing */
}
.status-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
font-size: 14px;
}
.ping-display {
color: #4caf50;
}
.player-list {
background-color: #252525;
border-radius: 3px;
padding: 10px;
margin-bottom: 10px;
font-size: 14px;
}
.game-state {
flex: 1;
overflow-y: visible; /* Changed from auto to visible for non-scrollable */
background-color: #252525;
border-radius: 3px;
padding: 10px;
font-size: 9px; /* Reduced from 10.5px to 9px */
}
/* Override inline styles in game-state content */
.game-state div {
font-size: inherit !important;
}
.game-state strong {
font-size: inherit !important;
}
.game-state span {
font-size: inherit !important;
}
.verification-info {
background-color: #252525;
border-radius: 3px;
padding: 10px;
}
.server-name {
font-weight: bold;
color: #4fc3f7;
font-size: 12px; /* Larger than server-info (9px) */
}
.server-info {
font-size: 9px; /* Reduced to 75% of 12px = 9px */
color: #aaa;
}
.status-indicator {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
margin-right: 5px;
}
.status-connected {
background-color: #4caf50;
}
.status-disconnected {
background-color: #f44336;
}
/* ANSI color simulation */
.ansi-green {
color: #4caf50;
}
.ansi-red {
color: #f44336;
}
.ansi-yellow {
color: #ffeb3b;
}
.ansi-blue {
color: #2196f3;
}
.ansi-cyan {
color: #00bcd4;
}
.ansi-magenta {
color: #e91e63;
}
.ansi-white {
color: #ffffff;
}
.ansi-gray {
color: #9e9e9e;
}
.chat-message {
margin-bottom: 5px;
}
.chat-timestamp {
color: #9e9e9e;
font-size: 6px; /* Reduced by half: was 12px, now 6px */
margin-right: 5px;
}
.chat-sender {
font-weight: bold;
margin-right: 5px;
}
.chat-sender-server {
color: #ffeb3b;
}
.chat-sender-self {
color: #4fc3f7;
}
.chat-text {
word-break: break-word;
}
/* Game iframe styles */
.game-container {
width: 100%;
flex: 1; /* Take all available space */
min-height: 650px; /* Minimum height */
height: calc(100vh - 100px); /* Adjusted viewport height calculation */
margin-bottom: 5px; /* Reduced margin */
position: relative;
border-radius: 5px;
overflow: hidden;
display: flex; /* Enable flex layout */
flex-direction: column; /* Stack children vertically */
}
/* Add keyboard focus indicator as a separate element for better browser compatibility */
.keyboard-indicator {
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 5px 10px;
border-radius: 4px;
font-size: 14px;
pointer-events: none; /* Allow clicks to pass through */
opacity: 0.8;
transition: opacity 0.3s;
z-index: 5;
}
/* Hide the indicator when the game has focus - will be managed by JavaScript */
.keyboard-indicator.hidden {
opacity: 0;
}
.game-iframe {
width: 100%;
height: 100%;
border: none;
background-color: #000;
flex: 1; /* Take up all available space in the container */
object-fit: contain; /* Maintain aspect ratio while filling space */
}
.game-iframe:focus {
outline: 4px solid #4caf50 !important; /* Thicker outline for better visibility */
box-shadow: 0 0 15px rgba(76, 175, 80, 0.6); /* Add glow effect when focused */
}
/* Fix for Firefox and some browsers to ensure iframe gets keyboard focus */
.game-iframe.active-iframe {
z-index: 10;
box-shadow: 0 0 20px rgba(76, 175, 80, 0.7) inset; /* Interior glow effect */
}
/* We'll handle this via JavaScript instead of CSS :has which isn't supported in all browsers */
/* Tabs for game view and client panel */
.tabs {
display: flex;
margin-bottom: 10px;
}
.tab {
padding: 8px 16px;
background-color: #3d3d3d;
border-radius: 3px 3px 0 0;
cursor: pointer;
margin-right: 5px;
}
.tab.active {
background-color: #2196f3;
}
.tab-content {
display: none;
flex: 1;
flex-direction: column;
}
.tab-content.active {
display: flex;
}
/* Play button overlay styles */
.play-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.8);
z-index: 20;
cursor: pointer;
}
.play-button {
background-color: #4caf50;
color: white;
border: none;
border-radius: 50%;
width: 150px;
height: 150px;
font-size: 48px;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(76, 175, 80, 0.5);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 0;
}
.play-button:hover {
background-color: #45a049;
transform: scale(1.1);
box-shadow: 0 6px 20px rgba(76, 175, 80, 0.7);
}
.play-button:active:not(:disabled) {
transform: scale(0.95);
}
.play-button:disabled {
background-color: #666;
cursor: not-allowed;
opacity: 0.6;
}
.play-button:disabled:hover {
background-color: #666;
transform: none;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}
.play-button-icon {
font-size: 60px;
margin-left: 10px; /* Offset to center the triangle */
}
.play-button-text {
font-size: 20px;
margin-top: 5px;
font-weight: normal;
}
.play-overlay.hidden {
display: none;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<div class="player-info" id="player-info">
<button id="clear-identity-button" class="clear-button">Clear</button>
<input type="text" id="player-name-input" class="player-name-input" placeholder="Enter your player name..." maxlength="16">
<span class="player-address" id="player-address">Generating address...
<span class="copy-hint" id="address-copy-hint">Copied to clipboard</span>
</span>
<span class="player-balance" id="player-balance">Balance: 0</span>
</div>
</div>
<div class="main-content">
<div class="left-panel panel">
<div class="status-row">
<div>
<span class="status-indicator" id="connection-status"></span>
<span id="connection-text">Disconnected</span>
</div>
<div class="ping-display" id="ping-display"></div>
</div>
<h2>Game Servers</h2>
<div style="font-size: 12px; color: #aaa; margin-bottom: 10px;">Click a server to connect</div>
<div id="servers-container" class="server-list"></div>
<div class="button-row">
<button id="refresh-button">Refresh Servers</button>
<button id="connect-button" disabled style="display: none;">Connect</button>
<button id="disconnect-button" disabled>Disconnect</button>
</div>
<div class="button-row">
<button id="create-server-button" style="background-color: #ffeb3b; color: #000; font-weight: bold; width: 100%;">Create New Server</button>
</div>
<!-- Direct connection button removed for security -->
<!--
<div class="button-row" style="margin-top: 15px; padding-top: 10px; border-top: 1px solid #444;">
<button id="direct-connect-button" style="background-color: #4caf50; width: 100%;">Connect to Dedicated Server via Original Web Server</button>
</div>
-->
<h2>Game State</h2>
<div class="game-state" id="game-state">No game state available</div>
<h2>Chat</h2>
<div class="chat-log" id="chat-log"></div>
<div class="chat-input">
<input type="text" id="chat-input" placeholder="Type your message..." disabled>
<button id="send-button" disabled>Send</button>
</div>
</div>
<div class="resizer" id="resizer"></div>
<div class="right-panels">
<div class="game-container">
<iframe id="game-iframe" class="game-iframe" tabindex="0" title="Click to enable keyboard controls" allow="autoplay; fullscreen; gamepad; keyboard-map"></iframe>
<div class="keyboard-indicator hidden" id="keyboard-indicator">Click game to enable keyboard & mouse controls</div>
<div class="play-overlay" id="play-overlay">
<button class="play-button" id="play-button">
<span class="play-button-icon">▶</span>
<span class="play-button-text">PLAY</span>
</button>
</div>
</div>
</div>
</div>
</div>
<!-- Load scripts -->
<script src="lib/client/uniquake-token-service.js"></script>
<script src="lib/client/browser-mock-game.js"></script>
<script src="lib/client/browser-mock-client.js"></script>
<script src="lib/client/game-integration.js"></script>
<script>
// Load WebRTC adapter directly, bypassing the auto-connect behavior
window.UNIQUAKE_CONFIG = {
useWebRTC: false, // Disable WebRTC, use plain WebSockets
masterServer: 'ws://localhost:27950', // Original Quake master server
serverAddress: 'ws://localhost:27960', // Explicitly use WebSocket protocol
noAutoConnect: true // Flag to prevent auto-connection
};
// Load the adapter script
var script = document.createElement('script');
script.src = '/webrtc-adapter.js';
script.onload = function() {
initializeClient();
};
document.head.appendChild(script);
// Main client, game, and integration instances
let client, game, integration;
let selectedServerId = null;
let currentPlayerName = null;
// Client-side timer tracking for smooth countdown updates
let serverTimers = {}; // Store timer data for each server
let localTimerInterval = null; // Interval for updating local timers
// Get player name from localStorage or generate default
function getPlayerName() {
const savedName = localStorage.getItem('uniquake_player_name');
if (savedName && savedName.trim()) {
return savedName.trim();
}
return 'Player_' + Math.floor(Math.random() * 1000);
}
// Save player name to localStorage
function savePlayerName(name) {
if (name && name.trim()) {
const cleanName = name.trim().substring(0, 16); // Limit to 16 chars
localStorage.setItem('uniquake_player_name', cleanName);
currentPlayerName = cleanName;
return cleanName;
}
return null;
}
// Save player identity to localStorage (pubkey, secret, tokens)
function savePlayerIdentity() {
if (!client || !client.clientState.tokenService) {
console.warn('Cannot save identity: token service not initialized');
return false;
}
try {
const identity = client.clientState.tokenService.getIdentity();
const tokenStatus = client.clientState.tokenService.getTokenStatus();
// Use current player name instead of token service username to ensure consistency
const currentName = currentPlayerName || client.clientInfo.name || identity.username;
// Save identity data
const identityData = {
username: currentName,
pubkey: identity.pubkey,
secret: client.clientState.tokenService.secret, // Save secret for full recovery
tokens: tokenStatus.tokens,
savedAt: Date.now()
};
localStorage.setItem('uniquake_player_identity', JSON.stringify(identityData));
return true;
} catch (error) {
console.error('Failed to save player identity:', error);
return false;
}
}
// Load player identity from localStorage
function loadPlayerIdentity() {
try {
const savedData = localStorage.getItem('uniquake_player_identity');
if (!savedData) {
return null;
}
const identityData = JSON.parse(savedData);
return identityData;
} catch (error) {
console.error('Failed to load player identity:', error);
return null;
}
}
// Clear all player data from localStorage
function clearPlayerData() {
try {
localStorage.removeItem('uniquake_player_name');
localStorage.removeItem('uniquake_player_identity');
return true;
} catch (error) {
console.error('Failed to clear player data:', error);
return false;
}
}
// Initialize client
async function initializeClient() {
// Load player name from storage or generate default
currentPlayerName = getPlayerName();
// Update UI with current player name
const playerNameInput = document.getElementById('player-name-input');
if (playerNameInput) {
playerNameInput.value = currentPlayerName;
}
// Create mock game
game = new BrowserMockGame({
updateInterval: 2000,
onStateChange: updateGameState
});
// Use the current player name
const playerName = currentPlayerName;
// Create mock client
client = new BrowserMockClient({
masterServer: window.UNIQUAKE_CONFIG.masterServer || 'ws://localhost:27950',
name: playerName,
verbose: true,
debug: true,
mintTokens: 5, // Will be overridden if we have saved tokens
onStatusUpdate: updateClientStatus,
onChatMessage: displayChatMessage,
onConnectionChange: handleConnectionChange,
onServerList: updateServerList,
// Add handler for the new serverStateUpdate event
onServerStateUpdate: function(serverInfo) {
// Call updateGameState to refresh the UI with the latest server info
if (game) {
updateGameState(game.getGameState());
}
},
// Add handler for player score updates
onPlayerScoreUpdate: function(scoreData) {
// Update the player score overlay with new data
updatePlayerScoreOverlay();
}
});
// Create game integration
integration = new GameIntegration({
client: client,
debug: true,
onGameStateUpdate: updateGameState,
onTokenEvent: handleTokenEvent
});
// Initialize all components
await game.init();
// Try to restore saved identity before initializing client
const savedIdentity = loadPlayerIdentity();
if (savedIdentity) {
// Modify client's token service config to use saved identity
client.config.restoreIdentity = savedIdentity;
}
await client.init();
await integration.init(game);
// Store reference to game integration for syncing
client.gameIntegration = integration;
// Set up UI event handlers
setupUIHandlers();
// Initialize resizer functionality
initializeResizer();
// Set up auto-save on page unload
setupPageUnloadAutoSave();
// Connect to master server and fetch server list
client.connectToMasterServer().then(() => {
// Automatically request the server list
client.requestServerList();
// Set up periodic server list refresh every 5 seconds
setInterval(() => {
if (client && client.requestServerList) {
client.requestServerList();
}
}, 5000);
});
// Update initial token info
updateTokenInfo();
// Save initial identity to localStorage
setTimeout(() => {
savePlayerIdentity();
}, 1000); // Allow token service to fully initialize
// Set up periodic identity saving (every 30 seconds)
setInterval(() => {
if (client && client.clientState.tokenService) {
savePlayerIdentity();
}
}, 30000);
// Set up automatic game state verification every 2 seconds when connected
// This ensures the frame counter is updated frequently
setInterval(() => {
if (client.clientState.connected) {
// Request verification from server
client.sendMessage({
type: 'request:game:state:token'
});
// Only log in debug mode to avoid console spam
if (client.config.debug) {
}
}
}, 2000);
// Set up periodic player score overlay updates using direct master server requests
setInterval(() => {
updatePlayerScoreOverlayFromMaster();