Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local nk = require("nakama")
- local function UpdateMetadata(context, payload)
- local user_id = payload.user_id
- local user_ids = {
- user_id
- }
- local users = nk.users_fetch_id(user_ids)
- local myMetaData = users[1].Metadata
- local user_updates = {}
- function tableHasKey(table,key)
- return table[key] ~= nil
- end
- function replace( oldjson , newjson )
- for key, val in pairs(newjson) do
- if (tableHasKey(oldjson,key) ) then
- if(type(val) == "table") then
- oldjson[key] = replace( oldjson[key] , val )
- else
- oldjson[key] = val
- end
- elseif(not tableHasKey(oldjson,key) ) then
- oldjson[key] = val
- end
- end
- return oldjson
- end
- user_updates = {
- { UserId = user_id, Metadata = replace(myMetaData,payload.json) }
- }
- local status, err = pcall(nk.users_update, user_updates)
- if (not status) then
- print(("User update error: %q"):format(err))
- end
- return replace(myMetaData,payload.json)
- end
- nk.register_http(UpdateMetadata, "Metadata")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement