Skip to content

Commit

Permalink
Liro V1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Alydus committed Dec 22, 2017
1 parent f8a2054 commit a1ee4b3
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 127 deletions.
6 changes: 0 additions & 6 deletions liro/entities/entities/liro_testentity/cl_init.lua

This file was deleted.

24 changes: 0 additions & 24 deletions liro/entities/entities/liro_testentity/init.lua

This file was deleted.

8 changes: 0 additions & 8 deletions liro/entities/entities/liro_testentity/shared.lua

This file was deleted.

4 changes: 4 additions & 0 deletions liro/gamemode/cl_init.lua
Expand Up @@ -3,6 +3,10 @@
-- Include dependant files
include("shared.lua")

if liro then
hook.Call("Initialize", GAMEMODE)
end

-- Define base Liro data array
liro = liro or {}

Expand Down
2 changes: 1 addition & 1 deletion liro/gamemode/how-to-create-a-module.txt
@@ -1,4 +1,4 @@
* How to create a module
- How to create a module

1. Create a folder within 'modules' directory with your modulename. The name may contain no spaces, and preferably no special characters or uppercase characters.
2. Copy the registermodule.lua from here https://github.com/Alydus/liro/blob/master/liro/gamemode/modules/examplemodule/registermodule.lua and put it into your module folder.
Expand Down
12 changes: 8 additions & 4 deletions liro/gamemode/init.lua
Expand Up @@ -5,6 +5,10 @@ include("shared.lua")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

if liro then
hook.Call("Initialize", GAMEMODE)
end

-- Define base Liro data array
liro = liro or {}

Expand All @@ -22,9 +26,9 @@ AddCSLuaFile("liro/config.lua")
include("liro/functions.lua")
AddCSLuaFile("liro/functions.lua")

-- Include data management
include("liro/datamanagement.lua")

-- Include module loader
include("liro/moduleloader.lua")
AddCSLuaFile("liro/moduleloader.lua")

-- Include data management
include("liro/datamanagement.lua")
AddCSLuaFile("liro/moduleloader.lua")
5 changes: 4 additions & 1 deletion liro/gamemode/liro/config.lua
Expand Up @@ -23,6 +23,9 @@ liro.config = {

-- Enable a Linux Uppercase Path Warning on post initialization?
doLinuxUppercasePathWarning = true,

-- Show the average load time of every player that has joined when a player finishes loading Liro,
averageLoadTime = true,

-- Enable adding "DSB_" to the beginning of a moduleFolderName to disable it
doQuickDisableModulePrefix = true,
Expand All @@ -31,7 +34,7 @@ liro.config = {
showConsoleLoadSequenceClientside = true,

-- Show the module loading sequence in clientside console for clients with ranks defined in showConsoleLoadSequenceClientsideRanks
showConsoleLoadSequenceClientsideRanksOnly = true,
showConsoleLoadSequenceClientsideRanksOnly = false,

-- Ranks that will see module loading sequence in clientside console, works if only showConsoleLoadSequenceClientside/RanksOnly is true
showConsoleLoadSequenceClientsideRanks = {"superadmin", "admin"},
Expand Down
11 changes: 11 additions & 0 deletions liro/gamemode/liro/datamanagement.lua
@@ -1,10 +1,21 @@
-- Liro - datamanagement.lua

averageLLT = averageLTT or {0}

-- Handling of players serverside when they post-initialize Liro on their clients
net.Receive("liro.receiveClientInformation", function(len, ply)
local playerDataTable = net.ReadString()
playerDataTable = util.JSONToTable(playerDataTable)

liro.activateDeveloperHook("liro.newClient", playerDataTable)

if not ply:IsBot() then
table.insert(averageLLT, playerDataTable.loadTime)
if liro.config.averageLoadTime then
liro.diagnosticPrint("Liro has calculated an average LLT (Client Load Time) of " .. liro.mean(averageLLT))
end
end

if liro.config.doPlayerInitializationMessage then
liro.diagnosticPrint("[C] " .. ply:GetName() .. " (SteamID: " .. ply:SteamID() .. ", Screen Res: " .. playerDataTable.screenWidth .. "x" .. playerDataTable.screenHeight .. ", Country: " .. playerDataTable.country .. ", liroLoadTime = " .. playerDataTable.loadTime .. "s, OS: " .. playerDataTable.os .. ", Battery: " .. liro.formatBatteryPower(playerDataTable.batteryPower) .. ") has reached Liro Post-Initialization.")
end
Expand Down
19 changes: 19 additions & 0 deletions liro/gamemode/liro/functions.lua
Expand Up @@ -37,6 +37,25 @@ function liro.getSystemOS()
end
end


-- liro.mean(table)
-- Returns the mean/average number in a table
function liro.mean(t)
local sum = 0
local count= 0

for _, v in pairs(t) do
if type(v) == "number" then
sum = sum + v
count = count + 1
end
end

return sum / count
end

-- liro.formatBatteryPower(batteryPower)
-- Returns formatted battery power, returns "Plug" if not on battery or plugged in
function liro.formatBatteryPower(batteryPower)
if batteryPower == 255 or not batteryPower then
return "Plug"
Expand Down
173 changes: 91 additions & 82 deletions liro/gamemode/liro/moduleloader.lua
Expand Up @@ -48,10 +48,10 @@ function liro.recursiveInclusion(moduleData, folderPath)
if CLIENT then
include(relativePath)
end
end
end
end
end
end

-- liro.countModules()
-- Returns the amount of modules in the modules folder with no checking
Expand Down Expand Up @@ -97,26 +97,29 @@ function liro.initalizeModules()
end
end

-- liro.loadEntities()
-- WIP Entity Loader for gamemode/entities/entities
function liro.loadEntities()
local entityFoldersPath = gamemodeFolderName .. "/gamemode/entities/entities"
local entitys = file.Find(entityFoldersPath .. "/*", "LUA")

for _, entityFolderName in pairs(entitys) do
if file.IsDir(entityFolderName) then
-- Entity is in a folder structure, will attempt to load three different files
-- cl_init, shared.lua, init.lua in retrospective environments
liro.diagnosticPrint("Attempting to load entity '" .. entityFolderName .. "'")

elseif string.Right(entityFolderName, 4) == ".lua" then

-- Entity is a single lua file (probably shared, so will load it that way)
liro.diagnosticPrint("Attempting to load entity '" .. entityFolderName .. "'")

-- liro.versionCheck()
-- Checks for a new version of liro
function liro.versionCheck()
http.Fetch("https://api.github.com/repos/Alydus/liro/releases/latest", function(body, len, headers, code)
if not liro.isEmpty(body) then
local json = util.JSONToTable(body)
local latestVersion = tostring(json.tag_name)
latestVersion = string.gsub(latestVersion, "V", "")

-- Outdated Liro version warning
if liro.config.doOutdatedWarning and latestVersion != "" and tonumber(latestVersion) > tonumber(GAMEMODE.Version) and latestVersion and json then
liro.diagnosticPrint("Liro is outdated, updating is recommended. (Running V" .. GAMEMODE.Version .. ", Latest is " .. latestVersion .. ")")
end

-- If GAMEMODE.Version is higher than the latest release version, display a developmental version warning
if liro.config.doOutdatedWarning and latestVersion != "" and tonumber(latestVersion) < tonumber(GAMEMODE.Version) and latestVersion and json then
liro.diagnosticPrint("Liro is running a developmental version, most likely from development branch, expect issues. (Running V" .. GAMEMODE.Version .. ", Latest is " .. latestVersion .. ")")
end
end
end
end,
function(error)
liro.diagnosticPrint("liro.versionCheck() - HTTP Error has occured; error states: \"" .. error .. "\"")
end)
end

-- liro.loadModules()
Expand All @@ -128,12 +131,9 @@ function liro.loadModules()
table.insert(liro.networkStrings, networkString)
util.AddNetworkString(networkString)
else
liro.diagnosticPrint("Liro detected a empty network string in the config (liro.config.networkStrings[" .. networkStringIndex .. "])")
liro.diagnosticPrint("Liro detected a empty network string in the Liro config networkStrings (liro.config.networkStrings[" .. networkStringIndex .. "])")
end
end

-- Load entities, after the global network strings so they can be used within entity files
liro.loadEntities()

-- Sort modules in order of loadPriority, taken from module data
table.sort(liro.toLoadModules, function(module1, module2)
Expand All @@ -159,95 +159,102 @@ function liro.loadModules()
end

if SERVER and moduleData.networkStrings and moduleData.networkStrings[1] then
for _, networkString in pairs(moduleData.networkStrings) do
for networkStringIndex, networkString in pairs(moduleData.networkStrings) do
if networkString != "" then
table.insert(liro.networkStrings, networkString)
util.AddNetworkString(networkString)
else
liro.diagnosticPrint("Liro detected a empty network string in module '" .. moduleData.folderName .. "'")
liro.diagnosticPrint("Liro detected a empty network string in module '" .. moduleData.folderName .. "' (moduleData.networkStrings[" .. networkStringIndex .. "]), it will not be added.")
end
end
end

liro.activateDeveloperHook("liro.attemptLoad" .. moduleData.folderName)

liro.recursiveInclusion(moduleData, gamemodeFolderName .. "/gamemode/modules")
-- Check if the module is empty, no point running recursive inclusion if it's empty
local folderFiles, folderDirectories = file.Find(gamemodeFolderName .. "/gamemode/modules/" .. moduleData.folderName .. "/*", "LUA")

if #folderFiles == 0 and #folderDirectories == 0 then
liro.diagnosticPrint("Liro has detected an empty module (" .. moduleData.folderName .. "), it will not load.")
else
liro.activateDeveloperHook("liro.attemptLoad" .. moduleData.folderName)

liro.activateDeveloperHook("liro.successfullyLoaded" .. moduleData.folderName, moduleData)
liro.recursiveInclusion(moduleData, gamemodeFolderName .. "/gamemode/modules")

liro.loadedModules[moduleName] = moduleData
liro.activateDeveloperHook("liro.successfullyLoaded" .. moduleData.folderName, moduleData)

liro.loadedModules[moduleName] = moduleData
end
end

elseif table.HasValue(liro.config.disabledModuleNames, moduleName) then
elseif table.HasValue(liro.config.disabledModuleNames, moduleName) then
liro.unloadedDisabledModules[moduleName] = moduleData
end
end
end

-- Console Output
if liro.config.doModuleLoadMessages then
-- Version Checker
http.Fetch("https://api.github.com/repos/Alydus/liro/releases/latest", function(body, len, headers, code)
if not liro.isEmpty(body) then
local json = util.JSONToTable(body)
local latestVersion = tostring(json.tag_name)
latestVersion = string.gsub(latestVersion, "V", "")

-- Outdated Liro version warning
if liro.config.doOutdatedWarning and latestVersion != "" and tonumber(latestVersion) > tonumber(GAMEMODE.Version) and latestVersion and json then
liro.diagnosticPrint("Liro is outdated, updating is recommended. (Running V" .. GAMEMODE.Version .. ", Latest is " .. latestVersion .. ")")
end
local loadTime = math.Round(os.clock() - liro.startTime, 3)
if SERVER or (CLIENT and liro.config.showConsoleLoadSequenceClientside) then

if SERVER or (CLIENT and liro.config.showConsoleLoadSequenceClientside and liro.config.showConsoleLoadSequenceRanksOnly and LocalPlayer() and LocalPlayer():GetUserGroup() and table.HasValue(liro.config.showConsoleLoadSequenceClientsideRanks, LocalPlayer():GetUserGroup())) then

-- Linux System uppercase filenames/paths warning
if system.IsLinux() and liro.config.doLinuxUppercasePathWarning then
liro.diagnosticPrint("Liro is running on Linux, module(s) and/or uppercase file name paths will cause issues, same with spaces/tabs.")
end

if SERVER or (CLIENT and liro.config.showConsoleLoadSequenceClientside) then

if SERVER or (CLIENT and liro.config.showConsoleLoadSequenceClientside and liro.config.showConsoleLoadSequenceRanksOnly and LocalPlayer() and LocalPlayer():GetUserGroup() and table.HasValue(liro.config.showConsoleLoadSequenceClientsideRanks, LocalPlayer():GetUserGroup())) then

print("/////////////////////////////////////////")
print("// / Liro V" .. GAMEMODE.Version .. " / //")
print("// / OS: " .. liro.getSystemOS() .. " / LT: " .. math.Round(os.clock() - liro.startTime, 3) .. "s /")
print("/////////////////////////////////////////")
print("// Post-Initialization Complete //")

if next(liro.loadedModules) then
print("/////////////////////////////////////////")
print("// Loaded module(s): //")
for moduleLoadedOrderKey, moduleData in pairs(liro.loadedModules) do
if liro.moduleIntegrity(moduleData) then
print("// Module: \"" .. moduleData.folderName .. "\" by \"" .. moduleData.author .. "\"")
end
end
print("/////////////////////////////////////////////////////////////////////")
print("//")
print("// Liro V" .. GAMEMODE.Version)
print("//")
print("// OS: " .. liro.getSystemOS())
print("// LLT (Load Time): " .. loadTime .. "s")
print("// IP (Public IP:Listen Port): " .. game.GetIPAddress())
print("// Enabled Modules: " .. table.Count(liro.loadedModules))
print("// Disabled Modules: " .. table.Count(liro.unloadedDisabledModules))
print("//")
print("/////////////////////////////////////////////////////////////////////")
print("// Post-Initialization Complete //")

if next(liro.loadedModules) then
print("/////////////////////////////////////////////////////////////////////")
print("// Loaded Module(s):")
print("//")
for moduleLoadedOrderKey, moduleData in pairs(liro.loadedModules) do
if liro.moduleIntegrity(moduleData) then
print("// -- MODULE: " .. moduleData.folderName)
print("// -- Developer: " .. moduleData.author .. ", Website: " .. moduleData.website .. ", Network Strings: " .. table.Count(moduleData.networkStrings))
end

if next(liro.unloadedDisabledModules) then
print("/////////////////////////////////////////")
print("// Disabled module(s): //")
for _, moduleData in pairs(liro.unloadedDisabledModules) do
if liro.moduleIntegrity(moduleData) then
print("// Module: \"" .. moduleData.folderName .. "\" by \"" .. moduleData.author .. "\"")
end
end
end

print("/////////////////////////////////////////")
print("// Disabled: " .. table.Count(liro.unloadedDisabledModules) .. " | Enabled: " .. table.Count(liro.loadedModules))
print("/////////////////////////////////////////")
end
end

if CLIENT then
net.Start("liro.receiveClientInformation")
net.WriteString(util.TableToJSON({loadTime = math.Round(os.clock() - liro.startTime, 3), os = liro.getSystemOS(), country = system.GetCountry(), windowed = system.IsWindowed(), steamTime = system.SteamTime(), upTime = system.UpTime(), screenWidth = ScrW(), screenHeight = ScrH(), batteryPower = system.BatteryPower()}))
net.SendToServer()
if next(liro.unloadedDisabledModules) then
print("/////////////////////////////////////////////////////////////////////")
print("// Disabled Module(s):")
print("//")
for _, moduleData in pairs(liro.unloadedDisabledModules) do
if liro.moduleIntegrity(moduleData) then
print("// -- MODULE: " .. moduleData.folderName)
print("// -- Developer: \"" .. moduleData.author .. "\", Website: \"" .. moduleData.website .. "\", Network Strings: " .. table.Count(moduleData.networkStrings))
end
end
end
print("//")
print("/////////////////////////////////////////////////////////////////////")
end
end)
end

if CLIENT then
net.Start("liro.receiveClientInformation")
net.WriteString(util.TableToJSON({loadTime = math.Round(os.clock() - liro.startTime, 3), os = liro.getSystemOS(), country = system.GetCountry(), windowed = system.IsWindowed(), steamTime = system.SteamTime(), upTime = system.UpTime(), screenWidth = ScrW(), screenHeight = ScrH(), batteryPower = system.BatteryPower()}))
net.SendToServer()
end

liro.diagnosticPrint("Liro has completed the multi-stage loading process in " .. loadTime .. "s.")
end

liro.activateDeveloperHook("liro.successfullyLoadedModules")

liro.versionCheck()
end

hook.Add("liro.registerModule", "loadModuleHook", function(moduleData)
Expand All @@ -271,4 +278,6 @@ hook.Add("liro.registerModule", "loadModuleHook", function(moduleData)
end
end)

liro.initalizeModules()
function GM:Initialize()
liro.initalizeModules()
end

0 comments on commit a1ee4b3

Please sign in to comment.