Hello! I am trying to send map to client from server.
Server:
func _network_peer_connected(peer_id:int):
var player = load("res://Nodes/Character.tscn").instance()
player.set_name(String(peer_id))
player.set_network_master(peer_id)
$"/root/Game/Players".add_child(player)
players.append(peer_id)
for playerModel in $"/root/Game/Players".get_children():
if playerModel != player:
rpc_id(peer_id, "new_player", int(playerModel.name))
rpc_id(peer_id, "load_new_user_map", getMap())
rpc("new_player", peer_id)
print("A new plr connected!")
getMap:
func getMap():
var GetMapRequest = HTTPRequest.new()
add_child(GetMapRequest)
GetMapRequest.request("url" + gameId)
var map_request_completed_info = yield(GetMapRequest, "request_completed")
var map_response_code: int = map_request_completed_info[1]
var map_body: PoolByteArray = map_request_completed_info[3]
var map_data = str(map_body.get_string_from_utf8())
GetMapRequest.queue_free()
if map_response_code != 200:
return "ORPHAN"
return map_data
Client:
remotesync func load_new_user_map(map_str):
if get_tree().get_rpc_sender_id() == 1:
var map = JSON.parse(map_str)
if "CONTENT" in map:
# The "CONTENT" key holds the actual game content
var game_content = JSON.parse(map["CONTENT"])
# Access the content elements, for example:
if "Level" in game_content:
var levels = game_content["Level"]
print("Levels:", levels)
if "Scripts" in game_content:
var scripts = game_content["Scripts"]
print("Scripts:", scripts)
if "LocalGUI" in game_content:
var local_gui = game_content["LocalGUI"]
print("Local GUI:", local_gui)
if "GameSettings" in game_content:
var game_settings = game_content["GameSettings"]
print("Game Settings:", game_settings)
else:
print("Map is orphan")
This is what the getMap() returns:
"{"CONTENT":"{\"Level\":[{\"name\":\"Objects\",\"position\":[0,0,0],\"rotation\":[0,0,0],\"size\":[1,1,1],\"children\":[],\"type\":\"ObjectsNode\",\"color\":\"#NULL\"}],\"Scripts\":[],\"LocalGUI\":[{\"name\":\"Button\",\"type\":\"Button\",\"buttonText\":\"Button\"},{\"name\":\"Text\",\"type\":\"Text\",\"Text\":\"Text\"}],\"GameSettings\":[{\"Time\":\"Day\",\"IsPublic\":true,\"FogEnabled\":true,\"FogColor\":\"#FFFFFF\"}]}"}"