Skip to content

rocklan/zanstat

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zanstat - .NET code for querying Zandronum servers

This repository provides a Nuget package and a command line console application for querying Zandronum using the Launcher Protocol and also using the RCon protocol.

Example Console Usage

Using this library it is very possible to build a discord bot (currently a work in progress):

Example Discord Bot

Console Application

Usage:

zanstat <-server hostname:port> <-rcon RConServerPassword> [command]

where [command] is one of:

   -getname       Print server name
   -getmapname    Print current map name
   -getmaxplayers Print max players  
   -getpwads      Print pwads in use  
   -getiwad       Print iwad in use  
   -getskill      Print skill setting  
   -getlimits     Print various server limits  
   -getplayers    Print players currently on the server  
   -getteams      Print teams  

Notes:

  • If -server is not supplied then it will default to localhost and port 10666
  • If -rcon is supplied then no command is needed. It will go into interactive mode where you can pass through any command you wish.
  • -getteams doesn't currently work! My server returns no data for this command.
  • For commands, you may only query the server every sv_queryignoretime seconds. If you query too frequently, the server will return an error code and the library will throw an exception.

Nuget Package

To use, instantiate the Zandronum class and pass through the server URL and port:

var zandronum = new Rocklan.Zanstat.Zandronum("example.com", 10666);

Once instantiated you can then query the server for information like Server Name, Current Map, current Players, etc:

var mapName = _zandronum.MapName.Get();
var players = zandronum.Players.Get();

Console.WriteLine($"Players current on map: {mapName}");

foreach (var player in players)
{
    Console.WriteLine($"  {player}");
}

You can also connect to the server using RCon and it will raise events whenever the server raises events:

class MyCode
{
   function ConnectToZandronumServer()
   {
       var zandronum = new Rocklan.Zanstat.Zandronum("example.com", 10666);
       
       zandronum.Rcon.ServerMessage += Rcon_ServerMessage;
       zandronum.Rcon.ConnectToRcon("ThisIsMyRconPassword");

       Console.WriteLine("Listening to server messages, press enter to quit...");
       Console.ReadLine();
   }

   private void Rcon_ServerMessage(object sender, EventArgs e)
   {
       string message = (e as ZandronumMessageEventArgs).Message;
       
       // Messages from the server have a newline appended, and they also 
       // have color coding embedded. You might want to filter out \\c- from the message
       
       Console.Write(message);
   }
}

If you'd like to send message to the server you can do so using the SendCommand() function:

// return the list of maps
_zandronum.Rcon.SendCommand("ListMaps");
   
// change to map03:
_zandronum.Rcon.SendCommand("MAP MAP03");

Dev Notes

Many, many thanks go to legend Sam Izzo for doing 99% of the work - porting (and improving) the Java Huffman encoder, the UDP launcher code, and helping me get the RCon stuff working.

Beware, this library is using UDP, not TCP! UDP is a strange, weird world, brace yourself.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%