Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FPtje committed Jan 2, 2017
1 parent 87459d5 commit 8213de1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gamemode/config/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ GM.Config.allowvehicleowning = true
GM.Config.allowvnocollide = false
-- alltalk - Enable for global chat, disable for local chat.
GM.Config.alltalk = false
-- antimultirun - Disallow people joining your server(s) twice on the same account
GM.Config.antimultirun = true
-- autovehiclelock - Enable/Disable automatic locking of a vehicle when a player exits it.
GM.Config.autovehiclelock = false
-- babygod - people spawn godded (prevent spawn killing).
Expand Down
70 changes: 70 additions & 0 deletions gamemode/modules/workarounds/sv_antimultirun.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
local kickMessage = [[You cannot join these server(s) twice with the same account.
If you're a developer, please disable antimultirun in the DarkRP config.
]]

local function clearServerEntries()
MySQLite.query(string.format([[
DELETE FROM darkrp_serverplayer WHERE serverid = %s
]], MySQLite.SQLStr(DarkRP.serverId)))
end

local function insertUid(uid)
MySQLite.query(string.format([[
INSERT INTO darkrp_serverplayer VALUES(%s, %s)
]], uid, MySQLite.SQLStr(DarkRP.serverId)))
end

local function insertPlayer(ply)
insertUid(ply:SteamID64())
end


local function removePlayer(ply)
MySQLite.query(string.format([[
DELETE FROM darkrp_serverplayer WHERE uid = %s AND serverid = %s
]], ply:SteamID64(), MySQLite.SQLStr(DarkRP.serverId)))
end

local function addHooks()
hook.Add("PlayerAuthed", "DarkRP_antimultirun", function(ply, steamId)
local uid = util.SteamIDTo64(steamId)
local userid = ply:UserID()

MySQLite.queryValue(string.format([[
SELECT serverid FROM darkrp_serverplayer WHERE serverid = %s AND uid = %s
]], MySQLite.SQLStr(DarkRP.serverId), uid), function(sid)
if sid then
game.KickID(userid, kickMessage)
else
insertUid(uid)
end
end, error)
end)

hook.Add("PlayerDisconnected", "DarkRP_antimultirun", removePlayer)
hook.Add("ShutDown", "DarkRP_antimultirun", clearServerEntries)
end

hook.Add("DarkRPDBInitialized", "DarkRP_antimultirun", function()
if not GAMEMODE.Config.antimultirun then return end
if not MySQLite.isMySQL() then return end
if not game.IsDedicated() then return end

DarkRP.serverId = game.GetIPAddress()

MySQLite.query([[
CREATE TABLE IF NOT EXISTS darkrp_serverplayer(
uid BIGINT NOT NULL,
serverid VARCHAR(32) NOT NULL,
PRIMARY KEY(uid, serverid)
);
]])

-- Clear this server's entries in case the server wasn't cleanly shut down
clearServerEntries()

-- Re-insert players currently in the game
fn.Map(insertPlayer, player.GetAll())

addHooks()
end)

0 comments on commit 8213de1

Please sign in to comment.