https://github.com/justmavi/sampquery
Library for sending queries to SAMP servers
https://github.com/justmavi/sampquery
csharp samp sampapi sampquery
Last synced: 6 months ago
JSON representation
Library for sending queries to SAMP servers
- Host: GitHub
- URL: https://github.com/justmavi/sampquery
- Owner: justmavi
- License: mit
- Created: 2020-11-18T00:28:26.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-11-22T19:32:53.000Z (7 months ago)
- Last Synced: 2025-11-22T21:07:57.768Z (7 months ago)
- Topics: csharp, samp, sampapi, sampquery
- Language: C#
- Homepage: https://www.nuget.org/packages/SAMPQuery/
- Size: 439 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/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
- [SAMPQuery](#sampquery)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Usage](#usage)
- [Documentation](#documentation)
- [Constructor](#constructor)
- [GetServerInfoAsync](#getserverinfoasync)
- [GetServerRulesAsync](#getserverrulesasync)
- [GetServerPlayersAsync](#getserverplayersasync)
- [SendRconCommandAsync](#sendrconcommandasync)
- [ServerInfo](#serverinfo)
- [ServerRules](#serverrules)
- [ServerPlayer](#serverplayer)
- [Gratitude](#gratitude)
- [Stay in touch](#stay-in-touch)
## Installation
Package manager
```nuget
Install-Package SAMPQuery -Version 1.1.1
```
Terminal
```shell
$ dotnet add package SAMPQuery --version 1.1.1
```
Package Reference
```xml
```
Clone repository
```shell
$ git clone https://github.com/justmavi/sampquery.git
```
## Usage
```csharp
var server = new SampQuery("localhost", 7777);
ServerInfo serverInfo = await server.GetServerInfoAsync();
ServerRules serverRules = await server.GetServerRulesAsync();
IEnumerable 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
```csharp
var server = new SampQuery("127.0.0.1", 7777);
```
The constructor also has overloads
```csharp
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
```csharp
var server = new SampQuery("localhost", 7777);
```
### GetServerInfoAsync
Asynchronously requests basic information about the server
```csharp
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
```csharp
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)
```csharp
var server = new SampQuery("127.0.0.1", 7777);
IEnumerable 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
```csharp
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](https://www.linkedin.com/in/grishpoghosyan)