-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoteinterface.js
923 lines (795 loc) · 30.9 KB
/
remoteinterface.js
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
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function (from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
/* Remote Interface for Urban Terror
* Oct 2009 - jgen
*/
/* Remote Interface Namespace */
var RemoteInterface = {};
// IP Address conversion functions By jgen
RemoteInterface.long2ip = function (proper_address) {
// Convert 4-byte unsigned integer to human-readable address [IPv4 only]
var input = parseInt(proper_address, 10);
if (isNaN(input) || (input < 0) || (input > 4294967295)) {
return '';
}
return Math.floor(input / 16777216) + '.' +
Math.floor((input % 16777216) / 65536) + '.' +
Math.floor(((input % 16777216) % 65536) / 256) + '.' +
Math.floor(((input % 16777216) % 65536) % 256);
};
RemoteInterface.ip2long = function (ip_address) {
// Convert IP address string to unsigned integer [IPv4 only]
// quick check on ip ( matches 0.0.0.0 - 999.999.999.999)
var parts = [];
if (ip_address.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) {
parts = ip_address.split('.');
return ((parts[0] * 16777216) + (parts[1] * 65536) + (parts[2] * 256) + (parts[3] * 1));
}
return '';
};
RemoteInterface.search_panels = new Array();
RemoteInterface.init = function() {
// Configuration Options are wrapped in an object.
var config = {};
config.sUrlBase = 'interface.php';
config.bColorizeNames = false;
config.bConvertDuration = true;
config.bHideIds = true;
config.bHideNumericIps = true;
config.bHideCreationDate = true;
config.sDatetimeFormat = '%D %R';
// Menu setup
var aItemData = [
{
text: "Main",
submenu: {
id: "mainmenuitem",
itemdata: [
{ text: "Status", id: "mainstatus", selected: true },
{
text: "Configure",
id: "configuremenuitem",
submenu: {
id: "configmenu",
itemdata: [ { text: "RCON password", id: 'serverpassword' },
{ text: "Server Setup", id: 'serverconfig' },
{ text: "Database Setup", id: 'databaseconfig' }
]
}
},
{ text: "Options", id: "options" }
]
}
},
{
text: "Server",
submenu: {
id: "servermenuitem",
itemdata: [
{ text: "Current Players", id: "currentplayers", helptext: "Alt + C", selected: true },
[
{ text: "Search by Name", id: 'searchname', helptext:"Alt + Z" },
{ text: "Search by IP", id: 'searchip', helptext:"Alt + X" }
]
]
}
},
{
text: "Help",
submenu: {
id: "helpmenuitem",
itemdata: [ { text: "Help", id: "help_reference" },
{ text: "About", id: "about" }
]
}
}
];
var oMainMenu = new YAHOO.widget.MenuBar("mainmenubar", { position: "static", lazyload: false, itemdata: aItemData });
oMainMenu.render(document.body);
// Generic 'Alert' Dialog
var alert_panel = new YAHOO.widget.SimpleDialog('alert', {
fixedcenter: true,
visible: false,
modal: true,
width: '300px',
constraintoviewport: true,
icon: YAHOO.widget.SimpleDialog.ICON_WARN,
// keylisteners: esckey,
buttons: [
{ text: 'OK', handler: function() { alert_panel.hide(); }, isDefault: true }
]
});
alert_panel.setHeader('Alert');
alert_panel.setBody('...');
alert_panel.render(document.body);
// Create a namepaced alert method
RemoteInterface.alert = function(str) {
alert_panel.setBody(str);
alert_panel.cfg.setProperty('icon', YAHOO.widget.SimpleDialog.ICON_WARN);
alert_panel.bringToTop();
alert_panel.show();
};
var oAboutPanel = new YAHOO.widget.Panel("about_info", {
width:"350px",
height:"150px",
visible:false,
draggable:true,
dragOnly:true,
close:true,
underlay:"Shadow",
fixedcenter:true,
constraintoviewport:true,
zIndex: 5
} );
oAboutPanel.render(document.body);
var oHelpPanel = new YAHOO.widget.Panel("help_panel", {
visible:false,
draggable:true,
dragOnly:true,
close:true,
underlay:"none",
fixedcenter:true,
constraintoviewport:true,
zIndex: 5
} );
oHelpPanel.render(document.body);
var oOptionsPanel = new YAHOO.widget.Dialog("options_panel", {
width:'360px',
height:'275px',
visible:false,
draggable:true,
dragOnly:true,
close:true,
underlay:"none",
fixedcenter:true,
constraintoviewport:true,
zIndex: 3,
buttons: [ { text: "Close", handler: function(o){ this.hide(); } } ]
} );
oOptionsPanel.render(document.body);
var fLoadOptionsPanel = function() {
var temp;
temp = document.getElementById('config_colornames');
temp.checked = config.bColorizeNames;
temp = document.getElementById('config_convertduration');
temp.checked = config.bConvertDuration;
temp = document.getElementById('config_showplayerids');
temp.checked = !config.bHideIds;
temp = document.getElementById('config_shownumericips');
temp.checked = !config.bHideNumericIps;
temp = document.getElementById('config_showcreation');
temp.checked = !config.bHideCreationDate;
temp = document.getElementById('config_datetimeformat');
temp.value = config.sDatetimeFormat;
oOptionsPanel.show();
};
var fSearchRedrawTables = function() {
for (var i =0; i < RemoteInterface.search_panels.length; i++) {
if (RemoteInterface.search_panels[i].oSearchTable) {
RemoteInterface.search_panels[i].oSearchTable.render();
}
}
};
var fColorNames = function() {
config.bColorizeNames = !config.bColorizeNames;
fSearchRedrawTables();
};
var fConvertDuration = function() {
config.bConvertDuration = !config.bConvertDuration;
fSearchRedrawTables();
};
// Hide() or Show() a column depending on boolean bToggle.
// ( bToggle = true -> Column is Hidden )
var fToggleColumn = function(bToggle, sColumnId) {
if (sColumnId) {
for (var i=0; i < RemoteInterface.search_panels.length; i++) {
if (RemoteInterface.search_panels[i].oSearchTable) {
var column1 = RemoteInterface.search_panels[i].oSearchTable.getColumn(sColumnId);
if (column1) {
if (bToggle) {
RemoteInterface.search_panels[i].oSearchTable.hideColumn(column1);
} else {
RemoteInterface.search_panels[i].oSearchTable.showColumn(column1);
}
}
}
}
for (var k=0; k < aSearchNameTableColums.length; k++) {
if (aSearchNameTableColums[k].key == sColumnId) {
aSearchNameTableColums[k].hidden = bToggle;
}
}
}
};
var fShowIds = function() {
config.bHideIds = !config.bHideIds;
fToggleColumn(config.bHideIds, 'player_id');
fSearchRedrawTables();
};
var fShowNumericIps = function() {
config.bHideNumericIps = !config.bHideNumericIps;
fToggleColumn(config.bHideNumericIps, 'ip');
fSearchRedrawTables();
};
var fShowCreation = function() {
config.bHideCreationDate = !config.bHideCreationDate;
fToggleColumn(config.bHideCreationDate, 'creation');
fSearchRedrawTables();
};
var fUpdateDateTime = function() {
var temp = document.getElementById('config_datetimeformat');
if (temp) {
config.sDatetimeFormat = temp.value;
fSearchRedrawTables();
} else {
RemoteInterface.alert("Error - missing format string.");
}
};
var oApplyDateTimeBtn = new YAHOO.widget.Button({ label:"Apply", id:"config_applydatetime", container:"config_applybtn", type: "button" });
oApplyDateTimeBtn.on("click", fUpdateDateTime);
var oStatusPanel = new YAHOO.widget.Panel("status_panel", {
width:"430px",
visible:false,
draggable:true,
dragOnly:true,
close:true,
underlay:"shadow",
constraintoviewport:true,
zIndex: 2
} );
oStatusPanel.setHeader("Status");
oStatusPanel.setBody("This panel contains information on the backend.<br><br><div id='status_tabs'><\/div>");
oStatusPanel.setFooter("<span id='status_refresh'><\/span>");
oStatusPanel.render(document.body);
var oTabView = new YAHOO.widget.TabView();
oTabView.addTab( new YAHOO.widget.Tab({ label: 'Backend', content: '<div id="status_backend_tab"><\/div>', active: true }) );
//oTabView.addTab( new YAHOO.widget.Tab({ label: 'Log Files', content: '<div id="backend_log_tab"><\/div>' }) );
oTabView.addTab( new YAHOO.widget.Tab({ label: 'Server', content: '<div id="status_server_tab"><\/div>' }) );
oTabView.appendTo("status_tabs");
var fUpdateStatus = function() {
var back_tab = document.getElementById('status_backend_tab');
var serv_tab = document.getElementById('status_server_tab');
var sQuery = config.sUrlBase + '?serverstatus';
var tmp_str = '';
var hdl_successful = function(o) {
if (o.responseText !== undefined) {
var status_data = '';
try { status_data = YAHOO.lang.JSON.parse(o.responseText); }
catch (e) { RemoteInterface.alert('An error occured while parsing the reply from the server...'); }
if (status_data.backend !== undefined) {
var status = parseInt(status_data.backend.backend_status, 10);
var last_update = status_data.backend.last_update;
var msg = '';
switch (status) {
case 2:
msg = 'Backend reports OK status.'; break;
case 1:
msg = 'Backend reports last shutdown was unclean.'; break;
case 0:
msg = 'The backend is not running.'; break;
case -1:
msg = 'Backend error: Could not open a socket.'; break;
case -2:
msg = 'Backend error: Could not connect to external address.'; break;
case -3:
msg = 'Backend error: Could not send message to server.'; break;
case -4:
msg = 'Backend error: Error recieving data from server.'; break;
case -5:
msg = 'Backend reports that the Server did not respond - request timed out.'; break;
case -6:
msg = 'Backend error: Could not close the socket.'; break;
case -10:
msg = 'Backend reports: Bad rcon password.'; break;
case -11:
msg = 'Backend reports: The server did not recognize the command.'; break;
case -12:
msg = 'Backend reports: No rcon password set yet.'; break;
case -13:
msg = 'Backend reports: Server config is missing or incorrect.'; break;
default:
msg = 'Unknown status value.';
}
if (status > 1) {
back_tab.innerHTML = "<p class='status_ok'>" + msg + "<\/p><p>Last Update: "+ last_update +"<\/p>";
} else {
back_tab.innerHTML = "<p class='status_err'>" + msg + "<\/p><p>Last Update: "+ last_update +"<\/p>";
}
}
if (status_data.server !== undefined) {
var name = status_data.server.name;
var map = status_data.server.current_map;
var ip = RemoteInterface.long2ip(parseInt(status_data.server.ip, 10));
var port = parseInt(status_data.server.port, 10);
var t_delay = parseInt(status_data.server.timeout_delay, 10);
var t_wait = parseInt(status_data.server.timeout_wait_delay, 10);
var timeouts = parseInt(status_data.server.timeouts, 10);
//var timeout_last = parseInt(status_data.server.timeout_last, 10);
//var timeout_Date = new Date(timeout_last * 1000);
var srv_port = document.getElementById('srv_port');
if (srv_port && srv_port.value == '') { srv_port.value = port; }
var srv_t_delay = document.getElementById('srv_timeout');
if (srv_t_delay && srv_t_delay.value == '') { srv_t_delay.value = t_delay; }
var srv_t_wait = document.getElementById('srv_timeout_wait');
if (srv_t_wait && srv_t_wait.value == '') { srv_t_wait.value = t_wait; }
var srv_ip = document.getElementById('srv_ip_address');
if (srv_ip && srv_ip.value == '') { srv_ip.value = ip; }
tmp_str = "<table class='server_info'><tbody>";
tmp_str += "<tr><td>Server Name<\/td><td class='name'>"+ name +"<\/td><\/tr>";
tmp_str += "<tr><td>IP Address<\/td><td>"+ ip +"<\/td><\/tr>";
tmp_str += "<tr><td>Port<\/td><td>"+ port +"<\/td><\/tr>";
tmp_str += "<tr><td>Map<\/td><td>"+ map +"<\/td><\/tr>";
tmp_str += "<tr><td>Timeouts<\/td><td>"+ timeouts +"<\/td><\/tr>";
//tmp_str += "<tr><td>Last Timeout<\/td><td>"+ timeout_Date.toGMTString() +"<\/td><\/tr>";
tmp_str += "<\/tbody><\/table>";
serv_tab.innerHTML = tmp_str;
return true;
}
}
RemoteInterface.alert('The server response was invalid.');
return false;
};
var hdl_failure = function(o) {
if (o.responseText !== undefined) {
tmp_str = "<p class='error_title'>An error occured while communcating to the server<\/p>";
tmp_str += "<p class='error_small'><u>Details:<\/u><br>";
tmp_str += "Transaction id: "+ o.tId +"<br>HTTP status: "+ o.status +"<br>";
tmp_str += "Status code message: "+ o.statusText +"<\/p>";
back_tab.innerHTML = tmp_str;
} else {
RemoteInterface.alert('The server response was invalid.');
}
};
var status_callback = {
success: hdl_successful,
failure: hdl_failure,
argument: null,
timeout: 1500
};
YAHOO.util.Connect.asyncRequest('GET', sQuery, status_callback, null);
};
var oStatusRefresh = new YAHOO.widget.Button({ label:"Refresh", id:"statusupdate", container:"status_refresh", type: "button" });
oStatusRefresh.on("click", fUpdateStatus);
// Generic 'Cancel' handler, simply hides the dialog box
var handleGenericCancel = function(o) { this.cancel(); };
var handleServerCfgApply = function(o) {
var ans = confirm("Are you sure you want to change the server config?");
if ( ans ) {
this.submit();
} else {
this.cancel();
}
};
var oServerCfgDlg = new YAHOO.widget.Dialog("server_config", {
width: "325px",
fixedcenter: true,
visible:false,
draggable:true,
dragOnly:true,
close:true,
underlay:"Shadow",
zIndex: 3,
constraintoviewport: true,
buttons: [ { text: "Apply", handler: handleServerCfgApply }, { text: "Cancel", handler: handleGenericCancel, isDefault: true } ]
} );
oServerCfgDlg.validate = function(o) {
var data = this.getData();
if (data.ip == "" ) {
alert("Please enter an IP address.");
} else if (data.port == "") {
alert("Please enter a Port number.");
} else if (data.timeout_delay == "") {
alert("Please enter a timeout delay.");
} else if (data.timeout_wait == "") {
alert("Please enter a time to wait between timeouts.");
} else {
return true;
}
return false;
};
oServerCfgDlg.callback.success = function(o) {
RemoteInterface.alert("Successfully updated the server config.");
alert( YAHOO.lang.dump(o) );
};
oServerCfgDlg.callback.failure = function(o) {
RemoteInterface.alert("Failed to update the server config.");
alert( YAHOO.lang.dump(o) );
};
oServerCfgDlg.render(document.body);
var oServerRconPwDlg = new YAHOO.widget.Dialog("server_rcon_pw", {
width: "305px",
fixedcenter: true,
visible:false,
draggable:true,
dragOnly:true,
close:true,
underlay:"Shadow",
zIndex: 3,
constraintoviewport: true,
buttons: [ { text: "Apply", handler:function(){this.submit();} }, { text: "Cancel", handler: handleGenericCancel, isDefault: true } ]
} );
oServerRconPwDlg.validate = function(o) {
var data = this.getData();
if (data.pw == "") {
alert("Please enter a password.");
return false;
} else {
return true;
}
};
oServerRconPwDlg.callback.success = function(o) {
RemoteInterface.alert("Updated the rcon password.");
alert( YAHOO.lang.dump(o) );
};
oServerRconPwDlg.callback.failure = function(o) {
RemoteInterface.alert("Failed to update the rcon password");
alert( YAHOO.lang.dump(o) );
};
oServerRconPwDlg.render(document.body);
var fSearchGarbageCollect = function() {
for (var i =0; i < RemoteInterface.search_panels.length; i++) {
if (RemoteInterface.search_panels[i] && RemoteInterface.search_panels[i].cfg.config.visible.value === false) {
if (RemoteInterface.search_panels[i].oSearchTable) {
RemoteInterface.search_panels[i].oSearchTable.destroy();
}
RemoteInterface.search_panels[i].destroy();
RemoteInterface.search_panels.remove(i);
i--;
}
}
};
var fNewSearchPanel = function(o) {
if (o && o.responseText !== undefined) {
var search_data = '';
try { search_data = YAHOO.lang.JSON.parse(o.responseText); }
catch (e) { RemoteInterface.alert('An error occured while parsing the reply from the server...'); }
var id_name = "search_panel_" + o.tId;
var id_table = "search_table_" + o.tId;
var id_page = "search_paginator_" + o.tId;
var temp = new YAHOO.widget.Panel( id_name, {
visible:false,
draggable:true,
dragOnly:true,
close:true,
underlay:"Shadow",
constraintoviewport:false,
zIndex:1
} );
temp.setHeader("Search Results");
temp.setBody("<div class='search_pager' id='"+ id_page +"'><\/div><div id='"+ id_table +"'><\/div>");
temp.render( document.getElementById("search_results_container") );
temp.oSearchPaginator = new YAHOO.widget.Paginator({
containers: id_page,
rowsPerPage: 15,
rowsPerPageOptions : [10,15,25,30,40,50],
alwaysVisible: false,
template: '<b>{FirstPageLink} {PreviousPageLink}<\/b>{CurrentPageReport}<b>{NextPageLink} {LastPageLink}<\/b> {RowsPerPageDropdown}per page',
firstPageLinkLabel: "<<",
lastPageLinkLabel: ">>",
nextPageLinkLabel: ">",
previousPageLinkLabel: "<"
});
/* Table column configs */
var aSearchNameTableColums = [
{ key:"player_id", label:"ID", sortable:true, hidden: config.bHideIds },
{ key:"name", label:"Name", formatter: formatNameColors },
{ key:"ip", label:"IP Address", sortable:true, hidden: config.bHideNumericIps },
{ key:"ip_text", label:"IP Address"},
{ key:"duration", label:"Duration", formatter: formatDuration, sortable:true },
{ key:"creation", label:"Creation", formatter: formatDateTime, hidden: config.bHideCreationDate }
];
var oSearchNameSchema = {
resultsList: 'data',
fields:[{key:'player_id', parser:'number'},
{key:'name'},
{key:'duration', parser:'number'},
{key:'creation'},
{key:'ip', parser:'number'},
{key:'ip_text'} ],
metaFields: { rows: 'rows' }
};
var aSearchIpTableColums = [
{ key:"player_id", label:"Player ID", sortable:true, hidden: config.bHideIds },
{ key:"ip", label:"IP", sortable:true, hidden: config.bHideNumericIps },
{ key:"ip_text", label:"IP Address" },
{ key:"name", label:"Player Name", formatter: formatNameColors },
{ key:"creation", label:"Creation", formatter: formatDateTime, hidden: config.bHideCreationDate }
];
var oSearchIpSchema = {
resultsList: 'data',
fields:[{key:'player_id', parser:'number'},
{key:'ip', parser:'number'},
{key:'ip_text'},
{key:'name'},
{key:'creation'} ],
metaFields: { rows: 'rows' }
};
var oSearchNameTableConfigs = {
sortedBy: { key:'player_id', dir: YAHOO.widget.DataTable.CLASS_ASC },
selectionMode: 'single',
paginator: temp.oSearchPaginator
};
var oSearchIpTableConfigs = {
sortedBy: { key:'ip', dir: YAHOO.widget.DataTable.CLASS_ASC },
selectionMode: 'single',
paginator: temp.oSearchPaginator
};
/* End table configs*/
temp.oSearchDataSource = new YAHOO.util.LocalDataSource( o.responseText );
temp.oSearchDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
if (search_data.type == "search_name") {
temp.oSearchDataSource.responseSchema = oSearchNameSchema;
temp.oSearchTable = new YAHOO.widget.DataTable( id_table, aSearchNameTableColums, temp.oSearchDataSource, oSearchNameTableConfigs);
} else if (search_data.type == "search_ip") {
temp.oSearchDataSource.responseSchema = oSearchIpSchema;
temp.oSearchTable = new YAHOO.widget.DataTable( id_table, aSearchIpTableColums, temp.oSearchDataSource, oSearchIpTableConfigs);
} else {
RemoteInterface.alert('The server response is the wrong type.');
}
RemoteInterface.search_panels.push(temp);
temp.show();
} else {
RemoteInterface.alert('The server response was invalid.');
}
fSearchGarbageCollect();
};
/* Functions used by the Search Panel Tables */
var formatNameColors = function(elCell, oRecord, oColumn, oData) {
var list = oData;
if (config.bColorizeNames) {
list = list.replace(/\^0/g, "<font color='#000000'>");
list = list.replace(/\^1/g, "<font color='#FF0000'>");
list = list.replace(/\^2/g, "<font color='#00FF00'>");
list = list.replace(/\^3/g, "<font color='#FFFF00'>");
list = list.replace(/\^4/g, "<font color='#0000FF'>");
list = list.replace(/\^5/g, "<font color='#00FFFF'>");
list = list.replace(/\^6/g, "<font color='#FF00FF'>");
list = list.replace(/\^7/g, "<font color='#FFFFFF'>");
}
elCell.innerHTML = list;
};
var formatDuration = function(elCell, oRecord, oColumn, oData) {
if (config.bConvertDuration) {
var days, hr, min, sec;
if (oData > 86400) {
days = Math.floor(oData / 86400);
hr = Math.floor((oData % 86400) / 3600);
min = Math.floor((oData % 3600) / 60);
sec = oData % 60;
elCell.innerHTML = days + ' d ' + hr + ' hr ' + min + ' min ' + sec + ' sec';
} else if (oData > 3600) {
hr = Math.floor(oData / 3600);
min = Math.floor((oData % 3600) / 60);
sec = oData % 60;
elCell.innerHTML = hr + ' hr ' + min + ' min ' + sec + ' sec';
} else if (oData > 60) {
min = Math.floor(oData / 60);
sec = oData % 60;
elCell.innerHTML = min + ' min ' + sec + ' sec';
} else {
elCell.innerHTML = oData + ' sec';
}
} else {
elCell.innerHTML = oData;
}
};
var formatDateTime = function(elCell, oRecord, oColumn, oData) {
if (oData) {
var oDate = new Date(oData);
elCell.innerHTML = YAHOO.util.Date.format( oDate, {format: config.sDatetimeFormat} );
} else {
elCell.innerHTML = 'No Data';
}
};
var formatList = function(elCell, oRecord, oColumn, oData) {
if (oData) {
var str = oData.toString();
var list = str.split(',');
str = '';
for (var i=0; i < list.length; i++) {
str = str + list[i] + ', ';
}
elCell.innerHTML = str.substring(0, str.length - 2);
}
};
var formatNameList = function(elCell, oRecord, oColumn, oData) {
var list = oData.slice(1, oData.length - 1);
if (bColorizeNames) {
//list = '<span style="background-color: #AAAAAA;">' + list;
list = list.replace(/\^0/g, "<font color='#000000'>");
list = list.replace(/","/g, "<font color='#000000'>\",\"");
list = list.replace(/"$/, "<font color='#000000'>\"");
list = list.replace(/\^1/g, "<font color='#FF0000'>");
list = list.replace(/\^2/g, "<font color='#00FF00'>");
list = list.replace(/\^3/g, "<font color='#FFFF00'>");
list = list.replace(/\^4/g, "<font color='#0000FF'>");
list = list.replace(/\^5/g, "<font color='#00FFFF'>");
list = list.replace(/\^6/g, "<font color='#FF00FF'>");
list = list.replace(/\^7/g, "<font color='#FFFFFF'>");
//list = list + '<\/span>';
}
elCell.innerHTML = list;
};
/* End of Search Panel Functions */
var msgSearchError = function() {
RemoteInterface.alert("There was an error preforming the search.");
};
var handleSubmitName = function(o) { this.submit(); };
var oSearchNameDlg = new YAHOO.widget.Dialog("search_name",
{ width: "350px",
visible: false,
draggable: true,
dragOnly: true,
close: true,
fixedcenter:true,
underlay: "none",
zIndex: 3,
constraintoviewport: true,
buttons: [ { text: "Search", handler: handleSubmitName, isDefault: true }, { text: "Close", handler: handleGenericCancel } ]
} );
oSearchNameDlg.validate = function(o) {
var data = this.getData();
if (data && data.name_text == "") {
alert("Please enter some text to search for..");
return false;
} else {
return true;
}
};
oSearchNameDlg.callback.success = fNewSearchPanel;
oSearchNameDlg.callback.failure = msgSearchError;
oSearchNameDlg.render(document.body);
var handleSubmitIp = function(o) { this.submit(); };
var oSearchIpDlg = new YAHOO.widget.Dialog("search_ip", {
width: "275px",
visible: false,
draggable: true,
dragOnly: true,
close: true,
fixedcenter:true,
underlay: "none",
zIndex: 3,
constraintoviewport: true,
buttons: [ { text:"Search", handler: handleSubmitIp }, { text:"Close", handler: handleGenericCancel, isDefault: true } ]
} );
oSearchIpDlg.validate = function(o) {
var data = this.getData();
if (data && data.ip_text == "") {
alert("Please enter something to search for..");
return false;
} else {
return true;
}
};
oSearchIpDlg.callback.success = fNewSearchPanel;
oSearchIpDlg.callback.failure = msgSearchError;
oSearchIpDlg.render(document.body);
var fUpdateServerInfo = function() {
var server_info_area = document.getElementById('server_info_section');
var sQuery = config.sUrlBase + '?status';
var tmp_str = '';
var hdl_successful = function(o) {
if (o.responseText !== undefined) {
var status_data = '';
try { status_data = YAHOO.lang.JSON.parse(o.responseText); }
catch (e) { RemoteInterface.alert('An error occured while parsing the reply from the server...'); }
if (status_data.server !== undefined) {
var name = status_data.server.name;
var map = status_data.server.current_map;
var ip = RemoteInterface.long2ip(parseInt(status_data.server.ip, 10));
var port = parseInt(status_data.server.port, 10);
var srv_port = document.getElementById('srv_port');
if (srv_port && srv_port.value == '') { srv_port.value = port; }
var srv_ip = document.getElementById('srv_ip_address');
if (srv_ip && srv_ip.value == '') { srv_ip.value = ip; }
tmp_str = "<table class='server_info'><tbody>";
tmp_str += "<tr><td>Server Name<\/td><td class='name'>"+ name +"<\/td><\/tr>";
tmp_str += "<tr><td>Address<\/td><td>"+ ip +":"+ port +"<\/td><\/tr>";
//tmp_str += "<tr><td>Port<\/td><td>"+ port +"<\/td><\/tr>";
tmp_str += "<tr><td>Map<\/td><td>"+ map +"<\/td><\/tr>";
tmp_str += "<\/tbody><\/table>";
server_info_area.innerHTML = tmp_str;
return true;
}
}
};
var hdl_failure = function(o) {
if (o.responseText !== undefined) {
tmp_str = "<p class='error_title'>An error occured while communcating to the server<\/p>";
tmp_str += "<p class='error_small'><u>Details:<\/u><br>";
tmp_str += "Transaction id: "+ o.tId +"<br>HTTP status: "+ o.status +"<br>";
tmp_str += "Status code message: "+ o.statusText +"<\/p>";
server_info_area.innerHTML = tmp_str;
} else {
RemoteInterface.alert('The server response was invalid.');
}
};
var status_callback = {
success: hdl_successful,
failure: hdl_failure,
argument: null,
timeout: 1500
};
YAHOO.util.Connect.asyncRequest('GET', sQuery, status_callback, null);
};
var oCurrentPlayers = new YAHOO.widget.Panel("current_players", {
/* width:"700px",
height:"400px", */
visible:false,
draggable:true,
dragOnly:true,
close:true,
underlay:"none",
fixedcenter:true,
constraintoviewport:true,
zIndex: -1
} );
oCurrentPlayers.setBody("<div id='server_info_section'><\/div><div id='player_table'><\/div>");
oCurrentPlayers.render(document.body);
var aPlayerTableColumns = [
{ key:"slot_num", label:"Slot", formatter:"number", sortable:true },
{ key:"score", label:"Score", formatter:"number", sortable:true },
{ key:"ping", label:"Ping", formatter:"number", sortable:true },
{ key:"name", label:"Player Name", formatter: formatNameColors },
{ key:"ip", label:"IP Address" },
{ key:"qport", label:"q Port", formatter:"number", sortable:true },
{ key:"rate", label:"Rate", formatter:"number", sortable:true }
];
var oPlayerDataSource = new YAHOO.util.DataSource( config.sUrlBase + '?players' );
oPlayerDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
oPlayerDataSource.responseSchema = {
resultsList: 'data',
fields:[{key:'slot_num', parser:'number'},
{key:'score', parser:'number'},
{key:'ping', parser:'number'},
{key:'name'},
{key:'ip', parser: RemoteInterface.long2ip },
{key:'qport', parser:'number'},
{key:'rate', parser:'number'} ],
metaFields: { rows: 'rows' }
};
var oPlayerTableConfigs = {
sortedBy:{key:'slot_num',dir:'asc'},
selectionMode: 'single'
};
var oPlayerTable = new YAHOO.widget.DataTable("player_table", aPlayerTableColumns, oPlayerDataSource, oPlayerTableConfigs);
var oPlayerTableState = oPlayerTable.getState();
var PlayerDataCallback = {
success: oPlayerTable.onDataReturnSetRows,
failure: oPlayerTable.onDataReturnSetRows, /* function() { alert("Error getting player list from database backend."); }, */
scope: oPlayerTable,
argument: oPlayerTable.getState()
};
// TODO: If Possible: only poll backend if the playerlist panel is visible...
oPlayerDataSource.setInterval(4000, null, PlayerDataCallback);
oPlayerDataSource.subscribe("responseEvent", fUpdateServerInfo);
// Listeners for the MenuBar
YAHOO.util.Event.addListener("about", "click", oAboutPanel.show, oAboutPanel, true);
YAHOO.util.Event.addListener("help_reference", "click", oHelpPanel.show, oHelpPanel, true);
YAHOO.util.Event.addListener("options", "click", fLoadOptionsPanel);
YAHOO.util.Event.addListener("serverpassword", "click", oServerRconPwDlg.show, oServerRconPwDlg, true);
YAHOO.util.Event.addListener("currentplayers", "click", oCurrentPlayers.show, oCurrentPlayers, true);
YAHOO.util.Event.addListener("mainstatus", "click", oStatusPanel.show, oStatusPanel, true);
YAHOO.util.Event.addListener("serverconfig", "click", oServerCfgDlg.show, oServerCfgDlg, true);
YAHOO.util.Event.addListener("searchname", "click", oSearchNameDlg.show, oSearchNameDlg, true);
YAHOO.util.Event.addListener("searchip", "click", oSearchIpDlg.show, oSearchIpDlg, true);
// Listeners for Options Panel
YAHOO.util.Event.addListener("config_colornames", "click", fColorNames);
YAHOO.util.Event.addListener("config_convertduration", "click", fConvertDuration);
YAHOO.util.Event.addListener("config_showplayerids", "click", fShowIds);
YAHOO.util.Event.addListener("config_shownumericips", "click", fShowNumericIps);
YAHOO.util.Event.addListener("config_showcreation", "click", fShowCreation);
// Listeners for Keyboard shortcuts
var key1 = new YAHOO.util.KeyListener(document, { alt:true, keys:90}, {fn:oSearchNameDlg.show, scope:oSearchNameDlg, correctScope:true});
var key2 = new YAHOO.util.KeyListener(document, { alt:true, keys:88}, {fn:oSearchIpDlg.show, scope:oSearchIpDlg, correctScope:true});
var key3 = new YAHOO.util.KeyListener(document, { alt:true, keys:67}, {fn:oCurrentPlayers.show, scope:oCurrentPlayers, correctScope:true});
key1.enable();
key2.enable();
key3.enable();
};
/*** Initialize and render when the DOM is ready to be scripted. ***/
YAHOO.util.Event.onDOMReady( RemoteInterface.init );