fix(network): isolate auth sessions for multiple instances on same pc

This commit is contained in:
2026-07-13 11:40:27 +08:00
parent 8718e2d245
commit dea822987b
3 changed files with 42 additions and 34 deletions
+31 -31
View File
@@ -50,10 +50,10 @@ The dock allows you to define and manage custom cell states:
2. **Custom States**: 2. **Custom States**:
- Add new states with the "Add Item State" button. - Add new states with the "Add Item State" button.
- For each state, you can set: - For each state, you can set:
- Name - Name
- ID (used in scripts to reference the state) - ID (used in scripts to reference the state)
- Include in Randomize (toggle) - Include in Randomize (toggle)
- Randomize Percentage (when included in randomization) - Randomize Percentage (when included in randomization)
3. **State Management**: 3. **State Management**:
- Edit existing states - Edit existing states
@@ -193,10 +193,10 @@ extends Node3D
@onready var player = $Player @onready var player = $Player
func _ready(): func _ready():
player.enhanced_gridmap_path = enhanced_gridmap.get_path() player.enhanced_gridmap_path = enhanced_gridmap.get_path()
player.player_path = player.get_path() player.player_path = player.get_path()
player.cell_size = Vector3(2, 2, 2) player.cell_size = Vector3(2, 2, 2)
player.use_diagonal_movement = true player.use_diagonal_movement = true
``` ```
This setup allows for click-to-move functionality on your EnhancedGridMap, with the player finding and following optimal paths while avoiding non-walkable cells. This setup allows for click-to-move functionality on your EnhancedGridMap, with the player finding and following optimal paths while avoiding non-walkable cells.
@@ -282,12 +282,12 @@ Override the `get_cell_cost` method in a script extending EnhancedGridMap to imp
extends EnhancedGridMap extends EnhancedGridMap
func get_cell_cost(x: int, z: int) -> float: func get_cell_cost(x: int, z: int) -> float:
var cell_item = get_cell_item(Vector3i(x, 0, z)) var cell_item = get_cell_item(Vector3i(x, 0, z))
match cell_item: match cell_item:
0: return 1.0 # Normal cell 0: return 1.0 # Normal cell
1: return 2.0 # Slow terrain 1: return 2.0 # Slow terrain
2: return 0.5 # Fast terrain 2: return 0.5 # Fast terrain
_: return INF # Non-walkable _: return INF # Non-walkable
``` ```
### Custom Grid Generation ### Custom Grid Generation
@@ -298,14 +298,14 @@ You can implement custom grid generation by overriding the `generate_grid` metho
extends EnhancedGridMap extends EnhancedGridMap
func generate_grid(): func generate_grid():
clear() clear()
for x in range(columns): for x in range(columns):
for z in range(rows): for z in range(rows):
var item_index = (x + z) % 2 # Checkerboard pattern var item_index = (x + z) % 2 # Checkerboard pattern
set_cell_item(Vector3i(x, 0, z), item_index) set_cell_item(Vector3i(x, 0, z), item_index)
update_grid_data() update_grid_data()
initialize_astar() initialize_astar()
update_astar_costs() update_astar_costs()
``` ```
## Extending the Player Movement ## Extending the Player Movement
@@ -318,9 +318,9 @@ You can extend the player movement functionality by overriding or adding methods
extends "res://addons/enhanced_gridmap/examples/player.gd" extends "res://addons/enhanced_gridmap/examples/player.gd"
func is_valid_move(from: Vector2i, to: Vector2i) -> bool: func is_valid_move(from: Vector2i, to: Vector2i) -> bool:
# Add custom logic for valid moves # Add custom logic for valid moves
var distance = from.distance_to(to) var distance = from.distance_to(to)
return distance <= 1 and super.is_valid_move(from, to) return distance <= 1 and super.is_valid_move(from, to)
``` ```
### Additional Interactions ### Additional Interactions
@@ -329,14 +329,14 @@ func is_valid_move(from: Vector2i, to: Vector2i) -> bool:
extends "res://addons/enhanced_gridmap/examples/player.gd" extends "res://addons/enhanced_gridmap/examples/player.gd"
func _unhandled_input(event): func _unhandled_input(event):
super._unhandled_input(event) super._unhandled_input(event)
if event.is_action_pressed("interact"): if event.is_action_pressed("interact"):
interact_with_current_cell() interact_with_current_cell()
func interact_with_current_cell(): func interact_with_current_cell():
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(current_position.x, 0, current_position.y)) var cell_item = enhanced_gridmap.get_cell_item(Vector3i(current_position.x, 0, current_position.y))
# Add custom interaction logic based on cell_item # Add custom interaction logic based on cell_item
``` ```
These examples demonstrate how you can build upon the provided player movement script to create more complex game mechanics that integrate seamlessly with the EnhancedGridMap plugin. These examples demonstrate how you can build upon the provided player movement script to create more complex game mechanics that integrate seamlessly with the EnhancedGridMap plugin.
-1
View File
@@ -18,4 +18,3 @@ The generated code is designed to be supported Godot Engine `3.1+`.
### Limitations ### Limitations
The code generator has __only__ been checked against the Swagger specification generated for Nakama server. YMMV. The code generator has __only__ been checked against the Swagger specification generated for Nakama server. YMMV.
+11 -2
View File
@@ -21,13 +21,19 @@ var is_guest: bool = false
var auth_mode: AuthMode = AuthMode.GUEST var auth_mode: AuthMode = AuthMode.GUEST
# Session persistence # Session persistence
const SESSION_FILE := "user://auth_session.dat" var SESSION_FILE := "user://auth_session.dat"
const CREDENTIALS_FILE := "user://auth_credentials.dat" var CREDENTIALS_FILE := "user://auth_credentials.dat"
# Encryption key for session storage (device-specific) # Encryption key for session storage (device-specific)
var ENCRYPTION_KEY: String = OS.get_unique_id().sha256_text() var ENCRYPTION_KEY: String = OS.get_unique_id().sha256_text()
func _ready() -> void: func _ready() -> void:
# In debug mode, suffix session files with the process ID to allow multiple instances
if OS.is_debug_build():
var suffix = "_" + str(OS.get_process_id())
SESSION_FILE = "user://auth_session%s.dat" % suffix
CREDENTIALS_FILE = "user://auth_credentials%s.dat" % suffix
# Try to restore session on startup # Try to restore session on startup
call_deferred("_try_restore_session") call_deferred("_try_restore_session")
@@ -155,6 +161,9 @@ func login_as_guest() -> bool:
func _get_device_id() -> String: func _get_device_id() -> String:
# Try to load saved device ID for consistent guest identity # Try to load saved device ID for consistent guest identity
var id_file := "user://device_id.txt" var id_file := "user://device_id.txt"
if OS.is_debug_build():
id_file = "user://device_id_%s.txt" % str(OS.get_process_id())
if FileAccess.file_exists(id_file): if FileAccess.file_exists(id_file):
var file_read := FileAccess.open(id_file, FileAccess.READ) var file_read := FileAccess.open(id_file, FileAccess.READ)
if file_read: if file_read: