Skip to content

Commit 06a4546

Browse files
Feature Update
Implemented feature #37 When you change the rank of a user the rank immediantly get saved. For that we added a new function to be able to save a rank by using a steamid and the rank to be saved.
1 parent 8868aba commit 06a4546

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

lua/msync/client_gui/modules/cl_mrsync.lua

Lines changed: 2 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.2
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.2"
2020
}
2121

2222
--[[

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.2
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.2"
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)