Fixed the handshake not happening and changing the way avatars are cached
This commit is contained in:
parent
39ae47a520
commit
4252317d82
@ -28,8 +28,7 @@ func _initialize() -> void:
|
|||||||
my_username = Steam.getFriendPersonaName(my_steam_id)
|
my_username = Steam.getFriendPersonaName(my_steam_id)
|
||||||
GameConsole.print_line("Steam ID: " + my_username)
|
GameConsole.print_line("Steam ID: " + my_username)
|
||||||
|
|
||||||
Steam.getPlayerAvatar()
|
cache_avatar(my_steam_id)
|
||||||
Steam.avatar_loaded.connect(_on_avatar_loaded)
|
|
||||||
|
|
||||||
Steam.lobby_created.connect(_on_lobby_created)
|
Steam.lobby_created.connect(_on_lobby_created)
|
||||||
Steam.lobby_joined.connect(_on_lobby_joined)
|
Steam.lobby_joined.connect(_on_lobby_joined)
|
||||||
@ -42,23 +41,27 @@ func _process(_delta: float) -> void:
|
|||||||
read_all_p2p_packets()
|
read_all_p2p_packets()
|
||||||
|
|
||||||
|
|
||||||
func _on_avatar_loaded(user_id: int, avatar_size: int, avatar_buffer: PackedByteArray) -> void:
|
func cache_avatar(user_id: int) -> bool:
|
||||||
if lobby_members_avatar_cache.has(user_id):
|
if lobby_members_avatar_cache.has(user_id):
|
||||||
return
|
return true
|
||||||
|
else:
|
||||||
|
Steam.getPlayerAvatar(user_id)
|
||||||
|
|
||||||
|
Steam.avatar_loaded.connect(func(user_id: int, avatar_size: int, avatar_buffer: PackedByteArray):
|
||||||
var avatar_image: Image = Image.create_from_data(avatar_size, avatar_size, false, Image.FORMAT_RGBA8, avatar_buffer)
|
var avatar_image: Image = Image.create_from_data(avatar_size, avatar_size, false, Image.FORMAT_RGBA8, avatar_buffer)
|
||||||
if avatar_size > 128:
|
if avatar_size > 128:
|
||||||
avatar_image.resize(128, 128, Image.INTERPOLATE_LANCZOS)
|
avatar_image.resize(128, 128, Image.INTERPOLATE_LANCZOS)
|
||||||
|
|
||||||
if avatar_image != null:
|
if avatar_image != null:
|
||||||
var avatar_texture = ImageTexture.create_from_image(avatar_image)
|
var avatar_texture = ImageTexture.create_from_image(avatar_image)
|
||||||
if user_id == my_steam_id:
|
GameConsole.print_line("Avatar cached for: " + Steam.getFriendPersonaName(user_id))
|
||||||
my_avatar_texture = avatar_texture
|
|
||||||
|
|
||||||
GameConsole.print_line("Avatar loaded for: " + Steam.getFriendPersonaName(user_id))
|
|
||||||
lobby_members_avatar_cache[user_id] = avatar_texture
|
lobby_members_avatar_cache[user_id] = avatar_texture
|
||||||
|
return true
|
||||||
else:
|
else:
|
||||||
GameConsole.log_error("Failed to create avatar image for: " + Steam.getFriendPersonaName(user_id))
|
GameConsole.log_error("Failed to create avatar image for: " + Steam.getFriendPersonaName(user_id))
|
||||||
|
return false
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
func _on_lobby_created(connection_status: int, this_lobby_id: int) -> void:
|
func _on_lobby_created(connection_status: int, this_lobby_id: int) -> void:
|
||||||
@ -117,9 +120,7 @@ func get_lobby_members():
|
|||||||
var member_id: int = Steam.getLobbyMemberByIndex(lobby_id, member)
|
var member_id: int = Steam.getLobbyMemberByIndex(lobby_id, member)
|
||||||
var member_username: String = Steam.getFriendPersonaName(member_id)
|
var member_username: String = Steam.getFriendPersonaName(member_id)
|
||||||
lobby_members.append({"steam_id": member_id, "username": member_username})
|
lobby_members.append({"steam_id": member_id, "username": member_username})
|
||||||
Steam.getPlayerAvatar(member_id)
|
|
||||||
user_joined_lobby.emit(member_id, member_username)
|
user_joined_lobby.emit(member_id, member_username)
|
||||||
await get_tree().create_timer(0.3).timeout
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -152,7 +153,8 @@ func read_p2p_packet() -> void:
|
|||||||
match read_data["message"]:
|
match read_data["message"]:
|
||||||
"handshake":
|
"handshake":
|
||||||
GameConsole.print_line("Handshake from: " + read_data["username"])
|
GameConsole.print_line("Handshake from: " + read_data["username"])
|
||||||
await get_lobby_members()
|
get_lobby_members()
|
||||||
|
cache_avatar(read_data["steam_id"])
|
||||||
"chat":
|
"chat":
|
||||||
GameConsole.print_line(read_data["username"] + ": " + read_data["message"])
|
GameConsole.print_line(read_data["username"] + ": " + read_data["message"])
|
||||||
_:
|
_:
|
||||||
|
@ -47,7 +47,7 @@ func _on_join_button_pressed() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_user_joined_lobby(user_id: int, username: String) -> void:
|
func _on_user_joined_lobby(user_id: int, username: String) -> void:
|
||||||
if user_id == network_manager.MY_steam_id:
|
if user_id == network_manager.my_steam_id:
|
||||||
return
|
return
|
||||||
print(user_id, Steam.getFriendPersonaName(user_id))
|
print(user_id, Steam.getFriendPersonaName(user_id))
|
||||||
var user_box: Node = user_box_prefab.instantiate()
|
var user_box: Node = user_box_prefab.instantiate()
|
||||||
|
Loading…
Reference in New Issue
Block a user