This repository has been archived by the owner on Nov 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
script.js
187 lines (164 loc) · 4.86 KB
/
script.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
$( document ).ready(function() {
var lastCommand = "";
$("#txtCommand").bind("enterKey",function(e){
lastCommand = $("#txtCommand").val();
sendCommand(lastCommand);
});
$("#txtCommand").keyup(function(e){
if(e.keyCode == 13)
{
$(this).trigger("enterKey");
$(this).val("");
}
if(e.keyCode == 38)
{
$(this).val(lastCommand);
}
});
$( "#btnSend" ).click(function() {
if($("#txtCommand").val() != "") $("#btnSend").prop('disabled', true);
sendCommand($("#txtCommand").val());
if ($("#chkAutoScroll").is(':checked')) scrollLogsDown();
});
$( "#btnClearLog" ).click(function() {
$("#groupConsole").empty();
alertInfo("Console has cleared.");
});
});
function logSuccess(log)
{
datetime = getCurrentTime();
datetime += " <- ";
var fullLog = datetime + log;
$("#groupConsole").append('<li class="list-group-item list-group-item-success">' + fullLog + '</li>');
$("#btnSend").prop('disabled', false);
clearOldLogs();
}
function logInfo(log)
{
datetime = getCurrentTime();
datetime += " <- ";
var fullLog = datetime + log;
$("#groupConsole").append('<li class="list-group-item list-group-item-info">' + fullLog + '</li>');
$("#btnSend").prop('disabled', false);
clearOldLogs();
}
function logWarning(log)
{
datetime = getCurrentTime();
datetime += " <- ";
var fullLog = datetime + log;
$("#groupConsole").append('<li class="list-group-item list-group-item-warning">' + fullLog + '</li>');
$("#btnSend").prop('disabled', false);
clearOldLogs();
}
function logDenger(log)
{
datetime = getCurrentTime();
datetime += " <- ";
var fullLog = datetime + log;
$("#groupConsole").append('<li class="list-group-item list-group-item-danger">' + fullLog + '</li>');
$("#btnSend").prop('disabled', false);
clearOldLogs();
}
function alertSuccess(messenge)
{
$( "#alertMessenge" ).fadeOut( "slow", function() {
$("#alertMessenge").attr('class', 'alert alert-success');
$("#alertMessenge").html(messenge);
$( "#alertMessenge" ).fadeIn( "slow", function() {
});
});
}
function alertInfo(messenge)
{
$( "#alertMessenge" ).fadeOut( "slow", function() {
$("#alertMessenge").attr('class', 'alert alert-info');
$("#alertMessenge").html(messenge);
$( "#alertMessenge" ).fadeIn( "slow", function() {
});
});
}
function alertWarning(messenge)
{
$( "#alertMessenge" ).fadeOut( "slow", function() {
$("#alertMessenge").attr('class', 'alert alert-warning');
$("#alertMessenge").html(messenge);
$( "#alertMessenge" ).fadeIn( "slow", function() {
});
});
}
function alertDenger(messenge)
{
$( "#alertMessenge" ).fadeOut( "slow", function() {
$("#alertMessenge").attr('class', 'alert alert-danger');
$("#alertMessenge").html(messenge);
$( "#alertMessenge" ).fadeIn( "slow", function() {
});
});
}
function sendCommand(command)
{
if (command == "") {alertDenger("Please enter command."); return;}
var datetime = getCurrentTime();
datetime += " -> ";
datetime += command;
$("#groupConsole").append('<li class="list-group-item list-group-item-success">' + datetime + '</li>');
clearOldLogs();
$.post( "rcon/index.php", { cmd: command}) .done(function( data ) {
if(data.indexOf("Unknown command") != -1)
{
alertDenger("Unknown command : Please check your command.");
logDenger(data);
clearOldLogs();
if ($("#chkAutoScroll").is(':checked')) scrollLogsDown();
return;
}
else if(data.indexOf("Usage") != -1)
{
alertWarning(data);
logWarning(data);
if ($("#chkAutoScroll").is(':checked')) scrollLogsDown();
return;
}
alertSuccess("Send success!");
datetime = getCurrentTime();
datetime += " <- ";
datetime += data;
$("#groupConsole").append('<li class="list-group-item list-group-item-info">' + datetime + '</li>');
$("#btnSend").prop('disabled', false);
clearOldLogs();
if ($("#chkAutoScroll").is(':checked')) scrollLogsDown();
}).fail(function() {
alertDenger("Error!");
datetime = getCurrentTime();
datetime += " <- ";
datetime += "Error!";
$("#groupConsole").append('<li class="list-group-item list-group-item-danger">' + datetime + '</li>');
$("#btnSend").prop('disabled', false);
clearOldLogs();
if ($("#chkAutoScroll").is(':checked')) scrollLogsDown();
});
if ($("#chkAutoScroll").is(':checked')) scrollLogsDown();
}
function clearOldLogs()
{
var logItemSize = $("#groupConsole li").size();
if(logItemSize > 50) {
$('#groupConsole li:first').remove();
}
}
function scrollLogsDown(){
$("#groupConsole").scrollTop($("#groupConsole").get(0).scrollHeight);
}
function getCurrentTime()
{
var currentdate = new Date();
var datetime = currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " @ "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
return datetime;
}