Fixed Player List Logger and added config section for it.

This commit is contained in:
Milutinke 2022-09-25 22:06:26 +02:00
parent 8809ad41d8
commit 697025040f
3 changed files with 35 additions and 12 deletions

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Net.Mime.MediaTypeNames;
namespace MinecraftClient.ChatBots
{
@ -34,19 +35,26 @@ namespace MinecraftClient.ChatBots
count++;
if (count == timeping)
{
SendText("/list");
count = 0;
}
string[] playerList = GetOnlinePlayers();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < playerList.Length; i++)
{
sb.Append(playerList[i]);
// Do not add a comma after the last username
if (i != playerList.Length - 1)
sb.Append(", ");
}
public override void GetText(string text)
{
if (text.Contains("Joueurs en ligne") || text.Contains("Connected:") || text.Contains("online:"))
{
LogToConsole("Saving Player List");
LogDebugToConsole("Saving Player List");
DateTime now = DateTime.Now;
string TimeStamp = "[" + now.Year + '/' + now.Month + '/' + now.Day + ' ' + now.Hour + ':' + now.Minute + ']';
System.IO.File.AppendAllText(file, TimeStamp + "\n" + GetVerbatim(text) + "\n\n");
System.IO.File.AppendAllText(file, TimeStamp + "\n" + sb.ToString() + "\n\n");
count = 0;
}
}
}

View file

@ -276,3 +276,8 @@ backupinterval=300 # How long should replay file be auto-saved, i
enabled=false
update_limit=10 # The rate at which the bot does calculations (10 = 1s) (Default: 5) (You can tweak this if you feel the bot is too slow)
stop_at_distance=3 # Do not follow the player if he is in the range of 3 blocks (prevents the bot from pushing a player in an infinite loop)
[PlayerListLogger]
enabled=false
log_file=playerlog.txt
log_delay=600 # 10 = 1s

View file

@ -10,6 +10,8 @@ using MinecraftClient.Mapping;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using MinecraftClient.ChatBots;
using System.Diagnostics.CodeAnalysis;
namespace MinecraftClient
{
@ -256,7 +258,7 @@ namespace MinecraftClient
private static string ServerAliasTemp = null;
//Mapping for settings sections in the INI file
private enum Section { Default, Main, AppVars, Proxy, MCSettings, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl, ChatFormat, AutoRespond, AutoAttack, AutoFishing, AutoEat, AutoCraft, AutoDrop, Mailer, ReplayMod, FollowPlayer, Logging, Signature };
private enum Section { Default, Main, AppVars, Proxy, MCSettings, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl, ChatFormat, AutoRespond, AutoAttack, AutoFishing, AutoEat, AutoCraft, AutoDrop, Mailer, ReplayMod, FollowPlayer, PlayerListLogger, Logging, Signature };
/// <summary>
/// Get settings section from name
@ -854,6 +856,14 @@ namespace MinecraftClient
case "stop_at_distance": FollowPlayer_StopAtDistance = str2int(argValue); return true;
}
break;
case Section.PlayerListLogger:
switch (ToLowerIfNeed(argName))
{
case "enabled": PlayerLog_Enabled = str2bool(argValue); return true;
case "log_file": PlayerLog_File = argValue; return true;
case "log_delay": PlayerLog_Delay = str2int(argValue); return true;
}
break;
}
return false;
}