Files
tactical-shooter/examples/shared/scripts/noray-bootstrapper.gd
T
shawn b0c83af092 Fresh start: replace with naxIO/netfox-cs-sample foundation
Complete replacement of the tactical-shooter project with the
netfox-cs-sample (MIT) — a CS 1.6 inspired multiplayer FPS built
with Godot 4 and netfox.

## What's new
- Full CS-style gameplay: teams (T/CT), rounds, economy, buy menu
- 6 weapons: Knife, Glock, USP, AK-47, M4A1, AWP
- Bomb plant/defuse with 2 bombsites
- Flashbang & smoke grenades
- Proper netfox rollback netcode at 64 tick
- Network popup UI for host/join
- HUD, crosshair, round timer, scoreboard
- All netfox singletons registered as autoloads (works in exported builds)

## Architecture
- Listen-server (host from client, no dedicated server binary)
- Multiplayer-fps game lives at examples/multiplayer-fps/
- Netfox addons registered as autoloads for exported build compat
- Godot 4.7 with Forward+ renderer

## Removed
- Old headless-server architecture (client_main, server_main, player.gd, etc.)
- Custom netfox bootstrap with ENet fallback
- Old ChaffGames FPS template (2,420 lines, 844 KB)
- SimulationServer GDExtension stub
- Godot-jolt physics (netfox sample uses default Godot physics)
- Duplicate weapon_data.gd, anti_cheat.gd, round_manager.gd, etc.
- Server browser API Python venv (87 MB)
- test_range map and modular assets

## Preserved
- Git history
- Server config at config/default_server_config.cfg
- Windows export preset
- Build directory (gitignored)

Co-authored-by: naxIO <naxIO@users.noreply.github.com>
2026-07-02 20:55:20 -04:00

179 lines
5.0 KiB
GDScript

extends Node
enum Role { NONE, HOST, CLIENT }
@export_category("UI")
@export var connect_ui: Control
@export var noray_address_input: LineEdit
@export var oid_input: LineEdit
@export var host_oid_input: LineEdit
@export var force_relay_check: CheckBox
var role = Role.NONE
func _ready():
Noray.on_oid.connect(func(oid): oid_input.text = oid)
Noray.on_connect_nat.connect(_handle_connect_nat)
Noray.on_connect_relay.connect(_handle_connect_relay)
func connect_to_noray():
# Connect to noray
var err = OK
var address = noray_address_input.text
if address.contains(":"):
var parts = address.split(":")
var host = parts[0]
var port = (parts[1] as String).to_int()
err = await Noray.connect_to_host(host, port)
else:
err = await Noray.connect_to_host(address)
if err != OK:
print("Failed to connect to Noray: %s" % error_string(err))
return err
# Get IDs
Noray.register_host()
await Noray.on_pid
# Register remote address
err = await Noray.register_remote()
if err != OK:
print("Failed to register remote address: %s" % error_string(err))
return err
# Our local port is a remote port to Noray, hence the weird naming
print("Registered local port: %d" % Noray.local_port)
return OK
func disconnect_from_noray():
Noray.disconnect_from_host()
oid_input.clear()
func host_only():
var brawler_spawner: BrawlerSpawner = %"Brawler Spawner"
if brawler_spawner != null:
brawler_spawner.spawn_host_avatar = false
host()
func host():
if Noray.local_port <= 0:
return ERR_UNCONFIGURED
# Start host
var err = OK
var port = Noray.local_port
print("Starting host on port %s" % port)
var peer = ENetMultiplayerPeer.new()
err = peer.create_server(port)
if err != OK:
print("Failed to listen on port %s: %s" % [port, error_string(err)])
return err
get_tree().get_multiplayer().multiplayer_peer = peer
print("Listening on port %s" % port)
# Wait for server to start
while peer.get_connection_status() == MultiplayerPeer.CONNECTION_CONNECTING:
await get_tree().process_frame
if peer.get_connection_status() != MultiplayerPeer.CONNECTION_CONNECTED:
OS.alert("Failed to start server!")
return FAILED
get_tree().get_multiplayer().server_relay = true
role = Role.HOST
connect_ui.hide()
# Only start manually if NetworkEvents is not handling it (e.g. multiplayer-simple)
if not NetworkEvents.enabled:
NetworkTime.start()
func join():
role = Role.CLIENT
if force_relay_check.button_pressed:
Noray.connect_relay(host_oid_input.text)
else:
Noray.connect_nat(host_oid_input.text)
func _handle_connect_nat(address: String, port: int) -> Error:
var err = await _handle_connect(address, port)
# If client failed to connect over NAT, try again over relay
if err != OK and role != Role.HOST:
print("NAT connect failed with reason %s, retrying with relay" % error_string(err))
Noray.connect_relay(host_oid_input.text)
err = OK
return err
func _handle_connect_relay(address: String, port: int) -> Error:
return await _handle_connect(address, port)
func _handle_connect(address: String, port: int) -> Error:
if not Noray.local_port:
return ERR_UNCONFIGURED
var err = OK
if role == Role.NONE:
push_warning("Refusing connection, not running as client nor host")
err = ERR_UNAVAILABLE
if role == Role.CLIENT:
var udp = PacketPeerUDP.new()
udp.bind(Noray.local_port)
udp.set_dest_address(address, port)
print("Attempting handshake with %s:%s" % [address, port])
err = await PacketHandshake.over_packet_peer(udp)
udp.close()
if err != OK:
if err == ERR_BUSY:
print("Handshake to %s:%s succeeded partially, attempting connection anyway" % [address, port])
else:
print("Handshake to %s:%s failed: %s" % [address, port, error_string(err)])
return err
else:
print("Handshake to %s:%s succeeded" % [address, port])
# Connect
var peer = ENetMultiplayerPeer.new()
err = peer.create_client(address, port, 0, 0, 0, Noray.local_port)
if err != OK:
print("Failed to create client: %s" % error_string(err))
return err
get_tree().get_multiplayer().multiplayer_peer = peer
# Wait for connection to succeed
await Async.condition(
func(): return peer.get_connection_status() != MultiplayerPeer.CONNECTION_CONNECTING
)
if peer.get_connection_status() != MultiplayerPeer.CONNECTION_CONNECTED:
print("Failed to connect to %s:%s with status %s" % [address, port, peer.get_connection_status()])
get_tree().get_multiplayer().multiplayer_peer = null
return ERR_CANT_CONNECT
connect_ui.hide()
# Only start manually if NetworkEvents is not handling it (e.g. multiplayer-simple)
if not NetworkEvents.enabled:
NetworkTime.start()
if role == Role.HOST:
# We should already have the connection configured, only thing to do is a handshake
var peer = get_tree().get_multiplayer().multiplayer_peer as ENetMultiplayerPeer
err = await PacketHandshake.over_enet_peer(peer, address, port)
if err != OK:
print("Handshake to %s:%s failed: %s" % [address, port, error_string(err)])
return err
print("Handshake to %s:%s concluded" % [address, port])
return err