b0c83af092
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>
112 lines
2.8 KiB
GDScript
112 lines
2.8 KiB
GDScript
extends Node
|
|
|
|
@export_category("UI")
|
|
@export var connect_ui: Control
|
|
@export var address_input: LineEdit
|
|
@export var port_input: LineEdit
|
|
|
|
func host_only():
|
|
var brawler_spawner: BrawlerSpawner = %"Brawler Spawner"
|
|
if brawler_spawner != null:
|
|
brawler_spawner.spawn_host_avatar = false
|
|
host()
|
|
|
|
func host():
|
|
var host = _parse_input()
|
|
if host.size() == 0:
|
|
return ERR_CANT_RESOLVE
|
|
|
|
var port = host.port
|
|
|
|
# Start host
|
|
print("Starting host on port %s" % port)
|
|
|
|
var peer = ENetMultiplayerPeer.new()
|
|
if peer.create_server(port) != OK:
|
|
print("Failed to listen on port %s" % port)
|
|
|
|
get_tree().get_multiplayer().multiplayer_peer = peer
|
|
print("Listening on port %s" % port)
|
|
|
|
# Wait for server to start
|
|
await Async.condition(
|
|
func():
|
|
return peer.get_connection_status() != MultiplayerPeer.CONNECTION_CONNECTING
|
|
)
|
|
|
|
if peer.get_connection_status() != MultiplayerPeer.CONNECTION_CONNECTED:
|
|
OS.alert("Failed to start server!")
|
|
return
|
|
|
|
print("Server started")
|
|
get_tree().get_multiplayer().server_relay = true
|
|
|
|
connect_ui.hide()
|
|
|
|
# Only start manually if NetworkEvents is not handling it (e.g. multiplayer-simple)
|
|
if not NetworkEvents.enabled:
|
|
NetworkTime.start()
|
|
|
|
func join():
|
|
var host = _parse_input()
|
|
if host.size() == 0:
|
|
return ERR_CANT_RESOLVE
|
|
|
|
var address = host.address
|
|
var port = host.port
|
|
|
|
# Connect
|
|
print("Connecting to %s:%s" % [address, port])
|
|
var peer = ENetMultiplayerPeer.new()
|
|
var err = peer.create_client(address, port)
|
|
if err != OK:
|
|
OS.alert("Failed to create client, reason: %s" % error_string(err))
|
|
return err
|
|
|
|
get_tree().get_multiplayer().multiplayer_peer = peer
|
|
|
|
# Wait for connection process to conclude
|
|
await Async.condition(
|
|
func():
|
|
return peer.get_connection_status() != MultiplayerPeer.CONNECTION_CONNECTING
|
|
)
|
|
|
|
if peer.get_connection_status() != MultiplayerPeer.CONNECTION_CONNECTED:
|
|
OS.alert("Failed to connect to %s:%s" % [address, port])
|
|
return
|
|
|
|
print("Client started")
|
|
connect_ui.hide()
|
|
|
|
# Only start manually if NetworkEvents is not handling it (e.g. multiplayer-simple)
|
|
if not NetworkEvents.enabled:
|
|
NetworkTime.start()
|
|
|
|
func _enter_tree():
|
|
# Hide and show UI as appropriate
|
|
# These handlers are necessary, since the game could have started via
|
|
# autoconnect, or any other method
|
|
NetworkEvents.on_client_start.connect(func(__): connect_ui.hide())
|
|
NetworkEvents.on_server_start.connect(func(): connect_ui.hide())
|
|
NetworkEvents.on_client_stop.connect(func(): connect_ui.show())
|
|
NetworkEvents.on_server_stop.connect(func(): connect_ui.show())
|
|
|
|
func _parse_input() -> Dictionary:
|
|
# Validate inputs
|
|
var address = address_input.text
|
|
var port = port_input.text
|
|
|
|
if address == "":
|
|
OS.alert("No host specified!")
|
|
return {}
|
|
|
|
if not port.is_valid_int():
|
|
OS.alert("Invalid port!")
|
|
return {}
|
|
port = port.to_int()
|
|
|
|
return {
|
|
"address": address,
|
|
"port": port
|
|
}
|