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>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
class_name _NetworkIdentifier
|
||||
extends RefCounted
|
||||
|
||||
var _subject: Object
|
||||
var _full_name: String
|
||||
var _ids: Dictionary = {} # peer to id
|
||||
var _local_id: int
|
||||
|
||||
signal on_id(peer: int, id: int)
|
||||
|
||||
func _init(subject: Object, full_name: String, local_id: int, local_peer: int):
|
||||
_subject = subject
|
||||
_full_name = full_name
|
||||
_local_id = local_id
|
||||
_ids[local_peer] = local_id
|
||||
|
||||
func has_id_for(peer: int) -> bool:
|
||||
return _ids.has(peer)
|
||||
|
||||
func get_id_for(peer: int) -> int:
|
||||
return _ids.get(peer, -1)
|
||||
|
||||
func set_id_for(peer: int, id: int) -> void:
|
||||
assert(not _ids.has(peer), "ID for peer #%d is already set!" % [peer])
|
||||
_ids[peer] = id
|
||||
on_id.emit(peer, id)
|
||||
|
||||
func get_local_id() -> int:
|
||||
return _local_id
|
||||
|
||||
func get_full_name() -> String:
|
||||
return _full_name
|
||||
|
||||
func get_subject() -> Object:
|
||||
return _subject
|
||||
|
||||
func get_known_peers() -> Array[int]:
|
||||
var result := [] as Array[int]
|
||||
result.assign(_ids.keys())
|
||||
return result
|
||||
|
||||
func reference_for(peer: int) -> _NetworkIdentityReference:
|
||||
if has_id_for(peer):
|
||||
return _NetworkIdentityReference.of_id(get_id_for(peer))
|
||||
else:
|
||||
return _NetworkIdentityReference.of_full_name(get_full_name())
|
||||
|
||||
func _to_string() -> String:
|
||||
return "NetworkIdentifier(%s)" % [_full_name]
|
||||
@@ -0,0 +1 @@
|
||||
uid://gnyygflpr78h
|
||||
@@ -0,0 +1,35 @@
|
||||
class_name _NetworkIdentityReference
|
||||
extends RefCounted
|
||||
|
||||
var _full_name: String = ""
|
||||
var _id: int = -1
|
||||
|
||||
static func of_full_name(full_name: String) -> _NetworkIdentityReference:
|
||||
var reference := _NetworkIdentityReference.new()
|
||||
reference._full_name = full_name
|
||||
return reference
|
||||
|
||||
static func of_id(id: int) -> _NetworkIdentityReference:
|
||||
var reference := _NetworkIdentityReference.new()
|
||||
reference._id = id
|
||||
return reference
|
||||
|
||||
func has_id() -> bool:
|
||||
return _id >= 0
|
||||
|
||||
func get_id() -> int:
|
||||
return _id
|
||||
|
||||
func get_full_name() -> String:
|
||||
return _full_name
|
||||
|
||||
func equals(other: Variant) -> bool:
|
||||
if other is _NetworkIdentityReference:
|
||||
return _full_name == other._full_name and _id == other._id
|
||||
return false
|
||||
|
||||
func _to_string() -> String:
|
||||
if has_id():
|
||||
return "NetworkIdentityReference#%d" % [_id]
|
||||
else:
|
||||
return "NetworkIdentityReference(%s)" % [_full_name]
|
||||
@@ -0,0 +1 @@
|
||||
uid://c6eyaau5r8g51
|
||||
@@ -0,0 +1,47 @@
|
||||
extends RefCounted
|
||||
class_name _ObjectSnapshot
|
||||
|
||||
# Represents snapshot data for a single object, by storing the object's values
|
||||
# for specified properties
|
||||
|
||||
var _object: Object
|
||||
var _is_auth: bool = false
|
||||
var _data: Dictionary = {}
|
||||
|
||||
func _init(p_object: Object) -> void:
|
||||
_object = p_object
|
||||
|
||||
func duplicate() -> _ObjectSnapshot:
|
||||
var result := _ObjectSnapshot.new(_object)
|
||||
result._is_auth = _is_auth
|
||||
result._data = _data.duplicate()
|
||||
return result
|
||||
|
||||
func get_value(property: NodePath, default: Variant = null) -> Variant:
|
||||
return _data.get(property, default)
|
||||
|
||||
func set_value(property: NodePath, value: Variant) -> void:
|
||||
_data[property] = value
|
||||
|
||||
func has_value(property: NodePath) -> bool:
|
||||
return _data.has(property)
|
||||
|
||||
func record_property(property: NodePath) -> void:
|
||||
set_value(property, _object.get_indexed(property))
|
||||
|
||||
func apply() -> void:
|
||||
for property in properties():
|
||||
var value := get_value(property)
|
||||
_object.set_indexed(property, value)
|
||||
|
||||
func is_auth() -> bool:
|
||||
return _is_auth
|
||||
|
||||
func set_auth(p_auth: bool) -> void:
|
||||
_is_auth = p_auth
|
||||
|
||||
func properties() -> Array:
|
||||
return _data.keys()
|
||||
|
||||
func _to_string() -> String:
|
||||
return "ObjectSnapshot(%s(%d), %s, %s)" % [_object, (_object as Node).get_multiplayer_authority() if _object is Node else -1, _is_auth, _data]
|
||||
@@ -0,0 +1 @@
|
||||
uid://bx4b8w54gleym
|
||||
@@ -0,0 +1,103 @@
|
||||
extends RefCounted
|
||||
class_name _PerObjectHistory
|
||||
|
||||
# Stores a per-object history of ObjectSnapshots
|
||||
# Each managed object has its own timeline of snapshots
|
||||
|
||||
var _history_size: int
|
||||
var _data := {} # Object to _HistoryBuffer
|
||||
|
||||
func _init(p_history_size: int):
|
||||
_history_size = p_history_size
|
||||
|
||||
func subjects() -> Array[Object]:
|
||||
var result := [] as Array[Object]
|
||||
result.assign(_data.keys())
|
||||
return result
|
||||
|
||||
func is_auth(tick: int, subject: Object) -> bool:
|
||||
if not _data.has(subject):
|
||||
return false
|
||||
|
||||
var history := _data[subject] as _HistoryBuffer
|
||||
if not history.has_at(tick):
|
||||
return false
|
||||
|
||||
var snapshot := history.get_at(tick) as _ObjectSnapshot
|
||||
return snapshot.is_auth()
|
||||
|
||||
func erase_subject(subject: Object) -> void:
|
||||
_data.erase(subject)
|
||||
|
||||
func ensure_snapshot(tick: int, subject: Object, carry_forward: bool) -> _ObjectSnapshot:
|
||||
var has_subject := _data.has(subject)
|
||||
if not _data.has(subject):
|
||||
_data[subject] = _HistoryBuffer.new(_history_size)
|
||||
|
||||
var history := _data[subject] as _HistoryBuffer
|
||||
var has_tick := history.has_at(tick)
|
||||
var has_latest := history.has_latest_at(tick)
|
||||
|
||||
if not history.has_at(tick):
|
||||
if not history.has_latest_at(tick):
|
||||
history.set_at(tick, _ObjectSnapshot.new(subject))
|
||||
elif carry_forward:
|
||||
history.set_at(tick, history.get_latest_at(tick).duplicate())
|
||||
else:
|
||||
history.set_at(tick, _ObjectSnapshot.new(subject))
|
||||
|
||||
assert(history.get_at(tick) != null, "Failed to ensure snapshot!")
|
||||
return history.get_at(tick) as _ObjectSnapshot
|
||||
|
||||
func get_latest_snapshot(tick: int, subject: Object) -> _ObjectSnapshot:
|
||||
if not _data.has(subject):
|
||||
return null
|
||||
|
||||
var history := _data[subject] as _HistoryBuffer
|
||||
if not history.has_latest_at(tick):
|
||||
return null
|
||||
|
||||
return history.get_latest_at(tick) as _ObjectSnapshot
|
||||
|
||||
func get_latest_tick(tick: int, subject: Object) -> int:
|
||||
if not _data.has(subject):
|
||||
return -1
|
||||
|
||||
var history := _data[subject] as _HistoryBuffer
|
||||
if not history.has_latest_at(tick):
|
||||
return -1
|
||||
|
||||
return history.get_latest_index_at(tick)
|
||||
|
||||
func set_property(tick: int, subject: Object, property: NodePath, value: Variant) -> void:
|
||||
if not _data.has(subject):
|
||||
_data[subject] = _HistoryBuffer.new(_history_size)
|
||||
|
||||
var history := _data[subject] as _HistoryBuffer
|
||||
if not history.has_at(tick):
|
||||
history.set_at(tick, _ObjectSnapshot.new(subject))
|
||||
|
||||
var snapshot := history.get_at(tick) as _ObjectSnapshot
|
||||
snapshot.set_value(property, value)
|
||||
|
||||
func has_property(tick: int, subject: Object, property: NodePath) -> bool:
|
||||
if not _data.has(subject):
|
||||
return false
|
||||
|
||||
var history := _data[subject] as _HistoryBuffer
|
||||
if not history.has_at(tick):
|
||||
return false
|
||||
|
||||
var snapshot := history.get_at(tick) as _ObjectSnapshot
|
||||
return snapshot.has_value(property)
|
||||
|
||||
func get_property(tick: int, subject: Object, property: NodePath, default: Variant = null) -> Variant:
|
||||
if not _data.has(subject):
|
||||
return default
|
||||
|
||||
var history := _data[subject] as _HistoryBuffer
|
||||
if not history.has_at(tick):
|
||||
return default
|
||||
|
||||
var snapshot := history.get_at(tick) as _ObjectSnapshot
|
||||
return snapshot.get_value(property, default)
|
||||
@@ -0,0 +1 @@
|
||||
uid://70ow466d8yqh
|
||||
@@ -0,0 +1,64 @@
|
||||
extends RefCounted
|
||||
class_name _PropertyPool
|
||||
|
||||
# Stores a set of properties, with each property belonging to a subject
|
||||
|
||||
var _properties_by_subject := {} # object to property array
|
||||
|
||||
static func of(entries: Array[Array]) -> _PropertyPool:
|
||||
var pool := _PropertyPool.new()
|
||||
|
||||
for entry in entries:
|
||||
var subject := entry[0] as Object
|
||||
var property := entry[1] as NodePath
|
||||
pool.add(subject, property)
|
||||
|
||||
return pool
|
||||
|
||||
func add(subject: Object, property: NodePath) -> void:
|
||||
if has(subject, property):
|
||||
return
|
||||
|
||||
if not _properties_by_subject.has(subject):
|
||||
_properties_by_subject[subject] = [property]
|
||||
else:
|
||||
_properties_by_subject[subject].append(property)
|
||||
|
||||
func has(subject: Object, property: NodePath) -> bool:
|
||||
return (_properties_by_subject.get(subject, []) as Array).has(property)
|
||||
|
||||
func erase(subject: Object, property: NodePath) -> void:
|
||||
if not _properties_by_subject.has(subject):
|
||||
return
|
||||
|
||||
var props := _properties_by_subject[subject] as Array
|
||||
props.erase(property)
|
||||
|
||||
if props.is_empty():
|
||||
_properties_by_subject.erase(subject)
|
||||
|
||||
func erase_subject(subject: Object) -> void:
|
||||
_properties_by_subject.erase(subject)
|
||||
|
||||
func clear() -> void:
|
||||
_properties_by_subject.clear()
|
||||
|
||||
func get_properties_of(subject: Object) -> Array[NodePath]:
|
||||
var properties := [] as Array[NodePath]
|
||||
properties.assign(_properties_by_subject.get(subject, []))
|
||||
return properties
|
||||
|
||||
func get_subjects() -> Array[Object]:
|
||||
var subjects := [] as Array[Object]
|
||||
subjects.assign(_properties_by_subject.keys())
|
||||
return subjects
|
||||
|
||||
func is_empty() -> bool:
|
||||
return _properties_by_subject.is_empty()
|
||||
|
||||
func set_from_paths(root: Node, paths: Array[String]) -> void:
|
||||
clear()
|
||||
|
||||
for path in paths:
|
||||
var prop := PropertyEntry.parse(root, path)
|
||||
add(prop.node, prop.property)
|
||||
@@ -0,0 +1 @@
|
||||
uid://j4luqnbeo8jv
|
||||
@@ -0,0 +1,171 @@
|
||||
extends RefCounted
|
||||
class_name _Snapshot
|
||||
|
||||
# Stores property values of multiple subjects, recorded for a specific tick
|
||||
|
||||
var tick: int
|
||||
var _data := {} # object to (property to variant)
|
||||
var _auth_subjects := _Set.new()
|
||||
|
||||
static func make_patch(from: _Snapshot, to: _Snapshot, tick: int = to.tick) -> _Snapshot:
|
||||
var patch := _Snapshot.new(tick)
|
||||
|
||||
for subject in from._data:
|
||||
# Target has no knowledge of subject, don't patch
|
||||
if not to._data.has(subject):
|
||||
continue
|
||||
# Only patch to auth subjects
|
||||
if not to.is_auth(subject):
|
||||
continue
|
||||
|
||||
for property in to._data[subject]:
|
||||
# Target snapshot has different value, patch it
|
||||
if from.get_property(subject, property) != to.get_property(subject, property):
|
||||
patch.set_property(subject, property, to.get_property(subject, property))
|
||||
patch.set_auth(subject, to.is_auth(subject))
|
||||
|
||||
return patch
|
||||
|
||||
# Each entry should be [subject, property, value]
|
||||
static func of(tick: int, entries: Array[Array], auth_subjects: Array[Object]) -> _Snapshot:
|
||||
var snapshot := _Snapshot.new(tick)
|
||||
for entry in entries:
|
||||
var subject := entry[0] as Object
|
||||
var property := entry[1] as NodePath
|
||||
var value := entry[2] as Variant
|
||||
|
||||
snapshot.set_property(subject, property, value)
|
||||
|
||||
for subject in auth_subjects:
|
||||
snapshot.set_auth(subject, true)
|
||||
|
||||
return snapshot
|
||||
|
||||
func _init(p_tick: int):
|
||||
tick = p_tick
|
||||
|
||||
func duplicate() -> _Snapshot:
|
||||
var result := _Snapshot.new(tick)
|
||||
result._data = _data.duplicate(true)
|
||||
result._auth_subjects = _auth_subjects.duplicate()
|
||||
return result
|
||||
|
||||
func set_auth(subject: Object, is_auth: bool) -> void:
|
||||
if is_auth:
|
||||
_auth_subjects.add(subject)
|
||||
else:
|
||||
_auth_subjects.erase(subject)
|
||||
|
||||
func set_property(subject: Object, property: NodePath, value: Variant) -> void:
|
||||
if not _data.has(subject):
|
||||
_data[subject] = { property: value }
|
||||
else:
|
||||
_data[subject][property] = value
|
||||
|
||||
func record_property(subject: Object, property: NodePath) -> void:
|
||||
var value := subject.get_indexed(property)
|
||||
set_property(subject, property, value)
|
||||
|
||||
func get_property(subject: Object, property: NodePath) -> Variant:
|
||||
return _data.get(subject, {}).get(property)
|
||||
|
||||
func has_property(subject: Object, property: NodePath) -> bool:
|
||||
if not _data.has(subject):
|
||||
return false
|
||||
if not _data[subject].has(property):
|
||||
return false
|
||||
return true
|
||||
|
||||
func merge(snapshot: _Snapshot) -> bool:
|
||||
var has_changed := false
|
||||
|
||||
for subject in snapshot._data:
|
||||
if not _data.has(subject):
|
||||
# We have no data of the subject, copy all
|
||||
_data[subject] = snapshot._data[subject].duplicate()
|
||||
set_auth(subject, snapshot.is_auth(subject))
|
||||
has_changed = true
|
||||
continue
|
||||
|
||||
if snapshot.is_auth(subject) or not is_auth(subject):
|
||||
var own_props := _data[subject] as Dictionary
|
||||
var their_props := snapshot._data[subject] as Dictionary
|
||||
|
||||
has_changed = has_changed or own_props != their_props
|
||||
|
||||
own_props.merge(their_props, true)
|
||||
set_auth(subject, snapshot.is_auth(subject))
|
||||
|
||||
return has_changed
|
||||
|
||||
func apply() -> void:
|
||||
for subject in _data:
|
||||
for property in _data[subject]:
|
||||
var value = _data[subject][property]
|
||||
(subject as Object).set_indexed(property, value)
|
||||
|
||||
func sanitize(sender: int) -> void:
|
||||
var invalid_subjects := []
|
||||
for subject in _data:
|
||||
if subject is Node:
|
||||
if subject.get_multiplayer_authority() != sender:
|
||||
invalid_subjects.append(subject)
|
||||
|
||||
for subject in invalid_subjects:
|
||||
_data.erase(invalid_subjects)
|
||||
|
||||
func has_subject(subject: Object, require_auth: bool = false) -> bool:
|
||||
if not _data.has(subject):
|
||||
return false
|
||||
if require_auth and not is_auth(subject):
|
||||
return false
|
||||
return true
|
||||
|
||||
func has_subjects(subjects: Array, require_auth: bool = false) -> bool:
|
||||
for subject in subjects:
|
||||
if not has_subject(subject, require_auth):
|
||||
return false
|
||||
return true
|
||||
|
||||
func get_subjects() -> Array:
|
||||
return _data.keys()
|
||||
|
||||
func get_auth_subjects() -> Array:
|
||||
return _auth_subjects.values()
|
||||
|
||||
func get_subject_properties(subject: Object) -> Array:
|
||||
return _data.get(subject, {}).keys()
|
||||
|
||||
func is_empty() -> bool:
|
||||
return _data.is_empty()
|
||||
|
||||
func size() -> int:
|
||||
var result := 0
|
||||
for subject in _data:
|
||||
result += (_data[subject] as Dictionary).size()
|
||||
return result
|
||||
|
||||
func is_auth(subject: Object) -> bool:
|
||||
return _auth_subjects.has(subject)
|
||||
|
||||
func equals(other) -> bool:
|
||||
if other is _Snapshot:
|
||||
return tick == other.tick and _data == other._data and _auth_subjects.equals(other._auth_subjects)
|
||||
else:
|
||||
return false
|
||||
|
||||
func _to_string() -> String:
|
||||
var result := "_Snapshot(#%d" % [tick]
|
||||
for subject in _data:
|
||||
for property in _data[subject]:
|
||||
var value = _data[subject][property]
|
||||
result += ", %s:%s(%s): %s" % [subject, property, is_auth(subject), value]
|
||||
result += ")"
|
||||
return result
|
||||
|
||||
func _to_vest():
|
||||
return {
|
||||
"tick": tick,
|
||||
"data": _data,
|
||||
"auth_subjects": _auth_subjects
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b76plodlwp2u6
|
||||
@@ -0,0 +1 @@
|
||||
uid://ch0j0cclkpey6
|
||||
Reference in New Issue
Block a user