Core: made ban and kick functions accessible to other plugins
Core: fixed banning and whitelisting in OnLogin git-svn-id: http://mc-server.googlecode.com/svn/trunk@947 0a769ca7-a7f5-676a-18bf-c427514a06d6master
parent
e421e9077c
commit
0433de9955
|
@ -4,27 +4,37 @@ function HandleBanCommand( Split, Player )
|
|||
return true
|
||||
end
|
||||
|
||||
local World = Player:GetWorld()
|
||||
local OtherPlayer = World:GetPlayer( Split[2] )
|
||||
if( OtherPlayer == nil ) then
|
||||
Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] )
|
||||
return true
|
||||
end
|
||||
|
||||
local Reason = "You have been banned"
|
||||
if( #Split > 2 ) then
|
||||
Reason = table.concat(Split, " ", 3)
|
||||
end
|
||||
|
||||
local Server = cRoot:Get():GetServer()
|
||||
LOGINFO( Player:GetName() .. " is banning " .. OtherPlayer:GetName() .. " ( "..Reason..") " )
|
||||
Server:SendMessage( "Banning " .. OtherPlayer:GetName() )
|
||||
|
||||
local ClientHandle = OtherPlayer:GetClientHandle()
|
||||
ClientHandle:Kick( Reason )
|
||||
|
||||
BannedPlayersIni:SetValueB("Banned", OtherPlayer:GetName(), true)
|
||||
BannedPlayersIni:WriteFile()
|
||||
|
||||
if( BanPlayer(Split[2], Reason) == false ) then
|
||||
Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] )
|
||||
return true
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function BanPlayer( PlayerName, Reason )
|
||||
if( Reason == nil ) then
|
||||
Reason = "You have been banned"
|
||||
end
|
||||
|
||||
local Success, RealName = KickPlayer( PlayerName, Reason )
|
||||
if( Success == false ) then
|
||||
return false
|
||||
end
|
||||
|
||||
LOGINFO( "'" .. RealName .. "' is being banned for ( "..Reason..") " )
|
||||
|
||||
local Server = cRoot:Get():GetServer()
|
||||
Server:SendMessage( "Banning " .. RealName )
|
||||
|
||||
BannedPlayersIni:SetValueB("Banned", RealName, true)
|
||||
BannedPlayersIni:WriteFile()
|
||||
|
||||
return true
|
||||
end
|
|
@ -4,26 +4,39 @@ function HandleKickCommand( Split, Player )
|
|||
return true
|
||||
end
|
||||
|
||||
local Reason = "You have been kicked"
|
||||
if( #Split > 2 ) then
|
||||
Reason = table.concat(Split, " ", 3)
|
||||
end
|
||||
|
||||
if( KickPlayer( Split[2], Reason ) == false ) then
|
||||
Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] )
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function KickPlayer( PlayerName, Reason )
|
||||
local RealName = ""
|
||||
local FoundPlayerCallback = function( OtherPlayer )
|
||||
local Reason = "You have been kicked"
|
||||
if( #Split > 2 ) then
|
||||
Reason = table.concat(Split, " ", 3)
|
||||
if( Reason == nil ) then
|
||||
Reason = "You have been kicked"
|
||||
end
|
||||
|
||||
RealName = OtherPlayer:GetName()
|
||||
|
||||
local Server = cRoot:Get():GetServer()
|
||||
LOGINFO( Player:GetName() .. " is kicking " .. OtherPlayer:GetName() .. " ( "..Reason..") " )
|
||||
Server:SendMessage( "Kicking " .. OtherPlayer:GetName() )
|
||||
LOGINFO( "'" .. RealName .. "' is being kicked for ( "..Reason..") " )
|
||||
Server:SendMessage( "Kicking " .. RealName )
|
||||
|
||||
local ClientHandle = OtherPlayer:GetClientHandle()
|
||||
ClientHandle:Kick( Reason )
|
||||
end
|
||||
|
||||
if( cRoot:Get():FindAndDoWithPlayer( Split[2], FoundPlayerCallback ) == false ) then
|
||||
Player:SendMessage( cChatColor.Green .. "Could not find player " .. Split[2] )
|
||||
return true
|
||||
if( cRoot:Get():FindAndDoWithPlayer( PlayerName, FoundPlayerCallback ) == false ) then
|
||||
return false -- could not find player
|
||||
end
|
||||
|
||||
|
||||
|
||||
return true
|
||||
|
||||
return true, RealName -- player should be kicked now
|
||||
end
|
|
@ -1,16 +1,16 @@
|
|||
function OnLogin( PacketData )
|
||||
if( PacketData.m_Username ~= "" ) then
|
||||
if( BannedPlayersIni:GetValueB("Banned", PacketData.m_Username, false) == true ) then
|
||||
function OnLogin(Client, ProtocolVersion, Username)
|
||||
if( Username ~= "" ) then
|
||||
if( BannedPlayersIni:GetValueB("Banned", Username, false) == true ) then
|
||||
local Server = cRoot:Get():GetServer()
|
||||
Server:SendMessage( PacketData.m_Username .. " tried to join, but is banned!" )
|
||||
LOGINFO( PacketData.m_Username .. " tried to join, but is banned!")
|
||||
Server:SendMessage( Username .. " tried to join, but is banned!" )
|
||||
LOGINFO( Username .. " tried to join, but is banned!")
|
||||
return true -- Player is banned, return true to deny access
|
||||
end
|
||||
if( WhiteListIni:GetValueB("WhiteListSettings", "WhiteListOn", false ) == true ) then
|
||||
if( WhiteListIni:GetValueB("WhiteList", PacketData.m_Username, false ) == false ) then -- not on whitelist
|
||||
if( WhiteListIni:GetValueB("WhiteList", Username, false ) == false ) then -- not on whitelist
|
||||
local Server = cRoot:Get():GetServer()
|
||||
Server:SendMessage( PacketData.m_Username .. " tried to join, but is not on the whitelist." )
|
||||
LOGINFO( PacketData.m_Username .. " tried to join, but is not on the whitelist." )
|
||||
Server:SendMessage( Username .. " tried to join, but is not on the whitelist." )
|
||||
LOGINFO( Username .. " tried to join, but is not on the whitelist." )
|
||||
return true -- Deny access to the server
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue