Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Release/2.3.3 (#33)
Browse files Browse the repository at this point in the history
* fix: ensure logging loads before everything

* tweak: sanity check for steam mode, http errors

* feature: check map/listener ports to ensure correct settings

* tweak: missed print for debug

* Update index.html (#32)

Removed notice about session loss on login as multi-session is now supported with Sonoran CAD.

* feature: add sonoran dumpconsole
This command dumps the console buffer to disk.

* fix: linux updater, fixes #31

* tweak: additional config file checks

Co-authored-by: Brian Sosnowski <[email protected]>
  • Loading branch information
nathanctech and SonoranBrian authored Dec 14, 2020
1 parent 5eb575b commit 7d24704
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 26 deletions.
8 changes: 7 additions & 1 deletion sonorancad/core/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ if Config.devHiddenSwitch then
Wait(5000)
end
end)
end
end

local inited = false
AddEventHandler("playerSpawned", function()
TriggerServerEvent("SonoranCAD::core:PlayerReady")
inited = true
end)
6 changes: 6 additions & 0 deletions sonorancad/core/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ SonoranCAD Help
elseif args[1] == "update" then --update - attempt to auto-update
infoLog("Checking for core update...")
RunAutoUpdater(true)
elseif args[1] == "dumpconsole" then
local savePath = GetResourcePath(GetCurrentResourceName()).."/buffer.log"
local f = assert(io.open(savePath, 'wb'))
f:write(GetConsoleBuffer())
f:close()
infoLog("Wrote buffer to "..savePath)
else
print("Missing command. Try \"sonoran help\" for help.")
end
Expand Down
43 changes: 42 additions & 1 deletion sonorancad/core/configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ Config = {
}

local conf = LoadResourceFile(GetCurrentResourceName(), "config.json")
if not conf or conf == nil then
if conf == nil then
errorLog("Failed to load core configuration. Ensure config.json is present.")
assert(false, "Invalid configuration file.")
return
end
local parsedConfig = json.decode(conf)
if parsedConfig == nil then
errorLog("Failed to parse your config file. Make sure it is valid JSON.")
assert(false "Invalid configuration file format")
return
end
for k, v in pairs(json.decode(conf)) do
Config[k] = v
end
Expand Down Expand Up @@ -77,4 +83,39 @@ AddEventHandler("SonoranCAD::core:sendClientConfig", function()
statusLabels = Config.statusLabels
}
TriggerClientEvent("SonoranCAD::core:recvClientConfig", source, config)
end)

CreateThread(function()
Wait(2000) -- wait for server to settle
local detectedMapPort = GetConvar("socket_port", "30121")
local detectedPushPort = GetConvar("SonoranListenPort", "3232")
local isMapRunning = (isPluginLoaded("livemap") and GetResourceState("sonoran_livemap") == "started")
local isPushEventsRunning = isPluginLoaded("pushevents")
local serverId = Config.serverId

debugLog(("r: %s %s %s %s"):format(detectedMapPort, detectedPushPort, isMapRunning, isPushEventsRunning))

if isMapRunning or isPushEventsRunning then
performApiRequest({}, "GET_SERVERS", function(response)
local info = json.decode(response)
for k, v in pairs(info.servers) do
print(("Check %s = %s"):format(v.id, serverId))
if tostring(v.id) == tostring(serverId) then
ServerInfo = v
break
end
end
if ServerInfo == nil then
errorLog(("Could not find valid server information for server ID %s. Ensure you have configured your server in the CAD before using the map or push events."):format(serverId))
return
end
if ServerInfo.mapPort ~= tostring(detectedMapPort) and isMapRunning then
errorLog(("CONFIGURATION PROBLEM: Map port on the server (%s) does not match your CAD configuration (%s) for server ID (%s). Please ensure they match."):format(detectedMapPort, ServerInfo.mapPort, serverId))
end
if ServerInfo.listenerPort ~= tostring(detectedPushPort) and isPushEventsRunning then
errorLog(("CONFIGURATION PROBLEM: Listener port on the server (%s) does not match your CAD configuration (%s) for server ID (%s). Please ensure they match."):format(detectedPushPort, ServerInfo.listenerPort, serverId))
end

end)
end
end)
2 changes: 1 addition & 1 deletion sonorancad/core/logging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function debugPrint(message)
end

function errorLog(message)
sendConsole("ERROR", "^8", message)
sendConsole("ERROR", "^1", message)
end

function warnLog(message)
Expand Down
27 changes: 23 additions & 4 deletions sonorancad/core/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ CreateThread(function()
debugLog(("Set version %s from response %s"):format(ApiVersion, result))
infoLog(("Loaded community ID %s with API URL: %s"):format(Config.communityID, Config.apiUrl))
end)
if Config.primaryIdentifier == "steam" and GetConvar("steam_webapiKey", "none") == "none" then
errorLog("You have set SonoranCAD to Steam mode, but have not configured a Steam Web API key. Please see FXServer documentation. SonoranCAD will not function in Steam mode without this set.")
end
end)

-- Toggles API sender.
Expand All @@ -47,7 +50,8 @@ ApiEndpoints = {
["UNIT_LOCATION"] = "emergency",
["CALL_911"] = "emergency",
["UNIT_PANIC"] = "emergency",
["GET_VERSION"] = "general"
["GET_VERSION"] = "general",
["GET_SERVERS"] = "general"
}

