2013-07-27 16:54:25 +01:00
|
|
|
--COMMENCE VARIABLES
|
|
|
|
|
PLUGIN = {}
|
2013-07-27 16:24:03 +01:00
|
|
|
BannedPlayersIni = {}
|
|
|
|
|
WhiteListIni = {}
|
|
|
|
|
BackCoords = {}
|
|
|
|
|
Messages = {}
|
2013-08-11 16:00:53 +01:00
|
|
|
Destination = {}
|
2013-07-27 16:54:25 +01:00
|
|
|
--END VARIABLES
|
2013-07-27 16:24:03 +01:00
|
|
|
|
2013-08-13 17:55:46 +01:00
|
|
|
-- Configuration
|
|
|
|
|
-- Use prefixes or not.
|
|
|
|
|
-- If set to true, messages are prefixed, e. g. "[FATAL]". If false, messages are colored.
|
|
|
|
|
g_UsePrefixes = true
|
|
|
|
|
|
2013-07-27 16:54:25 +01:00
|
|
|
--COMMENCE AWESOMENESS!
|
2013-08-11 16:00:53 +01:00
|
|
|
function Initialize( Plugin )
|
2013-07-27 16:24:03 +01:00
|
|
|
PLUGIN = Plugin
|
2013-07-27 19:45:44 +01:00
|
|
|
|
2013-08-11 16:00:53 +01:00
|
|
|
Plugin:SetName( "Core" )
|
|
|
|
|
Plugin:SetVersion( 13 )
|
2013-07-27 19:45:44 +01:00
|
|
|
|
2013-08-11 16:00:53 +01:00
|
|
|
--ADD HOOKS
|
2013-07-27 16:24:03 +01:00
|
|
|
PluginManager = cRoot:Get():GetPluginManager()
|
2013-08-11 16:00:53 +01:00
|
|
|
PluginManager:AddHook( Plugin, cPluginManager.HOOK_PLAYER_JOINED )
|
|
|
|
|
PluginManager:AddHook( Plugin, cPluginManager.HOOK_DISCONNECT )
|
|
|
|
|
PluginManager:AddHook( Plugin, cPluginManager.HOOK_PLAYER_BREAKING_BLOCK )
|
|
|
|
|
PluginManager:AddHook( Plugin, cPluginManager.HOOK_PLAYER_PLACING_BLOCK )
|
|
|
|
|
PluginManager:AddHook( Plugin, cPluginManager.HOOK_LOGIN )
|
|
|
|
|
PluginManager:AddHook( Plugin, cPluginManager.HOOK_KILLING )
|
|
|
|
|
PluginManager:AddHook( Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE )
|
|
|
|
|
PluginManager:AddHook( Plugin, cPluginManager.HOOK_CHAT ) -- used in web_chat.lua
|
|
|
|
|
PluginManager:AddHook( Plugin, cPluginManager.HOOK_PLAYER_MOVING )
|
2013-07-27 19:45:44 +01:00
|
|
|
|
2013-08-02 07:48:47 +01:00
|
|
|
--PLEASE ALPHA SORT http://elmosaukko.com/sort-alphabetically/ THIS LIST
|
2013-08-11 16:00:53 +01:00
|
|
|
--BIND COMMANDS
|
|
|
|
|
PluginManager:BindCommand("/back", "core.back", HandleBackCommand, " - Return to your last position")
|
|
|
|
|
PluginManager:BindCommand("/ban", "core.ban", HandleBanCommand, " ~ Ban a player")
|
|
|
|
|
PluginManager:BindCommand("/clear", "core.clear", HandleClearCommand, " - Clear the inventory of some player")
|
|
|
|
|
PluginManager:BindCommand("/give", "core.give", HandleGiveCommand, " ~ Give someone an item")
|
|
|
|
|
PluginManager:BindCommand("/gm", "core.changegm", HandleChangeGMCommand, " ~ Change your gamemode")
|
|
|
|
|
PluginManager:BindCommand("/groups", "core.groups", HandleGroupsCommand, " - Shows a list of all the groups")
|
|
|
|
|
PluginManager:BindCommand("/help", "core.help", HandleHelpCommand, " ~ Show available commands")
|
2013-08-07 18:36:38 +01:00
|
|
|
PluginManager:BindCommand("/i", "core.give", HandleItemCommand, "")
|
|
|
|
|
PluginManager:BindCommand("/item", "core.give", HandleItemCommand, " - Give yourself an item.")
|
2013-08-11 16:00:53 +01:00
|
|
|
PluginManager:BindCommand("/kick", "core.kick", HandleKickCommand, " ~ Kick a player")
|
|
|
|
|
PluginManager:BindCommand("/kill", "core.kill", HandleKillCommand, " - Kill some player")
|
|
|
|
|
PluginManager:BindCommand("/locate", "core.locate", HandleLocateCommand, " - Show your current server coordinates")
|
|
|
|
|
PluginManager:BindCommand("/me", "core.me", HandleMeCommand, " ~ Tell what you are doing")
|
|
|
|
|
PluginManager:BindCommand("/motd", "core.motd", HandleMOTDCommand, " - Show message of the day")
|
|
|
|
|
PluginManager:BindCommand("/msg", "core.tell", HandleTellCommand, "")
|
|
|
|
|
PluginManager:BindCommand("/plugins", "core.plugins", HandlePluginsCommand, " - Show list of plugins")
|
|
|
|
|
PluginManager:BindCommand("/portal", "core.portal", HandlePortalCommand, " ~ Move to a different world")
|
|
|
|
|
PluginManager:BindCommand("/rank", "core.rank", HandleRankCommand, " ~ Add someone to a group")
|
|
|
|
|
PluginManager:BindCommand("/regen", "core.regen", HandleRegenCommand, " ~ Regenerates a chunk, current or specified")
|
|
|
|
|
PluginManager:BindCommand("/reload", "core.reload", HandleReloadCommand, " - Reload all plugins")
|
|
|
|
|
PluginManager:BindCommand("/save-all", "core.save-all", HandleSaveAllCommand, " - Saves all your worlds")
|
|
|
|
|
PluginManager:BindCommand("/spawn", "core.spawn", HandleSpawnCommand, " - Return to the spawn")
|
|
|
|
|
PluginManager:BindCommand("/stop", "core.stop", HandleStopCommand, " - Stops the server")
|
|
|
|
|
PluginManager:BindCommand("/tell", "core.tell", HandleTellCommand, " ~ Send a private message")
|
|
|
|
|
PluginManager:BindCommand("/time", "core.time", HandleTimeCommand, " ~ Sets the time of day")
|
|
|
|
|
PluginManager:BindCommand("/toggledownfall", "core.toggledownfall", HandleDownfallCommand, " - Toggles the weather")
|
|
|
|
|
PluginManager:BindCommand("/top", "core.top", HandleTopCommand, " - Teleport yourself to the top most block")
|
|
|
|
|
PluginManager:BindCommand("/tp", "core.teleport", HandleTPCommand, " ~ Teleport yourself to a player")
|
|
|
|
|
PluginManager:BindCommand("/tpa", "core.teleport", HandleTPACommand, " ~ Ask to teleport yourself to a player")
|
|
|
|
|
PluginManager:BindCommand("/tpaccept", "core.teleport", HandleTPAcceptCommand, " ~ Accept a teleportation request")
|
|
|
|
|
PluginManager:BindCommand("/unban", "core.unban", HandleUnbanCommand, " ~ Unban a player")
|
2013-07-27 16:24:03 +01:00
|
|
|
PluginManager:BindCommand("/viewdistance", "core.viewdistance", HandleViewDistanceCommand, " [".. cClientHandle.MIN_VIEW_DISTANCE .."-".. cClientHandle.MAX_VIEW_DISTANCE .."] - Change your view distance")
|
2013-08-11 16:00:53 +01:00
|
|
|
PluginManager:BindCommand("/weather", "core.weather", HandleWeatherCommand, " ~ Change world weather")
|
|
|
|
|
PluginManager:BindCommand("/worlds", "core.worlds", HandleWorldsCommand, " - Shows a list of all the worlds")
|
2013-08-13 17:55:46 +01:00
|
|
|
PluginManager:BindCommand("/sudo", "core.sudo", HandleSudoCommand, " - Runs a command as a player, ignoring permissions")
|
|
|
|
|
PluginManager:BindCommand("/do", "core.do", HandleDoCommand, " - Runs a command as a player.")
|
2013-07-27 19:45:44 +01:00
|
|
|
|
2013-08-11 16:00:53 +01:00
|
|
|
InitConsoleCommands()
|
2013-07-27 19:45:44 +01:00
|
|
|
|
2013-07-27 16:54:25 +01:00
|
|
|
--LOAD SETTINGS
|
2013-08-11 16:00:53 +01:00
|
|
|
IniFile = cIniFile( "settings.ini" )
|
|
|
|
|
if IniFile:ReadFile() == true then
|
|
|
|
|
HardCore = IniFile:GetValueSet( "GameMode", "Hardcore", "false" )
|
2013-07-27 16:24:03 +01:00
|
|
|
IniFile:WriteFile()
|
|
|
|
|
end
|
2013-08-11 16:00:53 +01:00
|
|
|
|
2013-08-02 07:48:47 +01:00
|
|
|
WorldsSpawnProtect = {}
|
2013-08-11 16:00:53 +01:00
|
|
|
local KeyIdx = IniFile:FindKey( "Worlds" ) --(FIND WHERE 'WORLDS' KEY IS LOCATED)
|
|
|
|
|
local NumValues = IniFile:GetNumValues( KeyIdx ) --(HOW MANY VALUES ARE THERE?)
|
2013-07-30 20:03:31 +01:00
|
|
|
for i = 0, NumValues - 1 do --(FOR EVERY WORLD KEY, TAKING ACCOUNT OF OFF BY ONE ERRORS)
|
2013-08-11 16:00:53 +01:00
|
|
|
WorldIni = cIniFile( IniFile:GetValue(KeyIdx, i) .. "/world.ini" )
|
2013-08-02 07:48:47 +01:00
|
|
|
if WorldIni:ReadFile() == true then
|
2013-08-11 16:00:53 +01:00
|
|
|
WorldsSpawnProtect[IniFile:GetValue(KeyIdx, i)] = WorldIni:GetValueSetI( "SpawnProtect", "ProtectRadius", 10 )
|
2013-08-02 07:48:47 +01:00
|
|
|
WorldIni:WriteFile()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
WorldsWorldLimit = {}
|
2013-08-11 16:00:53 +01:00
|
|
|
local KeyIdx = IniFile:FindKey( "Worlds" ) --(FIND WHERE 'WORLDS' KEY IS LOCATED)
|
|
|
|
|
local NumValues = IniFile:GetNumValues( KeyIdx ) --(HOW MANY VALUES ARE THERE?)
|
2013-08-02 07:48:47 +01:00
|
|
|
for i = 0, NumValues - 1 do --(FOR EVERY WORLD KEY, TAKING ACCOUNT OF OFF BY ONE ERRORS)
|
2013-08-11 16:00:53 +01:00
|
|
|
WorldIni = cIniFile( IniFile:GetValue(KeyIdx, i) .. "/world.ini" )
|
2013-08-02 07:48:47 +01:00
|
|
|
if WorldIni:ReadFile() == true then
|
2013-08-11 16:00:53 +01:00
|
|
|
WorldsWorldLimit[IniFile:GetValue(KeyIdx, i)] = WorldIni:GetValueSetI( "WorldLimit", "LimitRadius", 0 )
|
2013-08-02 07:48:47 +01:00
|
|
|
WorldIni:WriteFile()
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-07-30 20:03:31 +01:00
|
|
|
|
2013-07-27 16:54:25 +01:00
|
|
|
--LOAD WHITELIST
|
2013-07-27 16:24:03 +01:00
|
|
|
WhiteListIni = cIniFile( Plugin:GetLocalDirectory() .. "/whitelist.ini" )
|
2013-08-11 16:00:53 +01:00
|
|
|
if WhiteListIni:ReadFile() == true then
|
|
|
|
|
if WhiteListIni:GetValueB( "WhiteListSettings", "WhiteListOn", false ) == true then
|
|
|
|
|
if WhiteListIni:GetNumValues( "WhiteList" ) > 0 then
|
|
|
|
|
LOGINFO( "Core: loaded " .. WhiteListIni:GetNumValues('WhiteList') .. " whitelisted players." )
|
2013-07-27 16:24:03 +01:00
|
|
|
else
|
2013-08-11 16:00:53 +01:00
|
|
|
LOGWARN( "WARNING: WhiteList is on, but there are no people in the whitelist!" )
|
2013-07-27 16:24:03 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
2013-08-11 16:00:53 +01:00
|
|
|
WhiteListIni:SetValueB( "WhiteListSettings", "WhiteListOn", false )
|
|
|
|
|
WhiteListIni:SetValue( "WhiteList", "", "" ) -- So it adds an empty header
|
|
|
|
|
WhiteListIni:DeleteValue( "WhiteList", "" ) -- And remove the value
|
|
|
|
|
WhiteListIni:KeyComment( "WhiteList", "PlayerName=1" )
|
|
|
|
|
if WhiteListIni:WriteFile() == false then
|
|
|
|
|
LOGWARN( "WARNING: Could not write to whitelist.ini" )
|
2013-07-27 16:24:03 +01:00
|
|
|
end
|
|
|
|
|
end
|
2013-07-27 19:45:44 +01:00
|
|
|
|
2013-07-27 16:54:25 +01:00
|
|
|
--LOAD BANNED (BAD LUCK, BRO)
|
2013-07-27 16:24:03 +01:00
|
|
|
BannedPlayersIni = cIniFile( Plugin:GetLocalDirectory() .. "/banned.ini" )
|
2013-08-11 16:00:53 +01:00
|
|
|
if BannedPlayersIni:ReadFile() == true then
|
|
|
|
|
if BannedPlayersIni:GetNumValues( "Banned" ) > 0 then
|
|
|
|
|
LOGINFO( "Core: loaded " .. BannedPlayersIni:GetNumValues("Banned") .. " banned players." )
|
2013-07-27 16:24:03 +01:00
|
|
|
end
|
|
|
|
|
else
|
2013-08-11 16:00:53 +01:00
|
|
|
BannedPlayersIni:SetValue( "Banned", "", "" ) -- So it adds an empty header
|
|
|
|
|
BannedPlayersIni:DeleteValue( "Banned", "" ) -- And remove the value
|
|
|
|
|
BannedPlayersIni:KeyComment( "Banned", "PlayerName=1" )
|
|
|
|
|
if BannedPlayersIni:WriteFile() == false then
|
|
|
|
|
LOGWARN( "WARNING: Could not write to banned.ini" )
|
2013-07-27 16:24:03 +01:00
|
|
|
end
|
|
|
|
|
end
|
2013-07-27 19:45:44 +01:00
|
|
|
|
2013-08-02 07:48:47 +01:00
|
|
|
--ADD WEB INTERFACE TABULATES
|
2013-08-11 16:00:53 +01:00
|
|
|
Plugin:AddWebTab( "Manage Server", HandleRequest_ManageServer )
|
|
|
|
|
Plugin:AddWebTab( "Server Settings", HandleRequest_ServerSettings )
|
|
|
|
|
Plugin:AddWebTab( "Chat", HandleRequest_Chat )
|
|
|
|
|
Plugin:AddWebTab( "Playerlist", HandleRequest_PlayerList )
|
|
|
|
|
Plugin:AddWebTab( "Whitelist", HandleRequest_WhiteList )
|
|
|
|
|
Plugin:AddWebTab( "Permissions", HandleRequest_Permissions )
|
|
|
|
|
Plugin:AddWebTab( "Manage Plugins", HandleRequest_ManagePlugins )
|
2013-07-27 19:45:44 +01:00
|
|
|
|
2013-07-27 16:24:03 +01:00
|
|
|
LoadMotd()
|
|
|
|
|
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
|
|
|
|
|
|
2013-08-02 07:48:47 +01:00
|
|
|
return true
|
2013-08-11 16:00:53 +01:00
|
|
|
|
2013-07-27 16:24:03 +01:00
|
|
|
end
|
2013-07-27 16:54:25 +01:00
|
|
|
--AWESOMENESS STILL GOING!
|
2013-07-27 16:24:03 +01:00
|
|
|
|
2013-07-27 16:54:25 +01:00
|
|
|
--BEGIN SPAWNPROTECT LOGFILE CODE (COURTSEY OF BEARBIN)
|
2013-08-11 16:00:53 +01:00
|
|
|
function WriteLog( breakPlace, X, Y, Z, player, id, meta )
|
|
|
|
|
|
2013-07-27 16:24:03 +01:00
|
|
|
local logText = {}
|
|
|
|
|
|
2013-08-11 16:00:53 +01:00
|
|
|
table.insert( logText, player )
|
|
|
|
|
table.insert( logText, " tried to " )
|
2013-07-27 16:24:03 +01:00
|
|
|
|
|
|
|
|
if breakPlace == 0 then
|
2013-08-11 16:00:53 +01:00
|
|
|
table.insert( logText, "break " )
|
2013-08-02 07:48:47 +01:00
|
|
|
else
|
2013-08-11 16:00:53 +01:00
|
|
|
table.insert( logText, "place " )
|
2013-07-27 16:24:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2013-08-11 16:00:53 +01:00
|
|
|
table.insert( logText, ItemToString(cItem(id, 1, meta)) )
|
|
|
|
|
table.insert( logText, " at ")
|
|
|
|
|
table.insert( logText, tostring(X) )
|
|
|
|
|
table.insert( logText, ", ")
|
|
|
|
|
table.insert( logText, tostring(Y) )
|
|
|
|
|
table.insert( logText, ", ")
|
|
|
|
|
table.insert( logText, tostring(Z) )
|
|
|
|
|
table.insert( logText, "." )
|
2013-07-27 16:24:03 +01:00
|
|
|
|
2013-08-11 16:00:53 +01:00
|
|
|
LOGINFO( table.concat( logText, '') )
|
2013-07-27 16:24:03 +01:00
|
|
|
|
|
|
|
|
if LOGTOFILE then
|
2013-08-11 16:00:53 +01:00
|
|
|
local logFile = io.open( Plugin:GetLocalDirectory() .. '/blocks.log', 'a' )
|
|
|
|
|
logFile:write( table.concat( logText, '' ) .. "\n" )
|
2013-08-02 07:48:47 +01:00
|
|
|
logFile:close()
|
|
|
|
|
end
|
2013-07-27 16:24:03 +01:00
|
|
|
|
|
|
|
|
return
|
|
|
|
|
end
|
2013-08-11 16:00:53 +01:00
|
|
|
|
|
|
|
|
function WarnPlayer( Player )
|
|
|
|
|
SendMessageFailure( Player, "Go further from spawn to build" )
|
|
|
|
|
return true
|
2013-07-27 16:24:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function OnDisable()
|
2013-08-11 16:00:53 +01:00
|
|
|
LOG( "Disabled Core!" )
|
2013-07-27 16:54:25 +01:00
|
|
|
end
|
2013-07-27 19:45:44 +01:00
|
|
|
--END AWESOMENESS :'(
|