1 Minetest-c55 protocol (incomplete, early draft):
4 A custom protocol over UDP.
5 Integers are big endian.
6 Refer to connection.{h,cpp} for further reference.
9 - A dummy reliable packet with peer_id=PEER_ID_INEXISTENT=0 is sent to the server:
10 - Actually this can be sent without the reliable packet header, too, i guess,
11 but the sequence number in the header allows the sender to re-send the
12 packet without accidentally getting a double initialization.
15 u32 protocol_id = PROTOCOL_ID = 0x4f457403
16 u16 sender_peer_id = PEER_ID_INEXISTENT = 0
18 # Reliable packet header
19 u8 type = TYPE_RELIABLE = 3
20 u16 seqnum = SEQNUM_INITIAL = 65500
21 # Original packet header
22 u8 type = TYPE_ORIGINAL = 1
23 # And no actual payload.
24 - Server responds with something like this:
27 u32 protocol_id = PROTOCOL_ID = 0x4f457403
28 u16 sender_peer_id = PEER_ID_INEXISTENT = 0
30 # Reliable packet header
31 u8 type = TYPE_RELIABLE = 3
32 u16 seqnum = SEQNUM_INITIAL = 65500
33 # Control packet header
34 u8 type = TYPE_CONTROL = 0
35 u8 controltype = CONTROLTYPE_SET_PEER_ID = 1
36 u16 peer_id_new = assigned peer id to client (other than 0 or 1)
37 - Then the connection can be disconnected by sending:
40 u32 protocol_id = PROTOCOL_ID = 0x4f457403
41 u16 sender_peer_id = whatever was gotten in CONTROLTYPE_SET_PEER_ID
43 # Control packet header
44 u8 type = TYPE_CONTROL = 0
45 u8 controltype = CONTROLTYPE_DISCO = 3
47 - Here's a quick untested connect-disconnect done in PHP:
48 # host: ip of server (use gethostbyname(hostname) to get from a dns name)
49 # port: port of server
50 function check_if_minetestserver_up($host, $port)
52 $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
53 $timeout = array("sec" => 1, "usec" => 0);
54 socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $timeout);
55 $buf = "\x4f\x45\x74\x03\x00\x00\x00\x03\xff\xdc\x01";
56 socket_sendto($socket, $buf, strlen($buf), 0, $host, $port);
57 $buf = socket_read($socket, 1000);
60 # We got a reply! read the peer id from it.
61 $peer_id = substr($buf, 9, 2);
64 $buf = "\x4f\x45\x74\x03".$peer_id."\x00\x00\x03";
65 socket_sendto($socket, $buf, strlen($buf), 0, $host, $port);
66 socket_close($socket);