Skip to content

BenBout/SampQueryService

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAMP Asynchronous Query Service License

A simple client service to query SA-MP servers. www.sa-mp.com.

Supported platforms

Nuget

Installing

  • To install Pastebin.cs, run the following command in the Package Manager Console

    PM> Install-Package SampQueryService

Sample

static async Task SimpleQuery()
{
    var serverIP = IPAddress.Parse("151.80.94.179");
    int port = 7777;

    var sampQuery = new SampQueryClient();
    var playerList = await sampQuery.SendQueryAsync<PlayerList>(serverIP, port);


    // IsCompletedProperty returns false when 
    // query timeout or playerlist is upper 100.
    // http://wiki.sa-mp.com/wiki/Query_Mechanism
    if (playerList.IsCompleted)
    {
        var filteredPlayerList = playerList.Players
        .Where(p => p.Level > 5)
        .OrderByDescending(p => p.Level);

        foreach (var player in filteredPlayerList)
            Console.WriteLine($"ID: {player.ID} Username: {player.UserName} Ping: {player.ping}");
    }
}

static async Task MultipleQueriesWithSameQueryResultType()
{
    var ipEndList = new List<IPEndPoint>(); // we suppose a list of 10 ipendpoint.
    var serverInfoList = await  new SampQueryClient().SendQueryAsync<ServerInfo>(ipEndList);

    foreach (var server in serverInfoList)
    {
        if(server.IsCompleted)
            Console.WriteLine($"Server name: {server.HostName}");
    }
}

About

A simple client service to query SA-MP servers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages