mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-12 03:33:43 +00:00
feat(multiplayer): enforce allocated initial connect policy
This commit is contained in:
@@ -311,6 +311,10 @@ var _late_joiners: Array[Dictionary] = []
|
||||
# to this scene; static because the loop cannot hold a reference to a node that
|
||||
# does not exist yet, and consumed on read so it cannot leak into a later match.
|
||||
static var server_arena_override := ""
|
||||
# Set only by ServerMatchLoop after an allocated casual match passes the
|
||||
# initial-connect policy. It is consumed once while building the authoritative
|
||||
# six-slot lineup, so direct servers and ranked allocations cannot add bots.
|
||||
static var server_bot_fill_override := false
|
||||
# §6.3's "cap with --max-spectators". Server only; 0 disables spectating
|
||||
# entirely, negative means unlimited.
|
||||
var _max_spectators := -1
|
||||
@@ -451,24 +455,47 @@ func _start_server() -> void:
|
||||
var teams := PackedInt32Array()
|
||||
var spawn_indices := PackedInt32Array()
|
||||
var team_counts := {0: 0, 1: 0}
|
||||
var sorted_peer_ids: Array = MatchNet.roster.keys()
|
||||
sorted_peer_ids.sort()
|
||||
for peer_id in sorted_peer_ids:
|
||||
var info: MatchNet.PlayerInfo = MatchNet.roster[peer_id]
|
||||
var spawn_index: int = info.spawn_index if info.spawn_index >= 0 else team_counts.get(info.team, 0)
|
||||
if info.spawn_index < 0:
|
||||
team_counts[info.team] = spawn_index + 1
|
||||
var config := ServerConfig.parse(OS.get_cmdline_user_args(), false)
|
||||
var use_assigned_bot_fill := server_bot_fill_override and bool(config.get_value("allocated-mode"))
|
||||
server_bot_fill_override = false
|
||||
var spawn_entries: Array[Dictionary] = []
|
||||
if use_assigned_bot_fill:
|
||||
var by_identity := {}
|
||||
for peer_id in MatchNet.roster.keys():
|
||||
var roster_info: MatchNet.PlayerInfo = MatchNet.roster[peer_id]
|
||||
by_identity[roster_info.player_identity] = {"peer_id": int(peer_id), "info": roster_info}
|
||||
for assigned: Dictionary in MatchNet.assigned_player_slots():
|
||||
var identity := String(assigned["player_identity"])
|
||||
if by_identity.has(identity):
|
||||
var human: Dictionary = by_identity[identity]
|
||||
spawn_entries.append({"peer_id": human["peer_id"], "info": human["info"], "team": int(assigned["team"]), "spawn_index": int(assigned["slot"]) % 3, "bot": false})
|
||||
else:
|
||||
spawn_entries.append({"peer_id": -1, "info": null, "team": int(assigned["team"]), "spawn_index": int(assigned["slot"]) % 3, "bot": true})
|
||||
else:
|
||||
var sorted_peer_ids: Array = MatchNet.roster.keys()
|
||||
sorted_peer_ids.sort()
|
||||
for peer_id in sorted_peer_ids:
|
||||
var info: MatchNet.PlayerInfo = MatchNet.roster[peer_id]
|
||||
var spawn_index: int = info.spawn_index if info.spawn_index >= 0 else team_counts.get(info.team, 0)
|
||||
if info.spawn_index < 0:
|
||||
team_counts[info.team] = spawn_index + 1
|
||||
spawn_entries.append({"peer_id": peer_id, "info": info, "team": info.team, "spawn_index": spawn_index, "bot": false})
|
||||
for entry: Dictionary in spawn_entries:
|
||||
var peer_id: int = int(entry["peer_id"])
|
||||
var info: MatchNet.PlayerInfo = entry["info"]
|
||||
var team: int = int(entry["team"])
|
||||
var spawn_index: int = int(entry["spawn_index"])
|
||||
var slot := SlotInfo.new()
|
||||
slot.peer_id = peer_id
|
||||
slot.team = info.team
|
||||
slot.team = team
|
||||
slot.spawn_index = spawn_index
|
||||
slot.player_name = info.player_name
|
||||
slot.player_identity = MatchNet.player_identity(peer_id)
|
||||
slot.controller = RLShipController.new()
|
||||
slot.ship = spawn_ship(info.team, spawn_index, slot.controller)
|
||||
slot.player_name = "Bot %d" % spawn_index if bool(entry["bot"]) else info.player_name
|
||||
slot.player_identity = "" if bool(entry["bot"]) else MatchNet.player_identity(peer_id)
|
||||
slot.controller = _build_opponent(bot_model_path, bot_reaction_ticks, bot_action_noise, "NetworkedMatch") if bool(entry["bot"]) else RLShipController.new()
|
||||
slot.ship = spawn_ship(team, spawn_index, slot.controller)
|
||||
_slots.append(slot)
|
||||
peer_ids.append(peer_id)
|
||||
teams.append(info.team)
|
||||
teams.append(team)
|
||||
spawn_indices.append(spawn_index)
|
||||
|
||||
MatchSim.send_match_config(arena_path, peer_ids, teams, spawn_indices)
|
||||
|
||||
Reference in New Issue
Block a user