heroiclabs / nakama-defold Goto Github PK
View Code? Open in Web Editor NEWDefold client for Nakama server.
Home Page: https://heroiclabs.com
License: Apache License 2.0
Defold client for Nakama server.
Home Page: https://heroiclabs.com
License: Apache License 2.0
Hello,
I am planning to develop a game using Defiold and Nakama server. Still, I found out the latest release for this extension was in 2022 while other Nakama extensions for other engines (e.g. nakama-js) have several versions in 2023.
Is this defold extension still active and supports all Nakama features?
I'm having problems receiving messages in HTML5 builds using the native WebSocket extension introduced in recent releases of Nakama-Defold.The same works well on desktop.
I'm able to connect to a Nakama Cloud hosted server and I can send a message (a matchmaker_add message), but I never get a response. I see that the socket starts receiving an empty message repeatedly after I send the first message.
The WebSocket extension can successfully send and receive data in an HTML5 build when connecting to wss://echo.websocket.org.
There's something different with the connection to the Nakama server. Any ideas? @novabyte?
@uncleNight have you successfully connected in an HTML5 build?
function M.update_group(client, **group_id_str**, avatarUrl, description, **groupId**, langTag, name, open, callback)
Restore sessions (See https://heroiclabs.com/docs/nakama/client-libraries/unity/index.html#session-lifecycle)
Retry failed requests (See https://heroiclabs.com/docs/nakama/client-libraries/unity/index.html#handling-retries)
I'm in the process of making a test project to get to grips with Nakama in Defold.
When using nakama.create_socket() I get the following error:
ERROR:SCRIPT: Unable to create a timer, the lua context does not have a timer world
I believe this is ultimately triggered by: https://github.com/heroiclabs/nakama-defold/blob/master/nakama/engine/defold.lua#L95
There is no reference to timer in nakama.create_socket(), but the function does call create_socket() in the Defold engine module.
Reproduce by receiving a socket event that does not have a bound listener.
ERROR:SCRIPT: nakama/socket.lua:18: attempt to call global 'log' (a nil value)
stack traceback:
nakama/socket.lua:18: in function on_message
nakama/engine/defold.lua:122: in function on_message
nakama/engine/defold.lua:164: in function <nakama/engine/defold.lua:152>
Thanks for the client implementation! I am trying to make this example work https://defold.com/2021/03/02/Creating-online-games-using-Nakama-and-Defold/ but I was not able to use the same matchmaking function. It seems to have been renamed to matchmaker_add
. Now I'm trying to make that work. https://heroiclabs.com/docs/nakama/concepts/multiplayer/matchmaker/ would probably have been helpful but docs are missing there. Would it be possible to restore them?
I think the party API is missing from the interface.
https://heroiclabs.com/docs/social-realtime-parties/#join-party
I have tried to manually add it, but Im not sure its working properly (dont know if there needs to be an extra module on the server).
I'm running the docker-compose nakama with version 3.3.0 in it. Server is Ubuntu 16.04 - xenial (this may be an issue - will be moving to 20 soon)
https://github.com/heroiclabs/nakama
I have tried extending the interfaces like so:
--------------------------------------------------------------------------------
--- Create a match_create socket message
function M.create_party_create_message( open, maxsize )
local message = {
party_create = {
open = open,
maxsize = maxsize,
}
}
return message
end
Im not sure if this is correct, but according to the JS client, it looks right.
Id like to use this feature for a very simple way to join people together - seems like an ideal method.
I suspect a client side implementation may be required. If so, I'm happy to contribute if you can point me towards some info to do so - I have been looking at the JS code, so this may be the best starting point anyway.
Hi when calling any function of the client that uses uri_encode I get this error /nakama/nakama.lua:3296: attempt to call global 'uri_encode' (a nil value)
(rpc_func(...) in this case). Seems like uri_encode is missing within the scope of the client.
Discussion on gitter regarding this https://gitter.im/heroiclabs/nakama?at=5f932453eb82301c1a451c88
The nakama.rpc_func(()
function uses payload
as one of the arguments while the code is hardcoded to use body
.
Nakama uses rxi's json implementation written in pure Lua. And it is quite slow - if you send/receive lots of messages per frame, the most of the CPU time is wasted in JSON encoding/decoding.
Defold has had a fast built-in JSON encoder/decoder since version 1.3.7 - https://defold.com/ref/json/
It would be great if Nakama Defold Client upgraded to the new JSON API.
After referring to a number of examples and documents here:
https://heroiclabs.com/docs/runtime-code-basics/#rpc-example
https://heroiclabs.com/docs/gameplay-multiplayer-server-multiplayer/#manually
And api references, I was going a little crazy trying to determine why my payload was always and empty string.
I havent tracked it in the code (nor am I going to spend time doing so right now) but there is no need to use it.
All the payload and information in lua modules can be extracted from the first param - context.
Heres a quick example for people having problems getting rpc to work:
local function my_test_rpc(context)
local payload = context.query_params.payload
local data = nk.json_decode(payload[1])
print("data.name = ", data.name)
end
nk.register_rpc(my_test_rpc, "test_rpc")
To call it from the client I use something like this:
local json = require "nakama.util.json"
local myobj = { name = "David" }
local jsonbody = json.encode(myobj)
nakama.rpc_func2( self.nk_client, "test_rpc", jsonbody, nil, function(result)
print("done")
end)
If you have any problems please let me know. The above is untested, but its very close to what Im using.
Hi there,
I have cloned this and run the example.
(To build HTML5, I removed codegen
folder. and no change anything)
When build and run HTML5, I got Disconnected
when call socket_send
nakama.socket_send(socket, channel_join_message)
You can see log here: https://anotepad.com/note/read/94xi4wqj
Could you please take a look for this?
Hi, stumbled upon the curious issue where the latest bob
can't build the project while the Editor builds are fine:
The build failed for the following reasons:
ERROR nakama/util/uuid.lua:0 the module '/math.lua' can't be found
According to this forum post, Defold runtime exports most of the std library modules so requiring them is not necessary.
Fixed it in my forked repo by editing the UUID module (removed require()
statements), but decided to create an issue before submitting a PR to discuss whether it's the right thing to do. I'm aware that BOB and Defold Editor builds work differently under the hood and it feels like this should be addressed in bob repo in the first place. Since the Editor builds are okay with requiring a stdlib modules, maybe improving bob is what should be done instead.
What do you suggest?
Thanks for reading another text sheet ๐
Add it in an engine agnostic way, configurable using the config table that is passed to nakama.create_client()
Hi guys,
Started implementing user logins with custom usernames, needed to validate existing usernames, stumbled upon this:
DEBUG:SCRIPT: init()
DEBUG:SCRIPT: authenticate_device() with coroutine
DEBUG:SCRIPT: HTTP POST http://192.168.0.234:1750/v2/account/authenticate/device?create=true&username=Test
DEBUG:SCRIPT: DATA {"id":"81a40de2-134c-4e82-ceb4-68545ab2cb63"}
DEBUG:SCRIPT: {"code":6,"message":"Username is already in use."}
ERROR:SCRIPT: /nakama/session.lua:17: You must provide a token
stack traceback:
[C]:-1: in function assert
/nakama/session.lua:17: in function create
/nakama/nakama.lua:1756: in function callback
/nakama/engine/defold.lua:74: in function </nakama/engine/defold.lua:68>
without debug enabled it just looks like an out-of-nowhere error although what I'm supposed to get is Username is already in use
as a message returned.
Here, the response that the client gets from the server actually looks like this:
{
status = 409,
response = "{"code":6,"message":"Username is already in use."}",
headers = {
date = "Wed, 03 Feb 2021 19:41:38 GMT",
content-length = "50",
content-type = "application/json",
cache-control = "no-store, no-cache, must-revalidate"
}
}
but in the code (nakama/nakama.lua:1755
) the client doesn't check for HTTP status code and relies on result.error
property of the response (which is absent in the message):
return async(function(done)
client.engine.http(client.config, url_path, query_params, "POST", post_data, function(result)
if not result.error and api_session then
result = api_session.create(result)
end
done(result)
end)
end)
Pretty much the same code is used across all the authenticate_*
functions which means server responses like this one throw exceptions instead.
I believe the client should rely on the HTTP status code to determine if the response actually makes sense to continue authentication - plus, 409 is not the most common HTTP code which means Nakama devs are actually following the RFCs so the server responding with 200 or 201 is to be expected if the authentication has succeeded.
Configurable similar to the Unity lib:
auto_refresh_session
- Boolean value indicating if this feature is enabled, true
by defaultdefault_expired_timespan
- The time prior to session expiry when auto-refresh will occur, set to 5 minutes be defaultAuthenticating with Nakama returns this error when using nakama.authenticate_device()
, nakama.authenticate_custom()
, nakama.authenticate_apple()
, nakama.authenticate_game_center()
and nakama.authenticate_email()
on iOS:
ERROR:SCRIPT: HTTP request to 'http://127.0.0.1:7350/v2/account/authenticate/apple?username=Niclas&create=true' failed (http result: -1 socket result: -24)
DEBUG:SCRIPT:
{ --[[0x10b469ad0]]
message = "Unable to decode response",
error = true
}
This line (and probably some other logs):
https://github.com/heroiclabs/nakama-defold/blob/master/nakama/engine/defold.lua#L67
Returns this:
DEBUG:SCRIPT: /v2/account/authenticate/device with coroutine
DEBUG:SCRIPT: HTTP POST http://127.0.0.1:7350/v2/account/authenticate/device?username=Niclas&create=true
DEBUG:SCRIPT: DATA {"id":"ccac5124-3e27-49c8-c93a-020000000000"}
Using nakama.authenticate_device()
, nakama.authenticate_custom()
and nakama.authenticate_email()
works in the local Defold player on Mac.
reposting this issue that I reported on the forum.
I get all the data from server, I just do not receive the opcode.
socket.on_match_data(Constants.SOCKET_CONNECTION, function(message)
print('opcode', message.match_data.op_code) ---> nil
print('match_data', json.encode(message.match_data))
end
dispatcher.broadcast_message(opcode, nk.json_encode(data), nil, message.sender)
nothing too much crazy, since I can pass the opcode to the data payload, just reporting because it's how it is on the docs.
RPCs over the Socket to complement existing RPC functionality of Client (See https://heroiclabs.com/docs/nakama/client-libraries/unity/index.html#socket-rpcs)
We need to investigate what the IAP support in Defold engine looks like as well as introduce the new session refresh APIs to the client object.
I couldn't find Lua reference to create a Match (not a matchmaker) , i used the javascript api as refence .
To Create Match in js you have to use
var response = await socket.createMatch();
console.log("Created match with ID:", response.match.match_id);
You can share the match id with other players to join .
i want to do the same thing using Defold and Lua .
if i am not mistaken , the same should be in Lua :
local match_create_message = {
match_create = {} -- empty , no arguments
}
local match_result = nakama.socket_send(socket, match_create_message,callback)
This caused the server to disconnect with :
{"level":"warn","ts":"2021-01-04T11:23:32.727Z","msg":"Received malformed payload","uid":"51fc50d1-da4e-4f4c-b74a-ea60e75bad37","sid":"71335a58-9d9d-4d72-8cd4-3942df576269","data":"eyJjaWQiOiIxIiwibWF0Y2hfY3JlYXRlIjpbXX0="}
after decoding the data
{"cid":"1","match_create":[]}
Note :
A list with supported messages / arguments by nakama.socket_send()
will be very helpful in these cases , the official documentation only covers creating a channel_join
massage type example .
Add unit tests. Tests:
See line https://github.com/heroiclabs/nakama-defold/blob/master/codegen/main.go#L201 and https://github.com/heroiclabs/nakama-defold/blob/master/codegen/main.go#L213
The functions take user_id
as a param and use user_ids
in their logic.
No response is received when sending match data using the socket.match_data_send() method.
Sample project attached. The project is based on this repo. Sample code added to the example.script at the end of the init() lifecycle method.
It seems that the Nakama client does lots of base64 encode-decode for RPC. I'm pretty sure that the pure Lua implementation of base64 hurts performance a lot (especially in HTML5).
It would be great if Nakama Defold Client could optionally use base64 functions from the official crypt
extension.
Hello, I followed the Defold+Nakama tutorial and created a similar game, then tried to upgrade the libraries to V3 and started getting errors on the server with "Received malformed payload".
I had some differences in code and setup so I continued my testing on the xoxo sample project branch and got the same results. Tried with multiple versions of the Nakama server and same thing.
Here's the decoded payload the server was complaining about:
{"match_data_send":{"op_code":1,"data":"{\"row\":1,\"col\":1}","match_id":"1325d106-4ea1-495f-be90-f0d33d73777c.nakama1"},"cid":"3"}
When going back to main
and enabling debug
level on the server but I could only find this message:
{"level":"debug","ts":"2022-10-26T19:35:35.207Z","caller":"server/pipeline.go:66","msg":"Received *rtapi.Envelope_MatchDataSend message","uid":"3a59222c-9749-4100-869f-0fe975a72be0","sid":"4cb4ce7b-5565-11ed-9018-7106fdcb5b46","cid":"3","message":{"MatchDataSend":{"match_id":"da0d6d5e-9665-4943-90af-785050561cdd.nakama1","op_code":1,"data":"eyJyb3ciOjEsImNvbCI6M30="}}}
There are some visible differences:
match_data_send
vsMatchDataSend
Not sure if they should match one to one though, could be a red herring.
nakama/util/uri.lua
includes a link to the original source blob, but doesn't mention or include the project's MIT license.
The license should be included, perhaps adding that module to it's own folder, renaming it to init.lua
and including their LICENSE.md
file.
cc @britzl
The use of Defold's new websocket extension will reduce the executable size a lot, as well as improve the speed of the socket communications.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.