heroiclabs / nakama-godot

Godot client for Nakama server written in GDScript.
Apache License 2.0
601 stars 71 forks source link

Matchmaker not finding match #61

Closed KoramaG closed 3 years ago

KoramaG commented 3 years ago

Hi all,

Development is going really well, Nakama's making setting up multiplayer stuff so much easier than I thought I would be, so thank you for all your effort in enabling that :)

The problem:

I've got the matchmaker function set up in Godot like the one below. Problem is when I call it, it doesn't match with anything, even if another user is running an identical copy of it (it does successfully generate matchmaker tickets though). It does, however, work when I set the query to "*". Any idea why this could be?

func matchmaker()
    var query = "+properties.property1:placeholder +properties.property2:placeholder"
    var min_count = 2
    var max_count = 2
    var string_properties = {
        "property1":"placeholder",
        "property2":"placeholder"
        }
    var numeric_properties = {"property3" : 1}
    #matchmaker_ticket : NakamaRTAPI.MatchmakerTicket
    matchmaker_ticket = yield(socket.add_matchmaker_async(query, min_count, max_count, string_properties, numeric_properties), "completed")
novabyte commented 3 years ago

@KoramaG can you share the relevant logs output by the server when in DEBUG level and you run the matchmaker logic with your query above?

KoramaG commented 3 years ago

@novabyte

Player1:

{"level":"debug","ts":"2020-11-18T20:57:00.206Z","caller":"server/pipeline.go:62","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"d557779d-ff29-4ec1-9d02-21c1dc299a95","sid":"8d47a378-29e0-11eb-9c7e-7106fdcb5b46","cid":"3","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"+properties.property1:placeholder +properties.property2:placeholder"}}}

{"level":"debug","ts":"2020-11-18T20:57:00.207Z","caller":"server/session_ws.go:390","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"d557779d-ff29-4ec1-9d02-21c1dc299a95","sid":"8d47a378-29e0-11eb-9c7e-7106fdcb5b46","envelope":"cid:\"3\" matchmaker_ticket:{ticket:\"673bfb71-a1fd-4312-9174-2860908a0907\"}"}

Player2:

{"level":"debug","ts":"2020-11-18T20:57:14.777Z","caller":"server/pipeline.go:62","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"8a75e219-64dd-4416-8d6f-6a5f02b5e74c","sid":"92970780-29e0-11eb-9c7e-7106fdcb5b46","cid":"2","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"+properties.property1:placeholder +properties.property2:placeholder"}}}

{"level":"debug","ts":"2020-11-18T20:57:14.780Z","caller":"server/session_ws.go:390","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"8a75e219-64dd-4416-8d6f-6a5f02b5e74c","sid":"92970780-29e0-11eb-9c7e-7106fdcb5b46","envelope":"cid:\"2\" matchmaker_ticket:{ticket:\"9692e7fa-5420-47a8-80b0-c98c07187f1b\"}"}
KoramaG commented 3 years ago

@novabyte any idea what this could be? do you need more info?

novabyte commented 3 years ago

@KoramaG Sorry I've not had the chance to look into this yet. It's not an issue with the server so its likely some kind of encoding error with the way the matchmaker request is sent to the server. Would you be able to compare it with the inputs to the server which are described here?

https://github.com/heroiclabs/nakama-common/blob/master/rtapi/realtime.proto#L330-L342

KoramaG commented 3 years ago

@novabyte no worries ^^ I'll take a look, thank you 👍

floppyhammer commented 3 years ago

I came across the very same problem, and setting query as also makes it work. This is what the "received_matchmaker_matched" signal returns in this case (query as ).

Code: func _when_received_matchmaker_matched(p_matched : NakamaRTAPI.MatchmakerMatched): print("Matched users: %s" % [p_matched.users])

Output: Matched users: [<MatchmakerUser presence=UserPresence<persistence=False, session_id=1d56b21d-67e9-435c-aa18-6916f75debae, status=, username=deRLOKvIJF, user_id=8ae065ab-607c-4ec5-8644-8bcba54f8b39>, numeric_properties={}, string_properties={}>, <MatchmakerUser presence=UserPresence<persistence=False, session_id=1faa8f36-399d-4b91-9e72-1f05bec27341, status=, username=vOIsdWPoXm, user_id=6f9520b3-8cfa-4c64-82fc-56e78e7462f1>, numeric_properties={}, string_properties={}>]

You can see the numeric_properties and string_properties are both empty although they are set properly before calling "add_matchmaker_async()". This may explains why only setting query as gives you successful matches, since any query other than matches no property in an empty dictionary.

floppyhammer commented 3 years ago

I was trying to fix the bug but didn't realize it was already fixed. FYI, the problem is caused by the serialize() function in NakamaSerializer.gd. It failed to parse numeric_properties and string_properties dictionaries correctly. It works like a charm now.

KoramaG commented 3 years ago

Ah, thanks @floppyhammer !! I'd put it on the backburner/forgotten about it, but glad to hear there's a solution :) imma try now. Thanks!

OrangePaintGaming commented 3 years ago

Hi. I'm experiencing exactly the same situation as presented by KoramaG above except that I am using Nakama 3.2.1. I wanted to check if floppyhammer's diagnosis applies to me but I cannot tell if the dictionaries for the numeric and stirng properties are parsed well (sorry, kind of new to game dev).

I followed the Godot tutorial with the Fish Game demonstration.

I printed the output of the serialize() function and it shows something like: {max_count:2, min_count:2, query=+properties.game:salpakan_gg +properties.engine:godot properties.current_version:v2.0}

I'm not sure if numeric_properties and string_properties are also supposed to appear in the result above.

Player 1: {"level":"debug","ts":"2021-08-16T14:40:59.488Z","caller":"server/pipeline.go:66","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"3b6f9d51-1d80-462b-8c9a-8be204fb328e","sid":"f8e5e822-fe9f-11eb-a2c1-7106fdcb5b46","cid":"1","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"+properties.game:salpakan_gg +properties.engine:godot +properties.client_version:v2.0"}}} {"level":"debug","ts":"2021-08-16T14:40:59.492Z","caller":"server/session_ws.go:393","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"3b6f9d51-1d80-462b-8c9a-8be204fb328e","sid":"f8e5e822-fe9f-11eb-a2c1-7106fdcb5b46","envelope":"cid:\"1\" matchmaker_ticket:{ticket:\"68e5b1f9-dab6-48eb-a2c2-06fb64708a2e\"}"}

Player2: {"level":"debug","ts":"2021-08-16T14:42:54.083Z","caller":"server/pipeline.go:66","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"29805de7-3467-46f7-b23f-bd7eb6d20b53","sid":"3d39c351-fea0-11eb-a2c1-7106fdcb5b46","cid":"1","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"+properties.game:salpakan_gg +properties.engine:godot +properties.client_version:v2.0"}}} {"level":"debug","ts":"2021-08-16T14:42:54.085Z","caller":"server/session_ws.go:393","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"29805de7-3467-46f7-b23f-bd7eb6d20b53","sid":"3d39c351-fea0-11eb-a2c1-7106fdcb5b46","envelope":"cid:\"1\" matchmaker_ticket:{ticket:\"64ccb56d-f2e6-4668-ad2c-ad355a7d2931\"}"}

However, if I just use for the query, everything goes well. I'd appreciate me if someone can explain me why this is not working when the query is ''

floppyhammer commented 3 years ago

@OrangePaintGaming I'm not sure if I got what you meant exactly. If you want to find other players when querying with some string properties (game, engine, and version), you need to set the string_properties parameter accordingly when calling add_matchmaker_async(). query is to describe what kind of players you want to match with, and string_properties is to describe yourself.

OrangePaintGaming commented 3 years ago

@OrangePaintGaming I'm not sure if I got what you meant exactly. If you want to find other players when querying with some string properties (game, engine, and version), you need to set the string_properties parameter accordingly when calling add_matchmaker_async(). query is to describe what kind of players you want to match with, and string_properties is to describe yourself.

Thank you for the quick response and thanks for clarifying the use of string_properties and query. This is how I wrote my code (GDScript):

var data = { min_count = 2, max_count = 2, string_properties = { game = "salpakan_gg", engine = "godot", current_version = "v2.0" }, query = "+properties.game:salpakan_gg +properties.engine:godot +properties.current_version:v2.0" } var result = yield(nakama_socket.add_matchmaker_async(data.get('query', '*'), data['min_count'], data['max_count'], data.get('string_properties', {}), data.get('numeric_properties', {})), 'completed') if result.is_exception(): leave() # a function to remove existing sockets emit_signal("error", "Unable to join match making pool") else: matchmaker_ticket = result.ticket print("Matching ticket generated: %s" % str(matchmaker_ticket))

The output shows matchmaking tickets are successfully generated. However, I never get two running instances to match together (unless I change query to '*').

floppyhammer commented 3 years ago

@OrangePaintGaming Your code snippet seems correct to me.

amuuu commented 2 years ago

Hello,

I have the same problem. The client code I'm trying to run, worked fine on another computer (Unity client + Nakama docker container). But in the computer I'm currently trying to run the same code on, matchmaking is not working.

The log messages are exactly the same as the ones mentioned above;

Nakama receives a client's message: {"level":"debug","ts":"2022-03-01T11:54:09.573Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"2e0384fa-98d2-4f2c-adaf-487d7263f74d","sid":"4cf03a7d-9956-11ec-b7c8-7106fdcb5b46","cid":"0","message":{"MatchmakerAdd":{"min_count":3,"max_count":4,"query":"*"}}} It sends back a ticket: {"level":"debug","ts":"2022-03-01T11:54:09.575Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"2e0384fa-98d2-4f2c-adaf-487d7263f74d","sid":"4cf03a7d-9956-11ec-b7c8-7106fdcb5b46","envelope":"cid:\"0\" matchmaker_ticket:{ticket:\"a5e16d09-8517-4ec6-a4de-58bbd69012f8\"}"}

And the clients receive the ticket properly. However, it seems like inside the Nakama, somehow, it's not matching them together to create a new room.

Any hint/help is highly appreciated :)