Skip to content

Commit

Permalink
Fix PartyData serialization and deserialization by using base64. (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwinterpixel authored Apr 25, 2022
1 parent 85cd707 commit 2c3af46
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p
- Add support for creating match by name
- Add support for "count_multple" on "NakamaSocket.add_matchmaker_async()" and "NakamaSocket.add_matchmaker_party_async()"
- Add C# support classes to better integrate the .NET client with the Mono version of Godot, allowing HTML5 exports to work
- Fixed sending and receiving of PartyData

### Fixed

Expand Down
5 changes: 4 additions & 1 deletion addons/com.heroiclabs.nakama/api/NakamaRTAPI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,10 @@ class PartyData extends NakamaAsyncResult:
return "PartyData<party_id=%s, presence=%s, op_code=%d, data%s>" % [party_id, presence, op_code, data]

static func create(p_ns : GDScript, p_dict : Dictionary) -> PartyData:
return _safe_ret(NakamaSerializer.deserialize(p_ns, "PartyData", p_dict), PartyData) as PartyData
var out := _safe_ret(NakamaSerializer.deserialize(p_ns, "PartyData", p_dict), PartyData) as PartyData
if out.data: # Decode base64 received data
out.data = Marshalls.base64_to_utf8(out.data)
return out

static func get_result_key() -> String:
return "party_data"
Expand Down
5 changes: 3 additions & 2 deletions addons/com.heroiclabs.nakama/socket/NakamaSocket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -570,5 +570,6 @@ func remove_party_member_async(p_party_id : String, p_presence : NakamaRTAPI.Use
# @param p_op_code - Op code value.
# @param data - Data payload, if any.
# Returns a task which represents the asynchronous operation.
func send_party_data_async(p_party_id : String, p_op_code : int, p_data = null):
return _send_async(NakamaRTMessage.PartyDataSend.new(p_party_id, p_op_code, p_data))
func send_party_data_async(p_party_id : String, p_op_code : int, p_data:String = ""):
var base64_data = null if p_data.empty() else Marshalls.utf8_to_base64(p_data)
return _send_async(NakamaRTMessage.PartyDataSend.new(p_party_id, p_op_code, base64_data))

0 comments on commit 2c3af46

Please sign in to comment.