Skip to content

Commit

Permalink
Fix socket usage inside api_unit_tracker_gl4 and camera_joystick. (#3981
Browse files Browse the repository at this point in the history
)

* Fix slightly incorrect socket usage inside api_unit_tracker_gl4 and camera_joystick.
* Also make camera_joystick remove itself when it can't connect.
  • Loading branch information
saurtron authored Dec 12, 2024
1 parent ce8a8b5 commit 7ac7740
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions luaui/Widgets/api_unit_tracker_gl4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,13 @@ function widget:GameStart()

local client=socket.tcp()
local res, err = client:connect("server4.beyondallreason.info", 8200)
if not res and not res=="timeout" then
if not res and err ~= "timeout" then
--Spring.Echo("Failure",res,err)
else
local message = "c.telemetry.log_client_event lobby:info " .. string.base64Encode(Json.encode(pnl)).." ZGVhZGJlZWZkZWFkYmVlZmRlYWRiZWVmZGVhZGJlZWY=\n"
client:send(message)
end
if client ~= nil then client:close() end
client:close()
end
--local succes, res = pcall(LobbyInfo)
end
Expand Down
5 changes: 4 additions & 1 deletion luaui/Widgets/camera_joystick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ local function SocketConnect(host, port)
client=socket.tcp()
client:settimeout(0)
res, err = client:connect(host, port)
if not res and not res=="timeout" then
if not res and err ~= "timeout" then
client:close()
Spring.Echo("Unable to connect to joystick server: ",res, err, "Restart widget after server is started")
return false
end
Expand Down Expand Up @@ -357,6 +358,8 @@ function widget:Initialize()
local connected = SocketConnect(host, port)
if connected then
Spring.SetConfigInt("RotOverheadClampMap",0)
else
widgetHandler:RemoveWidget()
end
end

Expand Down

0 comments on commit 7ac7740

Please sign in to comment.