diff --git a/plugin/src/Config.lua b/plugin/src/Config.lua index a3bb163a..1525c2f8 100644 --- a/plugin/src/Config.lua +++ b/plugin/src/Config.lua @@ -1,7 +1,7 @@ return { + codename = "Epiphany", version = {0, 5, 0}, - expectedServerVersionString = "0.5.x", + expectedServerVersionString = "0.5.0 or newer", protocolVersion = 2, port = 34872, - dev = false, } diff --git a/plugin/src/Config.spec.lua b/plugin/src/Config.spec.lua deleted file mode 100644 index ce9b43fd..00000000 --- a/plugin/src/Config.spec.lua +++ /dev/null @@ -1,7 +0,0 @@ -return function() - local Config = require(script.Parent.Config) - - it("should have 'dev' disabled", function() - expect(Config.dev).to.equal(false) - end) -end diff --git a/plugin/src/DevSettings.lua b/plugin/src/DevSettings.lua new file mode 100644 index 00000000..efca1e3f --- /dev/null +++ b/plugin/src/DevSettings.lua @@ -0,0 +1,53 @@ +local Config = require(script.Parent.Config) + +local function getValueContainer() + return game:FindFirstChild("RojoDev-" .. Config.codename) +end + +local valueContainer = getValueContainer() + +local function create() + valueContainer = getValueContainer() + + if valueContainer == nil then + valueContainer = Instance.new("Folder") + valueContainer.Name = "RojoDev-" .. Config.codename + valueContainer.Parent = game + end + + local valueLogLevel = valueContainer:FindFirstChild("LogLevel") + if valueLogLevel == nil then + valueLogLevel = Instance.new("IntValue") + valueLogLevel.Name = "LogLevel" + valueLogLevel.Value = 2 + valueLogLevel.Parent = valueContainer + end +end + +_G[("ROJO_%s_DEV_CREATE"):format(Config.codename:upper())] = create + +local function getValue(name) + if valueContainer == nil then + return nil + end + + local valueObject = valueContainer:FindFirstChild(name) + + if valueObject == nil then + return nil + end + + return valueObject.Value +end + +local DevSettings = {} + +function DevSettings:isEnabled() + return valueContainer ~= nil +end + +function DevSettings:getLogLevel() + return getValue("LogLevel") +end + +return DevSettings \ No newline at end of file diff --git a/plugin/src/HttpError.lua b/plugin/src/HttpError.lua index 462ed5f1..e28bc392 100644 --- a/plugin/src/HttpError.lua +++ b/plugin/src/HttpError.lua @@ -12,14 +12,11 @@ HttpError.Error = { "Check your game settings, located in the 'Home' tab of Studio.", }, ConnectFailed = { - message = "Rojo plugin couldn't connect to the Rojo server.\n" .. + message = "Couldn't connect to the Rojo server.\n" .. "Make sure the server is running -- use 'rojo serve' to run it!", }, - Timeout = { - message = "Rojo timed out during a request.", - }, Unknown = { - message = "Rojo encountered an unknown error: {{message}}", + message = "Unknown error: {{message}}", }, } @@ -44,22 +41,18 @@ end --[[ This method shouldn't have to exist. Ugh. ]] -function HttpError.fromErrorString(err) - err = err:lower() +function HttpError.fromErrorString(message) + local lower = message:lower() - if err:find("^http requests are not enabled") then + if lower:find("^http requests are not enabled") then return HttpError.new(HttpError.Error.HttpNotEnabled) end - if err:find("^curl error") then - if err:find("couldn't connect to server") then - return HttpError.new(HttpError.Error.ConnectFailed) - elseif err:find("timeout was reached") then - return HttpError.new(HttpError.Error.Timeout) - end + if lower:find("^httperror: connectfail") then + return HttpError.new(HttpError.Error.ConnectFailed) end - return HttpError.new(HttpError.Error.Unknown, err) + return HttpError.new(HttpError.Error.Unknown, message) end function HttpError:report() diff --git a/plugin/src/Logging.lua b/plugin/src/Logging.lua index a7f15c55..b6f24c3b 100644 --- a/plugin/src/Logging.lua +++ b/plugin/src/Logging.lua @@ -1,5 +1,6 @@ +local DevSettings = require(script.Parent.DevSettings) + local testLogLevel = nil -local configValue = game:FindFirstChild("ROJO_LOG") local Level = { Error = 0, @@ -17,32 +18,37 @@ local function getLogLevel() return _G.ROJO_LOG end - if configValue ~= nil then - return configValue.Value + local hyperValue = DevSettings:getLogLevel() + if hyperValue ~= nil then + return hyperValue end return Level.Info end +local function addTags(tag, message) + return tag .. message:gsub("\n", "\n" .. tag) +end + local Log = {} Log.Level = Level function Log.trace(template, ...) if getLogLevel() >= Level.Trace then - print("[Rojo-Trace] " .. string.format(template, ...)) + print(addTags("[Rojo-Trace] ", string.format(template, ...))) end end function Log.info(template, ...) if getLogLevel() >= Level.Info then - print("[Rojo-Info] " .. string.format(template, ...)) + print(addTags("[Rojo-Info] ", string.format(template, ...))) end end function Log.warn(template, ...) if getLogLevel() >= Level.Warning then - warn("[Rojo-Warn] " .. string.format(template, ...)) + warn(addTags("[Rojo-Warn] ", string.format(template, ...))) end end diff --git a/plugin/src/Session.lua b/plugin/src/Session.lua index ab47170a..b01c30d7 100644 --- a/plugin/src/Session.lua +++ b/plugin/src/Session.lua @@ -28,6 +28,9 @@ function Session.new() :andThen(function() return api:retrieveMessages() end) + :catch(function(message) + Logging.warn("Couldn't start a new Rojo session: %s", tostring(message)) + end) return setmetatable(self, Session) end diff --git a/plugin/src/Main.server.lua b/plugin/src/init.server.lua similarity index 77% rename from plugin/src/Main.server.lua rename to plugin/src/init.server.lua index 844c5e87..e4edfcb2 100644 --- a/plugin/src/Main.server.lua +++ b/plugin/src/init.server.lua @@ -2,10 +2,11 @@ if not plugin then return end -local Session = require(script.Parent.Session) -local Config = require(script.Parent.Config) -local Version = require(script.Parent.Version) -local Logging = require(script.Parent.Logging) +local Session = require(script.Session) +local Config = require(script.Config) +local Version = require(script.Version) +local Logging = require(script.Logging) +local DevSettings = require(script.DevSettings) --[[ Check if the user is using a newer version of Rojo than last time. If they @@ -13,7 +14,7 @@ local Logging = require(script.Parent.Logging) ]] local function checkUpgrade() -- When developing Rojo, there's no use in doing version checks - if Config.dev then + if DevSettings:isEnabled() then return end @@ -26,7 +27,7 @@ local function checkUpgrade() local message = ( "\nRojo detected an upgrade from version %s to version %s." .. "\nMake sure you have also upgraded your server!" .. - "\n\nRojo version %s is intended for use with server version %s.\n" + "\n\nRojo plugin version %s is intended for use with server version %s.\n" ):format( Version.display(lastVersion), Version.display(Config.version), Version.display(Config.version), Config.expectedServerVersionString @@ -40,7 +41,7 @@ local function checkUpgrade() end local function main() - local displayedVersion = Config.dev and "DEV" or Version.display(Config.version) + local displayedVersion = DevSettings:isEnabled() and "DEV" or Version.display(Config.version) Logging.trace("Rojo %s initialized", displayedVersion)