This project is read-only.

Listening to logs

Feb 4, 2015 at 3:09 PM
Edited Feb 4, 2015 at 3:10 PM
I'm trying to subscribe to chat events, however I'm having some issues.

Is the following local port supposed to be defined anywhere else or is it just for the purpose of the program?

Logs logs = server.GetLogs(<local port>);

Also, does it require any configuration server side other than ensuring logging is enabled?
Feb 4, 2015 at 6:54 PM
Hi Meekel,
You need to do few things before subscribing to any event

1.Enable logging on server side

2.Add your ip-address to server's log address list
you can directly add it to server using log_address command
or use Querymaster
Rcon rcon = server.GetControl("<rcon password>");
if (rcon != null)
     rcon.AddlogAddress("<ip>",<port>); 
3.Now you can subscribe to any event of your choice
eg:-listen to chat
Logs logs = server.GetLogs(<port>);//the port number which you added to server's log list
logs.Say += new EventHandler<ChatEventArgs>(logs_Say);

static void logs_Say(object sender, ChatEventArgs e)
{
            Console.WriteLine("Sender :");
            Console.WriteLine("\tName : " + e.Player.Name);
            Console.WriteLine("\tUid : " + e.Player.Uid);
            Console.WriteLine("\tWonid : " + e.Player.WonId);
            Console.WriteLine("\tTeam : " + e.Player.Team);
            Console.WriteLine("Message : " + e.Message);
            Console.WriteLine("Timestamp : " + e.Timestamp);
}
Feb 15, 2015 at 12:13 AM
Could someone point me in the right direction on how to have my application just continuously echo back the server logs? I am incorporating the DLLs into a C# Console Application and I guess I am not familiar with how you have an application not run code and exit, but rather, continue to listen to the logs and echo back?
Feb 17, 2015 at 5:17 PM
hi worktech,
Its not the fault of the dll.
Add Console.Read() at the end to keep the console window open.
Feb 17, 2015 at 10:05 PM
When you use console.read() does the program not stop executing other code until you complete the read operation?

The following code does not echo any server logs, but it does correctly output the name of the map:
class Program
{
    static void Main(string[] args)
    {
        Server server = ServerQuery.GetServerInstance(EngineType.GoldSource, "MyGameServerIP", 27025);
        ServerInfo info = server.GetInfo();
        Console.WriteLine(info.Map);
        //Console.ReadKey();

        Rcon rcon = server.GetControl("myPW");
        if(rcon != null) rcon.AddlogAddress("myIP", 7131);

        Logs logs = server.GetLogs(7131);

        logs.Say += new EventHandler<ChatEventArgs>(logs_Say);
        logs.Listen(LogListener);

        Console.Read();

        //server.Dispose();
    }

    static void LogListener(string logMsg)
    {
        Console.WriteLine(logMsg);
    }

    static void logs_Say(object sender, ChatEventArgs e)
    {
        Console.WriteLine("Sender :");
        Console.WriteLine("\tName : " + e.Player.Name);
        Console.WriteLine("\tUid : " + e.Player.Uid);
        Console.WriteLine("\tWonid : " + e.Player.WonId);
        Console.WriteLine("\tTeam : " + e.Player.Team);
        Console.WriteLine("Message : " + e.Message);
        Console.WriteLine("Timestamp : " + e.Timestamp);
    }
}
Feb 19, 2015 at 8:26 PM
It should work.
you sure you entered right rcon password and server logging is turned on?
if you are behind a router, do port forwarding.
Logging occurs only during game events mentioned here and also during some events introduced by custom mods like Amxmodx