Initial commit

This commit is contained in:
2026-01-21 23:51:53 +01:00
commit 60b208fee0
1703 changed files with 100223 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
[configuration]
entry_symbol = "godotsteam_init"
compatibility_minimum = "4.4"
[libraries]
macos.debug = "res://addons/godotsteam/osx/libgodotsteam.macos.template_debug.framework"
macos.release = "res://addons/godotsteam/osx/libgodotsteam.macos.template_release.framework"
windows.debug.x86_64 = "res://addons/godotsteam/win64/libgodotsteam.windows.template_debug.x86_64.dll"
windows.debug.x86_32 = "res://addons/godotsteam/win32/libgodotsteam.windows.template_debug.x86_32.dll"
windows.release.x86_64 = "res://addons/godotsteam/win64/libgodotsteam.windows.template_release.x86_64.dll"
windows.release.x86_32 = "res://addons/godotsteam/win32/libgodotsteam.windows.template_release.x86_32.dll"
linux.debug.x86_64 = "res://addons/godotsteam/linux64/libgodotsteam.linux.template_debug.x86_64.so"
linux.debug.x86_32 = "res://addons/godotsteam/linux32/libgodotsteam.linux.template_debug.x86_32.so"
linux.release.x86_64 = "res://addons/godotsteam/linux64/libgodotsteam.linux.template_release.x86_64.so"
linux.release.x86_32 = "res://addons/godotsteam/linux32/libgodotsteam.linux.template_release.x86_32.so"
[dependencies]
macos.universal = { "res://addons/godotsteam/osx/libsteam_api.dylib": "" }
windows.x86_64 = { "res://addons/godotsteam/win64/steam_api64.dll": "" }
windows.x86_32 = { "res://addons/godotsteam/win32/steam_api.dll": "" }
linux.x86_64 = { "res://addons/godotsteam/linux64/libsteam_api.so": "" }
linux.x86_32 = { "res://addons/godotsteam/linux32/libsteam_api.so": "" }

View File

