Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sfphoton-web-plugin-minecraft
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Schulcz Ferenc
sfphoton-web-plugin-minecraft
Commits
97ccafd7
Commit
97ccafd7
authored
7 months ago
by
Ferenc Schulcz
Browse files
Options
Downloads
Patches
Plain Diff
Add last pay dates to web view
parent
97138190
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
minecraft_admin.py
+33
-1
33 additions, 1 deletion
minecraft_admin.py
templates/minecraft_admin.html
+2
-1
2 additions, 1 deletion
templates/minecraft_admin.html
with
35 additions
and
2 deletions
minecraft_admin.py
+
33
−
1
View file @
97ccafd7
import
datetime
from
rcon
import
Client
import
services
import
db
...
...
@@ -5,6 +6,7 @@ import pymongo
import
socket
import
os
import
config
import
mysql.connector
plugin_dir
=
os
.
path
.
dirname
(
__file__
)
# parent folder name of the absolute path of this file
...
...
@@ -41,6 +43,9 @@ def mcadmin(**kwargs):
serverworking
=
False
if
not
serverworking
and
"
serverstatus
"
not
in
request
.
args
.
keys
():
serverstatus
=
"
The server is down or loading.
"
lastplaydates
=
last_player_logins
()
if
lastplaydates
is
None
:
serverstatus
+=
"
Minecraft database is down.
"
if
blacklist
!=
"
There are no bans
"
:
blacklist
=
blacklist
[
blacklist
.
index
(
'
:
'
)
+
1
:]
# trim header text away
bans
=
blacklist
.
split
(
'
.
'
)
...
...
@@ -48,7 +53,7 @@ def mcadmin(**kwargs):
banneduserlist
.
append
(
bans
[
i
].
split
()[
0
])
ulist
=
db
.
mc_users
.
find
()
for
u
in
ulist
:
mcuserlist
.
append
({
'
mcuser
'
:
u
[
'
mcuser
'
],
'
webuser
'
:
u
[
'
username
'
]})
mcuserlist
.
append
({
'
mcuser
'
:
u
[
'
mcuser
'
],
'
webuser
'
:
u
[
'
username
'
]
,
'
lastplayed
'
:
lastplaydates
[
u
[
'
mcuser
'
]]
})
return
rqtools
.
render_template
(
plugin_dir
+
'
/templates/minecraft_admin.html
'
,
mcuserlist
=
mcuserlist
,
banneduserlist
=
banneduserlist
,
serverstatus
=
serverstatus
)
...
...
@@ -137,3 +142,30 @@ def player_exists(name):
if
x
is
None
:
return
False
return
True
def
last_player_logins
():
try
:
authmedb
=
mysql
.
connector
.
connect
(
host
=
config
.
get
(
'
MINECRAFT_AUTHME_DB_HOST
'
),
user
=
config
.
get
(
'
MINECRAFT_AUTHME_DB_USER
'
),
password
=
config
.
get
(
'
MINECRAFT_AUTHME_DB_PASSWORD
'
),
database
=
'
authme
'
,
charset
=
"
utf8mb3
"
)
cursor
=
authmedb
.
cursor
()
# Query to get realname and timestamp
query
=
"
SELECT realname, timestamp FROM authme
"
cursor
.
execute
(
query
)
# Fetch and process the results
results
=
{}
for
realname
,
timestamp
in
cursor
.
fetchall
():
if
timestamp
==
None
:
results
[
realname
]
=
'
never
'
else
:
human_readable_date
=
datetime
.
utcfromtimestamp
(
timestamp
).
strftime
(
'
%Y-%m-%d
'
)
results
[
realname
]
=
human_readable_date
except
:
return
None
finally
:
if
authmedb
:
authmedb
.
close
()
return
results
\ No newline at end of file
This diff is collapsed.
Click to expand it.
templates/minecraft_admin.html
+
2
−
1
View file @
97ccafd7
...
...
@@ -32,7 +32,8 @@
{% for user in mcuserlist %}
<div
class=
"row"
>
<p>
{{ user['mcuser'] }}
<span
style=
"opacity: 50%;"
>
(on website: {{ user['webuser'] }})
</span></p>
<p>
{{ user['mcuser'] }}
<span
style=
"opacity: 50%;"
>
(on website: {{ user['webuser'] }}, last played: {{
user['lastplayed'] }})
</span></p>
<a
href=
"{{ url_for('service', servicename='mcban', player=user['mcuser']) }}"
class=
"button"
>
Ban
</a>
</div>
{% endfor %}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment