-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Antimultirun - See https://facepunch.com/showthread.php?t=1547100
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |