Skip to content

Commit

Permalink
Auto login players who want to, hopefully sans the race condition pro…
Browse files Browse the repository at this point in the history
…blems (#698)

* Reapply "Auto log in users who want to auto log in. (#696)"

This reverts commit 5ccb0df.

* Disable startWithTabOpen as it seems to cause a race condition when  on figuring out the name of the game

* Try really hard to get the correct game name
  • Loading branch information
Beherith authored Jun 5, 2024
1 parent 5ccb0df commit 1eef283
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 12 deletions.
33 changes: 28 additions & 5 deletions LuaMenu/widgets/chobby/components/chat_windows.lua
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,24 @@ function ChatWindows:init()
lobby:AddListener("OnDisconnected",
function ()
if self.tabPanel.tabBar.visible then
self.tabPanel.tabBar:Hide()
self.joinButton:Hide()
-- self.tabPanel.tabBar:Hide()
-- self.joinButton:Hide()
end
self.window:ClearChildren()
self.window:AddChild(self.loginButton)

-- self.window:ClearChildren()
-- self.window:AddChild(self.loginButton)
-- Instead of showing this, how about disabling the text entry boxen with "Login required for chat"
-- The point being that they need to be enabled again :D

for chanName, channelConsole in pairs(self.channelConsoles) do
if channelConsole.ebInputText then
channelConsole.ebInputText.hint = "Login required for chat."
channelConsole.ebInputText.editable = false
channelConsole.ebInputText.selectable = false
channelConsole.ebInputText:Update()
end
end

end
)

Expand All @@ -373,6 +386,16 @@ function ChatWindows:init()
self.tabPanel.tabBar:Show()
self.joinButton:Show()
end

for chanName, channelConsole in pairs(self.channelConsoles) do
if channelConsole.ebInputText then
channelConsole.ebInputText.hint = ""
channelConsole.ebInputText.editable = true
channelConsole.ebInputText.selectable = true
channelConsole.ebInputText:Update()
end
end

self.window:ClearChildren()
self.window:AddChild(self.chatWindow)
end
Expand Down Expand Up @@ -777,7 +800,7 @@ function ChatWindows:GetChannelConsole(chanName)
-- keep it nil like scum
-- userListPanel = UserListPanel(function() return {} end, 22, true)
else
userListPanel = UserListPanel(function() return lobby:GetChannel(chanName) end, 22, true)
userListPanel = UserListPanel(function() return lobby:GetChannel(chanName) end, 22, true, nil, chanName)
end
self.userListPanels[chanName] = userListPanel
local caption = "#" .. chanName
Expand Down
9 changes: 8 additions & 1 deletion LuaMenu/widgets/chobby/components/configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1076,11 +1076,18 @@ function Configuration:GetPlayerName(allowBlank)
end

function Configuration:GetDefaultGameName()
local rapidTag = "byar:test"
if not self.gameConfig then
Spring.Log(LOG_SECTION, LOG.ERROR, "self.gameConfig not present in Configuration:GetDefaultGameName()")
return false
end

if self.gameConfig and self.gameConfig._defaultGameRapidTag then
rapidTag = self.gameConfig._defaultGameRapidTag
else
Spring.Log(LOG_SECTION, LOG.ERROR, "self.gameConfig._defaultGameRapidTag not present in Configuration:GetDefaultGameName()")
end

local rapidTag = self.gameConfig._defaultGameRapidTag
if rapidTag and VFS.GetNameFromRapidTag then
local rapidName = VFS.GetNameFromRapidTag(rapidTag)
if rapidName then
Expand Down
5 changes: 4 additions & 1 deletion LuaMenu/widgets/chobby/components/interface_root.lua
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,15 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction)
name = "singleplayer",
tabs = Configuration.gameConfig.singleplayerConfig,
titleText = i18n("singleplayercoop"),
--startWithTabOpen = 1,
},
{
name = "multiplayer_and_coop",
entryCheck = WG.LoginWindowHandler.TryLoginMultiplayer,
tabs = multiPlayerTabs,
cleanupFunction = Configuration.leaveMultiplayerOnMainMenu and CleanMultiplayerState or nil,
twoline = true,
--startWithTabOpen = 1,
},
{
name = "replays",
Expand All @@ -515,7 +517,8 @@ function GetInterfaceRoot(optionsParent, mainWindowParent, fontFunction)
},
{
name = "help",
tabs = Configuration.gameConfig.helpSubmenuConfig
tabs = Configuration.gameConfig.helpSubmenuConfig,
--startWithTabOpen = 1,
},
}

Expand Down
6 changes: 4 additions & 2 deletions LuaMenu/widgets/chobby/components/user_list_panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ UserListPanel = LCS.class {}

LOG_SECTION = "UserListPanel"

