Skip to content

Commit bb6f589

Browse files
author
KirillMysnik
committed
Added "Lift SteamID Ban" and "Lift IP Address Ban" live lists to MoTD frontend
1 parent 83f1e52 commit bb6f589

File tree

6 files changed

+499
-2
lines changed

6 files changed

+499
-2
lines changed

flask-motd/motdplayer_applications/admin/included/admin_kick_ban/__init__.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
from motdplayer_applications.admin.wrp import WebRequestProcessor
88

99

10+
# =============================================================================
11+
# >> CONSTANTS
12+
# =============================================================================
13+
MAX_BAN_ID_ABS_VALUE = 3000000000
14+
15+
1016
# =============================================================================
1117
# >> WEB REQUEST PROCESSORS
1218
# =============================================================================
@@ -15,6 +21,10 @@
1521
'included', 'admin_kick_ban', 'ban_steamid')
1622
ban_ip_address_page = WebRequestProcessor(
1723
'included', 'admin_kick_ban', 'ban_ip_address')
24+
lift_steamid_page = WebRequestProcessor(
25+
'included', 'admin_kick_ban', 'lift_steamid')
26+
lift_ip_address_page = WebRequestProcessor(
27+
'included', 'admin_kick_ban', 'lift_ip_address')
1828

1929

