Track real player sessions and tower builds
This commit is contained in:
1 parent
8777f28595
commit
1294000348
8 files changed
+213
-8
No files matched your search
@@ -73,6 +73,8 @@ var pending_snapshot_payloads: Array[String] = []
|
||||
var friends: Array[Dictionary] = []
|
||||
var friend_statuses: Dictionary = {}
|
||||
var presence_status := ""
|
||||
var player_event_flush_busy := false
|
||||
var player_event_flush_again := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -349,6 +351,7 @@ func _after_authentication() -> void:
|
||||
var parent_game = get_parent()
|
||||
await set_presence_status("playing" if parent_game != null and parent_game.game_mode in ["playing", "paused", "victory", "game_over", "endless_offer", "endless_result"] else "menu")
|
||||
authenticated.emit(session.user_id, session.username)
|
||||
await flush_pending_player_events()
|
||||
await flush_pending_scores()
|
||||
|
||||
|
||||
@@ -362,6 +365,44 @@ func _record_activity() -> void:
|
||||
await client.rpc_async(session, "record_activity", JSON.stringify(payload))
|
||||
|
||||
|
||||
func record_local_play_start() -> void:
|
||||
_queue_player_event("play_start")
|
||||
|
||||
|
||||
func record_local_tower_build(tower_type: int) -> void:
|
||||
if tower_type < 0 or tower_type >= 7:
|
||||
return
|
||||
_queue_player_event("tower_build", tower_type)
|
||||
|
||||
|
||||
func _queue_player_event(event_name: String, tower_type := -1) -> void:
|
||||
if not account_manager:
|
||||
return
|
||||
account_manager.queue_player_event(event_name, tower_type)
|
||||
if is_authenticated():
|
||||
flush_pending_player_events()
|
||||
|
||||
|
||||
func flush_pending_player_events() -> void:
|
||||
if player_event_flush_busy:
|
||||
player_event_flush_again = true
|
||||
return
|
||||
if not account_manager or not is_authenticated():
|
||||
return
|
||||
player_event_flush_busy = true
|
||||
while is_authenticated() and not account_manager.pending_player_events.is_empty():
|
||||
var event: Dictionary = account_manager.pending_player_events[0]
|
||||
var result = await client.rpc_async(session, "record_player_event", JSON.stringify(event))
|
||||
var parsed := _parse_rpc_result(result)
|
||||
if not bool(parsed.get("accepted", false)):
|
||||
break
|
||||
account_manager.mark_player_event_complete(int(event.get("sequence", -1)))
|
||||
player_event_flush_busy = false
|
||||
if player_event_flush_again:
|
||||
player_event_flush_again = false
|
||||
call_deferred("flush_pending_player_events")
|
||||
|
||||
|
||||
func _bind_socket_signals() -> void:
|
||||
socket.received_matchmaker_matched.connect(_on_matchmaker_matched)
|
||||
socket.received_match_state.connect(_on_match_state)
|
||||
|
||||
Reference in new issue
Block a user