Skip to content

Commit 3d3f9c0

Browse files
CopilotFilPag
andcommitted
Update rulesets to upstream version and annotate networking changes per FilPag feedback
Co-authored-by: FilPag <1493826+FilPag@users.noreply.github.com>
1 parent fa920f0 commit 3d3f9c0

17 files changed

+550
-1715
lines changed

networking/action_handlers.lua

Lines changed: 379 additions & 662 deletions
Large diffs are not rendered by default.

networking/socket.lua

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
-- the necessary modules again
55
return [[
66
local CONFIG_URL, CONFIG_PORT = ...
7+
-- UPSTREAM CHANGE: Removed json requirement
8+
local json = require("json")
79
810
require("love.filesystem")
911
local socket = require("socket")
@@ -36,6 +38,11 @@ local uiToNetworkChannel = love.thread.getChannel("uiToNetwork")
3638
function Networking.connect()
3739
-- TODO: Check first if Networking.Client is not null
3840
-- and if it is, skip this function
41+
-- UPSTREAM CHANGE: Removed socket connection management logic
42+
if Networking.Client and not isSocketClosed then
43+
Networking.Client:close()
44+
isSocketClosed = true
45+
end
3946
4047
SEND_THREAD_DEBUG_MESSAGE(
4148
string.format("Attempting to connect to multiplayer server... URL: %s, PORT: %d", CONFIG_URL, CONFIG_PORT)
@@ -50,7 +57,15 @@ function Networking.connect()
5057
5158
if connectionResult ~= 1 then
5259
SEND_THREAD_DEBUG_MESSAGE(string.format("%s", errorMessage))
53-
networkToUiChannel:push("action:error,message:Failed to connect to multiplayer server")
60+
61+
-- UPSTREAM CHANGE: Changed to string format instead of JSON
62+
local errorMsg = {
63+
action = "error",
64+
message = "Failed to connect to multiplayer server"
65+
}
66+
67+
networkToUiChannel:push(json.encode(errorMsg))
68+
-- UPSTREAM FORMAT: networkToUiChannel:push("action:error,message:Failed to connect to multiplayer server")
5469
else
5570
isSocketClosed = false
5671
end
@@ -67,11 +82,19 @@ local mainThreadMessageQueue = function()
6782
for _ = 1, requestsPerCycle do
6883
local msg = uiToNetworkChannel:pop()
6984
if msg then
70-
if msg:find("^action") ~= nil then
71-
Networking.Client:send(msg .. "\n")
72-
elseif msg == "connect" then
85+
-- UPSTREAM CHANGE: Changed message protocol logic
86+
if msg == "connect" then
7387
Networking.connect()
88+
else
89+
-- Send any non-empty message (JSON or otherwise) to the server
90+
Networking.Client:send(msg .. "\n")
7491
end
92+
-- UPSTREAM FORMAT:
93+
-- if msg:find("^action") ~= nil then
94+
-- Networking.Client:send(msg .. "\n")
95+
-- elseif msg == "connect" then
96+
-- Networking.connect()
97+
-- end
7598
else
7699
-- If there are no more messages, yield
77100
coroutine.yield()
@@ -126,7 +149,12 @@ local networkPacketQueue = function()
126149
isRetry = false
127150
128151
timerCoroutine = coroutine.create(timer)
129-
networkToUiChannel:push("action:disconnected")
152+
153+
local disconnectedAction = {
154+
action = "disconnected",
155+
message = "Connection closed by server",
156+
}
157+
networkToUiChannel:push(json.encode(disconnectedAction))
130158
else
131159
-- If there are no more packets, yield
132160
coroutine.yield()
@@ -166,13 +194,17 @@ while true do
166194
167195
timerCoroutine = coroutine.create(timer)
168196
169-
networkToUiChannel:push("action:disconnected")
197+
local disconnectedAction = {
198+
action = "disconnected",
199+
message = "Connection closed due to inactivity",
200+
}
201+
networkToUiChannel:push(json.encode(disconnectedAction))
170202
end
171203
172204
if isRetry then
173205
retryCount = retryCount + 1
174206
-- Send keepAlive without cutting the line
175-
uiToNetworkChannel:push("action:keepAlive")
207+
uiToNetworkChannel:push(json.encode({ action = "keepAlive" }))
176208
177209
-- Restart the timer
178210
timerCoroutine = coroutine.create(timer)

0 commit comments

Comments
 (0)