Skip to content

Commit 9a0d364

Browse files
Merge pull request #41 from Aperture-Development/MRSync
MRSync bugfix and Feature Update
2 parents 0c62728 + 9b706c0 commit 9a0d364

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

lua/msync/client_gui/modules/cl_mrsync.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MSync.modules.MRSync = MSync.modules.MRSync or {}
66
* @package MySQL Rank Sync
77
* @author Aperture Development
88
* @license root_dir/LICENCE
9-
* @version 2.0.2
9+
* @version 2.1.3
1010
]]
1111

1212
--[[
@@ -16,7 +16,7 @@ MSync.modules.MRSync.info = {
1616
Name = "MySQL Rank Sync",
1717
ModuleIdentifier = "MRSync",
1818
Description = "Synchronise your ranks across your servers",
19-
Version = "2.0.2"
19+
Version = "2.1.3"
2020
}
2121

2222
--[[
@@ -72,7 +72,7 @@ function MSync.modules.MRSync.adminPanel(sheet)
7272
allserver_button:SetSize( 130, 20 )
7373
allserver_button.DoClick = function()
7474
if string.len(allserver_textentry:GetValue()) > 0 and not MSync.modules.MRSync.settings.nosync[allserver_textentry:GetValue()] and not MSync.modules.MRSync.settings.syncall[allserver_textentry:GetValue()] then
75-
if string.match(allserver_textentry:GetValue(), "^%s*$") or string.match(allserver_textentry:GetValue(), "%s+$") then return end
75+
if string.match(allserver_textentry:GetValue(), "^%s*$") or string.match(allserver_textentry:GetValue(), "^%s") or string.match(allserver_textentry:GetValue(), "%s$") then return end
7676
allserver_table:AddLine(allserver_textentry:GetValue())
7777
MSync.modules.MRSync.settings.syncall[allserver_textentry:GetValue()] = true
7878
allserver_textentry:SetText("")
@@ -119,7 +119,7 @@ function MSync.modules.MRSync.adminPanel(sheet)
119119
nosync_button:SetSize( 130, 20 )
120120
nosync_button.DoClick = function()
121121
if string.len(nosync_textentry:GetValue()) > 0 and not MSync.modules.MRSync.settings.nosync[nosync_textentry:GetValue()] and not MSync.modules.MRSync.settings.syncall[nosync_textentry:GetValue()] then
122-
if string.match(nosync_textentry:GetValue(), "^%s*$") or string.match(nosync_textentry:GetValue(), "%s+$") then return end
122+
if string.match(nosync_textentry:GetValue(), "^%s*$") or string.match(nosync_textentry:GetValue(), "^%s") or string.match(nosync_textentry:GetValue(), "%s$") then return end
123123
nosync_table:AddLine(nosync_textentry:GetValue())
124124
MSync.modules.MRSync.settings.nosync[nosync_textentry:GetValue()] = true
125125
nosync_textentry:SetText("")

lua/msync/server/modules/sv_mrsync.lua

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MSync.modules.MRSync = MSync.modules.MRSync or {}
66
* @package MySQL Rank Sync
77
* @author Aperture Development
88
* @license root_dir/LICENCE
9-
* @version 2.0.2
9+
* @version 2.1.3
1010
]]
1111

1212
--[[
@@ -16,7 +16,7 @@ MSync.modules.MRSync.info = {
1616
Name = "MySQL Rank Sync",
1717
ModuleIdentifier = "MRSync",
1818
Description = "Synchronise your ranks across your servers",
19-
Version = "2.0.2"
19+
Version = "2.1.3"
2020
}
2121

2222
--[[
@@ -64,6 +64,35 @@ function MSync.modules.MRSync.init( transaction )
6464
addUserRankQ:start()
6565
end
6666

67+
--[[
68+
Description: Function to save a players rank using steamid and group name
69+
Returns: nothing
70+
]]
71+
function MSync.modules.MRSync.saveRankByID(steamid, group)
72+
73+
if MSync.modules.MRSync.settings.nosync[group] then return end;
74+
75+
local addUserRankQ = MSync.DBServer:prepare( [[
76+
INSERT INTO `tbl_mrsync` (user_id, rank, server_group)
77+
VALUES (
78+
(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?),
79+
?,
80+
(SELECT p_group_id FROM tbl_server_grp WHERE group_name=?)
81+
)
82+
ON DUPLICATE KEY UPDATE rank=VALUES(rank);
83+
]] )
84+
addUserRankQ:setString(1, steamid)
85+
addUserRankQ:setString(2, util.SteamIDTo64( steamid ))
86+
addUserRankQ:setString(3, group)
87+
if not MSync.modules.MRSync.settings.syncall[group] then
88+
addUserRankQ:setString(4, MSync.settings.data.serverGroup)
89+
else
90+
addUserRankQ:setString(4, "allservers")
91+
end
92+
93+
addUserRankQ:start()
94+
end
95+
6796
--[[
6897
Description: Function to load a players rank
6998
Returns: nothing
@@ -84,6 +113,11 @@ function MSync.modules.MRSync.init( transaction )
84113
loadUserQ:setString(3, MSync.settings.data.serverGroup)
85114

86115
function loadUserQ.onData( q, data )
116+
if not ULib.ucl.groups[data.rank] then
117+
print("[MRSync] Could not load rank "..data.rank.." for "..ply:Nick()..". Rank does not exist on this server")
118+
return
119+
end
120+
87121
if data.rank == ply:GetUserGroup() then return end;
88122

89123
ply:SetUserGroup(data.rank)
@@ -185,13 +219,20 @@ end
185219
]]
186220
function MSync.modules.MRSync.hooks()
187221

222+
-- Load rank on spawn
188223
hook.Add("PlayerInitialSpawn", "mrsync.H.loadRank", function(ply)
189224
MSync.modules.MRSync.loadRank(ply)
190225
end)
191226

227+
-- Save rank on disconnect
192228
hook.Add("PlayerDisconnected", "mrsync.H.saveRank", function(ply)
193229
MSync.modules.MRSync.saveRank(ply)
194230
end)
231+
232+
-- Save rank on GroupChange
233+
hook.Add("ULibUserGroupChange", "mrsync.H.saveRankOnUpdate", function(sid, _, _, new_group, _)
234+
MSync.modules.MRSync.saveRankByID(sid, new_group)
235+
end)
195236
end
196237

197238
--[[

0 commit comments

Comments
 (0)