colyseus-defold icon indicating copy to clipboard operation
colyseus-defold copied to clipboard

Lobby room send message with empty rooms array when join without option

Open bedryck opened this issue 1 year ago • 0 comments

``This is what happens in my opinion, when I am trying to connect without options, the library by default creates such payload for request: image image

Also, I add curl

curl 'http://localhost:3000/matchmake/joinOrCreate/lobby?' \
  -H 'Accept: application/json' \
  -H 'Accept-Language: en-US,en;q=0.9,ru-UA;q=0.8,ru;q=0.7,uk;q=0.6' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuaWNrbmFtZSI6InRlc3QyIiwiaWQiOiI2NWEyNGVlOTc2ZDBhNDZjMjk4OGExYmYiLCJpYXQiOjE3MDc0MjkyNDYsImV4cCI6MTcwNzUxNTY0Nn0.bMsByH_8yrWgFIdVk9FziDxUy4LjT313UtrHHOU4jg8' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Origin: http://localhost:58320' \
  -H 'Pragma: no-cache' \
  -H 'Referer: http://localhost:58320/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-site' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  --data-raw '[]' \
  --compressed

Then in https://github.com/colyseus/colyseus/blob/master/packages/core/src/rooms/LobbyRoom.ts when calls
client.send('rooms', this.filterItemsForClient(this.clientOptions[client.sessionId])); we call this method with options with value [] - array client.send('rooms', this.filterItemsForClient([])); and it can not work with such a data type And then in my socket connection I get "room" massage with empty rooms: image

This can be easily fixed if you send any option, to change the default value from an empty array to an object. Example image

curl "http://localhost:3000/matchmake/joinOrCreate/lobby?" ^
  -H "Accept: application/json" ^
  -H "Accept-Language: en-US,en;q=0.9,ru-UA;q=0.8,ru;q=0.7,uk;q=0.6" ^
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuaWNrbmFtZSI6InRlc3QyIiwiaWQiOiI2NWEyNGVlOTc2ZDBhNDZjMjk4OGExYmYiLCJpYXQiOjE3MDc0MjkyNDYsImV4cCI6MTcwNzUxNTY0Nn0.bMsByH_8yrWgFIdVk9FziDxUy4LjT313UtrHHOU4jg8" ^
  -H "Cache-Control: no-cache" ^
  -H "Connection: keep-alive" ^
  -H "Content-Type: application/json" ^
  -H "Origin: http://localhost:58320" ^
  -H "Pragma: no-cache" ^
  -H "Referer: http://localhost:58320/" ^
  -H "Sec-Fetch-Dest: empty" ^
  -H "Sec-Fetch-Mode: cors" ^
  -H "Sec-Fetch-Site: same-site" ^
  -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36" ^
  -H "sec-ch-ua: ^\^"Not A(Brand^\^";v=^\^"99^\^", ^\^"Google Chrome^\^";v=^\^"121^\^", ^\^"Chromium^\^";v=^\^"121^\^"" ^
  -H "sec-ch-ua-mobile: ?0" ^
  -H "sec-ch-ua-platform: ^\^"Windows^\^"" ^
  --data-raw "^{^\^"test^\^":^\^"test^\^"^}" ^
  --compressed

and then I get correct rooms data

image

bedryck avatar Feb 08 '24 23:02 bedryck