EndpointsRequireId = {
Expand Down Expand Up @@ -103,12 +107,17 @@ function performApiRequest(postData, type, cb)
end
elseif statusCode == 400 then
warnLog("Bad request was sent to the API. Enable debug mode and retry your request. Response: "..tostring(res))
-- additional safeguards
assert(res ~= "INVALID COMMUNITY ID", "Your community ID is invalid!")
assert(res ~= "API IS NOT ENABLED FOR THIS COMMUNITY", "You do not have access to the API.")
assert(res ~= "INVALID API KEY", "Your API Key is invalid. Please verify the configuration.")
elseif statusCode == 404 then -- handle 404 requests, like from CHECK_APIID
debugLog("404 response found")
cb(res, false)
elseif statusCode == 429 then -- rate limited :(
rateLimitedEndpoints[type] = true
warnLog(("You are being ratelimited (last request made to %s) - Ignoring all API requests to this endpoint for 30 seconds. If this is happening frequently, please review your configuration to ensure you're not sending data too quickly."):format(type))
SetTimeout(30000, function()
warnLog(("You are being ratelimited (last request made to %s) - Ignoring all API requests to this endpoint for 60 seconds. If this is happening frequently, please review your configuration to ensure you're not sending data too quickly."):format(type))
SetTimeout(60000, function()
rateLimitedEndpoints[type] = nil
infoLog(("Endpoint %s no longer ignored."):format(type))
end)
Expand Down Expand Up @@ -154,4 +163,14 @@ if Config.devHiddenSwitch then
RegisterCommand("cc", function()
TriggerClientEvent("chat:clear", -1)
end)
end
end

-- Missing identifier detection
RegisterNetEvent("SonoranCAD::core:PlayerReady")
AddEventHandler("SonoranCAD::core:PlayerReady", function()
local ids = GetIdentifiers(source)
if ids[Config.primaryIdentifier] == nil then
warnLog(("Player %s connected, but did not have an %s ID."):format(Config.primaryIdentifier))

end
end)
1 change: 1 addition & 0 deletions sonorancad/core/shared_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function GetIdentifiers(player)
local split = stringsplit(id, ":")
ids[split[1]] = split[2]
end
--debugLog("Returning "..json.encode(ids))
return ids
end

Expand Down
8 changes: 1 addition & 7 deletions sonorancad/core/updater.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ function RunAutoUpdater(manualRun)
versionFile = string.gsub(versionFile, "{branch}", Config.updateBranch)
local myVersion = GetResourceMetadata(GetCurrentResourceName(), "version", 0)

local osType = os.getenv("OS")
if osType ~= "Windows_NT" and Config.allowAutoUpdate then
warnLog("Auto update functionality is currently only available on Windows. Force disabled.")
Config.allowAutoUpdate = false
end

PerformHttpRequestS(versionFile, function(code, data, headers)
if code == 200 then
local remote = json.decode(data)
Expand Down Expand Up @@ -102,7 +96,7 @@ CreateThread(function()
warnLog("An update has been applied to SonoranCAD but requires a resource restart. Restart delayed until server is empty.")
else
infoLog("Server is empty, restarting resources...")
local f = assert(io.open(GetResourcePath("sonoran_updatehelper").."/run.lock"))
local f = assert(io.open(GetResourcePath("sonoran_updatehelper").."/run.lock", "w+"))
f:write("1")
f:close()
ExecuteCommand("ensure sonoran_updatehelper")
Expand Down
8 changes: 4 additions & 4 deletions sonorancad/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ games {'gta5'}

author 'Sonoran CAD'
description 'Sonoran CAD FiveM Integration'
version '2.3.2'
version '2.3.3'

server_scripts {
'core/http.js'
,'core/unzipper/unzip.js'
,'core/logging.lua'
,'core/shared_functions.lua'
,'core/configuration.lua'
,'config.lua'
,'core/logging.lua'
,'core/server.lua'
,'core/commands.lua'
,'core/httpd.lua'
Expand All @@ -22,8 +22,8 @@ server_scripts {
,'core/plugin_loader.lua'
}
client_scripts {
'core/shared_functions.lua'
,'core/logging.lua'
'core/logging.lua'
,'core/shared_functions.lua'
,'core/client.lua'
,'plugins/**/config_*.lua'
,'plugins/**/cl_*.lua'
Expand Down
2 changes: 1 addition & 1 deletion sonorancad/plugins/forcereg
Submodule forcereg updated from 8fa28a to 664e6d
2 changes: 1 addition & 1 deletion sonorancad/plugins/livemap
2 changes: 1 addition & 1 deletion sonorancad/plugins/lookups
2 changes: 1 addition & 1 deletion sonorancad/plugins/pushevents
2 changes: 1 addition & 1 deletion sonorancad/plugins/wraithv2
3 changes: 1 addition & 2 deletions tablet/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<div id="tablet">
<div class="content">

<div id ="blackbar"><font size="-1">NOTE: Logging in here will log you out of any browser sessions.</font><font size="-4"> </font></div>
<!-- Edit the src field below with your custom link, if used. You can also resize the tablet frame.-->
<iframe id="mdtFrame" src="https://app.sonorancad.com/#/" width="1100" height="510"></iframe>

Expand All @@ -29,4 +28,4 @@
<script src="config.js" type="text/javascript"></script>
<script src="script.js" type="text/javascript"></script>
</body>
</html>
</html>

0 comments on commit 7d24704

Please sign in to comment.