GetPlayerSerial: Difference between revisions
Jump to navigation
Jump to search
m (→See Also) |
m (Typo at →Serverside examples) |
||
(17 intermediate revisions by 13 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server | {{Server function}} | ||
This function returns the [[serial]] for a specified [[player]]. | This function returns the [[serial]] for a specified [[player]]. | ||
{{Note|The client side version of [[getPlayerSerial]] has been deprecated as it can return the wrong value for some players, and is potentially insecure. The following article assumes that the function is serverside only.}} | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
string getPlayerSerial ( player thePlayer ) | string getPlayerSerial ( player thePlayer ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[player]]:getSerial|serial|}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''thePlayer:''' A [[player]] object referencing the specified player. | *'''thePlayer:''' A [[player]] object referencing the specified player. | ||
==Returns== | ==Returns== | ||
Returns the serial as a ''string'' if it was found, ''false'' otherwise. | Returns the serial as a ''string'' if it was found, ''false'' otherwise. | ||
== | ==Serverside examples== | ||
This example creates a command with which player can check their own serial. | This example creates a command with which player can check their own serial. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 35: | Line 26: | ||
end | end | ||
end | end | ||
addCommandHandler( " | addCommandHandler( "myserial", checkMySerial ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This example adds a command to ban a player's serial. | |||
This example | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | local function banSerialCommand ( source, command, playerName, reason ) | ||
if | if playerName then | ||
local | local player, serial = getPlayerFromName ( playerName ), getPlayerSerial ( playerName ) | ||
if player then | |||
if | addBan ( serial, source, reason ) | ||
addBan( | |||
end | end | ||
end | end | ||
end | end | ||
addCommandHandler( " | addCommandHandler ( "banplayerserial", banSerialCommand ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This example only allows clients with a certain serial to log in into an account. | |||
This example | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | local allowedAccountSerials = | ||
{ | |||
-- List of allowed serials to log in into an account. Format: | |||
-- [ Account name ] = { Allowed serial array } | |||
end | [ "3ash8" ] = { "9C9F3B55D9D7BB7135FF274D3BF444E4" }, | ||
[ "test5" ] = { "1D6F76CF8D7193792D13789849498452" }, | |||
} | |||
addEventHandler("onPlayerLogin", root, | |||
function(_, account) | |||
-- Get the player serial and the allowed serial list for that account | |||
-- (If no serial is allowed for the account, do not allow the player to log in as a safety measure) | |||
local playerSerial, allowedSerials = getPlayerSerial(source), allowedAccountSerials[getAccountName(account)] or {} | |||
-- Check whether the client has an allowed serial or not | |||
for i = 1, #allowedSerials do | |||
if allowedSerials[i] == playerSerial then | |||
-- The serial is allowed. Proceed with the normal log in proccess | |||
return | |||
end | |||
end | |||
-- If we reach this point the serial is not allowed. Do not let the player log in | |||
cancelEvent(true, "Client serial not allowed to log in into the account") | |||
end | |||
) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Player functions}} | {{Player functions}} |
Revision as of 16:51, 13 October 2017
This function returns the serial for a specified player.
Note: The client side version of getPlayerSerial has been deprecated as it can return the wrong value for some players, and is potentially insecure. The following article assumes that the function is serverside only. |
Syntax
string getPlayerSerial ( player thePlayer )
OOP Syntax Help! I don't understand this!
- Method: player:getSerial(...)
- Variable: .serial
Required Arguments
- thePlayer: A player object referencing the specified player.
Returns
Returns the serial as a string if it was found, false otherwise.
Serverside examples
This example creates a command with which player can check their own serial.
function checkMySerial( thePlayer, command ) local theSerial = getPlayerSerial( thePlayer ) if theSerial then outputChatBox( "Your serial is: " .. theSerial, thePlayer ) else outputChatBox( "Sorry, you have no serial. =(", thePlayer ) end end addCommandHandler( "myserial", checkMySerial )
This example adds a command to ban a player's serial.
local function banSerialCommand ( source, command, playerName, reason ) if playerName then local player, serial = getPlayerFromName ( playerName ), getPlayerSerial ( playerName ) if player then addBan ( serial, source, reason ) end end end addCommandHandler ( "banplayerserial", banSerialCommand )
This example only allows clients with a certain serial to log in into an account.
local allowedAccountSerials = { -- List of allowed serials to log in into an account. Format: -- [ Account name ] = { Allowed serial array } [ "3ash8" ] = { "9C9F3B55D9D7BB7135FF274D3BF444E4" }, [ "test5" ] = { "1D6F76CF8D7193792D13789849498452" }, } addEventHandler("onPlayerLogin", root, function(_, account) -- Get the player serial and the allowed serial list for that account -- (If no serial is allowed for the account, do not allow the player to log in as a safety measure) local playerSerial, allowedSerials = getPlayerSerial(source), allowedAccountSerials[getAccountName(account)] or {} -- Check whether the client has an allowed serial or not for i = 1, #allowedSerials do if allowedSerials[i] == playerSerial then -- The serial is allowed. Proceed with the normal log in proccess return end end -- If we reach this point the serial is not allowed. Do not let the player log in cancelEvent(true, "Client serial not allowed to log in into the account") end )
See Also
- getAlivePlayers
- getDeadPlayers
- getPlayerACInfo
- getPlayerAnnounceValue
- getPlayerCount
- getPlayerIdleTime
- getPlayerIP
- getPlayerScriptDebugLevel
- getPlayerVersion
- getRandomPlayer
- isPlayerMuted
- redirectPlayer
- resendPlayerACInfo
- resendPlayerModInfo
- setPlayerAnnounceValue
- setPlayerMuted
- setPlayerScriptDebugLevel
- setPlayerTeam
- setPlayerVoiceBroadcastTo
- setPlayerVoiceIgnoreFrom
- setPlayerWantedLevel
- spawnPlayer
- takePlayerScreenShot
Shared
- getPlayerTeam
- getPlayerBlurLevel
- setPlayerBlurLevel
- getPlayerSerial
- forcePlayerMap
- getPlayerFromName
- getPlayerMoney
- getPlayerName
- getPlayerNametagColor
- getPlayerNametagText
- getPlayerPing
- getPlayerWantedLevel
- givePlayerMoney
- isPlayerMapForced
- isPlayerNametagShowing
- setPlayerHudComponentVisible
- setPlayerMoney
- setPlayerNametagColor
- setPlayerNametagShowing
- setPlayerNametagText
- takePlayerMoney
- countPlayersInTeam
- getPlayersInTeam
- isVoiceEnabled
- setControlState
- getControlState