2030
# =============================================================================
@@ -72,3 +82,74 @@ def callback(ex_data_func, data):
7282
@player_based_feature_page_ws_wrap
7383
def callback(data):
7484
pass
85+
86+
87+
# lift_steamid_page
88+
@lift_steamid_page.register_regular_callback
89+
def callback(ex_data_func):
90+
return "admin/included/admin_kick_ban/lift_steamid.html", dict()
91+
92+
93+
# lift_ip_address_page
94+
@lift_ip_address_page.register_regular_callback
95+
def callback(ex_data_func):
96+
return "admin/included/admin_kick_ban/lift_ip_address.html", dict()
97+
98+
99+
# lift_steamid_page/lift_ip_address_page
100+
@lift_steamid_page.register_ajax_callback
101+
@lift_ip_address_page.register_ajax_callback
102+
def callback(ex_data_func, data):
103+
if 'action' not in data:
104+
return
105+
106+
if data['action'] == "execute":
107+
if 'banId' not in data:
108+
return
109+
110+
ban_id = data['banId']
111+
112+
if not isinstance(ban_id, int):
113+
return
114+
115+
if not (-MAX_BAN_ID_ABS_VALUE <= ban_id <= MAX_BAN_ID_ABS_VALUE):
116+
return
117+
118+
return ex_data_func({
119+
'action': "execute",
120+
'banId': ban_id,
121+
})
122+
123+
if data['action'] == "get-bans":
124+
return ex_data_func({
125+
'action': "get-bans",
126+
})
127+
128+
129+
@lift_steamid_page.register_ws_callback
130+
@lift_ip_address_page.register_ws_callback
131+
def callback(data):
132+
if 'action' not in data:
133+
return
134+
135+
if data['action'] == "execute":
136+
if 'banId' not in data:
137+
return
138+
139+
ban_id = data['banId']
140+
141+
if not isinstance(ban_id, int):
142+
return
143+
144+
if not (-MAX_BAN_ID_ABS_VALUE <= ban_id <= MAX_BAN_ID_ABS_VALUE):
145+
return
146+
147+
return {
148+
'action': "execute",
149+
'banId': ban_id,
150+
}
151+
152+
if data['action'] == "get-bans":
153+
return {
154+
'action': "get-bans",
155+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@keyframes ban-table-row-remove {
2+
0% {
3+
height: 30px;
4+
color: #ffffff;
5+
}
6+
100% {
7+
height: 0;
8+
color: #252525;
9+
}
10+
}
11+
12+
@keyframes ban-table-row-add {
13+
0% {
14+
height: 0;
15+
background-color: #ffffff;
16+
}
17+
100% {
18+
height: 30px;
19+
background-color: transparent;
20+
}
21+
}
22+
23+
.ban-table {
24+
width: 80%;
25+
margin: 20px auto 80px auto;
26+
border: 2px solid rgba(255, 255, 255, .1);
27+
}
28+
29+
.ban-table-line {
30+
height: 30px;
31+
line-height: 30px;
32+
overflow: hidden;
33+
cursor: pointer;
34+
animation-duration: 1s;
35+
}
36+
37+
.ban-table-uniqueid {
38+
float: left;
39+
width: 200px;
40+
text-align: center;
41+
font-family: monospace;
42+
font-size: 9pt;
43+
background-color: rgba(255, 255, 255, .1);
44+
}
45+
46+
.ban-table-line:hover .ban-table-uniqueid {
47+
background-color: rgba(255, 255, 255, .33);
48+
}
49+
50+
.ban-table-name {
51+
overflow: hidden;
52+
text-align: center;
53+
}
54+
55+
.ban-table-line:hover .ban-table-name {
56+
color: #fa000d;
57+
}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
var PLUGIN = function () {
2+
var plugin = this;
3+
4+
var ANIMATION_DURATION = 1000;
5+
6+
var LiftBanPage = function (tableNode) {
7+
var liftBanPage = this;
8+
9+
var BanEntry = function (uniqueid, banId, name) {
10+
var banEntry = this;
11+
12+
this.uniqueid = uniqueid;
13+
this.banId = banId;
14+
this.name = name;
15+
16+
var lineNode;
17+
this.create = function (node) {
18+
lineNode = node.appendChild(document.createElement('div'));
19+
lineNode.classList.add('ban-table-line');
20+
21+
var cellNode = lineNode.appendChild(document.createElement('div'));
22+
cellNode.appendChild(document.createTextNode(banEntry.uniqueid));
23+
cellNode.classList.add('ban-table-uniqueid');
24+
25+
cellNode = lineNode.appendChild(document.createElement('div'));
26+
cellNode.appendChild(document.createTextNode(banEntry.name));
27+
cellNode.classList.add('ban-table-name');
28+
29+
lineNode.style.animationName = "ban-table-row-add";
30+
31+
lineNode.addEventListener('click', function (e) {
32+
if (banEntry.banId)
33+
execute(banEntry.banId);
34+
});
35+
};
36+
this.destroy = function () {
37+
banEntry.banId = undefined;
38+
lineNode.style.animationName = "ban-table-row-remove";
39+
setTimeout(function () {
40+
if (lineNode)
41+
lineNode.parentNode.removeChild(lineNode);
42+
lineNode = undefined;
43+
}, ANIMATION_DURATION);
44+
};
45+
this.destroyNoDelay = function () {
46+
banEntry.banId = undefined;
47+
lineNode.parentNode.removeChild(lineNode);
48+
lineNode = undefined;
49+
};
50+
};
51+
52+
var banEntries = [];
53+
54+
tableNode.classList.add('ban-table');
55+
56+
var clearBans = function () {
57+
banEntries.forEach(function (val, i, arr) {
58+
val.destroyNoDelay();
59+
});
60+
banEntries = [];
61+
};
62+
var addBan = function (uniqueid, banId, name) {
63+
removeBanId(banId);
64+
var banEntry = new BanEntry(uniqueid, banId, name);
65+
banEntry.create(tableNode);
66+
banEntries.push(banEntry);
67+
};
68+
var removeBanId = function (banId) {
69+
var invalidEntries = [];
70+
banEntries.forEach(function (val, i, arr) {
71+
if (val.banId == banId)
72+
invalidEntries.push(val);
73+
});
74+
invalidEntries.forEach(function (val, i, arr) {
75+
val.destroy();
76+
banEntries.splice(banEntries.indexOf(val), 1);
77+
});
78+
};
79+
80+
var mode = 'unknown';
81+
this.tryWS = function (wsSuccessCallback, wsMessageCallback, wsCloseCallback, wsErrorCallback) {
82+
MOTDPlayer.openWSConnection(function () {
83+
mode = 'ws';
84+
requestBans();
85+
if (wsSuccessCallback)
86+
wsSuccessCallback();
87+
}, function (data) {
88+
switch (data['action']) {
89+
case 'bans':
90+
data['bans'].forEach(function (val, i, arr) {
91+
addBan(val['uniqueid'], val['banId'], val['name']);
92+
});
93+
break;
94+
case 'remove-ban-id':
95+
removeBanId(data['banId']);
96+
break;
97+
}
98+
if (wsMessageCallback)
99+
wsMessageCallback(data);
100+
}, function () {
101+
clearBans();
102+
if (wsCloseCallback)
103+
wsCloseCallback();
104+
}, function (err) {
105+
if (mode == 'unknown') {
106+
mode = 'ajax';
107+
requestBans();
108+
}
109+
if (wsErrorCallback)
110+
wsErrorCallback(err);
111+
});
112+
};
113+
114+
var requestBans = function () {
115+
switch (mode) {
116+
case 'ajax':
117+
MOTDPlayer.post({
118+
action: 'get-bans',
119+
}, function (data) {
120+
clearBans();
121+
data['bans'].forEach(function (val, i, arr) {
122+
addBan(val['uniqueid'], val['banId'], val['name']);
123+
});
124+
}, function (err) {
125+
// TODO: Display error
126+
});
127+
break;
128+
129+
case 'ws':
130+
MOTDPlayer.sendWSData({
131+
action: 'get-bans',
132+
});
133+
break;
134+
}
135+
};
136+
137+
var execute = function (banId) {
138+
switch (mode) {
139+
case 'ajax':
140+
MOTDPlayer.post({
141+
action: 'execute',
142+
banId: banId,
143+
}, function (data) {
144+
if (data['status'] == "ok") ; // TODO: Display success popup
145+
clearBans();
146+
data['bans'].forEach(function (val, i, arr) {
147+
addBan(val['uniqueid'], val['banId'], val['name']);
148+
});
149+
}, function (err) {
150+
// TODO: Display error
151+
});
152+
break;
153+
154+
case 'ws':
155+
MOTDPlayer.sendWSData({
156+
action: 'execute',
157+
banId: banId,
158+
});
159+
break;
160+
}
161+
};
162+
};
163+
164+
this.init = function (tableNode, wsSuccessCallback, wsMessageCallback, wsCloseCallback, wsErrorCallback) {
165+
liftBanPage = new LiftBanPage(tableNode);
166+
liftBanPage.tryWS(wsSuccessCallback, wsMessageCallback, wsCloseCallback, wsErrorCallback);
167+
};
168+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% extends "admin/base.html" %}
2+
3+
{% block title %}Access Restriction - Lift IP Address Ban{% endblock %}
4+
5+
{% block head %}
6+
<script type="application/javascript" src="/static/admin/included/admin_kick_ban/js/lift_ban_page.js"></script>
7+
<link rel="stylesheet" type="text/css" href="/static/admin/included/admin_kick_ban/css/lift_ban_page.css" />
8+
<script type="application/javascript">
9+
var plugin = new PLUGIN();
10+
document.addEventListener('AppInit', function (e) {
11+
plugin.init(document.getElementById('admin-ban-table'));
12+
});
13+
</script>
14+
{% endblock %}
15+
16+
{% block main %}
17+
<h1>Click on the ban entries to lift them</h1>
18+
<div id="admin-ban-table"></div>
19+
{% endblock %}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% extends "admin/base.html" %}
2+
3+
{% block title %}Access Restriction - Lift SteamID Ban{% endblock %}
4+
5+
{% block head %}
6+
<script type="application/javascript" src="/static/admin/included/admin_kick_ban/js/lift_ban_page.js"></script>
7+
<link rel="stylesheet" type="text/css" href="/static/admin/included/admin_kick_ban/css/lift_ban_page.css" />
8+
<script type="application/javascript">
9+
var plugin = new PLUGIN();
10+
document.addEventListener('AppInit', function (e) {
11+
plugin.init(document.getElementById('admin-ban-table'));
12+
});
13+
</script>
14+
{% endblock %}
15+
16+
{% block main %}
17+
<h1>Click on the ban entries to lift them</h1>
18+
<div id="admin-ban-table"></div>
19+
{% endblock %}

0 commit comments

Comments
 (0)