@@ -0,0 +1 @@
uid://ve2vtibvt77m

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>libgodotsteam.debug</string>
<key>CFBundleIdentifier</key>
<string>org.godotsteam.godotsteam</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>libgodotsteam.debug</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.15</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>4.15</string>
<key>LSMinimumSystemVersion</key>
<string>10.12</string>
</dict>
</plist>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>libgodotsteam</string>
<key>CFBundleIdentifier</key>
<string>org.godotsteam.godotsteam</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>libgodotsteam</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.15</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>4.15</string>
<key>LSMinimumSystemVersion</key>
<string>10.12</string>
</dict>
</plist>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,23 @@
# Contributors
This addon, and the entirety of [netfox] is a shared effort of [Fox's Sake
Studio], and the community. The following is the list of community contributors
involved with netfox:
* Alberto Klocker <albertok@gmail.com>
* Bryan Lee <42545742+bryanmylee@users.noreply.github.com>
* Dustie <77035922+DustieDog@users.noreply.github.com>
* Jake Cattrall <krazyjakee@gmail.com>
* Jon Stevens <1030863+jonstvns@users.noreply.github.com>
* Joseph Michael Ware <9at25jnr3@mozmail.com>
* Nicolas Batty <nicolas.batty@gmail.com>
* Riordan-DC <44295008+Riordan-DC@users.noreply.github.com>
* Ryan Roden-Corrent <github@rcorre.net>
* TheYellowArchitect <dmalandris@uth.gr>
* TheYellowArchitect <hello@theyellowarchitect.com>
* gk98s <89647115+gk98s@users.noreply.github.com>
* zibetnu <9at25jnr3@mozmail.com>
[netfox]: https://github.com/foxssake/netfox
[Fox's Sake Studio]: https://github.com/foxssake/

View File

@@ -0,0 +1,18 @@
Copyright 2023 Gálffy Tamás
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,8 @@
# netfox.internals
Shared utilities for [netfox] addons. Not intended for standalone usage.
Instead, check out the other addons in the [netfox] repository.
[netfox]: https://github.com/foxssake/netfox

View File

@@ -0,0 +1,44 @@
extends Object
class_name _NetfoxEditorUtils
static func gather_properties(root: Node, callback_name: String, handler: Callable) -> Array[String]:
var result: Array[String] = []
var nodes: Array[Node] = root.find_children("*")
nodes.push_front(root)
for node in nodes:
if not node.has_method(callback_name):
continue
var readable_node_name := "\"%s\" (\"%s\")" % [node.name, root.get_path_to(node)]
if node.get(callback_name) == null:
result.push_back("Can't grab method \"%s\" from node %s! Is it a @tool?" % [callback_name, readable_node_name])
continue
var props = node.get(callback_name).call()
if not props is Array:
result.push_back("Node %s didn't return an array on calling \"%s\"" % [readable_node_name, callback_name])
continue
for prop in props:
if prop is String:
# Property is a string, meaning property path relative to node
handler.call(node, prop)
elif prop is Array and prop.size() >= 2:
# Property is a node-property tuple
var prop_node: Node = null
# Node can be a String, NodePath, or an actual Node
if prop[0] is String or prop[0] is NodePath:
prop_node = node.get_node(prop[0])
elif prop[0] is Node:
prop_node = prop[0]
else:
result.push_back("Node %s specified invalid node in \"%s\": %s" % [readable_node_name, callback_name, prop])
continue
handler.call(prop_node, prop[1])
else:
result.push_back("Node %s specified invalid property in \"%s\": %s" % [readable_node_name, callback_name, prop])
return result

View File

@@ -0,0 +1 @@
uid://0ohd4n5yjilb

View File

@@ -0,0 +1,66 @@
extends RefCounted
class_name _HistoryBuffer
# Maps ticks (int) to arbitrary data
var _buffer: Dictionary = {}
func get_snapshot(tick: int):
if _buffer.has(tick):
return _buffer[tick]
else:
return null
func set_snapshot(tick: int, data):
_buffer[tick] = data
func get_buffer() -> Dictionary:
return _buffer
func get_closest_tick(tick: int) -> int:
if _buffer.has(tick):
return tick
if _buffer.is_empty():
return -1
var earliest_tick = _buffer.keys().min()
if tick < earliest_tick:
return earliest_tick
var latest_tick = _buffer.keys().max()
if tick > latest_tick:
return latest_tick
return _buffer.keys() \
.filter(func (key): return key < tick) \
.max()
func get_history(tick: int):
var closest_tick = get_closest_tick(tick)
return _buffer.get(closest_tick)
func trim(earliest_tick_to_keep: int):
var ticks := _buffer.keys()
for tick in ticks:
if tick < earliest_tick_to_keep:
_buffer.erase(tick)
func clear():
_buffer.clear()
func size() -> int:
return _buffer.size()
func is_empty() -> bool:
return _buffer.is_empty()
func has(tick) -> bool:
return _buffer.has(tick)
func ticks() -> Array:
return _buffer.keys()
func erase(tick):
_buffer.erase(tick)

View File

@@ -0,0 +1 @@
uid://btuvvlw3jkx2e

View File

@@ -0,0 +1,146 @@
extends RefCounted
class_name _NetfoxLogger
enum {
LOG_MIN,
LOG_TRACE,
LOG_DEBUG,
LOG_INFO,
LOG_WARN,
LOG_ERROR,
LOG_MAX
}
const DEFAULT_LOG_LEVEL := LOG_DEBUG
static var log_level: int
static var module_log_level: Dictionary
static var _tags: Dictionary = {}
static var _ordered_tags: Array[Callable] = []
var module: String
var name: String
const level_prefixes: Array[String] = [
"",
"TRC",
"DBG",
"INF",
"WRN",
"ERR",
""
]
static func for_netfox(p_name: String) -> _NetfoxLogger:
return _NetfoxLogger.new("netfox", p_name)
static func for_noray(p_name: String) -> _NetfoxLogger:
return _NetfoxLogger.new("netfox.noray", p_name)
static func for_extras(p_name: String) -> _NetfoxLogger:
return _NetfoxLogger.new("netfox.extras", p_name)
static func make_setting(name: String) -> Dictionary:
return {
"name": name,
"value": DEFAULT_LOG_LEVEL,
"type": TYPE_INT,
"hint": PROPERTY_HINT_ENUM,
"hint_string": "All,Trace,Debug,Info,Warning,Error,None"
}
static func register_tag(tag: Callable, priority: int = 0) -> void:
# Save tag
if not _tags.has(priority):
_tags[priority] = [tag]
else:
_tags[priority].push_back(tag)
# Recalculate tag order
_ordered_tags.clear()
var prio_groups = _tags.keys()
prio_groups.sort()
for prio_group in prio_groups:
var tag_group = _tags[prio_group]
_ordered_tags.append_array(tag_group)
static func free_tag(tag: Callable) -> void:
for priority in _tags.keys():
var priority_group := _tags[priority] as Array
priority_group.erase(tag)
# NOTE: Arrays are passed as reference, no need to re-assign after modifying
if priority_group.is_empty():
_tags.erase(priority)
_ordered_tags.erase(tag)
static func _static_init():
log_level = ProjectSettings.get_setting("netfox/logging/log_level", DEFAULT_LOG_LEVEL)
module_log_level = {
"netfox": ProjectSettings.get_setting("netfox/logging/netfox_log_level", DEFAULT_LOG_LEVEL),
"netfox.noray": ProjectSettings.get_setting("netfox/logging/netfox_noray_log_level", DEFAULT_LOG_LEVEL),
"netfox.extras": ProjectSettings.get_setting("netfox/logging/netfox_extras_log_level", DEFAULT_LOG_LEVEL)
}
func _init(p_module: String, p_name: String):
module = p_module
name = p_name
func _check_log_level(level: int) -> bool:
var cmp_level = log_level
if level < cmp_level:
return false
if module_log_level.has(module):
var module_level = module_log_level.get(module)
return level >= module_level
return true
func _format_text(text: String, values: Array, level: int) -> String:
level = clampi(level, LOG_MIN, LOG_MAX)
var result := PackedStringArray()
result.append("[%s]" % [level_prefixes[level]])
for tag in _ordered_tags:
result.append("[%s]" % [tag.call()])
result.append("[%s::%s] " % [module, name])
if values.is_empty():
result.append(text)
else:
result.append(text % values)
return "".join(result)
func _log_text(text: String, values: Array, level: int):
if _check_log_level(level):
print(_format_text(text, values, level))
func trace(text: String, values: Array = []):
_log_text(text, values, LOG_TRACE)
func debug(text: String, values: Array = []):
_log_text(text, values, LOG_DEBUG)
func info(text: String, values: Array = []):
_log_text(text, values, LOG_INFO)
func warning(text: String, values: Array = []):
if _check_log_level(LOG_WARN):
var formatted_text = _format_text(text, values, LOG_WARN)
push_warning(formatted_text)
# Print so it shows up in the Output panel too
print(formatted_text)
func error(text: String, values: Array = []):
if _check_log_level(LOG_ERROR):
var formatted_text = _format_text(text, values, LOG_ERROR)
push_error(formatted_text)
# Print so it shows up in the Output panel too
print(formatted_text)

View File

@@ -0,0 +1 @@
uid://dp4rakv0drj1f

View File

@@ -0,0 +1,7 @@
[plugin]
name="netfox.internals"
description="Shared internals for netfox addons"
author="Tamas Galffy and contributors"
version="1.25.3"
script="plugin.gd"

View File

@@ -0,0 +1,34 @@
@tool
extends EditorPlugin
var SETTINGS = [
_NetfoxLogger.make_setting("netfox/logging/log_level")
]
func _enter_tree():
for setting in SETTINGS:
add_setting(setting)
func _exit_tree():
if ProjectSettings.get_setting("netfox/general/clear_settings", false):
for setting in SETTINGS:
remove_setting(setting)
func add_setting(setting: Dictionary):
if ProjectSettings.has_setting(setting.name):
return
ProjectSettings.set_setting(setting.name, setting.value)
ProjectSettings.set_initial_value(setting.name, setting.value)
ProjectSettings.add_property_info({
"name": setting.get("name"),
"type": setting.get("type"),
"hint": setting.get("hint", PROPERTY_HINT_NONE),
"hint_string": setting.get("hint_string", "")
})
func remove_setting(setting: Dictionary):
if not ProjectSettings.has_setting(setting.name):
return
ProjectSettings.clear(setting.name)

View File

@@ -0,0 +1 @@
uid://bvhj7f66i6yl4

View File

@@ -0,0 +1,34 @@
extends RefCounted
class_name _RingBuffer
var _data: Array
var _capacity: int
var _size: int = 0
var _head: int = 0
func _init(p_capacity: int):
_capacity = p_capacity
_data = []
_data.resize(p_capacity)
func push(item):
_data[_head] = item
_size += 1
_head = (_head + 1) % _capacity
func get_data() -> Array:
if _size < _capacity:
return _data.slice(0, _size)
else:
return _data
func size() -> int:
return _size
func is_empty() -> bool:
return _size == 0
func clear():
_size = 0
_head = 0

View File

@@ -0,0 +1 @@
uid://cmfbs3cx33lkw

View File

@@ -0,0 +1,64 @@
extends RefCounted
class_name _Set
var _data: Dictionary = {}
var _iterator_idx: int = -1
static func of(items: Array) -> _Set:
var result := _Set.new()
for item in items:
result.add(item)
return result
func add(value):
_data[value] = true
func has(value) -> bool:
return _data.has(value)
func size() -> int:
return _data.size()
func is_empty() -> bool:
return _data.is_empty()
func erase(value):
return _data.erase(value)
func clear():
_data.clear()
func values() -> Array:
return _data.keys()
func min():
return _data.keys().min()
func max():
return _data.keys().max()
func equals(other) -> bool:
if not other or not other is _Set:
return false
return values() == other.values()
func _to_string():
return "Set" + str(values())
func _iter_init(arg) -> bool:
_iterator_idx = 0
return _can_iterate()
func _iter_next(arg) -> bool:
_iterator_idx += 1
return _can_iterate()
func _iter_get(arg):
return _data.keys()[_iterator_idx]
func _can_iterate() -> bool:
if _data.is_empty() or _iterator_idx >= _data.size():
_iterator_idx = -1
return false
return true

View File

@@ -0,0 +1 @@
uid://bjvmp7eed1aj0

View File

@@ -0,0 +1,23 @@
# Contributors
This addon, and the entirety of [netfox] is a shared effort of [Fox's Sake
Studio], and the community. The following is the list of community contributors
involved with netfox:
* Alberto Klocker <albertok@gmail.com>
* Bryan Lee <42545742+bryanmylee@users.noreply.github.com>
* Dustie <77035922+DustieDog@users.noreply.github.com>
* Jake Cattrall <krazyjakee@gmail.com>
* Jon Stevens <1030863+jonstvns@users.noreply.github.com>
* Joseph Michael Ware <9at25jnr3@mozmail.com>
* Nicolas Batty <nicolas.batty@gmail.com>
* Riordan-DC <44295008+Riordan-DC@users.noreply.github.com>
* Ryan Roden-Corrent <github@rcorre.net>
* TheYellowArchitect <dmalandris@uth.gr>
* TheYellowArchitect <hello@theyellowarchitect.com>
* gk98s <89647115+gk98s@users.noreply.github.com>
* zibetnu <9at25jnr3@mozmail.com>
[netfox]: https://github.com/foxssake/netfox
[Fox's Sake Studio]: https://github.com/foxssake/

View File

@@ -0,0 +1,18 @@
Copyright 2023 Gálffy Tamás
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,39 @@
# netfox.noray
Bulletproof your connectivity with [netfox]'s [noray] integration!
## Features
* 🤝 Establish connectivity using NAT punchthrough
* Uses [noray] for orchestration
* Implements a full UDP handshake
* 🛜 Use [noray] as a relay
* Useful in cases where NAT punchthrough fails
* If you can see this repo, you probably can connect through [noray]
## Install
See the root [README](../../README.md).
> *Note*, that while *netfox.noray* is part of the *netfox* suite, it can be
> used alone, without installing *netfox* itself.
## Usage
See the [docs](https://foxssake.github.io/netfox/netfox.noray/guides/noray/).
For a full example, see [noray-bootstrapper.gd].
## License
netfox.noray is under the [MIT license](LICENSE).
## Issues
In case of any issues, comments, or questions, please feel free to [open an issue]!
[netfox]: https://github.com/foxssake/netfox
[source]: https://github.com/foxssake/netfox/archive/refs/heads/main.zip
[noray]: https://github.com/foxssake/noray
[noray-bootstrapper.gd]: ../../examples/shared/scripts/noray-bootstrapper.gd
[open an issue]: https://github.com/foxssake/netfox/issues

View File

@@ -0,0 +1,53 @@
@tool
extends EditorPlugin
const ROOT = "res://addons/netfox.noray"
var SETTINGS = [
_NetfoxLogger.make_setting("netfox/logging/netfox_noray_log_level")
]
const AUTOLOADS = [
{
"name": "Noray",
"path": ROOT + "/noray.gd"
},
{
"name": "PacketHandshake",
"path": ROOT + "/packet-handshake.gd"
}
]
func _enter_tree():
for setting in SETTINGS:
add_setting(setting)
for autoload in AUTOLOADS:
add_autoload_singleton(autoload.name, autoload.path)
func _exit_tree():
if ProjectSettings.get_setting("netfox/general/clear_settings", false):
for setting in SETTINGS:
remove_setting(setting)
for autoload in AUTOLOADS:
remove_autoload_singleton(autoload.name)
func add_setting(setting: Dictionary):
if ProjectSettings.has_setting(setting.name):
return
ProjectSettings.set_setting(setting.name, setting.value)
ProjectSettings.set_initial_value(setting.name, setting.value)
ProjectSettings.add_property_info({
"name": setting.get("name"),
"type": setting.get("type"),
"hint": setting.get("hint", PROPERTY_HINT_NONE),
"hint_string": setting.get("hint_string", "")
})
func remove_setting(setting: Dictionary):
if not ProjectSettings.has_setting(setting.name):
return
ProjectSettings.clear(setting.name)

View File

@@ -0,0 +1 @@
uid://dj8vvyvvf4cl1

View File

@@ -0,0 +1,207 @@
extends Node
## A noray client for Godot.
##
## See: https://github.com/foxssake/noray
var _peer: StreamPeerTCP = StreamPeerTCP.new()
var _protocol: NorayProtocolHandler = NorayProtocolHandler.new()
var _address: String = ""
var _oid: String = ""
var _pid: String = ""
var _local_port: int = -1
static var _logger: _NetfoxLogger = _NetfoxLogger.for_noray("Noray")
## Open ID.
##
## [i]read-only[/i], this is set after registering as host.
var oid: String:
get: return _oid
set(v): push_error("Trying to set read-only variable oid")
## Private ID.
##
## [i]read-only[/i], this is set after registering as host.
var pid: String:
get: return _pid
set(v): push_error("Trying to set read-only variable pid")
## Registered local port.
##
## This is the port that servers should listen on and the port that clients
## should bind to ( i.e. use as local port ), since this port has been
## registered with noray as part of this machine's external address, and this
## is the port over which any handshake happens.
##
## [i]read-only[/i], this is set after registering remote.
var local_port: int:
get: return _local_port
set(v): push_error("Trying to set read-only variable local_port")
## Emitted for any command received from noray.
signal on_command(command: String, data: String)
## Emitted when connected to noray.
signal on_connect_to_host()
## Emitted when disconnected from noray.
signal on_disconnect_from_host()
## Emitted when an OpenID is received from noray.
signal on_oid(oid: String)
## Emitted when a PrivateID is received from noray.
signal on_pid(pid: String)
## Emitted when a connect over NAT command is received from noray.
signal on_connect_nat(address: String, port: int)
## Emitted when a connect over relay command is received from noray.
signal on_connect_relay(address: String, port: int)
func _enter_tree():
_protocol.on_command.connect(func (cmd, data): on_command.emit(cmd, data))
on_command.connect(_handle_commands)
## Connect to noray at host.
func connect_to_host(hostname: String, port: int = 8890) -> Error:
if is_connected_to_host():
disconnect_from_host()
_logger.info("Trying to connect to noray at %s:%s", [hostname, port])
var address = IP.resolve_hostname(hostname, IP.TYPE_IPV4)
if address:
_logger.debug("Resolved noray host to %s", [address])
else:
_logger.error("Couldn't resolve hostname %s", [hostname])
var err = _peer.connect_to_host(address, port)
if err != Error.OK:
return err
_peer.set_no_delay(true)
_protocol.reset()
while _peer.get_status() < 2:
_peer.poll()
await get_tree().process_frame
if _peer.get_status() == _peer.STATUS_CONNECTED:
_address = address
_logger.info("Connected to noray at %s:%s", [address, port])
on_connect_to_host.emit()
return OK
else:
_logger.error("Connection failed to noray at %s:%s, connection status %s", [address, port, _peer.get_status()])
disconnect_from_host()
return ERR_CONNECTION_ERROR
## Check if connected to any host.
func is_connected_to_host() -> bool:
return _peer.get_status() == _peer.STATUS_CONNECTED
## Disconnect from noray.
##
## Does nothing if already disconnected.
func disconnect_from_host():
if is_connected_to_host():
on_disconnect_from_host.emit()
_peer.disconnect_from_host()
## Register as host.
func register_host() -> Error:
return _put_command("register-host")
## Register remote address.
func register_remote(registrar_port: int = 8809, timeout: float = 8, interval: float = 0.1) -> Error:
if not is_connected_to_host():
return ERR_CONNECTION_ERROR
if not pid:
return ERR_UNAUTHORIZED
var result = ERR_TIMEOUT
var udp = PacketPeerUDP.new()
udp.bind(0)
udp.set_dest_address(_address, registrar_port)
_logger.debug("Bound UDP to port %s", [udp.get_local_port()])
var packet = pid.to_utf8_buffer()
while timeout > 0:
udp.put_packet(packet)
while udp.get_available_packet_count() > 0:
var recv = udp.get_packet().get_string_from_utf8()
if recv == "OK":
_local_port = udp.get_local_port()
_logger.info("Registered local port %s to remote", [_local_port])
result = OK
timeout = 0 # Break outer loop
break
else:
_logger.error("Failed to register local port!")
result = FAILED
timeout = 0 # Break outer loop
break
# Sleep
await get_tree().create_timer(interval).timeout
timeout -= interval
udp.close()
return result
## Connect to a given host by OID over NAT.
func connect_nat(host_oid: String) -> Error:
return _put_command("connect", host_oid)
## Connect to a given host by OID over relay.
func connect_relay(host_oid: String) -> Error:
return _put_command("connect-relay", host_oid)
func _process(_delta):
if not is_connected_to_host():
return
_peer.poll()
var available = _peer.get_available_bytes()
if available <= 0:
return
_protocol.ingest(_peer.get_utf8_string(available))
func _put_command(command: String, data = null) -> Error:
if not is_connected_to_host():
return ERR_CONNECTION_ERROR
if data != null:
_peer.put_data(("%s %s\n" % [command, data]).to_utf8_buffer())
else:
_peer.put_data((command + "\n").to_utf8_buffer())
return OK
func _handle_commands(command: String, data: String):
if command == "set-oid":
_oid = data
on_oid.emit(oid)
_logger.debug("Saved OID: %s", [oid])
elif command == "set-pid":
_pid = data
on_pid.emit(pid)
_logger.debug("Saved PID: %s", [pid])
elif command == "connect":
var parts = data.split(":")
var host = parts[0]
var port = parts[1].to_int()
_logger.debug("Received connect command to %s:%s", [host, port])
on_connect_nat.emit(host, port)
elif command == "connect-relay":
var host = _address
var port = data.to_int()
_logger.debug("Received connect relay command to %s:%s", [host, port])
on_connect_relay.emit(host, port)
else:
_logger.trace("Received command %s %s", [command, data])

View File

@@ -0,0 +1 @@
uid://gu4bv4tgms3x

View File

@@ -0,0 +1,83 @@
extends Node
## This class implements a handshake protocol over UDP for multiple classes.
class HandshakeStatus:
var did_read: bool = false
var did_write: bool = false
var did_handshake: bool = false
func _to_string():
return "$" + \
("r" if did_read else "-") + \
("w" if did_write else "-") + \
("x" if did_handshake else "-")
static func from_string(str: String) -> HandshakeStatus:
var result = HandshakeStatus.new()
result.did_read = str.contains("r")
result.did_write = str.contains("w")
result.did_handshake = str.contains("x")
return result
## Conduct handshake over a [PacketPeer] instance.
func over_packet_peer(peer: PacketPeer, timeout: float = 8.0, frequency: float = 0.1) -> Error:
var result = ERR_TIMEOUT
var status = HandshakeStatus.new()
status.did_write = true
while timeout >= 0:
# Process incoming packets
while peer.get_available_packet_count() > 0:
var packet = peer.get_packet()
var incoming_status = HandshakeStatus.from_string(packet.get_string_from_ascii())
# We did get a packet, so that means we read them
status.did_read = true
# They already read us, so that's a handshake
if incoming_status.did_read:
status.did_handshake = true
# Both peers ack'd the handshake, we've succeeded
if incoming_status.did_handshake and status.did_handshake:
result = OK
timeout = 0 # Break outer loop
# Send our state
peer.put_packet(status.to_string().to_ascii_buffer())
await get_tree().create_timer(frequency).timeout
timeout -= frequency
# If we've read them and we know we've sent data to them successfully,
# we're *probably* good to connect, even if the handshake did not actually
# go through.
# Depending on the context, the calling code may decide to connect anyway,
# based on this return value.
if status.did_read and status.did_write and not status.did_handshake:
result = ERR_BUSY
return result
## Conduct handshake over an [ENetConnection].
##
## [i]Note[/i] that this is not a full-fledged handshake, since we can't receive
## data over the connection. Instead, we just pretend that the handshake is
## successful on our end and blast that status for a given time.
func over_enet(connection: ENetConnection, address: String, port: int, timeout: float = 8.0, frequency: float = 0.1) -> Error:
var result = OK
var status = HandshakeStatus.new()
# Pretend this is a perfectly healthy handshake, since we can't receive data here
status.did_write = true
status.did_read = true
status.did_handshake = true
while timeout >= 0:
# Send our state
connection.socket_send(address, port, status.to_string().to_ascii_buffer())
await get_tree().create_timer(frequency).timeout
timeout -= frequency
return result

View File

@@ -0,0 +1 @@
uid://tt3j25a05n7c

View File

@@ -0,0 +1,7 @@
[plugin]
name="netfox.noray"
description="Bulletproof your connectivity with noray integration for netfox"
author="Tamas Galffy and contributors"
version="1.25.3"
script="netfox-noray.gd"

View File

@@ -0,0 +1,34 @@
extends RefCounted
class_name NorayProtocolHandler
## This class parses incoming data from noray's protocol.
##
## Unless you're writing your own noray integration, [Noray] should cover most
## use cases.
## Emitted for every command parsed during a [method ingest] call.
signal on_command(command: String, data: String)
var _strbuf: String = ""
## Resets the parser.
func reset():
_strbuf = ""
## Parse an incoming piece of data.
func ingest(data: String):
_strbuf += data
if not _strbuf.contains("\n"):
return
var idx = _strbuf.rfind("\n")
var lines = _strbuf.substr(0, idx).split("\n", false)
_strbuf = _strbuf.erase(0, idx + 1)
for line in lines:
if not line.contains(" "):
on_command.emit(line, "")
else:
var parts = line.split(" ")
var command = parts[0]
var param = parts[1]
on_command.emit(command, param)

View File

@@ -0,0 +1 @@
uid://ou0pi8ebvqsi

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>libtwovoip.macos.template_debug.universal.dylib</string>
<key>CFBundleName</key>
<string>TwoVoIP</string>
<key>CFBundleDisplayName</key>
<string>TwoVoIP</string>
<key>CFBundleIdentifier</key>
<string>ru.dmitriysalnikov.twovoip</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright (c) Dmitriy Salnikov.</string>
<key>CFBundleVersion</key>
<string>1.1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.1.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>DTPlatformName</key>
<string>macosx</string>
<key>LSMinimumSystemVersion</key>
<string>10.15</string>
</dict>
</plist>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>libtwovoip.macos.template_release.universal.dylib</string>
<key>CFBundleName</key>
<string>TwoVoIP</string>
<key>CFBundleDisplayName</key>
<string>TwoVoIP</string>
<key>CFBundleIdentifier</key>
<string>ru.dmitriysalnikov.twovoip</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright (c) Dmitriy Salnikov.</string>
<key>CFBundleVersion</key>
<string>1.1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.1.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>DTPlatformName</key>
<string>macosx</string>
<key>LSMinimumSystemVersion</key>
<string>10.15</string>
</dict>
</plist>

View File

@@ -0,0 +1,79 @@
[configuration]
entry_symbol = "two_voip_library_init"
compatibility_minimum = "4.1.4"
reloadable = false
[dependencies]
; example.x86_64 = { "relative or absolute path to the dependency" : "the path relative to the exported project", }
; -------------------------------------
; debug
macos = { }
windows.x86_64 = { }
linux.x86_64 = { }
; by default godot is using threads
web.wasm32.nothreads = {}
web.wasm32 = {}
android.arm32 = { }
android.arm64 = { }
android.x86_32 = { }
android.x86_64 = { }
ios = {}
; -------------------------------------
; release
macos.template_release = { }
windows.template_release.x86_64 = { }
linux.template_release.x86_64 = { }
web.template_release.wasm32.nothreads = { }
web.template_release.wasm32 = { }
android.template_release.arm32 = { }
android.template_release.arm64 = { }
android.template_release.x86_32 = { }
android.template_release.x86_64 = { }
ios.template_release = {}
[libraries]
; -------------------------------------
; debug
macos = "libs/libtwovoip.macos.template_debug.universal.framework"
windows.x86_64 = "libs/libtwovoip.windows.template_debug.x86_64.dll"
linux.x86_64 = "libs/libtwovoip.linux.template_debug.x86_64.so"
web.wasm32.nothreads = "libs/libtwovoip.web.template_debug.wasm32.wasm"
web.wasm32 = "libs/libtwovoip.web.template_debug.wasm32.threads.wasm"
android.arm32 = "libs/libtwovoip.android.template_debug.arm32.so"
android.arm64 = "libs/libtwovoip.android.template_debug.arm64.so"
android.x86_32 = "libs/libtwovoip.android.template_debug.x86_32.so"
android.x86_64 = "libs/libtwovoip.android.template_debug.x86_64.so"
ios = "libs/libtwovoip.ios.template_debug.universal.dylib"
; -------------------------------------
; release
macos.template_release = "libs/libtwovoip.macos.template_release.universal.framework"
windows.template_release.x86_64 = "libs/libtwovoip.windows.template_release.x86_64.dll"
linux.template_release.x86_64 = "libs/libtwovoip.linux.template_release.x86_64.so"
web.template_release.wasm32.nothreads = "libs/libtwovoip.web.template_release.wasm32.wasm"
web.template_release.wasm32 = "libs/libtwovoip.web.template_release.wasm32.threads.wasm"
android.template_release.arm32 = "libs/libtwovoip.android.template_release.arm32.so"
android.template_release.arm64 = "libs/libtwovoip.android.template_release.arm64.so"
android.template_release.x86_32 = "libs/libtwovoip.android.template_release.x86_32.so"
android.template_release.x86_64 = "libs/libtwovoip.android.template_release.x86_64.so"
ios.template_release = "libs/libtwovoip.ios.template_release.universal.dylib"

View File

@@ -0,0 +1 @@
uid://byyt0elr1qagc