function UserListPanel:init(userUpdateFunction, spacing, showCount, getUserFunction)
function UserListPanel:init(userUpdateFunction, spacing, showCount, getUserFunction, channelName)
self.userUpdateFunction = userUpdateFunction
self.spacing = spacing
self.getUserFunction = getUserFunction
self.channelName = channelName

self.userComponentMap = {}
self.users = {}
Expand Down Expand Up @@ -169,6 +170,7 @@ function UserListPanel:AddUser(userName, alignComponents)
end
index = index + 1
end
--Spring.Echo("Added user ", userName, "to channel", self.channelName)
table.insert(self.users, index, userName)

local userControl =
Expand All @@ -194,7 +196,7 @@ function UserListPanel:RemoveUser(userName, alignComponents)
end
if index == nil then
if WG.Chobby.Configuration and WG.Chobby.Configuration.devMode then
Spring.Log(LOG_SECTION, LOG.ERROR, "Cannot find user to remove: " .. tostring(userName)) -- only show to devs for now
--Spring.Log(LOG_SECTION, LOG.ERROR, self.channelName ,"Cannot find user to remove: " .. tostring(userName)) -- only show to devs for now
end
return
end
Expand Down
20 changes: 18 additions & 2 deletions LuaMenu/widgets/gui_login_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ local function InitializeListeners()

local queueTime = 1
local function OnQueued(listener)
currentLoginWindow.txtError:SetText("Waiting in Login Queue for "..tostring(queueTime) .. " seconds (~7)")
if currentLoginWindow then
currentLoginWindow.txtError:SetText("Waiting in Login Queue for "..tostring(queueTime) .. " seconds (~7)")
end
queueTime = queueTime + 1
if WG and WG.Delay then
local function login_queue_heartbeat()
Expand All @@ -194,11 +196,23 @@ local function InitializeListeners()
end
end

function OnLoginInfoEnd()
-- Activate the multiplayer battle tab when login data is done
if WG and WG.Chobby and WG.Chobby.interfaceRoot and WG.Chobby.interfaceRoot.OpenMultiplayerTabByName then
-- Pass the name of the tab
WG.Chobby.interfaceRoot.OpenMultiplayerTabByName("battle_list")
lobby:RemoveListener("OnLoginInfoEnd", OnLoginInfoEnd)
end

end


lobby:AddListener("OnRegistrationAccepted", OnRegistrationAccepted)
lobby:AddListener("OnRegistrationDenied", OnRegistrationDenied)
lobby:AddListener("OnAccepted", OnLoginAccepted)
lobby:AddListener("OnDenied", OnLoginDenied)
lobby:AddListener("OnQueued", OnQueued)
lobby:AddListener("OnLoginInfoEnd", OnLoginInfoEnd)

-- Stored register on connect
local function OnConnect()
Expand Down Expand Up @@ -250,6 +264,8 @@ end
--------------------------------------------------------------------------------
-- Widget Interface



function widget:Initialize()
CHOBBY_DIR = LUA_DIRNAME .. "widgets/chobby/"
VFS.Include(LUA_DIRNAME .. "widgets/chobby/headers/exports.lua", nil, VFS.RAW_FIRST)
Expand All @@ -261,7 +277,7 @@ function widget:Initialize()
end

function widget:Update()
--WG.Delay(CheckAutologin, 1.5)
WG.Delay(CheckAutologin, 1.5)
WG.Delay(CheckFirstTimeRegister, 1.8)
widgetHandler:RemoveCallIn("Update")
end
Expand Down
13 changes: 12 additions & 1 deletion libs/liblobby/lobby/lobby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,10 @@ function Lobby:_OnAddUser(userName, status)
-- -- self.users[userName] = nil -- delete outdated user completly
-- end

-- Strange bug, Teiserver seems to send ADDUSER twice for each user. The first time with CLIENTSTATUS, then second time without

local userInfo = self.users[userName]
self.userCount = self.userCount + 1 -- correctly fix because lobby didnt clear user count on onAccepted

if not userInfo then
userInfo = {
userName = userName,
Expand All @@ -625,7 +627,14 @@ function Lobby:_OnAddUser(userName, status)
hasOutgoingFriendRequest = status and status.accountID and self.hasOutgoingFriendRequestsByID[status.accountID] or nil,
}
self.users[userName] = userInfo

-- New user we definitely didnt know about before
self.userCount = self.userCount + 1
else
-- A user we knew about, who went offline, but now has come back online again
if userInfo.isOffline == true then
self.userCount = self.userCount + 1
end
userInfo.isOffline = false
end

Expand Down Expand Up @@ -670,6 +679,8 @@ function Lobby:_OnRemoveUser(userName)
userInfo.hasFriendRequest = hasFriendRequest
userInfo.hasOutgoingFriendRequest = hasOutgoingFriendRequest
end

userInfo.isOffline = true
self.userCount = self.userCount - 1 -- this shows: userCount reflects the "online users"
self:_CallListeners("OnRemoveUser", userName)
end
Expand Down

0 comments on commit 1eef283

Please sign in to comment.