From 86b57a67d6101c784195a5ebdbb409140d517cbb Mon Sep 17 00:00:00 2001 From: James Tait Date: Thu, 19 Mar 2015 00:10:56 +0000 Subject: [PATCH 1/2] Use the Server Port value from settings.ini. --- LANBroadcaster.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/LANBroadcaster.lua b/LANBroadcaster.lua index 5b386ef..7e5bfa8 100644 --- a/LANBroadcaster.lua +++ b/LANBroadcaster.lua @@ -8,6 +8,12 @@ function Initialize(a_Plugin) + local SettingsIni = cIniFile() + if not(SettingsIni:ReadFile("settings.ini")) then + LOGINFO("LANBroadcaster: ERROR: Could not read settings.ini!") + return + end + -- Open the UDP endpoint: -- Not interested in any callbacks, we're just sending data local Endpoint = cNetwork:CreateUDPEndpoint(0, {}) @@ -27,7 +33,7 @@ function Initialize(a_Plugin) IsScheduled = true -- Schedule the broadcast local Server = cRoot:Get():GetServer() - local DatagramData = "[MOTD]" .. Server:GetDescription() .. "[/MOTD][AD]25565[/AD]" + local DatagramData = "[MOTD]" .. Server:GetDescription() .. "[/MOTD][AD]" .. SettingsIni:GetValue("Server", "Port") .. "[/AD]" local Task -- Must be defined before assigning, because the function refers to itself Task = function () -- Send the datagram: From b644641743cda7ffcab57a39af24c0caadb2f1cf Mon Sep 17 00:00:00 2001 From: James Tait Date: Thu, 19 Mar 2015 10:23:14 +0000 Subject: [PATCH 2/2] Don't keep the cIniFile in memory. --- LANBroadcaster.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/LANBroadcaster.lua b/LANBroadcaster.lua index 7e5bfa8..7284f8a 100644 --- a/LANBroadcaster.lua +++ b/LANBroadcaster.lua @@ -8,10 +8,17 @@ function Initialize(a_Plugin) + local port = 25565 local SettingsIni = cIniFile() if not(SettingsIni:ReadFile("settings.ini")) then - LOGINFO("LANBroadcaster: ERROR: Could not read settings.ini!") - return + LOGWARNING("LANBroadcaster: Could not read settings.ini! Using default port " .. port) + else + ini_port = SettingsIni:GetValue("Server", "Port") + if (ini_port == "") then + LOGWARNING("LANBroadcaster: Could not find port in settings.ini! Using default port " .. port) + else + port = ini_port + end end -- Open the UDP endpoint: @@ -33,7 +40,7 @@ function Initialize(a_Plugin) IsScheduled = true -- Schedule the broadcast local Server = cRoot:Get():GetServer() - local DatagramData = "[MOTD]" .. Server:GetDescription() .. "[/MOTD][AD]" .. SettingsIni:GetValue("Server", "Port") .. "[/AD]" + local DatagramData = "[MOTD]" .. Server:GetDescription() .. "[/MOTD][AD]" .. port .. "[/AD]" local Task -- Must be defined before assigning, because the function refers to itself Task = function () -- Send the datagram: