README.md
SAMPQuery
SAMPQuery is a library that allows you to query SAMP servers for information about it and execute RCON commands. It includes encoding correction, hostname resolution, asynchronous calls and much more.
Table of Contents
Installation
Package manager
Install-Package SAMPQuery -Version 1.1.1
Terminal
$ dotnet add package SAMPQuery --version 1.1.1
Package Reference
<PackageReference Include="SAMPQuery" Version="1.1.1" />
Clone repository
$ git clone https://github.com/justmavi/sampquery.git
Usage
var server = new SampQuery("localhost", 7777);
ServerInfo serverInfo = await server.GetServerInfoAsync();
ServerRules serverRules = await server.GetServerRulesAsync();
IEnumerable<ServerPlayer> serverPlayers = await server.GetServerPlayersAsync();
Console.WriteLine($"Welcome to ${serverInfo.HostName}! Mapname: ${serverRules.MapName}");
Console.WriteLine("Players online:");
serverPlayers.ToList().ForEach(player => Console.WriteLine(player.PlayerName));
Documentation
Constructor
var server = new SampQuery("127.0.0.1", 7777);
The constructor also has overloads
SampQuery(IPAddress ip, ushort port)
SampQuery(string ip, ushort port, string password)
SampQuery(IPAddress ip, ushort port, string password)
SampQuery(IPAddress ip) // will be used default 7777 port
SampQuery(string ip) // will be used default 7777 port or you can use "HOST:PORT" string
Hostname is also allowed
var server = new SampQuery("localhost", 7777);
GetServerInfoAsync
Asynchronously requests basic information about the server
var server = new SampQuery("127.0.0.1", 7777);
ServerInfo data = await server.GetServerInfoAsync();
Console.WriteLine($"Server {data.HostName}. Online: {data.Players}/{data.MaxPlayers}");
GetServerRulesAsync
Asynchronously requests the rules, set by the server
var server = new SampQuery("127.0.0.1", 7777);
ServerInfo data = await server.GetServerRulesAsync();
Console.WriteLine($"Lagcomp {(data.Lagcomp ? "On" : "Off")}. Map: {data.MapName}. SAMPCAC: {data.SAMPCAC_Version ?? "Isn't required"}");
The maximum value of the player ID is 255. Two-byte identifiers are not supported here (SA-MP limit).
GetServerPlayersAsync
Asynchronously requests players online with detailed information (works up to 100 online, SA-MP limit)
var server = new SampQuery("127.0.0.1", 7777);
IEnumerable<ServerPlayer> players = await server.GetServerPlayersAsync();
Console.WriteLine("ID | Nick | Score | Ping\n");
foreach(ServerPlayer player in players)
{
Console.WriteLine($"{player.PlayerId} | {player.PlayerName} | {player.PlayerScore} | {player.PlayerPing}");
}
The maximum value of the player ID is 255. Two-byte identifiers are not supported here (SA-MP limit).
SendRconCommandAsync
Asynchronously executes RCON command
var server = new SampQuery("127.0.0.1", 7777, "helloworld");
string answer = await sampQuery.SendRconCommandAsync("varlist");
Console.WriteLine($"Server says: {answer}");
ServerInfo
A class representing information about the server. Properties:
- HostName
- GameMode
- Language
- Players
- MaxPlayers
- Password
- ServerPing
ServerRules
A class representing server rules. Properties:
- Lagcomp
- MapName
- Version
- SAMPCAC_Version
- Weather
- Weburl
- WorldTime
- Gravity
ServerPlayer
A class representing information about the player. Properties:
- PlayerId
- PlayerName
- PlayerScore
- PlayerPing
Gratitude
- Separate gratitude to @continue98 for fixing bugs
Stay in touch
- Author - Grish Poghosyan
Страница собрана из того, что GitHub публикует о репозитории. samp.directory не хранит этот код. Сообщить о проблеме с этой записью