openmultiplayer_query

Crates.ioopenmultiplayer_query
lib.rsopenmultiplayer_query
version0.1.2
sourcesrc
created_at2023-11-30 23:15:40.95758
updated_at2023-12-02 12:16:16.087279
descriptionImplements the needed builders and parsers for SA:MP's/Open Multiplayer's Query Mechanism, allowing a developer to retrieve data from a running server.
homepage
repository
max_upload_size
id1054578
size20,780
Carlos Menezes (carlos-menezes)

documentation

README

openmultiplayer-query

ci workflow Crates.io

Implements the needed builders and parsers for SA:MP's/Open Multiplayer's Query Mechanism, allowing a developer to retrieve data from a running server.

You cannot send RCON packets yet.

Installation

cargo add openmultiplayer_query

Examples

Check test/build.rs and test/parse.rs to see how to use the library.

Building

let mut packet = PacketBuilder::new(Opcode::I, Ipv4Addr::new(127, 0, 0, 1), 7777)?;
let mut rcon_packet = RconPacket::new(Ipv4Addr::new(127, 0, 0, 1), 7777, "changeme", "varlist")?;

Parsing

use openmultiplayer_query::{Packet, Opcodes};

// Assume you have a UDP socket running
let socket = UdpSocket::bind("0.0.0.0:0")?;

// We'll send a packet to `149.56.84.18:7777`
let address: Ipv4Addr = "149.56.84.18".parse::<Ipv4Addr>().unwrap();
let port = 7777;

let mut packet = PacketBuilder::new(Opcodes::I, address, port)?;
// ...
packet.build()?; // This is needed in order to populate the data buffer with query data.

// Send the packet through the socket.
socket.send_to(packet.get_data().unwrap(), (address, port))?;
let mut recv_buf = [0u8; 2048];
socket.recv(&mut recv_buf)?;
let result: Result<Packet::InformationPacket, _> = (&recv_buf[..]).try_into();
// Use `result` as you please
Commit count: 0

cargo fmt