Fix/lounge lost session (#351)

* Maybe a fix

* Update CHANGELOG.md

* status reset
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2024-03-28 18:38:14 -04:00
1 parent 839f49888f
commit 20816d09f7
4 files changed
+62 -12

No files matched your search

+1
View File
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- [Attempt] A bug where the lounge would randomly lose the session id, making it unable to cast, and spam the same error over and over
- Dialog with timer now stops as expected if any button is pressed
## [0.22.0] - 2024-03-24
@@ -21,6 +21,7 @@ class LongPoller
private socket_timer
private status_code = 0
private status_text
private headers
function new()
@@ -182,16 +183,24 @@ class LongPoller
newLineIndex = m.socket_buffer.InStr(`\r\n`)
if newLineIndex > 0
operationLine = m.socket_buffer.Left(newLineIndex)
parts = operationLine.Split(" ")
if parts.Count() < 3 or parts[0] <> "HTTP/1.1"
if not operationLine.StartsWith("HTTP/1.1 ")
LogError("Invalid operation line:", operationLine)
m.CloseSocket()
return false
end if
m.status_code = Val(parts[1])
if not m.status_code = 200
LogError("Http status code:", m.status_code)
status = operationLine.Mid(9)
spaceIndex = status.InStr(" ")
if spaceIndex = -1
LogError("Invalid operation line:", operationLine)
m.CloseSocket()
return false
end if
statusCode = status.Left(spaceIndex)
m.status_code = Val(statusCode)
m.status_text = status.Mid(spaceIndex + 1)
if m.status_code <> 200
LogError("Invalid status code:", m.status_code, m.status_text)
LogError("Response data:", m.socket_buffer)
m.CloseSocket()
return false
@@ -283,15 +283,15 @@ class LoungeApi
end if
commandIndex = command[0]
if commandIndex <= m.lastProcessedCommandIndex
commandData = command[1]
commandType = commandData[0]
if commandIndex <= m.lastProcessedCommandIndex and commandType <> COMMAND_TYPE_G_SESSION_ID and commandType <> COMMAND_TYPE_SESSION_ID
LogDebug("Skipping command already processed:", command)
continue for
end if
m.lastProcessedCommandIndex = commandIndex
commandId = command[0]
commandData = command[1]
commandType = commandData[0]
commandArgs = invalid
if commandData.Count() > 1
commandArgs = commandData[1]
@@ -300,7 +300,7 @@ class LoungeApi
handler = COMMAND_HANDLER_PREFIX + commandType
if m.DoesExist(handler)
LogInfo(commandType)
m[handler](commandId, commandType, commandArgs, messagesToSend)
m[handler](commandIndex, commandType, commandArgs, messagesToSend)
else
LogWarn("Unknown command type:", commandType, "command:", command)
end if
@@ -502,11 +502,20 @@ class LoungeApi
m.outgoingMessagesRequests[requestId] = request
end function
function ProcessPendingOutgoingMessages()
function ProcessPendingOutgoingMessages() as object
results = []
for each key in m.outgoingMessagesRequests
request = m.outgoingMessagesRequests[key]
if request.IsCompleted()
response = request.Await()
status = response.StatusCode()
error = response.ErrorMessage()
results.Push({
"status": status
"error": error
})
if not response.IsSuccess()
LogError(response.ErrorMessage())
end if
@@ -514,6 +523,8 @@ class LoungeApi
m.outgoingMessagesRequests.Delete(key)
end if
end for
return results
end function
function SaveCurrentLoungeData() as void
@@ -117,10 +117,39 @@ function LoungeServiceLoop() as void
isOpen = api.Poll(socketMessages, outgoingLoungeMessages)
api.SendMessages(outgoingLoungeMessages)
api.ProcessPendingOutgoingMessages()
outgoingLoungeMessagesResults = api.ProcessPendingOutgoingMessages()
if not isOpen
sleep(3000)
unknownSid = false
' TODO:P2 move this check somewhere else
if api.poller.status_code = 400 and ValidString(api.poller.status_text) = "Unknown SID"
api.poller.status_code = 0
unknownSid = true
end if
if not unknownSid
for each result in outgoingLoungeMessagesResults
if result.status = 400 and result.error.InStr("Unknown SID") <> -1
unknownSid = true
exit for
end if
end for
end if
if unknownSid
' We lost the session for some reason, so we need to rejoin the lounge
LogWarn("Lost session, rejoining")
if not api.GetSessionData()
m.top.unobserveField("outgoingMessages", messagePort)
m.top.isRunning = false
return
end if
api.SaveCurrentLoungeData()
end if
api.FetchCommandsRpc(messagePort)
end if
end while