Supermike online players ip list output

11/15/2018 12:34 dooq#1
Hello,

I want to list the ip addresses of all connected players. I have edited the "WhoIsOnline()" function in the project. The output after the cycle does not work. AgentContext and AgentContext2 edited same function.

The program does not output when it is on for a long time. The first openings can be output.

Code:
static void ConsolePoolThread(){
...
if (cmd.Contains("/whos"))
{
    AgentContext.WhosOnline();
    if ((!FilterMain.AGENT_IP2.Equals("0")) && (FilterMain.AGENT_IP2 != String.Empty))
        AgentContext2.WhosOnline();
}
...
}
public static void WhosOnline()
{
    lock (locker) {
        try
        {
            string clipboard_data = "AGENT\r\nUSERID\tCHARNAME\tIP\r\n";
            int count = 0;
            foreach (AgentContext current in clientlistgame)
            {
                if (current.m_ClientSocket.Connected)
                {
                    Console.WriteLine("Method 1: " + current.user_id + " is online! IP: " + current.ip);
                }

                if (current.m_ClientSocket.Connected && current.m_ModuleSocket.Connected)
                {
                    Console.WriteLine("Method 2: " + current.user_id + " is online! IP: " + current.ip);
                }
                clipboard_data += current.user_id + "\t" + current.charname + "\t" + current.ip+"\r\n";
                count++;
            }
            Console.WriteLine("Total agent count: " + count);
            var rand = new Random();
            var _rand = rand.Next(99999);
            Program.OutputFile("iplog_" + string.Concat(DateTime.Now.ToString("yyyyMMddHHmmss")) + "_" + _rand + "_agent.txt", clipboard_data);
        }
        catch { }
    }
}
Output Function
11/15/2018 22:48 #HB#2
You can do something better for your Output function:
Code:
public static void OutputFile(string filename, string content)
        {
            try
            {
                System.IO.StreamWriter log = new System.IO.StreamWriter(filename, true);
                log.WriteLine(content);
                log.Close();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Output error. Error:" + e.Message);
                Console.ResetColor();
            }
        }
11/18/2018 17:13 B1Q#3
[Only registered and activated users can see links. Click Here To Register...]

use this one liner for the output function

Quote:
Originally Posted by #HB View Post
You can do something better for your Output function:
Code:
public static void OutputFile(string filename, string content)
        {
            try
            {
                System.IO.StreamWriter log = new System.IO.StreamWriter(filename, true);
                log.WriteLine(content *+ Environment.NewLine*);
                log.Close();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Output error. Error:" + e.Message);
                Console.ResetColor();
            }
        }
The WriteLine methods append a newline "\r\n" at each call