Godot Version
<> godot --version
4.4.1.stable.arch_linux
Question
Whether a LAN or online multiplayer game, EnetMultiplayerPeer and RPC are amazing! they are human-readable code. handles all the basic things for lazy gamedevs so they don’t have to worry about a them. but there is a problem. I don’t like that my player has to write down address and port. I want an easy interface for them. Just show them a list of servers, some info about them and give them a button to join. Yet EnetMultiplayerPeer cannot put_packet to everyone including not connected devices which is needed for a server browser. Is there a way to achieve a server browser on top of EnetMultiplayerPeer without going near the scary low-level multiplayer protocols like PacketPeerUDP?
another question: PacketPeerUDP cannot work with MultiplayerSynchronizer right?
You would need a server to host that information. From the client you may skirt around low-level PacketPeerUDP for an HTTPRequest if your host-list server uses HTTP, but you still need to make a host-list server.
I’m assuming this
You would need a server to host that information.
means to use an online VPS or something.
let’s say it’s a LAN game. the server will be whoever chose to be the host on their game and the other taps on join and then are showed the server browser. what about that?
For LAN you can actually broadcast to all connected/unconnected (anyone who will listen). But it does require PacketPeerUDP
Here’s how I wrote my LAN server broadcaster; the host must create this broadcaster.
extends Node
var socket := PacketPeerUDP.new()
const LAN_BROADCAST_PORT := 42355
func _ready() -> void:
socket.set_broadcast_enabled(true)
var err := socket.set_dest_address("255.255.255.255", LAN_BROADCAST_PORT)
assert(err == OK, "Couldn't set broadcasting")
var timer := Timer.new()
timer.autostart = true
timer.wait_time = 1.5
add_child(timer)
timer.timeout.connect(_broadcast)
func _broadcast() -> void:
var message := "Your Custom Message, maybe a player count/map name"
var packet := message.to_ascii_buffer()
socket.put_packet(packet)
And here’s my listener script. Your “Server Menu” will have a child node containing this, connect to the signals to recieve updates.
extends Node
signal new_server(ip: String, message: String)
signal update_server(index: int, ip: String, message: String)
var socket := PacketPeerUDP.new()
const LAN_BROADCAST_PORT := 42355
var found_servers: Array[String] = []
func _ready() -> void:
var bind_err := socket.bind(LAN_BROADCAST_PORT)
if bind_err != OK:
push_warning("Couldn't bind lan broadcast listener")
return
var timer := Timer.new()
timer.autostart = true
add_child(timer)
timer.timeout.connect(_check_packets)
func _check_packets() -> void:
while socket.get_available_packet_count() > 0:
var serverip: String = socket.get_packet_ip()
var port := socket.get_packet_port()
var bytes := socket.get_packet()
var message: String = bytes.get_string_from_ascii()
if serverip != '' and port > 0:
if serverip in found_servers:
update_server.emit(found_servers.find(serverip), serverip, message)
else:
new_server.emit(serverip, message)
found_servers.append(serverip)
else:
push_warning("Bad packet", message)
1 Like