-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathgames.js
374 lines (317 loc) · 12.9 KB
/
games.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
/*
*
* Game Configuration
*
*/
// Load server settings tab
function game_tab_startup(gameID)
{
if(gameID == "")
{
alert("No game ID given");
return false;
}
$.ajax({
url: ajaxURL,
data: 'a=games_startup&id='+gameID,
success:function(html){
$('#panel_center').hide().html(html).fadeIn('fast');
}
});
}
// Save
function game_save(gameID)
{
if(gameID == "")
{
alert("No game ID given!");
return false;
}
var port = encodeURIComponent($('#port').val());
var game_name = encodeURIComponent($('#name').val());
var game_intname = encodeURIComponent($('#intname').val());
var game_working_dir = encodeURIComponent($('#working_dir').val());
var game_pid_file = encodeURIComponent($('#pid_file').val());
var game_conf_file = encodeURIComponent($('#config_file').val());
var game_descr = encodeURIComponent($('#desc').val());
var game_inst_mirrors = encodeURIComponent($('#install_mirrors').val());
var game_installcmd = encodeURIComponent($('#install_cmd').val());
var game_updatecmd = encodeURIComponent($('#update_cmd').val());
var game_simplecmd = encodeURIComponent($('#simplecmd').val());
var game_bannedchars = encodeURIComponent($('#banned_chars').val());
var game_steam = encodeURIComponent($('#steam_based').val());
var game_steam_name = encodeURIComponent($('#steam_name').val());
var game_query_eng = encodeURIComponent($('#query_engine').val());
var game_startup = encodeURIComponent($('#startup').val());
var game_map = encodeURIComponent($('#def_map').val());
var game_maxpl = encodeURIComponent($('#def_maxplayers').val());
var game_hostname = encodeURIComponent($('#def_hostname').val());
var game_cfg_sep = encodeURIComponent($('#cfg_sep').val());
var game_cfg_ip = encodeURIComponent($('#cfg_ip').val());
var game_cfg_port = encodeURIComponent($('#cfg_port').val());
var game_cfg_maxpl = encodeURIComponent($('#cfg_maxplayers').val());
var game_cfg_map = encodeURIComponent($('#cfg_map').val());
var game_cfg_hostn = encodeURIComponent($('#cfg_hostname').val());
var game_cfg_rcon = encodeURIComponent($('#cfg_rcon').val());
var game_cfg_passw = encodeURIComponent($('#cfg_password').val());
if(port == "") { alert("You must fill out the Port field"); return false; }
else if(game_name == "") { alert("You must fill out the Name field"); return false; }
else if(game_intname == "") { alert("You must fill out the Internal Name field"); return false; }
// Check internal regex
var intRegex = new RegExp(/^[a-zA-Z0-9-_]+$/i);
if(!intRegex.test(game_intname))
{
alert("Invalid Internal Name specified! Only letters, numbers, - and _ are accepted.");
return false;
}
var datastr = "&id="+gameID+"&do=save&desc="+game_descr+"&port="+port+"&name="+game_name+"&intname="+game_intname+"&working_dir="+game_working_dir+"&pid_file="+game_pid_file+"&config_file="+game_conf_file+"&install_mirrors="+game_inst_mirrors+"&install_cmd="+game_installcmd+"&update_cmd="+game_updatecmd+"&simplecmd="+game_simplecmd+"&banned_chars="+game_bannedchars+"&is_steam="+game_steam+"&steam_name="+game_steam_name+"&query_engine="+game_query_eng+"&startup="+game_startup+"&cfg_sep="+game_cfg_sep+"&cfg_ip="+game_cfg_ip+"&cfg_port="+game_cfg_port+"&cfg_maxplayers="+game_cfg_maxpl+"&cfg_map="+game_cfg_map+"&cfg_hostname="+game_cfg_hostn+"&cfg_rcon="+game_cfg_rcon+"&cfg_password="+game_cfg_passw+"&map="+game_map+"&maxplayers="+game_maxpl+"&hostname="+game_hostname;
$.ajax({
url: ajaxURL,
type: "POST",
data: 'a=games_actions'+datastr,
success:function(html){
if(html == 'success') infobox('s','');
else infobox('f','Failed: '+html);
},
error:function(a,b,c){
infobox('f','Error: '+b+', '+c);
}
});
}
// Create new game
function game_add()
{
/*
var port = encodeURIComponent($('#add_port').val());
var game_name = encodeURIComponent($('#add_name').val());
var game_intname = encodeURIComponent($('#add_intname').val());
var game_working_dir = encodeURIComponent($('#add_working_dir').val());
var game_pid_file = encodeURIComponent($('#add_pid_file').val());
var game_descr = encodeURIComponent($('#add_desc').val());
var game_updatecmd = encodeURIComponent($('#add_update_cmd').val());
var game_simplecmd = encodeURIComponent($('#add_simplecmd').val());
var game_steam = encodeURIComponent($('#add_steam_based').val());
var game_steam_name = encodeURIComponent($('#steam_name').val());
var game_query_eng = encodeURIComponent($('#add_query_engine').val());
*/
var datastr = "";
var failed = "";
$('input, textarea, select').each(function(index){
var thisID = $(this).attr('id');
var thisVal = encodeURIComponent($(this).val());
// alert("ID: "+thisID+", val: "+thisVal+", index: "+index);
// Check required
if(thisID == "add_port" && thisVal == "") { alert("You must fill out the Port field"); failed="1"; return false; }
else if(thisID == "add_def_maxplayers" && thisVal == "") { alert("You must fill out the Max Players field"); failed="1"; return false; }
else if(thisID == "add_name" && thisVal == "") { alert("You must fill out the Name field"); failed="1"; return false; }
else if(thisID == "add_intname" && thisVal == "") { alert("You must fill out the Internal Name field"); failed="1"; return false; }
else if(thisID == "add_simplecmd" && thisVal == "") { alert("You must fill out the CMD field"); failed="1"; return false; }
// Check internal name regex
if(thisID == "add_intname")
{
var intRegex = new RegExp(/^[a-zA-Z0-9-_]+$/i);
if(!intRegex.test(thisID))
{
alert("Invalid Internal Name specified! Only letters, numbers, - and _ are accepted.");
failed="1";
return false;
}
}
datastr = datastr+"&"+thisID+"="+thisVal;
});
// alert("DATA: "+datastr);
if(failed == "1") return false;
//alert("DATA: "+dataList);
/*
// Check internal regex
var intRegex = new RegExp(/^[a-zA-Z0-9-_]+$/i);
if(!intRegex.test(game_intname))
{
alert("Invalid Internal Name specified! Only letters, numbers, - and _ are accepted.");
return false;
}
*/
/*
if(port == "") { alert("You must fill out the Port field"); return false; }
else if(game_name == "") { alert("You must fill out the Name field"); return false; }
else if(game_intname == "") { alert("You must fill out the Internal Name field"); return false; }
else if(game_simplecmd == "") { alert("You must fill out the CMD field"); return false; }
*/
// var datastr = "&do=add&desc="+game_descr+"&port="+port+"&name="+game_name+"&intname="+game_intname+"&working_dir="+game_working_dir+"&pid_file="+game_pid_file+"&update_cmd="+game_updatecmd+"&simplecmd="+game_simplecmd+"&is_steam="+game_steam+"&steam_name="+game_steam_name+"&query_engine="+game_query_eng;
$.ajax({
url: ajaxURL,
type: "POST",
data: 'a=games_actions&do=add'+datastr,
success:function(html){
if(html == 'success')
{
infobox('s','');
setTimeout("mainpage('games','')", 1000);
}
else
{
infobox('f','Failed: '+html);
}
},
error:function(a,b,c){
infobox('f','Error: '+b+', '+c);
}
});
}
// Confirm deleting a game
function game_confirm_del(gameID)
{
if(gameID == "")
{
alert("No game ID provided!");
return false;
}
var answer = confirm("Are you sure?\n\nDelete this game?");
if(answer) game_del(gameID);
else return false;
}
// Delete a game
function game_del(gameID)
{
if(gameID == "")
{
alert("No game ID provided!");
return false;
}
$.ajax({
url: ajaxURL,
data: 'a=games_actions&do=delete&id='+gameID,
success:function(html){
if(html == 'success')
{
infobox('s','');
setTimeout("mainpage('games','')", 1000);
}
else
{
infobox('f','Failed: '+html);
}
},
error:function(a,b,c){
infobox('f','Error: '+b+', '+c);
}
});
}
/*
*
* Startup Items / CMD Line Editor
*
*/
function games_save_startup(gameID)
{
if(gameID == "")
{
alert("No game ID provided!");
return false;
}
var data = "";
var sortList = $('#sort_list').val();
//var startType = $('#startup').val();
//var startType = $('input[name=startup]').val();
if($('#smp').is(':checked')) var startType = 'smp';
else var startType = 'str';
// Loop through all items and their values
$('input').each(function(index,value) {
var thisID = value.id;
var thisValue = encodeURIComponent(value.value);
// Update checkboxes
if($('#'+thisID).is(':checked'))
{
$('#'+thisID).val('1');
thisValue = '1';
}
data += "&"+thisID+"="+thisValue;
});
// a=server_startup_save
$.ajax({
url: ajaxURL,
data: "a=games_actions&do=startup_save&id="+gameID+data+"&start_type="+startType+"&sort_list="+sortList,
success:function(html){
if(html == 'success') infobox('s','');
else infobox('f','Failed: '+html);
},
error:function(a,b,c){
alert("Error: "+a+", b: "+b+", c: "+c);
}
});
}
// Delete a startup item
function games_del_startup(startID,serverID)
{
if(startID == "" || serverID == "")
{
alert("No startup ID or server ID provided!");
return false;
}
$.ajax({
url: ajaxURL,
data: "a=games_actions&do=startup_del_item&id="+startID+"&serverid="+serverID,
success:function(html){
if(html == 'success')
{
//infobox('s','');
$('#sortitm_'+startID).fadeOut('slow');
}
else
{
infobox('f','Failed: '+html);
}
},
error:function(a,b,c){
alert("Error: "+a+", b: "+b+", c: "+c);
}
});
}
// Confirm deleting a startup item
function games_confirm_del_startup(startID,serverID)
{
var answer = confirm("Are you sure?\n\nDelete this default startup item?");
if(answer) games_del_startup(startID,serverID)
else return false;
}
function game_showcreate()
{
$.ajax({
url: ajaxURL,
data: 'a=games_actions&do=show_creategame',
success:function(html){
// Show modal with info
$("#modal").html(html).modal({overlayClose:true,opacity:70,overlayCss:{backgroundColor:"#000"},onClose: function (dialog) {
dialog.data.fadeOut('fast',function () { $.modal.close(); });
}});
}
});
}
// Submit a new game to Cloud Games for review and potential addition
function game_submit_cloudgames_confirm(gameID)
{
if(gameID == "")
{
alert("No game provided!");
return false;
}
var answer = confirm("Are you sure?\n\nThis will submit this custom game to the public GamePanelX Cloud Games for review and addition. By submitting this game, you certify you have personally tested this server and that it is working to the best of your knowledge.\n\nBy submitting, you also show your understanding and agreement that we will receive the following Settings from your GamePanelX installation: Company Name, Email and GamePanelX Version.\n\nContinue with submission?");
if(answer) game_submit_cloudgames(gameID);
else return false;
}
function game_submit_cloudgames(gameID)
{
if(gameID == "")
{
alert("Submit: No game provided!");
return false;
}
$.ajax({
url: ajaxURL,
data: 'a=games_actions&do=submit_cloudgames&id='+gameID,
success:function(html){
if(html == 'success') infobox('s','');
else infobox('f','Failed: '+html);
}
});
}