Broadcast and SendLog to server console as well
Removed writing of log message to console
This commit is contained in:
parent
43ecc064bd
commit
42905f2317
3 changed files with 28 additions and 49 deletions
|
|
@ -58,54 +58,16 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
private static void Write(String message, LogLevel level)
|
||||
{
|
||||
StackTrace trace = new StackTrace();
|
||||
StackFrame frame = null;
|
||||
|
||||
frame = trace.GetFrame(2);
|
||||
|
||||
string caller = "TShock: ";
|
||||
|
||||
/*if (frame != null && frame.GetMethod().DeclaringType != null)
|
||||
{
|
||||
caller = frame.GetMethod().DeclaringType.Name + ": ";
|
||||
}*/
|
||||
|
||||
switch (level)
|
||||
{
|
||||
case LogLevel.Debug:
|
||||
message = "DEBUG: " + message;
|
||||
break;
|
||||
case LogLevel.Info:
|
||||
message = "INFO: " + message;
|
||||
break;
|
||||
case LogLevel.Warning:
|
||||
message = "WARNING: " + message;
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
message = "ERROR: " + message;
|
||||
break;
|
||||
}
|
||||
|
||||
/*try
|
||||
{
|
||||
_logWriter = new StreamWriter(_filename, true);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
_logWriter = new StreamWriter(_filename + "." + Process.GetCurrentProcess().Id.ToString(), true);
|
||||
}*/
|
||||
|
||||
String text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + " - " + caller +
|
||||
message;
|
||||
|
||||
Console.WriteLine(text);
|
||||
|
||||
if (!MayWriteType(level))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logWriter.WriteLine(text);
|
||||
string caller = "TShock";
|
||||
|
||||
_logWriter.WriteLine(string.Format("{0} - {1}: {2}: {3}",
|
||||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
caller, level.ToString().ToUpper(), message));
|
||||
_logWriter.Flush();
|
||||
}
|
||||
|
||||
|
|
@ -160,11 +122,6 @@ namespace TShockAPI
|
|||
/// <param name="message">The message to be written.</param>
|
||||
public static void Debug(String message)
|
||||
{
|
||||
if (!MayWriteType(LogLevel.Debug))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Write(message, LogLevel.Debug);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ namespace TShockAPI
|
|||
}
|
||||
string version = string.Format("TShock Version {0} ({1}) now running.", Version, VersionCodename);
|
||||
Console.WriteLine(version);
|
||||
|
||||
Log.Initialize(Path.Combine(SavePath, "log.txt"), LogLevel.All, false);
|
||||
Log.Info(version);
|
||||
Log.Info("Starting...");
|
||||
|
|
@ -157,16 +158,18 @@ namespace TShockAPI
|
|||
GameHooks.Update += OnUpdate;
|
||||
ServerHooks.Chat += OnChat;
|
||||
ServerHooks.Join += OnJoin;
|
||||
ServerHooks.Leave += OnLeave;
|
||||
NetHooks.GetData += GetData;
|
||||
NetHooks.GreetPlayer += OnGreetPlayer;
|
||||
NpcHooks.StrikeNpc += NpcHooks_OnStrikeNpc;
|
||||
ServerHooks.Command += ServerHooks_OnCommand;
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
Log.Info("Hooks initialized");
|
||||
|
||||
Bans.LoadBans();
|
||||
Log.Info("Bans initialized");
|
||||
|
||||
Log.Info("Hooks initialized");
|
||||
Commands.InitCommands();
|
||||
Log.Info("Commands initialized");
|
||||
|
||||
|
|
@ -248,6 +251,8 @@ namespace TShockAPI
|
|||
Console.WriteLine(string.Format("{0} players connected.", count));
|
||||
e.Handled = true;
|
||||
}
|
||||
if (text.StartsWith("say "))
|
||||
Log.Info(string.Format("Server said: {0}", text.Remove(0, 4)));
|
||||
}
|
||||
|
||||
public override void DeInitialize()
|
||||
|
|
@ -258,6 +263,7 @@ namespace TShockAPI
|
|||
GameHooks.Update -= OnUpdate;
|
||||
ServerHooks.Chat -= OnChat;
|
||||
ServerHooks.Join -= OnJoin;
|
||||
ServerHooks.Leave -= OnLeave;
|
||||
ServerHooks.Command -= ServerHooks_OnCommand;
|
||||
NetHooks.GetData -= GetData;
|
||||
NetHooks.GreetPlayer -= OnGreetPlayer;
|
||||
|
|
@ -708,6 +714,10 @@ namespace TShockAPI
|
|||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Info(string.Format("{0} said: {1}", tsplr.Name, text));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnJoin(int ply, HandledEventArgs handler)
|
||||
|
|
@ -745,6 +755,16 @@ namespace TShockAPI
|
|||
Netplay.serverSock[ply].spamCheck = ConfigurationManager.SpamChecks;
|
||||
}
|
||||
|
||||
private void OnLeave(int ply)
|
||||
{
|
||||
if (Main.netMode != 2)
|
||||
return;
|
||||
|
||||
var tsplr = Players[ply];
|
||||
if (tsplr != null)
|
||||
Log.Info(string.Format("{0} left.", tsplr.Name));
|
||||
}
|
||||
|
||||
private void OnPostInit()
|
||||
{
|
||||
if (!File.Exists(Path.Combine(SavePath, "auth.lck")))
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ namespace TShockAPI
|
|||
public static void Broadcast(string msg, byte red, byte green, byte blue)
|
||||
{
|
||||
TSPlayer.All.SendMessage(msg, red, green, blue);
|
||||
TSPlayer.Server.SendMessage(msg, red, green, blue);
|
||||
Log.Info(string.Format("Broadcast: {0}", msg));
|
||||
|
||||
}
|
||||
|
|
@ -123,6 +124,7 @@ namespace TShockAPI
|
|||
public static void SendLogs(string log, Color color)
|
||||
{
|
||||
Log.Info(log);
|
||||
TSPlayer.Server.SendMessage(log, color);
|
||||
for (int i = 0; i < Main.maxPlayers; i++)
|
||||
{
|
||||
if (TShock.Players[i] == null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue