Skip to content

Commit 141190d

Browse files
Exporting Bans
- Added first prototype to export bans from MSync 2 to ULX ( just the active ones that are linked to the server ) - Fixed a bug that could cause different time values when banning a user
1 parent 9178867 commit 141190d

File tree

2 files changed

+91
-20
lines changed

2 files changed

+91
-20
lines changed

lua/msync/client_gui/modules/cl_mbsync.lua

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ MSync.modules[info.ModuleIdentifier].init = function()
356356
local nickname_textentry = vgui.Create( "DTextEntry", panel )
357357
nickname_textentry:SetPos( 125, 35 )
358358
nickname_textentry:SetSize( 210, 20 )
359-
--nickname_textentry:SetText( "[ApDev] Rainbow Dash" )
360359
nickname_textentry:SetDisabled(true)
361360

362361
local steamid_text = vgui.Create( "DLabel", panel )
@@ -368,7 +367,6 @@ MSync.modules[info.ModuleIdentifier].init = function()
368367
local steamid_textentry = vgui.Create( "DTextEntry", panel )
369368
steamid_textentry:SetPos( 125, 60 )
370369
steamid_textentry:SetSize( 210, 20 )
371-
--steamid_textentry:SetText( "STEAM_0:0:0" )
372370
steamid_textentry:SetDisabled(true)
373371

374372
local steamid64_text = vgui.Create( "DLabel", panel )
@@ -380,17 +378,9 @@ MSync.modules[info.ModuleIdentifier].init = function()
380378
local steamid64_textentry = vgui.Create( "DTextEntry", panel )
381379
steamid64_textentry:SetPos( 125, 85 )
382380
steamid64_textentry:SetSize( 210, 20 )
383-
--steamid64_textentry:SetText( "7600000000" )
384381
steamid64_textentry:SetDisabled(true)
385382

386-
--local adminheader_text = vgui.Create( "DLabel", panel )
387-
--adminheader_text:SetPos( 15, 110 )
388-
--adminheader_text:SetColor( Color( 255, 255, 255 ) )
389-
--adminheader_text:SetText( "Admin" )
390-
--adminheader_text:SetSize(320, 15)
391-
--adminheader_text:SetContentAlignment( 5 )
392-
393-
--[[ (i*30)+1
383+
--[[
394384
Info about the banning Admin
395385
]]
396386

@@ -1360,7 +1350,7 @@ MSync.modules[info.ModuleIdentifier].net = function()
13601350
]]
13611351
net.Receive( "msync."..info.ModuleIdentifier..".recieveData", function( len, ply )
13621352
MSync.modules[info.ModuleIdentifier].explodeTable(MSync.modules[info.ModuleIdentifier].banTable, net.ReadTable())
1363-
print(MSync.modules[info.ModuleIdentifier].temporary['recieved'])
1353+
13641354
MSync.modules[info.ModuleIdentifier].temporary["recieved"] = MSync.modules[info.ModuleIdentifier].temporary["recieved"] + 1
13651355

13661356
if MSync.modules[info.ModuleIdentifier].temporary["recieved"] == MSync.modules[info.ModuleIdentifier].temporary["count"] then

lua/msync/server/modules/sv_mbsync.lua

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
4545
);
4646
]] ))
4747

48-
4948
--[[
5049
Description: Function to ban a player
5150
Returns: nothing
@@ -60,12 +59,13 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
6059
(SELECT p_group_id FROM tbl_server_grp WHERE group_name=?)
6160
);
6261
]] )
62+
local timestamp = os.time()
6363
banUserQ:setString(1, ply:SteamID())
6464
banUserQ:setString(2, ply:SteamID64())
6565
banUserQ:setString(3, calling_ply:SteamID())
6666
banUserQ:setString(4, calling_ply:SteamID64())
6767
banUserQ:setString(5, reason)
68-
banUserQ:setNumber(6, os.time())
68+
banUserQ:setNumber(6, timestamp)
6969
banUserQ:setNumber(7, length*60)
7070
if not allserver then
7171
banUserQ:setString(8, MSync.settings.data.serverGroup)
@@ -81,8 +81,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
8181
local banData = {
8282
admin = calling_ply:Nick(),
8383
reason = reason,
84-
unban = os.time()+(length*60),
85-
time = os.time()
84+
unban = timestamp+(length*60),
85+
time = timestamp
8686
}
8787
if length == 0 then
8888
banData["unban"] = length
@@ -129,12 +129,13 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
129129
(SELECT p_group_id FROM tbl_server_grp WHERE group_name=?)
130130
);
131131
]] )
132+
local timestamp = os.time()
132133
banUserIdQ:setString(1, userid)
133134
banUserIdQ:setString(2, userid)
134135
banUserIdQ:setString(3, calling_ply:SteamID())
135136
banUserIdQ:setString(4, calling_ply:SteamID64())
136137
banUserIdQ:setString(5, reason)
137-
banUserIdQ:setNumber(6, os.time())
138+
banUserIdQ:setNumber(6, timestamp)
138139
banUserIdQ:setNumber(7, length)
139140
if not allserver then
140141
banUserIdQ:setString(8, MSync.settings.data.serverGroup)
@@ -148,8 +149,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
148149
local banData = {
149150
admin = calling_ply:Nick(),
150151
reason = reason,
151-
unban = os.time()+(length*60),
152-
time = os.time()
152+
unban = timestamp+(length*60),
153+
time = timestamp
153154
}
154155
if length == 0 then
155156
banData["unban"] = length
@@ -513,6 +514,86 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
513514
getActiveBansQ:start()
514515
end
515516

