mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
ScriptScheduler: Add debug messages for issue #431
These messages will only apprear if debugmessages=true in config.
This commit is contained in:
parent
18fd24d2d5
commit
79aaa04775
4 changed files with 63 additions and 9 deletions
|
|
@ -6,6 +6,7 @@ using System.Threading;
|
||||||
using Microsoft.CSharp;
|
using Microsoft.CSharp;
|
||||||
using System.CodeDom.Compiler;
|
using System.CodeDom.Compiler;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace MinecraftClient.ChatBots
|
namespace MinecraftClient.ChatBots
|
||||||
{
|
{
|
||||||
|
|
@ -108,6 +109,20 @@ namespace MinecraftClient.ChatBots
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
{
|
||||||
|
string caller = "Script";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StackFrame frame = new StackFrame(1);
|
||||||
|
MethodBase method = frame.GetMethod();
|
||||||
|
Type type = method.DeclaringType;
|
||||||
|
caller = type.Name;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
ConsoleIO.WriteLineFormatted(String.Format("§8[MCC] [{0}] Cannot find script file: {1}", caller, filename));
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ namespace MinecraftClient.ChatBots
|
||||||
//Load the given file from the startup parameters
|
//Load the given file from the startup parameters
|
||||||
if (System.IO.File.Exists(tasksfile))
|
if (System.IO.File.Exists(tasksfile))
|
||||||
{
|
{
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
LogToConsole("Loading tasks from '" + tasksfile + "'");
|
||||||
TaskDesc current_task = null;
|
TaskDesc current_task = null;
|
||||||
String[] lines = System.IO.File.ReadAllLines(tasksfile);
|
String[] lines = System.IO.File.ReadAllLines(tasksfile);
|
||||||
foreach (string lineRAW in lines)
|
foreach (string lineRAW in lines)
|
||||||
|
|
@ -95,14 +97,27 @@ namespace MinecraftClient.ChatBots
|
||||||
if (current_task != null)
|
if (current_task != null)
|
||||||
{
|
{
|
||||||
//Check if we built a valid task before adding it
|
//Check if we built a valid task before adding it
|
||||||
if (current_task.script_file != null && Script.LookForScript(ref current_task.script_file) //Check if file exists
|
if (Script.LookForScript(ref current_task.script_file)) //Check if file exists
|
||||||
&& (current_task.triggerOnLogin
|
|
||||||
|| current_task.triggerOnFirstLogin
|
|
||||||
|| (current_task.triggerOnTime && current_task.triggerOnTime_Times.Count > 0))
|
|
||||||
|| (current_task.triggerOnInterval && current_task.triggerOnInterval_Interval > 0)) //Look for a valid trigger
|
|
||||||
{
|
{
|
||||||
current_task.triggerOnInterval_Interval_Countdown = current_task.triggerOnInterval_Interval; //Init countdown for interval
|
if (current_task.script_file != null
|
||||||
tasks.Add(current_task);
|
&& (current_task.triggerOnLogin
|
||||||
|
|| current_task.triggerOnFirstLogin
|
||||||
|
|| (current_task.triggerOnTime && current_task.triggerOnTime_Times.Count > 0))
|
||||||
|
|| (current_task.triggerOnInterval && current_task.triggerOnInterval_Interval > 0)) //Look for a valid trigger
|
||||||
|
{
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
LogToConsole("Loaded task:\n" + Task2String(current_task));
|
||||||
|
current_task.triggerOnInterval_Interval_Countdown = current_task.triggerOnInterval_Interval; //Init countdown for interval
|
||||||
|
tasks.Add(current_task);
|
||||||
|
}
|
||||||
|
else if (Settings.DebugMessages)
|
||||||
|
{
|
||||||
|
LogToConsole("This task will never trigger:\n" + Task2String(current_task));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Settings.DebugMessages)
|
||||||
|
{
|
||||||
|
LogToConsole("No valid script for task:\n" + Task2String(current_task));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -128,6 +143,8 @@ namespace MinecraftClient.ChatBots
|
||||||
if (!task.triggerOnTime_alreadyTriggered)
|
if (!task.triggerOnTime_alreadyTriggered)
|
||||||
{
|
{
|
||||||
task.triggerOnTime_alreadyTriggered = true;
|
task.triggerOnTime_alreadyTriggered = true;
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
LogToConsole("Time / Running script: " + task.script_file);
|
||||||
RunScript(task.script_file);
|
RunScript(task.script_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,6 +159,8 @@ namespace MinecraftClient.ChatBots
|
||||||
if (task.triggerOnInterval_Interval_Countdown == 0)
|
if (task.triggerOnInterval_Interval_Countdown == 0)
|
||||||
{
|
{
|
||||||
task.triggerOnInterval_Interval_Countdown = task.triggerOnInterval_Interval;
|
task.triggerOnInterval_Interval_Countdown = task.triggerOnInterval_Interval;
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
LogToConsole("Interval / Running script: " + task.script_file);
|
||||||
RunScript(task.script_file);
|
RunScript(task.script_file);
|
||||||
}
|
}
|
||||||
else task.triggerOnInterval_Interval_Countdown--;
|
else task.triggerOnInterval_Interval_Countdown--;
|
||||||
|
|
@ -153,7 +172,11 @@ namespace MinecraftClient.ChatBots
|
||||||
foreach (TaskDesc task in tasks)
|
foreach (TaskDesc task in tasks)
|
||||||
{
|
{
|
||||||
if (task.triggerOnLogin || (firstlogin_done == false && task.triggerOnFirstLogin))
|
if (task.triggerOnLogin || (firstlogin_done == false && task.triggerOnFirstLogin))
|
||||||
|
{
|
||||||
|
if (Settings.DebugMessages)
|
||||||
|
LogToConsole("Login / Running script: " + task.script_file);
|
||||||
RunScript(task.script_file);
|
RunScript(task.script_file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
firstlogin_done = true;
|
firstlogin_done = true;
|
||||||
|
|
@ -162,5 +185,20 @@ namespace MinecraftClient.ChatBots
|
||||||
}
|
}
|
||||||
else verifytasks_timeleft--;
|
else verifytasks_timeleft--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string Task2String(TaskDesc task)
|
||||||
|
{
|
||||||
|
return String.Format(
|
||||||
|
"triggeronfirstlogin = {0}\n triggeronlogin = {1}\n triggerontime = {2}\n "
|
||||||
|
+ "triggeroninterval = {3}\n timevalue = {4}\n timeinterval = {5}\n script = {6}",
|
||||||
|
task.triggerOnFirstLogin,
|
||||||
|
task.triggerOnLogin,
|
||||||
|
task.triggerOnTime,
|
||||||
|
task.triggerOnInterval,
|
||||||
|
String.Join(", ", task.triggerOnTime_Times),
|
||||||
|
task.triggerOnInterval_Interval,
|
||||||
|
task.script_file
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,11 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
if (IsPrivateMessage(text, ref message, ref username))
|
if (IsPrivateMessage(text, ref message, ref username))
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLine("Bot: " + username + " told me : " + message);
|
LogToConsole("Bot: " + username + " told me : " + message);
|
||||||
}
|
}
|
||||||
else if (IsChatMessage(text, ref message, ref username))
|
else if (IsChatMessage(text, ref message, ref username))
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLine("Bot: " + username + " said : " + message);
|
LogToConsole("Bot: " + username + " said : " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,7 @@ namespace MinecraftClient.Protocol.SessionCache
|
||||||
{
|
{
|
||||||
List<string> sessionCacheLines = new List<string>();
|
List<string> sessionCacheLines = new List<string>();
|
||||||
sessionCacheLines.Add("# Generated by MCC v" + Program.Version + " - Edit at own risk!");
|
sessionCacheLines.Add("# Generated by MCC v" + Program.Version + " - Edit at own risk!");
|
||||||
|
sessionCacheLines.Add("# Login=SessionID,PlayerName,UUID,ClientID");
|
||||||
foreach (KeyValuePair<string, SessionToken> entry in sessions)
|
foreach (KeyValuePair<string, SessionToken> entry in sessions)
|
||||||
sessionCacheLines.Add(entry.Key + '=' + entry.Value.ToString());
|
sessionCacheLines.Add(entry.Key + '=' + entry.Value.ToString());
|
||||||
File.WriteAllLines(SessionCacheFilePlaintext, sessionCacheLines);
|
File.WriteAllLines(SessionCacheFilePlaintext, sessionCacheLines);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue