diff --git a/ChunkWorx.deproj b/ChunkWorx.deproj
new file mode 100644
index 0000000..17420d1
--- /dev/null
+++ b/ChunkWorx.deproj
@@ -0,0 +1,9 @@
+
+
+
+ chunkworx_main.lua
+
+
+ chunkworx_web.lua
+
+
diff --git a/chunkworx_main.lua b/chunkworx_main.lua
new file mode 100644
index 0000000..88ecb39
--- /dev/null
+++ b/chunkworx_main.lua
@@ -0,0 +1,128 @@
+-- Global variables
+PLUGIN = {} -- Reference to own plugin object
+GENERATION_STATE = 0
+OPERATION_CODE = 0 -- 0 = generation
+CX = 0
+CZ = 0
+CURRENT = 0
+TOTAL = 0
+
+-- AREA Variables
+AreaStartX = -10
+AreaStartZ = -10
+AreaEndX = 10
+AreaEndZ = 10
+
+-- RADIAL Variables
+RadialX = 0
+RadialZ = 0
+Radius = 10
+
+-- WORLD
+WORK_WORLD = cRoot:Get():GetDefaultWorld():GetName()
+WW_instance = cRoot:Get():GetDefaultWorld()
+WORLDS = {}
+
+
+
+
+
+function Initialize(Plugin)
+ PLUGIN = Plugin
+
+ PLUGIN:SetName("ChunkWorx")
+ PLUGIN:SetVersion(6)
+
+ cPluginManager.AddHook(cPluginManager.HOOK_TICK, OnTick)
+
+ Plugin:AddWebTab("(Re)Generation", HandleRequest_Generation)
+
+ GENERATION_STATE = 0
+ WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
+ if (WW_instance == nil) then
+ LOG("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": NO WORLD found :(")
+ end
+
+ -- Read the stored values:
+ local SettingsIni = cIniFile();
+ SettingsIni:ReadFile("ChunkWorx.ini"); -- ignore any read errors
+ AreaStartX = SettingsIni:GetValueSetI("Area data", "StartX", AreaStartX)
+ AreaStartZ = SettingsIni:GetValueSetI("Area data", "StartZ", AreaStartZ)
+ AreaEndX = SettingsIni:GetValueSetI("Area data", "EndX", AreaEndX)
+ AreaEndZ = SettingsIni:GetValueSetI("Area data", "EndZ", AreaEndZ)
+ RadialX = SettingsIni:GetValueSetI("Radial data", "RadialX", RadialX)
+ RadialZ = SettingsIni:GetValueSetI("Radial data", "RadialZ", RadialZ)
+ Radius = SettingsIni:GetValueSetI("Radial data", "Radius", Radius)
+ SettingsIni:WriteFile("ChunkWorx.ini");
+
+ LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion())
+ return true
+end
+
+
+
+
+
+function OnTick( DeltaTime )
+ if (GENERATION_STATE == 1 or GENERATION_STATE == 3) then
+ LOGINFO("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": works STARTED!")
+ LOGINFO("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": At world: " .. WORK_WORLD)
+ WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
+ if (GENERATION_STATE == 1) then GENERATION_STATE = 2 end
+ if (GENERATION_STATE == 3) then GENERATION_STATE = 4 end
+
+ -- Changing in case coordinates are flipped
+ local shifter = AreaEndX
+ if (AreaStartX > AreaEndX) then
+ AreaEndX = AreaStartX
+ AreaStartX = shifter
+ end
+ shifter = AreaEndZ
+ if (AreaStartZ > AreaEndZ) then
+ AreaEndZ = AreaStartZ
+ AreaStartZ = shifter
+ end
+
+ CX = AreaStartX
+ CZ = AreaStartZ
+ CURRENT = 0
+
+ if (WW_instance == nil) then
+ LOGERROR("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": works ABORTED")
+ LOGERROR("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": NO WORLD found :(")
+ GENERATION_STATE = 0
+ end
+ end
+
+
+
+ if (GENERATION_STATE == 2 or GENERATION_STATE == 4) then
+ if (WW_instance:GetGeneratorQueueLength() < 200
+ and WW_instance:GetLightingQueueLength() < 200
+ and (WW_instance:GetStorageSaveQueueLength() + WW_instance:GetStorageLoadQueueLength()) < 80) then
+ local chunk_sum = (1+ AreaEndX - AreaStartX) * (1+ AreaEndZ - AreaStartZ)
+ TOTAL = chunk_sum
+ LOG("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": PROCESSING 100 chunks, (" .. CURRENT .. "/" .. chunk_sum .. ")")
+ for C = 1, 100 do
+ if (GENERATION_STATE == 2) then WW_instance:GenerateChunk(CX, CZ) end
+ if (GENERATION_STATE == 4) then WW_instance:RegenerateChunk(CX, CZ) end
+
+ CX = CX + 1
+ CURRENT = CURRENT + 1
+ if (CX > AreaEndX) then
+ CX = AreaStartX
+ CZ = CZ + 1
+ if (CZ > AreaEndZ) then
+ if (GENERATION_STATE == 2) then LOGINFO("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " - generation ENDED!") end
+ if (GENERATION_STATE == 4) then LOGINFO("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " - REgeneration ENDED!") end
+
+ GENERATION_STATE = 0
+ break
+ end
+ end
+ end
+ WW_instance:QueueSaveAllChunks()
+ WW_instance:QueueUnloadUnusedChunks()
+ end
+ end
+end
\ No newline at end of file
diff --git a/chunkworx_web.lua b/chunkworx_web.lua
new file mode 100644
index 0000000..9aec38b
--- /dev/null
+++ b/chunkworx_web.lua
@@ -0,0 +1,274 @@
+
+-- chunkworx_web.lua
+
+-- WebAdmin-related functions
+
+
+
+
+
+local function Buttons_Player( Name )
+ return "
"
+end
+
+
+
+
+
+local function Button_World( Name )
+ return ""
+end
+
+
+
+
+
+local function SaveSettings()
+ local SettingsIni = cIniFile()
+ SettingsIni:SetValueI("Area data", "StartX", AreaStartX)
+ SettingsIni:SetValueI("Area data", "StartZ", AreaStartZ)
+ SettingsIni:SetValueI("Area data", "EndX", AreaEndX)
+ SettingsIni:SetValueI("Area data", "EndZ", AreaEndZ)
+ SettingsIni:SetValueI("Radial data", "RadialX", RadialX)
+ SettingsIni:SetValueI("Radial data", "RadialZ", RadialZ)
+ SettingsIni:SetValueI("Radial data", "Radius", Radius)
+ SettingsIni:WriteFile("ChunkWorx.ini")
+end
+
+
+
+
+
+function HandleRequest_Generation( Request )
+ local Content = ""
+ if (Request.PostParams["AGHRRRR"] ~= nil) then
+ GENERATION_STATE = 0
+ WW_instance:QueueSaveAllChunks()
+ WW_instance:QueueUnloadUnusedChunks()
+ LOGERROR("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": works ABORTED by admin")
+ end
+ --Content = Content .. ""
+ -- PROCESSING
+ --------------------------------------------------------------------------------------------------
+ local function ProcessingContent()
+ local _small_content = ""
+ _small_content = _small_content .. ""
+ _small_content = _small_content .. "World for operations:
"..WORK_WORLD
+ if (OPERATION_CODE == 0) then
+ _small_content = _small_content .. "Operation:
Generation"
+ elseif (OPERATION_CODE == 1) then
+ _small_content = _small_content .. "Operation:
Regeneration"
+ end
+ _small_content = _small_content .. "Area:
["..AreaStartX..":"..AreaStartZ.."] ["..AreaEndX..":"..AreaEndZ.."]"
+ _small_content = _small_content .. "Progress:
"..CURRENT.."/"..TOTAL
+ _small_content = _small_content .. "
"
+ _small_content = _small_content .. ""
+ return _small_content
+ end
+ if (GENERATION_STATE == 2 or GENERATION_STATE == 4) then
+ Content = ProcessingContent()
+ return Content
+ end
+ -- SELECTING
+ --------------------------------------------------------------------------------------------------
+ if ( Request.PostParams["FormSetWorld"] ) then
+ WORK_WORLD = Request.PostParams["FormWorldName"]
+ WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
+ end
+
+ if( Request.PostParams["SelectWorld"] ~= nil
+ and Request.PostParams["WorldName"] ~= nil ) then -- World is selected!
+ WORK_WORLD = Request.PostParams["WorldName"]
+ WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
+ end
+
+ if(Request.PostParams["OperationGenerate"] ~= nil) then
+ OPERATION_CODE = 0
+ end
+ if(Request.PostParams["OperationReGenerate"] ~= nil) then
+ OPERATION_CODE = 1
+ end
+
+ if (GENERATION_STATE == 0) then
+ if( Request.PostParams["FormAreaStartX"] ~= nil
+ and Request.PostParams["FormAreaStartZ"] ~= nil
+ and Request.PostParams["FormAreaEndX"] ~= nil
+ and Request.PostParams["FormAreaEndZ"] ~= nil ) then --(Re)Generation valid!
+ -- COMMON (Re)gen
+ if( Request.PostParams["StartArea"]) then
+ AreaStartX = tonumber(Request.PostParams["FormAreaStartX"])
+ AreaStartZ = tonumber(Request.PostParams["FormAreaStartZ"])
+ AreaEndX = tonumber(Request.PostParams["FormAreaEndX"])
+ AreaEndZ = tonumber(Request.PostParams["FormAreaEndZ"])
+ SaveSettings();
+ if (OPERATION_CODE == 0) then
+ GENERATION_STATE = 1
+ elseif (OPERATION_CODE == 1) then
+ GENERATION_STATE = 3
+ end
+ Content = ProcessingContent()
+ return Content
+ end
+ end
+ if( Request.PostParams["FormRadialX"] ~= nil
+ and Request.PostParams["FormRadialZ"] ~= nil
+ and Request.PostParams["FormRadius"] ~= nil ) then --(Re)Generation valid!
+ -- COMMON (Re)gen
+ if( Request.PostParams["StartRadial"]) then
+ RadialX = tonumber(Request.PostParams["FormRadialX"]) or 0
+ RadialZ = tonumber(Request.PostParams["FormRadialZ"]) or 0
+ Radius = tonumber(Request.PostParams["FormRadius"]) or 10
+ AreaStartX = RadialX - Radius
+ AreaStartZ = RadialZ - Radius
+ AreaEndX = RadialX + Radius
+ AreaEndZ = RadialZ + Radius
+ SaveSettings()
+ if (OPERATION_CODE == 0) then
+ GENERATION_STATE = 1
+ elseif (OPERATION_CODE == 1) then
+ GENERATION_STATE = 3
+ end
+ Content = ProcessingContent()
+ return Content
+ end
+ end
+ -- POINT REGEN!
+ if( Request.PostParams["FormPointX"] ~= nil
+ and Request.PostParams["FormPointZ"] ~= nil ) then --ReGeneration valid!
+ -- EXACT
+ if ( Request.PostParams["PointExact"] ~= nil) then
+ AreaStartX = tonumber(Request.PostParams["FormPointX"])
+ AreaStartZ = tonumber(Request.PostParams["FormPointZ"])
+ AreaEndX = AreaStartX
+ AreaEndZ = AreaStartZ
+ GENERATION_STATE = 3
+ Content = ProcessingContent()
+ return Content
+ end
+ -- 3x3
+ if ( Request.PostParams["Point3x3"] ~= nil) then
+ AreaStartX = tonumber(Request.PostParams["FormPointX"]) - 1
+ AreaStartZ = tonumber(Request.PostParams["FormPointZ"]) - 1
+ AreaEndX = AreaStartX + 2
+ AreaEndZ = AreaStartZ + 2
+ GENERATION_STATE = 3
+ Content = ProcessingContent()
+ return Content
+ end
+ end
+
+ local GetAreaByPlayer = function(Player)
+ -- Player is valid only within this function, it cannot be stord and used later!
+ AreaStartX = Player:GetChunkX()
+ AreaStartZ = Player:GetChunkZ()
+ end
+ -- PLAYERS REGEN!
+ if( Request.PostParams["PlayerExact"] ~= nil
+ and Request.PostParams["PlayerName"] ~= nil ) then -- Making BOOM! I meant, regenereate...
+ cRoot:Get():GetWorld(WORK_WORLD):DoWithPlayer(Request.PostParams["PlayerName"],GetAreaByPlayer)
+ AreaEndX = AreaStartX
+ AreaEndZ = AreaStartZ
+ GENERATION_STATE = 3
+ Content = ProcessingContent()
+ return Content
+ end
+ if( Request.PostParams["Player3x3"] ~= nil
+ and Request.PostParams["PlayerName"] ~= nil ) then -- Making BOOM! I meant, regenereate...
+ cRoot:Get():GetWorld(WORK_WORLD):DoWithPlayer(Request.PostParams["PlayerName"],GetAreaByPlayer)
+ AreaStartX = AreaStartX - 1
+ AreaStartZ = AreaStartZ - 1
+ AreaEndX = AreaStartX + 2
+ AreaEndZ = AreaStartZ + 2
+ GENERATION_STATE = 3
+ Content = ProcessingContent()
+ return Content
+ end
+ end
+
+ --Content = Content .. "World for operations: " .. WORK_WORLD .. "
"
+ --Content = Content .. ""
+
+ -- SELECTING WORK_WORLD
+ Content = Content .. "World for operations: " .. WORK_WORLD .. "
"
+ Content = Content .. ""
+ local WorldNum = 0
+ local AddWorldToTable = function(World)
+ WorldNum = WorldNum + 1
+ Content = Content .. ""
+ Content = Content .. "" .. WorldNum .. ". | "
+ Content = Content .. "" .. World:GetName() .. " | "
+ Content = Content .. "" .. Button_World(World:GetName()) .. " | "
+ Content = Content .. "
"
+ end
+ cRoot:Get():ForEachWorld(AddWorldToTable)
+ if( WorldNum == 0 ) then
+ Content = Content .. "No worlds! O_O |
"
+ end
+ Content = Content .. "
"
+ Content = Content .. "
"
+
+ -- SELECTING OPERATION
+ if (OPERATION_CODE == 0) then
+ Content = Content .. "Operation: Generation
"
+ elseif (OPERATION_CODE == 1) then
+ Content = Content .. "Operation: Regeneration
"
+ end
+ Content = Content .. ""
+
+ -- SELECTING AREA
+ Content = Content .. "Area:
Start X, Start Z; End X, End Z"
+ Content = Content .. ""
+
+ -- SELECTING RADIAL
+ Content = Content .. "Radial:
Center X, Center Z, Radius"
+ Content = Content .. ""
+ Content = Content .. "
"
+ Content = Content .. "
"
+ Content = Content .. "
"
+
+ -- SELECTING POINT
+ Content = Content .. "Point regeneration:
X, Z"
+ Content = Content .. ""
+
+ -- SELECTING PLAYERS
+ Content = Content .. "Player-based regeneration:
"
+ Content = Content .. ""
+ local PlayerNum = 0
+ local AddPlayerToTable = function( Player )
+ PlayerNum = PlayerNum + 1
+ Content = Content .. ""
+ Content = Content .. "" .. PlayerNum .. ". | "
+ Content = Content .. "" .. Player:GetName() .. " | "
+ Content = Content .. "" .. Buttons_Player(Player:GetName()) .. " | "
+ Content = Content .. "
"
+ end
+ if (cRoot:Get():GetWorld(WORK_WORLD) == nil) then
+ Content = Content .. "Incorrect world selection |
"
+ else
+ cRoot:Get():GetWorld(WORK_WORLD):ForEachPlayer( AddPlayerToTable )
+ if( PlayerNum == 0 ) then
+ Content = Content .. "No connected players |
"
+ end
+ end
+ Content = Content .. "
"
+ Content = Content .. "
"
+ return Content
+end
\ No newline at end of file