517+
--[[
518+
Description: Function to get all active bans
519+
Returns: nothing
520+
]]
521+
MSync.modules[info.ModuleIdentifier].exportBansToULX = function()
522+
local exportActiveBans = MSync.DBServer:prepare( [[
523+
SELECT
524+
tbl_mbsync.*,
525+
banned.steamid,
526+
banned.steamid64,
527+
banned.nickname AS 'banned.nickname',
528+
admin.nickname AS 'admin.nickname',
529+
admin.steamid AS 'admin.steamid'
530+
FROM `tbl_mbsync`
531+
LEFT JOIN tbl_users AS banned
532+
ON tbl_mbsync.user_id = banned.p_user_id
533+
LEFT JOIN tbl_users AS admin
534+
ON tbl_mbsync.admin_id = admin.p_user_id
535+
WHERE
536+
ban_lifted IS NULL AND
537+
(
538+
(date_unix+length_unix)>? OR
539+
length_unix=0
540+
) AND
541+
(
542+
server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) OR
543+
server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers')
544+
)
545+
]] )
546+
exportActiveBans:setNumber(1, os.time())
547+
exportActiveBans:setString(8, MSync.settings.data.serverGroup)
548+
549+
exportActiveBans.onSuccess = function( q, data )
550+
551+
local function escapeString( str )
552+
if not str then
553+
return "NULL"
554+
else
555+
return sql.SQLStr(str)
556+
end
557+
end
558+
559+
print("[MBSync] Exporting Bans to ULX")
560+
for k,v in pairs(data) do
561+
local unban
562+
if v.length_unix == 0 then
563+
unban = 0
564+
else
565+
unban = v.date_unix + v.length_unix
566+
end
567+
568+
ULib.bans[ v["steamid"] ] = {
569+
admin = v["admin.nickname"],
570+
time = v.date_unix,
571+
unban = unban,
572+
reason = v.reason,
573+
name = v["banned.nickname"]
574+
}
575+
hook.Call( ULib.HOOK_USER_BANNED, _, v["steamid"], ULib.bans[ v["steamid"] ] )
576+
end
577+
ULib.fileWrite( ULib.BANS_FILE, ULib.makeKeyValues( ULib.bans ) )
578+
print("[MBSync] Export finished")
579+
580+
end
581+
582+
exportActiveBans.onError = function( q, err, sql )
583+
print("------------------------------------")
584+
print("[MBSync] SQL Error!")
585+
print("------------------------------------")
586+
print("Please include this in a Bug report:\n")
587+
print(err.."\n")
588+
print("------------------------------------")
589+
print("Do not include this, this is for debugging only:\n")
590+
print(sql.."\n")
591+
print("------------------------------------")
592+
end
593+
594+
exportActiveBans:start()
595+
end
596+
516597
--[[
517598
Description: Function to load the MSync settings file
518599
Returns: true
@@ -1123,7 +1204,7 @@ MSync.modules[info.ModuleIdentifier].hooks = function()
11231204

11241205
hook.Add("PlayerDisconnected", "msync."..info.ModuleIdentifier..".saveDisconnects", function( ply )
11251206
if ply:IsBot() then return end
1126-
local tableLength = #MSync.modules[info.ModuleIdentifier].recentDisconnects
1207+
local tableLength = table.Count(MSync.modules[info.ModuleIdentifier].recentDisconnects)
11271208
local data = {
11281209
name = ply:Name(),
11291210
steamid = ply:SteamID(),

0 commit comments

Comments
 (0)