Small changes

This commit is contained in:
EntenKoeniq
2022-03-30 16:14:25 +02:00
parent 7d2e3705ea
commit 0051504684
2 changed files with 21 additions and 11 deletions

View File

@ -123,28 +123,31 @@ namespace CoopClient
internal class ScriptContext
{
#region DELEGATES
// We currently have a bug here
// We can't use delegates with ClearScript without granting access, but how do we do that?
public delegate void EmptyEvent();
public delegate void PlayerConnectEvent(string username, long nethandle, string reason);
public delegate void ChatMessageEvent(string from, string message);
#endregion
#region EVENTS
public event EventHandler OnStart, OnStop, OnTick;
public event EmptyEvent OnStart, OnStop, OnTick;
public event PlayerConnectEvent OnPlayerConnect, OnPlayerDisconnect;
public event ChatMessageEvent OnChatMessage;
internal void InvokeStart()
{
OnStart?.Invoke(this, EventArgs.Empty);
OnStart?.Invoke();
}
internal void InvokeStop()
{
OnStop?.Invoke(this, EventArgs.Empty);
OnStop?.Invoke();
}
internal void InvokeTick()
{
OnTick?.Invoke(this, EventArgs.Empty);
OnTick?.Invoke();
}
internal void InvokePlayerConnect(string username, long nethandle)
@ -172,5 +175,10 @@ namespace CoopClient
{
return Main.MainSettings.Username;
}
public long GetLocalNetHandle()
{
return Main.LocalNetHandle;
}
}
}

View File

@ -13,7 +13,7 @@ namespace CoopClient
Custom
}
public static void Write(string message, LogLevel level = LogLevel.Normal, string filepath = null)
private static string GetFilePath(LogLevel level, string filepath)
{
string newFilePath = null;
@ -35,6 +35,13 @@ namespace CoopClient
break;
}
return newFilePath;
}
public static void Write(string message, LogLevel level = LogLevel.Normal, string filepath = null)
{
string newFilePath = GetFilePath(level, filepath);
try
{
if (File.Exists(newFilePath))
@ -53,7 +60,7 @@ namespace CoopClient
using (StreamWriter sw = new StreamWriter(newFilePath, true))
{
Log(message, sw);
sw.WriteLine($"[{DateTime.Now.ToLongTimeString()} {DateTime.Now.ToLongDateString()}] : {message}");
sw.Flush();
sw.Close();
@ -62,10 +69,5 @@ namespace CoopClient
catch
{ }
}
private static void Log(string message, TextWriter writer)
{
writer.WriteLine($"[{DateTime.Now.ToLongTimeString()} {DateTime.Now.ToLongDateString()}] : {message}");
}
}
}