SAMPQuery 1.1.1

dotnet add package SAMPQuery --version 1.1.1
NuGet\Install-Package SAMPQuery -Version 1.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SAMPQuery" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SAMPQuery --version 1.1.1
#r "nuget: SAMPQuery, 1.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SAMPQuery as a Cake Addin
#addin nuget:?package=SAMPQuery&version=1.1.1

// Install SAMPQuery as a Cake Tool
#tool nuget:?package=SAMPQuery&version=1.1.1

NuGet version (SAMPQuery)

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.0

Terminal

$ dotnet add package SAMPQuery --version 1.1.0

Package Reference

<PackageReference Include="SAMPQuery" Version="1.1.0" />

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);

GetServerInfo

Requests basic information about the server

var server = new SampQuery("127.0.0.1", 7777);
ServerInfo data =  server.GetServerInfo();

Console.WriteLine($"Server {data.HostName}. Online: {data.Players}/{data.MaxPlayers}");

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}");

GetServerRules

Requests the rules, set by the server

var server = new SampQuery("127.0.0.1", 7777);
ServerInfo data = server.GetServerRules();

Console.WriteLine($"Lagcomp {(data.Lagcomp ? "On" : "Off")}. Map: {data.MapName}. SAMPCAC: {data.SAMPCAC_Version ?? "Isn't required"}");

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"}");

GetServerPlayers

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 = server.GetServerPlayers();

 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).

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).

SendRconCommand

Executes RCON command

 var server = new SampQuery("127.0.0.1", 7777, "helloworld");
 string answer = sampQuery.SendRconCommand("varlist");

 Console.WriteLine($"Server says: {answer}");

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

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 172 10/14/2023
1.1.0 228 4/20/2023
1.0.2 483 7/21/2022
1.0.1 423 3/23/2022
1.0.0 406 3/20/2022