Skip to content

Commit

Permalink
Merge pull request #723 from FIr3baL/FB_DisconnectFixes
Browse files Browse the repository at this point in the history
disconnect reworks
  • Loading branch information
FIr3baL authored Jul 8, 2024
2 parents baa3ab0 + 523eed9 commit ecc2db0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LuaMenu/widgets/api_analytics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ function widget:Initialize()
-- disconnect
end

local function OnDisconnected(reason, intentional)
local function OnDisconnected(listener, reason, intentional)
--Spring.Echo("Analytics OnDisconnected")
Spring.Echo("Disconnected, reason:", reason, intentional)
isConnected = false
Expand Down
4 changes: 2 additions & 2 deletions LuaMenu/widgets/gui_settings_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1105,15 +1105,15 @@ local function GetLobbyTabControls()
local oldserveraddress = Configuration:GetServerAddress()
local newserveraddress = barservers[num]

Spring.Echo("Choosing a server in settings:",obj,num, oldserveraddress,newserveraddress)
Spring.Echo("Choosing a server in settings:", num, oldserveraddress,newserveraddress)

if oldserveraddress ~= newserveraddress then
Configuration.serverAddress = newserveraddress

if WG.LibLobby.lobby then -- force set the new one so that lobby:safeupdate doesnt fuck up
--Spring.Echo("FORCE SET",obj,num, barservers[num])
WG.LibLobby.lobby.host = newserveraddress
WG.LibLobby.lobby:Disconnect()
WG.LibLobby.lobby:Disconnect("changed lobby server")
if WG.LoginWindowHandler then
WG.LoginWindowHandler.TryLogin()
end
Expand Down
10 changes: 10 additions & 0 deletions libs/liblobby/lobby/interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ end
Interface.commands["DENIED"] = Interface._OnDenied
Interface.commandPattern["DENIED"] = "(.+)"

function Interface:_OnS_System_Disconnect(reason)
self:_OnDisconnected(reason, false)
end
Interface.commands["s.system.disconnect"] = Interface._OnDenied
Interface.commandPattern["s.system.disconnect"] = "(.+)"

function Interface:_OnAgreement(line)
self:super("_OnAgreement", line)
end
Expand Down Expand Up @@ -715,6 +721,10 @@ Interface.commands["QUEUED"] = Interface._OnQueued
function Interface:_OnWhois(id, data)
id = tonumber(id)
local userData = Spring.Utilities.json.decode(Spring.Utilities.Base64Decode(data))
if userData and userData.error then
Spring.Log(LOG_SECTION, LOG.ERROR, "_OnWhois error: " .. tostring(userData.error))
return self
end
self:super("_OnWhois", id, userData)
end
Interface.commands["s.user.whois"] = Interface._OnWhois
Expand Down
9 changes: 7 additions & 2 deletions libs/liblobby/lobby/interface_shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ function Interface:Connect(host, port, user, password, cpu, localIP, lobbyVersio
return true
end

function Interface:Disconnect()
function Interface:Disconnect(reason)
self.status = "offline"
self.finishedConnecting = false
if self.client then
self.client:close()
end
self:_OnDisconnected(nil, true)
self:_OnDisconnected(reason, true)
end

function Interface:TextEraseNewline(str)
Expand Down Expand Up @@ -119,6 +119,11 @@ function Interface:_SendCommand(command, sendMessageCount)
--Spring.Echo(command)
end

if errorCode and errorCode == "closed" then
self:Disconnect(errorCode)
return
end

self:_CallListeners("OnCommandSent", command:sub(1, #command-1))
self.lastSentSeconds = Spring.GetTimer()
end
Expand Down
5 changes: 3 additions & 2 deletions libs/liblobby/lobby/lobby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1975,8 +1975,9 @@ function Lobby:_OnDisconnected(reason, intentional)
for userName,_ in pairs(self.users) do
self:_OnRemoveUser(userName)
end

for battleID, battle in pairs(self.battles) do

local battles = ShallowCopy(self.battles) -- needs ShallowCopy because _OnBattleClosed is removing isntances of self.battles
for battleID, _ in pairs(battles) do
self:_OnBattleClosed(battleID)
end

Expand Down

0 comments on commit ecc2db0

Please sign in to comment.