[Bobbot-cvs] Plugins/Sphere SpherePlugin.cs,1.24,1.25
Status: Alpha
Brought to you by:
iainmckay
From: Mr S. C. <mrs...@us...> - 2005-10-18 20:24:42
|
Update of /cvsroot/bobbot/Plugins/Sphere In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20607/Sphere Modified Files: SpherePlugin.cs Log Message: -I changed stuff apparently :D Index: SpherePlugin.cs =================================================================== RCS file: /cvsroot/bobbot/Plugins/Sphere/SpherePlugin.cs,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** SpherePlugin.cs 17 Jul 2005 21:46:29 -0000 1.24 --- SpherePlugin.cs 18 Oct 2005 20:24:33 -0000 1.25 *************** *** 1,6 **** ! #region LGPL License /* Bastard of a Bot Library Copyright (C) 2004 Bastard of a Bot Team This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #endregion using System; using System.IO; using System.Net; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text.RegularExpressions; using System.Timers; using Bot.Core; using Bot.Core.Irc; using Bot.Core.Irc.Messages; using Bot.Core.RemoteAdmin; using Bot.Plugins.Sphere; using Bot.Plugins.Sphere.Messages; using Bot.Plugins.Sphere.PunishSystem; using Bot.Plugins.Sphere.Accounting; using Bot.Plugins.Sphere.LogManagement; using UltimaOnline.Sphere.Connection; using UltimaOnline.Sphere.Connection.Messages; namespace Bot.Plugins.Sphere { public class SpherePlugin : MarshalByRefObject, IPlugin { #region Private members private SphereConfig m_Config; private SphereAuth m_SphereAuth; private SphereConnection m_Server; private AccountRegistration m_Accounting; private JailSystem m_JailSystem; private BanSystem m_BanSystem; private LogManager m_LogManager; private MultiAccountSearch m_MultiAccountSearch; private AccountsReader m_AccountsReader; private int m_KillCount; private int m_PageCount; private int m_ClientPeak; private int m_ConnectCount; private int m_WorldSaveCount; private int m_ClientCommandsCount; private string m_LothBotUid; private Mobile m_LastVictim; private Mobile[] m_LastKillers; private Timer m_LastKillTimer; private StringCollection m_AccountWatch = new StringCollection(); private StringCollection m_IPWatch = new StringCollection(); private Regex m_IPRegex = new Regex( @"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", RegexOptions.Compiled); private StringCollection m_IgnoreList = new StringCollection(); private Timer m_WatchTimer = new Timer(100); private int m_WatchTime = 10000; private Timer m_Timer; private DateTime m_LogNextOpen; private StreamWriter m_CurrentLog; #endregion #region Public properties public SphereConfig InnerConfig { get { return m_Config; } } public SphereConnection InnerConnection { get { return m_Server; } } #endregion #region IPlugin implementation public string Name { get { return "Sphere"; } } public string Author { get { return "Iain Mckay <jo...@wi...>"; } } public void Start() { m_Config = (SphereConfig) ConfigurationSettings.GetConfig("SphereConfig"); m_PageCount = 0; m_ClientPeak = 0; m_ConnectCount = 0; m_WorldSaveCount = 0; m_ClientCommandsCount = 0; m_LothBotUid = ""; StreamReader peakRead; if (File.Exists("peak.txt")) { peakRead = File.OpenText("peak.txt"); string line = peakRead.ReadLine(); while (line != null) { if (line.StartsWith("PEAK")) { m_ClientPeak = Int32.Parse(line.Remove(0, 5)); } line = peakRead.ReadLine(); } peakRead.Close(); } if (File.Exists("accountwatch.txt")) { m_AccountWatch = new StringCollection(); peakRead = File.OpenText("accountwatch.txt"); string line = peakRead.ReadLine(); while (line != null) { if (line.StartsWith("ACCT")) { m_AccountWatch.Add( line.Remove(0, 5) ); } line = peakRead.ReadLine(); } peakRead.Close(); } if (File.Exists("ipwatch.txt")) { m_IPWatch = new StringCollection(); peakRead = File.OpenText("ipwatch.txt"); string line = peakRead.ReadLine(); while (line != null) { if (line.StartsWith("IP")) { m_IPWatch.Add( line.Remove(0, 3) ); } line = peakRead.ReadLine(); } peakRead.Close(); } m_Timer = new Timer(); m_Timer.Interval = m_Config.ResyncPeriod; m_Timer.AutoReset = true; m_Timer.Enabled = true; m_Timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed); m_WatchTimer.AutoReset = false; m_WatchTimer.Interval = m_WatchTime; m_WatchTimer.Elapsed += new ElapsedEventHandler(OnWatchTimerElapsed); m_LastKillTimer = new Timer(); m_LastKillTimer.Interval = 300000; m_LastKillTimer.AutoReset = false; m_LastKillTimer.Elapsed += new ElapsedEventHandler(OnLastKillTimerElapsed); m_LogNextOpen = DateTime.Now; m_Server = SphereConnection.Instance; m_Server.CustomLog += new CustomLogEventHandler(OnCustomLog); m_Server.ShowValue += new ShowValueEventHandler(OnShowValue); m_Server.ScriptError += new ScriptErrorEventHandler(OnScriptError); m_Server.WorldSave += new WorldSaveEventHandler(OnWorldSave); m_Server.ClientPage += new ClientPageEventHandler(OnClientPage); m_Server.ClientKilled +=new ClientKilledEventHandler(OnClientKilled); m_Server.Connected += new ConnectedEventHandler(OnConnected); m_Server.Disconnected += new DisconnectedEventHandler(OnDisconnected); m_Server.ConnectionLost += new DisconnectedEventHandler(OnConnectionLost); m_Server.AdminWelcome += new AdminWelcomeEventHandler(OnAdminWelcome); m_Server.ClientCommand += new ClientCommandEventHandler(OnClientCommand); m_Server.ConnectionFailed += new DisconnectedEventHandler(OnConnectionFailed); m_Server.MessageReceived += new MessageReceivedEventHandler(OnMessageReceived); m_Server.AdminBadPassword += new AdminBadPasswordEventHandler(OnAdminBadPassword); m_Server.AdminAccountInUse += new AdminAccountInUseEventHandler(OnAdminAccountInUse); m_Server.ClientConnected += new ClientConnectedEventHandler(OnClientConnected); m_Server.ClientLogin += new ClientLoginEventHandler(OnClientLogin); m_Server.RegisterHandler(typeof(HouseKillingMessage)); m_Server.RegisterHandler(typeof(PlayerJailedMessage)); m_Server.RegisterHandler(typeof(PlayerReleasedMessage)); m_Server.RegisterHandler(typeof(SkillNukeMessage)); m_Server.RegisterHandler(typeof(PlayerPunishedMessage)); m_Server.RegisterHandler(typeof(ResKillingMessage)); m_LastVictim = new Mobile(MobileType.Player, "Victim"); m_LastKillers = new Mobile[] { new Mobile(MobileType.Npc, "Aggressor") }; m_Server.Password = m_Config.Password; m_Server.Connect(IPAddress.Parse(m_Config.Address), m_Config.Port); if (this.m_Config.JailDatabase != "-1") m_JailSystem = new JailSystem(this, m_Config.JailDatabase); if (this.m_Config.BanDatabase != "-1") m_BanSystem = new BanSystem(this, m_Config.BanDatabase); m_Accounting = new AccountRegistration(m_Server, m_Config.AccountDatabase); m_SphereAuth = new SphereAuth(this); m_LogManager = new LogManager(m_Server, m_Config.LogDatabase); } public void Stop() { if(m_Server != null) { m_Server.Disconnect(); m_Server = null; } } #endregion #region Event handlers private void OnConnected(object sender, ConnectedEventArgs args) { Log.WriteLine("Sphere", "Connected to '{0}'", args.EndPoint.ToString()); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Connected to '{0}'", args.EndPoint.ToString())); } private void OnDisconnected(object sender, DisconnectedEventArgs args) { Log.WriteLine("Sphere", "Disconnected from '{0}'", args.EndPoint.ToString()); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Disconnected from '{0}'", args.EndPoint.ToString())); } private void OnConnectionLost(object sender, DisconnectedEventArgs args) { Log.WriteLine("Sphere", "Connection lost to '{0}'", args.EndPoint.ToString()); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Connection lost to '{0}'", args.EndPoint.ToString())); } private void OnConnectionFailed(object sender, DisconnectedEventArgs args) { Log.WriteLine("Sphere", "Failed to connect to '{0}'", args.EndPoint.ToString()); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Failed to connect to '{0}'", args.EndPoint.ToString())); } private void OnAdminWelcome(object sender, AdminWelcomeEventArgs args) { Log.WriteLine("Sphere", "Signed onto the administration console"); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, "Signed onto the administration console"); m_Server.WriteLine("show clients"); m_Server.WriteLine("show var.lothbot_uid"); /*string clicount = (string)m_GetValue.GetProperty("clients"); if (clicount != null) m_ClientCount = Int32.Parse(clicount); string botuid = (string)m_GetValue.GetProperty("var.lothbot_uid"); if (botuid != null && botuid.Trim() != "") m_LothBotUid = botuid;*/ } private void OnAdminBadPassword(object sender, AdminBadPasswordEventArgs args) { Log.WriteLine("Sphere", "Could not sign in, bad password."); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, "Could not sign in, bad password."); m_Server.Disconnect(); } private void OnAdminAccountInUse(object sender, AdminAccountInUseEventArgs args) { Log.WriteLine("Sphere", "Could not sign in, account in use."); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, "Could not sign in, account in use."); m_Server.Disconnect(); } private void OnClientPage(object sender, ClientPageEventArgs args) { m_PageCount++; Log.WriteLine("Sphere", "Page from '{0}': {1}", args.Message.Character, args.Message.Page); string pageStr = String.Format("Page from {0} [{1}] at {2}: {3}", args.Message.Character, args.Message.Serial, args.Message.Position.ToString(), args.Message.Page); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, pageStr); } private void OnClientKilled(object sender, ClientKilledEventArgs args) { m_KillCount++; m_LastVictim = args.Message.Victim; m_LastKillers = args.Message.Aggressors; } private void OnClientCommand(object sender, ClientCommandEventArgs args) { m_ClientCommandsCount++; } private void OnWorldSave(object sender, WorldSaveEventArgs args) { m_WorldSaveCount++; } private void OnMessageReceived(object sender, MessageReceivedEventArgs args) { // If we have passed midnight or we don't have a logfile open, open new log file. if((m_LogNextOpen <= DateTime.Now) || (m_CurrentLog == null)) { if(m_CurrentLog != null) { m_CurrentLog.Close(); m_CurrentLog = null; } string logFile = Path.Combine(m_Config.LogDirectory, String.Format("{0}-{1}-{2}.log", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)); try { m_CurrentLog = new StreamWriter(logFile, true); m_CurrentLog.AutoFlush = true; m_CurrentLog.WriteLine("---------------------------------------------------------------"); m_CurrentLog.WriteLine("Log opened at {0} on {1}", DateTime.Now.ToShortTimeString(), DateTime.Now.ToLongDateString()); m_CurrentLog.WriteLine("---------------------------------------------------------------"); Log.WriteLine("Sphere", "Rotated log file"); m_LogNextOpen = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); m_LogNextOpen = m_LogNextOpen.AddDays(1); } catch(Exception ex) { Log.WriteLine("Sphere", "Could not rotate log file, {0}", ex.Message); } } if(m_CurrentLog != null) m_CurrentLog.WriteLine(args.Message); } private void OnShowValue(object sender, ShowValueEventArgs args) { if((args.Message.Property.ToLower() == "var.lothbot_uid") && (args.Message.Value.Trim() != "")) m_LothBotUid = args.Message.Value; } private void OnScriptError(object sender, ScriptErrorEventArgs args) { if (args.Message.Script == "botgmnpc.scp") { Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, args.Message.Error); return; } //Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, "Error! Time:{0} Script:{1} Line:{2} Error:{3}", args.Message.Time.ToString(), args.Message.Script, args.Message.LineNumber.ToString(), args.Message.Error); } private void OnCustomLog(object sender, CustomLogEventArgs args) { if (args.Message.Script == "botgmnpc.scp") { Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, args.Message.Message); return; } } private void OnTimerElapsed(object sender, ElapsedEventArgs e) { if (m_Server.IsConnected) { string botuid = (string) m_Server.GetProperty("var.lothbot_uid"); if (botuid != null && botuid.Trim() != "") m_LothBotUid = botuid; } else m_Server.Connect(IPAddress.Parse(m_Config.Address), m_Config.Port); m_JailSystem.SaveDatabase(); m_BanSystem.SaveDatabase(); m_LogManager.SaveDatabase(); if (File.Exists("peak.txt")) File.Delete("peak.txt"); StreamWriter peakWrite = File.CreateText("peak.txt"); peakWrite.Write("PEAK={0}", m_ClientPeak); peakWrite.Close(); if (m_AccountWatch != null) { if (File.Exists("accountwatch.txt")) File.Delete("accountwatch.txt"); peakWrite = File.CreateText("accountwatch.txt"); foreach (string account in m_AccountWatch) peakWrite.WriteLine( "ACCT={0}", account ); peakWrite.Close(); Log.WriteLine("Sphere", "Written Account List ({0} Accounts)", m_AccountWatch.Count); } if (m_IPWatch != null) { if (File.Exists("ipwatch.txt")) File.Delete("ipwatch.txt"); peakWrite = File.CreateText("ipwatch.txt"); foreach (string ip in m_IPWatch) peakWrite.WriteLine( "IP={0}", ip ); peakWrite.Close(); Log.WriteLine("Sphere", "Written IP List ({0} IPs)", m_IPWatch.Count); } if (m_Timer.Interval == 1) { m_Timer.Stop(); m_Timer.Interval = m_Config.ResyncPeriod; m_Timer.Start(); } MultiAccountSearch.WriteAuthorisedMultis( m_Config.MultiFile ); } ! private void OnClientConnected(object sender, ClientConnectedEventArgs args) ! { m_ConnectCount++; --- 1,5 ---- ! #region LGPL License /* Bastard of a Bot Library Copyright (C) 2004 Bastard of a Bot Team This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #endregion using System; using System.IO; using System.Net; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text.RegularExpressions; using System.Timers; using Bot.Core; using Bot.Core.Irc; using Bot.Core.Irc.Messages; using Bot.Core.RemoteAdmin; using Bot.Plugins.Sphere; using Bot.Plugins.Sphere.Messages; using Bot.Plugins.Sphere.PunishSystem; using Bot.Plugins.Sphere.Accounting; using Bot.Plugins.Sphere.LogManagement; using UltimaOnline.Sphere.Connection; using UltimaOnline.Sphere.Connection.Messages; namespace Bot.Plugins.Sphere { public class SpherePlugin : MarshalByRefObject, IPlugin { #region Private members private SphereConfig m_Config; private SphereAuth m_SphereAuth; private SphereConnection m_Server; private AccountRegistration m_Accounting; private JailSystem m_JailSystem; private BanSystem m_BanSystem; private LogManager m_LogManager; private MultiAccountSearch m_MultiAccountSearch; private AccountsReader m_AccountsReader; private int m_KillCount; private int m_PageCount; private int m_ClientPeak; private int m_ConnectCount; private int m_WorldSaveCount; private int m_ClientCommandsCount; private string m_LothBotUid; private bool m_RetryConnect = true; private Mobile m_LastVictim; private Mobile[] m_LastKillers; private Timer m_LastKillTimer; private StringCollection m_AccountWatch = new StringCollection(); private StringCollection m_IPWatch = new StringCollection(); private Regex m_IPRegex = new Regex( @"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", RegexOptions.Compiled); private StringCollection m_IgnoreList = new StringCollection(); private Timer m_WatchTimer = new Timer(100); private int m_WatchTime = 10000; private Timer m_Timer; private DateTime m_LogNextOpen; private StreamWriter m_CurrentLog; #endregion #region Public properties public SphereConfig InnerConfig { get { return m_Config; } } public SphereConnection InnerConnection { get { return m_Server; } } #endregion #region IPlugin implementation public string Name { get { return "Sphere"; } } public string Author { get { return "Iain Mckay <jo...@wi...>"; } } public void Start() { m_Config = (SphereConfig) ConfigurationSettings.GetConfig("SphereConfig"); m_PageCount = 0; m_ClientPeak = 0; m_ConnectCount = 0; m_WorldSaveCount = 0; m_ClientCommandsCount = 0; m_LothBotUid = ""; StreamReader peakRead; if (File.Exists("peak.txt")) { peakRead = File.OpenText("peak.txt"); string line = peakRead.ReadLine(); while (line != null) { if (line.StartsWith("PEAK")) { m_ClientPeak = Int32.Parse(line.Remove(0, 5)); } line = peakRead.ReadLine(); } peakRead.Close(); } if (File.Exists("accountwatch.txt")) { m_AccountWatch = new StringCollection(); peakRead = File.OpenText("accountwatch.txt"); string line = peakRead.ReadLine(); while (line != null) { if (line.StartsWith("ACCT")) { m_AccountWatch.Add( line.Remove(0, 5) ); } line = peakRead.ReadLine(); } peakRead.Close(); } if (File.Exists("ipwatch.txt")) { m_IPWatch = new StringCollection(); peakRead = File.OpenText("ipwatch.txt"); string line = peakRead.ReadLine(); while (line != null) { if (line.StartsWith("IP")) { m_IPWatch.Add( line.Remove(0, 3) ); } line = peakRead.ReadLine(); } peakRead.Close(); } m_Timer = new Timer(); m_Timer.Interval = m_Config.ResyncPeriod; m_Timer.AutoReset = true; m_Timer.Enabled = true; m_Timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed); m_WatchTimer.AutoReset = false; m_WatchTimer.Interval = m_WatchTime; m_WatchTimer.Elapsed += new ElapsedEventHandler(OnWatchTimerElapsed); m_LastKillTimer = new Timer(); m_LastKillTimer.Interval = 300000; m_LastKillTimer.AutoReset = false; m_LastKillTimer.Elapsed += new ElapsedEventHandler(OnLastKillTimerElapsed); m_LogNextOpen = DateTime.Now; m_Server = SphereConnection.Instance; m_Server.CustomLog += new CustomLogEventHandler(OnCustomLog); m_Server.ShowValue += new ShowValueEventHandler(OnShowValue); m_Server.ScriptError += new ScriptErrorEventHandler(OnScriptError); m_Server.WorldSave += new WorldSaveEventHandler(OnWorldSave); m_Server.ClientPage += new ClientPageEventHandler(OnClientPage); m_Server.ClientKilled +=new ClientKilledEventHandler(OnClientKilled); m_Server.Connected += new ConnectedEventHandler(OnConnected); m_Server.Disconnected += new DisconnectedEventHandler(OnDisconnected); m_Server.ConnectionLost += new DisconnectedEventHandler(OnConnectionLost); m_Server.AdminWelcome += new AdminWelcomeEventHandler(OnAdminWelcome); m_Server.ClientCommand += new ClientCommandEventHandler(OnClientCommand); m_Server.ConnectionFailed += new DisconnectedEventHandler(OnConnectionFailed); m_Server.MessageReceived += new MessageReceivedEventHandler(OnMessageReceived); m_Server.AdminBadPassword += new AdminBadPasswordEventHandler(OnAdminBadPassword); m_Server.AdminAccountInUse += new AdminAccountInUseEventHandler(OnAdminAccountInUse); m_Server.ClientConnected += new ClientConnectedEventHandler(OnClientConnected); m_Server.ClientLogin += new ClientLoginEventHandler(OnClientLogin); m_Server.RegisterHandler(typeof(HouseKillingMessage)); m_Server.RegisterHandler(typeof(PlayerJailedMessage)); m_Server.RegisterHandler(typeof(PlayerReleasedMessage)); m_Server.RegisterHandler(typeof(SkillNukeMessage)); m_Server.RegisterHandler(typeof(PlayerPunishedMessage)); m_Server.RegisterHandler(typeof(ResKillingMessage)); m_Server.RegisterHandler(typeof(JSInformationRequestMessage)); m_LastVictim = new Mobile(MobileType.Player, "Victim"); m_LastKillers = new Mobile[] { new Mobile(MobileType.Npc, "Aggressor") }; m_Server.Password = m_Config.Password; m_Server.Connect(IPAddress.Parse(m_Config.Address), m_Config.Port); if (this.m_Config.JailDatabase != "-1") m_JailSystem = new JailSystem(this, m_Config.JailDatabase); if (this.m_Config.BanDatabase != "-1") m_BanSystem = new BanSystem(this, m_Config.BanDatabase); m_Accounting = new AccountRegistration(m_Server, m_Config.AccountDatabase); m_SphereAuth = new SphereAuth(this); m_LogManager = new LogManager(m_Server, m_Config.LogDatabase); } public void Stop() { if(m_Server != null) { m_Server.Disconnect(); m_Server = null; } } #endregion #region Event handlers private void OnConnected(object sender, ConnectedEventArgs args) { m_RetryConnect = true; Log.WriteLine("Sphere", "Connected to '{0}'", args.EndPoint.ToString()); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Connected to '{0}'", args.EndPoint.ToString())); } private void OnDisconnected(object sender, DisconnectedEventArgs args) { Log.WriteLine("Sphere", "Disconnected from '{0}'", args.EndPoint.ToString()); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Disconnected from '{0}'", args.EndPoint.ToString())); } private void OnConnectionLost(object sender, DisconnectedEventArgs args) { if (m_RetryConnect) { m_RetryConnect = false; Log.WriteLine("Sphere", "Connection lost to '{0}', attempting to reconnect...", args.EndPoint.ToString()); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Connection lost to '{0}', attempting to reconnect...", args.EndPoint.ToString())); m_Server.Connect(IPAddress.Parse(m_Config.Address), m_Config.Port); return; } Log.WriteLine("Sphere", "Connection lost to '{0}'", args.EndPoint.ToString()); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Connection lost to '{0}'", args.EndPoint.ToString())); } private void OnConnectionFailed(object sender, DisconnectedEventArgs args) { Log.WriteLine("Sphere", "Failed to connect to '{0}'", args.EndPoint.ToString()); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Failed to connect to '{0}'", args.EndPoint.ToString())); } private void OnAdminWelcome(object sender, AdminWelcomeEventArgs args) { Log.WriteLine("Sphere", "Signed onto the administration console"); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, "Signed onto the administration console"); m_Server.WriteLine("show clients"); m_Server.WriteLine("show var.lothbot_uid"); /*string clicount = (string)m_GetValue.GetProperty("clients"); if (clicount != null) m_ClientCount = Int32.Parse(clicount); string botuid = (string)m_GetValue.GetProperty("var.lothbot_uid"); if (botuid != null && botuid.Trim() != "") m_LothBotUid = botuid;*/ } private void OnAdminBadPassword(object sender, AdminBadPasswordEventArgs args) { Log.WriteLine("Sphere", "Could not sign in, bad password."); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, "Could not sign in, bad password."); m_Server.Disconnect(); } private void OnAdminAccountInUse(object sender, AdminAccountInUseEventArgs args) { Log.WriteLine("Sphere", "Could not sign in, account in use."); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, "Could not sign in, account in use."); m_Server.Disconnect(); } private void OnClientPage(object sender, ClientPageEventArgs args) { m_PageCount++; Log.WriteLine("Sphere", "Page from '{0}': {1}", args.Message.Character, args.Message.Page); string pageStr = String.Format("Page from {0} [{1}] at {2}: {3}", args.Message.Character, args.Message.Serial, args.Message.Position.ToString(), args.Message.Page); Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, pageStr); } private void OnClientKilled(object sender, ClientKilledEventArgs args) { m_KillCount++; m_LastVictim = args.Message.Victim; m_LastKillers = args.Message.Aggressors; } private void OnClientCommand(object sender, ClientCommandEventArgs args) { m_ClientCommandsCount++; } private void OnWorldSave(object sender, WorldSaveEventArgs args) { m_WorldSaveCount++; } private void OnMessageReceived(object sender, MessageReceivedEventArgs args) { // If we have passed midnight or we don't have a logfile open, open new log file. if((m_LogNextOpen <= DateTime.Now) || (m_CurrentLog == null)) { if(m_CurrentLog != null) { m_CurrentLog.Close(); m_CurrentLog = null; } string logFile = Path.Combine(m_Config.LogDirectory, String.Format("{0}-{1}-{2}.log", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)); try { m_CurrentLog = new StreamWriter(logFile, true); m_CurrentLog.AutoFlush = true; m_CurrentLog.WriteLine("---------------------------------------------------------------"); m_CurrentLog.WriteLine("Log opened at {0} on {1}", DateTime.Now.ToShortTimeString(), DateTime.Now.ToLongDateString()); m_CurrentLog.WriteLine("---------------------------------------------------------------"); Log.WriteLine("Sphere", "Rotated log file"); m_LogNextOpen = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); m_LogNextOpen = m_LogNextOpen.AddDays(1); } catch(Exception ex) { Log.WriteLine("Sphere", "Could not rotate log file, {0}", ex.Message); } } if(m_CurrentLog != null) m_CurrentLog.WriteLine(args.Message); } private void OnShowValue(object sender, ShowValueEventArgs args) { if((args.Message.Property.ToLower() == "var.lothbot_uid") && (args.Message.Value.Trim() != "")) m_LothBotUid = args.Message.Value; } private void OnScriptError(object sender, ScriptErrorEventArgs args) { if (args.Message.Script == "botgmnpc.scp") { Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, args.Message.Error); return; } //Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, "Error! Time:{0} Script:{1} Line:{2} Error:{3}", args.Message.Time.ToString(), args.Message.Script, args.Message.LineNumber.ToString(), args.Message.Error); } private void OnCustomLog(object sender, CustomLogEventArgs args) { if (args.Message.Script == "botgmnpc.scp") { Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, args.Message.Message); return; } } private void OnTimerElapsed(object sender, ElapsedEventArgs e) { if (m_Server.IsConnected) { string botuid = (string) m_Server.GetProperty("var.lothbot_uid"); if (botuid != null && botuid.Trim() != "") m_LothBotUid = botuid; } else m_Server.Connect(IPAddress.Parse(m_Config.Address), m_Config.Port); if (m_JailSystem != null) { m_JailSystem.SaveDatabase(); } if (m_BanSystem != null) { m_BanSystem.SaveDatabase(); } if (m_LogManager != null) { m_LogManager.SaveDatabase(); } if (File.Exists("peak.txt")) File.Delete("peak.txt"); StreamWriter peakWrite = File.CreateText("peak.txt"); peakWrite.Write("PEAK={0}", m_ClientPeak); peakWrite.Close(); if (m_AccountWatch != null) { if (File.Exists("accountwatch.txt")) File.Delete("accountwatch.txt"); peakWrite = File.CreateText("accountwatch.txt"); foreach (string account in m_AccountWatch) peakWrite.WriteLine( "ACCT={0}", account ); peakWrite.Close(); Log.WriteLine("Sphere", "Written Account List ({0} Accounts)", m_AccountWatch.Count); } if (m_IPWatch != null) { if (File.Exists("ipwatch.txt")) File.Delete("ipwatch.txt"); peakWrite = File.CreateText("ipwatch.txt"); foreach (string ip in m_IPWatch) peakWrite.WriteLine( "IP={0}", ip ); peakWrite.Close(); Log.WriteLine("Sphere", "Written IP List ({0} IPs)", m_IPWatch.Count); } if (m_Timer.Interval == 1) { m_Timer.Stop(); m_Timer.Interval = m_Config.ResyncPeriod; m_Timer.Start(); } MultiAccountSearch.WriteAuthorisedMultis( m_Config.MultiFile ); } ! private void OnClientConnected(object sender, ClientConnectedEventArgs args) { m_ConnectCount++; *************** *** 11,15 **** return; ! if (m_IPWatch.Contains( args.Message.Address.ToString() ) && !m_IgnoreList.Contains( args.Message.Address.ToString() )) { Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("IP '{0}' is attempting to connect.", args.Message.Address.ToString())); m_IgnoreList.Add( args.Message.Address.ToString() ); if (!m_WatchTimer.Enabled) --- 10,14 ---- return; ! if (m_IPWatch.Contains( args.Message.Address.ToString() ) && !m_IgnoreList.Contains( args.Message.Address.ToString() )) { Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("IP '{0}' is attempting to connect.", args.Message.Address.ToString())); m_IgnoreList.Add( args.Message.Address.ToString() ); if (!m_WatchTimer.Enabled) *************** *** 19,28 **** } ! private void OnClientLogin(object sender, ClientLoginEventArgs args) ! { if (m_AccountWatch == null) return; ! if (m_AccountWatch.Contains( args.Message.Account.ToLower() ) && !m_IgnoreList.Contains( args.Message.Account.ToLower() )) { Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Account '{0}' has connected.", args.Message.Account)); m_IgnoreList.Add( args.Message.Account.ToLower() ); if (!m_WatchTimer.Enabled) --- 18,26 ---- } ! private void OnClientLogin(object sender, ClientLoginEventArgs args) { if (m_AccountWatch == null) return; ! if (m_AccountWatch.Contains( args.Message.Account.ToLower() ) && !m_IgnoreList.Contains( args.Message.Account.ToLower() )) { Kernel.Instance.Network.SendChannelMessage(m_Config.OutputChannel, String.Format("Account '{0}' has connected.", args.Message.Account)); m_IgnoreList.Add( args.Message.Account.ToLower() ); if (!m_WatchTimer.Enabled) *************** *** 32,59 **** } ! private void OnWatchTimerElapsed(object sender, ElapsedEventArgs e) ! { m_IgnoreList.Clear(); m_WatchTimer.Stop(); } ! private void OnLastKillTimerElapsed(object sender, ElapsedEventArgs e) ! { m_LastKillTimer.Enabled = false; m_LastKillTimer.Stop(); ! } #endregion #region Test/Temp Commands [AllowCondition("LothStaff", AccountPriv.Owner, AllowConditionUsage.Equals)] [PrivateCommand("testval")] private void testvalcommand(NetworkUser user, string[] args) { object o; if (args.Length <= 0) o = m_Server.GetProperty("uid.1.name"); else o = m_Server.GetProperty(args[0]); Kernel.Instance.Network.SendPrivateMessage(user, "Value is '{0}'", (string)o); } [AllowCondition("LothStaff", AccountPriv.Owner, AllowConditionUsage.Equals)] [PrivateCommand("testaccount")] private void testcommand(NetworkUser user, string[] args) { if (args.Length <= 0) m_Server.WriteLine("account blah show {0}", m_Server.ValidAccountProperties[new Random().Next(0, m_Server.ValidAccountProperties.Count)]); else { if (!m_Accounting.AccountExists(args[0])) Kernel.Instance.Network.SendPrivateMessage(user, "Account '{0}' doesn't exist!", args[0]); else { Account temp = m_Accounting.GetAccount(args[0]); if (temp == null) { Kernel.Instance.Network.SendPrivateMessage(user, "Account '{0}' doesn't exist! (Error? :s)", args[0]); return; } Kernel.Instance.Network.SendPrivateMessage(user, "Account: {0} Password: {1}", temp.Name, temp.Password); Kernel.Instance.Network.SendPrivateMessage(user, "Lang: {0} PLevel: {1}", temp.Lang, Account.PrivToString(temp.Plevel)); Kernel.Instance.Network.SendPrivateMessage(user, "FirstIP: {0} FirstDate: {1}", temp.FirstIP, temp.FirstConnectDate); Kernel.Instance.Network.SendPrivateMessage(user, "LastIP: {0} LastDate: {1}", temp.LastIP, temp.LastConnectDate); Kernel.Instance.Network.SendPrivateMessage(user, "Chars: {0} LastChar: 0{1:x}", temp.Chars, temp.LastCharUID); Kernel.Instance.Network.SendPrivateMessage(user, "TotalConnect: {0} LastConnect: {1}", temp.TotalConnectTime, temp.LastConnectTime); Kernel.Instance.Network.SendPrivateMessage(user, "Priv: 0{0:x}", temp.Priv); Kernel.Instance.Network.SendPrivateMessage(user, "Jailed: {0} Blocked: {1}", ((temp.Jailed)? "Yes" : "No"), ((temp.Blocked)? "Yes" : "No")); } return; } } [AllowCondition("LothStaff", AccountPriv.Owner, AllowConditionUsage.Equals)] [PrivateCommand("testitem")] private void testitemcommand(NetworkUser user, string[] args) { if (args.Length != 2) return; user.SendMessage("Value '{0}' for '{1}' is {2}", args[1], args[0], m_Server.GetItemProperty(Int32.Parse(args[0], System.Globalization.NumberStyles.HexNumber), args[1])); } [PrivateCommand("mypriv")] private void myprivcommand(NetworkUser user, string[] args) { user.SendNotice("Your priv is: {0}", Account.PrivToString(m_SphereAuth.GetStaffPriv(user))); return; } [PrivateCommand("liststaff")] private void liststaffcommand(NetworkUser user, string[] args) { foreach (Bot.Core.User staff in m_SphereAuth.StaffMembers()) user.SendNotice("{0}, {1}", staff.Name, Account.PrivToString((AccountPriv)staff.GetProperty("LothStaff"))); } [ChannelCommand("listchan")] private void ListChan(NetworkChannel chan, NetworkUser user, string[] args) { Kernel.Instance.Network.SendChannelMessage(chan, "I am on the following channels:"); foreach(string channel in Kernel.Instance.Network.Channels.Keys) Kernel.Instance.Network.SendChannelMessage(chan, "\t\t{0}", channel); } #endregion #region 'Remote' Commands [AllowCondition("LothStaff", AccountPriv.Admin, AllowConditionUsage.GreaterThanOrEqual)] [RemoteCommand("account")] private static void RemoteAccountCommand(RemoteConnection sender, string[] args) { if (args.Length < 2) { sender.Send("Invalid Command or Format."); return; } if (args[0].ToLower() == "add") switch (args.Length) { case 2: { if (AccountRegistration.Instance.AccountAdd(args[1])) sender.Send("Account {0} created successfully.", args[1]); else sender.Send("Unable to create account!"); return; } case 3: { if (AccountRegistration.Instance.AccountAdd(args[1], args[2])) sender.Send("Account {0} created successfully.", args[1]); else sender.Send("Unable to create account!"); return; } default: { if (AccountRegistration.Instance.AccountAdd(args[1], args[2], Account.StringToPriv(args[3]))) sender.Send("Account {0} created successfully.", args[1]); else sender.Send("Unable to create account!"); return; } } else if (args[1].ToLower() == "delete") { if (AccountRegistration.Instance.AccountDel(args[0])) sender.Send("Account {0} deleted!", args[0]); ! else sender.Send("Unable to delete account!"); return; } else { string[] function = new string[ args.Length - 1 ]; Array.Copy(args, 1, function, 0, function.Length); sender.Send(AccountRegistration.Instance.AccountMod(args[0], function)); } } #endregion #region 'Staff' Commands #region Connection Commands [AllowCondition("LothStaff", AccountPriv.GM, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!recon")] private void ReconCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (m_Server.IsConnected) m_Server.Disconnect(); if (args.Length <= 0) m_Server.Connect(IPAddress.Parse(m_Config.Address), m_Config.Port); else m_Server.Connect(IPAddress.Parse(args[0]), m_Config.Port); } [AllowCondition("LothStaff", AccountPriv.GM, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!discon")] private void DisconCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (m_Server.IsConnected) m_Server.Disconnect(); else chan.SendMessage("Not Connected To Server."); } #endregion #region Misc Commands [AllowCondition("LothStaff", AccountPriv.Admin, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!watchip")] private void WatchIPCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (args.Length < 1) { chan.SendMessage("You didn't specify an IP to watch."); return; } chan.SendMessage( WatchIP(args[0]), args[0] ); } [AllowCondition("LothStaff", AccountPriv.Admin, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [PrivateCommand("watchip")] private void WatchIPCommand(NetworkUser user, string[] args) { if (args.Length < 1) { user.SendMessage("You didn't specify an IP to watch."); return; } user.SendMessage( WatchIP(args[0]), args[0] ); } [AllowCondition("LothStaff", AccountPriv.Admin, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!watchaccount")] private void WatchAccountCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (args.Length < 1) { chan.SendMessage("You didn't specify an account to watch."); return; } chan.SendMessage(WatchAccount(args[0]), args[0]); } [AllowCondition("LothStaff", AccountPriv.Admin, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [PrivateCommand("watchaccount")] private void WatchAccountCommand(NetworkUser user, string[] args) { if (args.Length < 1) { user.SendMessage("You didn't specify an account to watch."); return; } user.SendMessage(WatchAccount(args[0]), args[0]); } private string WatchAccount( string account ) { account = account.ToLower(); if (m_AccountWatch == null) m_AccountWatch = new StringCollection(); if (m_WatchTimer == null) m_WatchTimer = new Timer( 100 ); if (m_AccountWatch.Contains(account)) { m_AccountWatch.Remove( account ); return "This account is no longer being watched."; } m_AccountWatch.Add( account ); return "Account '{0}' is now being watched."; } private string WatchIP( string ip ) { if (!m_IPRegex.IsMatch( ip )) { return "That isn't a valid IP."; } if (m_IPWatch == null) m_IPWatch = new StringCollection(); if (m_WatchTimer == null) m_WatchTimer = new Timer( 100 ); if (m_IPWatch.Contains(ip)) { m_IPWatch.Remove( ip ); return "This IP is no longer being watched."; } m_IPWatch.Add( ip ); return "IP '{0}' is now being watched."; } [AllowCondition("LothStaff", AccountPriv.Admin, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!resync")] private void ResyncCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (!m_Server.IsConnected) { chan.SendMessage("Not Connected To Server"); return; } m_Server.WriteLine("r"); m_Server.WriteLine("r"); chan.SendMessage("Done."); } [AllowCondition("LothStaff", AccountPriv.GM, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!broadcast")] private void BroadcastCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (args.Length < 1) { chan.SendMessage("You didn't specify a message to send."); return; } if (!m_Server.IsConnected) { chan.SendMessage("Not Connected To Server"); return; } string message = ""; foreach (string i in args) message += " " + i; Kernel.Instance.Network.SendChannelMessage(m_Config.PublicChannel, "Broadcast: {0}", message); Log.WriteLine("Sphere", "Broadcast:{0}", message); if (message.Length < 70) { m_Server.WriteLine("b" + message); } else { message = message.Trim(); while (message.Length > 70) { m_Server.WriteLine("b " + message.Substring(0, 70)); message = message.Remove(0, 70); } m_Server.WriteLine("b " + message); } } [AllowCondition("LothStaff", AccountPriv.GM, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!broadcastirc")] private void BroadcastIrcCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (args.Length < 1) { Kernel.Instance.Network.SendChannelMessage(chan, "You didn't specify a message to send."); return; } if (!m_Server.IsConnected) { chan.SendMessage("Not Connected To Server"); return; } string message = ""; foreach (string i in args) message += " " + i; Kernel.Instance.Network.SendChannelMessage(m_Config.PublicChannel, "IRC Broadcast: {0}", message); Log.WriteLine("Sphere", "IRC Broadcast:{0}", message); } [AllowCondition("LothStaff", AccountPriv.GM, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!go")] private void GoCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (args.Length < 2) { chan.SendMessage("Usage: !Go <uid> <message>"); return; } if (!m_Server.IsConnected) { chan.SendMessage("Not Connected To Server"); return; } string message = ""; foreach (string i in args) { if (i != args[0]) message += " " + i; } if (message.Length > 250) { chan.SendMessage("The specified message is too long. You cannot use more than 250 characters."); return; } m_Server.WriteLine("var.lothbot_target={0}", args[0]); message = message.Trim(); m_Server.WriteLine("var.lothbot_msg"); while (message.Length > 50) { m_Server.WriteLine("uid.{0}.f_lothbot_msg \"{1}\"", m_LothBotUid, message.Substring(0, 50)); message = message.Remove(0, 50); } m_Server.WriteLine("uid.{0}.f_lothbot_msg \"{1}\"", m_LothBotUid, message); m_Server.WriteLine("uid.{0}.respondtoplayer", m_LothBotUid); } [AllowCondition("LothStaff", AccountPriv.GM, AllowConditionUsage.GreaterThanOrEqual)] [PrivateCommand("admin listlog")] private void AdminListLogCommand(NetworkUser user, string[] args) { string[] logFiles = Directory.GetFiles(m_Config.LogDirectory, "*.log"); if(logFiles.Length == 0) { user.SendMessage("There are no log files available."); } else { user.SendMessage("The following log files are available:"); foreach(string log in logFiles) user.SendMessage("\t{0}", log); } } [AllowCondition("LothStaff", AccountPriv.Admin, AllowConditionUsage.GreaterThanOrEqual)] [PrivateCommand("addstaff")] private void AddStaffCommand(NetworkUser user, string[] args) { if (args.Length < 1) { user.SendMessage("You must at least provide an account name."); return; } else if (args.Length > 3) { user.SendMessage("Too many arguments provided! (AddStaff <Account> [<Priv>] [<Password>]"); return; } if (!m_Server.IsConnected) { user.SendMessage("Unable to add accounts whilst not connected to the server!"); return; } switch (args.Length) { case 1: { if (m_Accounting.AccountAdd(args[0], AccountPriv.Counselor)) user.SendMessage("Counselor account '{0}' created successfully! Password is '{1}'", args[0], "blah"); else user.SendMessage("Unable to create account!"); return; } case 2: { if (m_Accounting.AccountAdd(args[0], Account.StringToPriv(args[1]))) user.SendMessage("{1} account '{0}' created successfully! Password is '{2}'", args[0], Account.PrivToString(Account.StringToPriv(args[1])), "blah"); else user.SendMessage("Unable to create account!"); return; } case 3: { if (m_Accounting.AccountAdd(args[0], args[2], Account.StringToPriv(args[1]))) user.SendMessage("{2} account '{0}' created successfully! Password is '{2}'", args[0], Account.PrivToString(Account.StringToPriv(args[1])), args[2]); else user.SendMessage("Unable to create account!"); return; } } } #endregion #region Jail Commands [PrivateCommand("jail")] private void JailCommand(NetworkUser user, string[] args) { if (m_JailSystem == null) { user.SendMessage("The Jail System is disabled and your command cannot be processed."); return; } if (args.Length <= 0) { user.SendNotice("Incorrect Usage. (Jail <command> [<arguments>])"); user.SendNotice("Following commands are available to you"); user.SendNotice("Use 'Jail Help <command>' for more information"); user.SendNotice("------------------------------------------------"); user.SendNotice("Jail Info Displays jail entry information"); user.SendNotice("Jail List Displays full list of jailed accounts."); if (m_SphereAuth.IsStaff(user)) { user.SendNotice("Jail Add Jails an account."); if (m_SphereAuth.GetStaffPriv(user) < AccountPriv.GM) return; user.SendNotice("Jail Del Releases an account from jail."); user.SendNotice("Jail Edit Edits an account entry."); if (m_SphereAuth.GetStaffPriv(user) >= AccountPriv.Admin) user.SendNotice("Jail Save Forces the Jail Database to be saved."); } return; } switch (args[0].ToLower()) { case "add": { if (!m_SphereAuth.IsStaff(user)) { user.SendNotice("You cannot use this command."); return; } if (args.Length < 3) { user.SendNotice("Incorrect Arguments: 'Jail Add <Account> <Length> [<Reason>]'"); return; } if (m_JailSystem.IsJailed(args[1])) { user.SendNotice("Account '{0}' is already jailed!", args[1]); return; } string jailargs = ""; for (int i = 3; i < args.Length; i++) jailargs += " " + args[i]; if (m_JailSystem.Jail(args[1], null, user.Nickname, args[2], jailargs.Trim())) user.SendNotice("'{0}' jailed for {1} hours!", args[1], args[2]); else user.SendNotice("Unable to jail '{0}'", args[1]); return; } case "del": { if (!m_SphereAuth.IsStaff(user) || (m_SphereAuth.GetStaffPriv(user) < AccountPriv.GM)) { user.SendNotice("You cannot use this command."); return; } if (args.Length < 2) { user.SendNotice("Incorrect Arguments: 'Jail Del <Account>'"); return; } if (!m_JailSystem.IsJailed(args[1])) { user.SendNotice("Account '{0}' wasn't jailed!", args[1]); return; } if (m_JailSystem.Release(args[1], user.Nickname)) user.SendNotice("'{0}' released!", args[1]); else user.SendNotice("Unable to release '{0}'", args[1]); return; } case "edit": { if (!m_SphereAuth.IsStaff(user) || (m_SphereAuth.GetStaffPriv(user) < AccountPriv.GM)) { user.SendNotice("You cannot use this command."); return; } if (args.Length < 3) { user.SendNotice("Incorrect Arguments: 'Jail Edit <Account> <Length> [<Reason>]'"); return; } if (!m_JailSystem.IsJailed(args[1])) { user.SendNotice("Account '{0}' wasn't jailed!", args[1]); return; } string jailargs = ""; for (int i = 3; i < args.Length; i++) jailargs += " " + args[i]; if (m_JailSystem.EditJail(args[1], user.Nickname, args[2], jailargs.Trim())) user.SendNotice("'{0}'s jail entry is edited!", args[1]); else user.SendNotice("Unable to edit jail entry '{0}'!", args[1]); return; } case "list": { if (m_JailSystem.JailedAccounts <= 0) { user.SendNotice("No Accounts are Jailed!"); return; } foreach (JailEntry entry in m_JailSystem.GetJailEntryList()) { user.SendNotice("Account: {0} Release Date: {1}", entry.Account, entry.JailedUntil.ToString()); } return; } case "info": { if (args.Length < 2) { user.SendNotice("Incorrect Arguments: 'Jail Info <Account>'"); return; } JailEntry entry = m_JailSystem.GetJailEntry(args[1]); if (entry != null) { user.SendNotice("Account: {0}", entry.Account); user.SendNotice("Character: {0}", entry.Character); user.SendNotice("Jailed By: {0}", entry.JailedBy); user.SendNotice("Jail Date: {0}", entry.JailedOn); user.SendNotice("Release Date: {0} ({1})", entry.JailedUntil, entry.TimeLeft); user.SendNotice("Reason: {0}", entry.Reason); } else user.SendNotice("Account '{0}' Not Jailed!", args[1]); return; } case "save": { if (!m_SphereAuth.IsStaff(user) || (m_SphereAuth.GetStaffPriv(user) < AccountPriv.Admin)) { user.SendNotice("You cannot use this command."); return; } if (m_JailSystem.SaveDatabase()) user.SendNotice("Database Saved Successfully."); else user.SendNotice("Database Failed to Save!"); return; } case "help": { if (args.Length < 2) { user.SendNotice("Incorrect Arguments: 'Jail Help <Command>'"); return; } switch (args[1].ToLower()) { case "add": { if (!m_SphereAuth.IsStaff(user)) { user.SendNotice("No help is available for this command."); return; } user.SendNotice("/msg {0} Jail Add <Account> <Length> [<Reason>]", Kernel.Instance.Network.Nickname); user.SendNotice("Adds a new jail database entry for <Account>. The account will"); user.SendNotice("automatically be jailed ingame."); user.SendNotice("The release date will be set <Length> hours after the jail"); user.SendNotice("time, and will automatically released from jail at that time."); user.SendNotice("The <Reason> argument is saved into the database for all users"); user.SendNotice("to view. This is optional and can be left out if not desired."); user.SendNotice("Example: /msg {0} Jail Add myAccount 24", Kernel.Instance.Network.Nickname); user.SendNotice(" /msg {0} Jail Add myAccount 24 Jailed for bug abuse.", Kernel.Instance.Network.Nickname); return; } case "del": { if (!m_SphereAuth.IsStaff(user) || (m_SphereAuth.GetStaffPriv(user) < AccountPriv.GM)) { user.SendNotice("No help is available for this command."); return; } user.SendNotice("/msg {0} Jail Del <Account>", Kernel.Instance.Network.Nickname); user.SendNotice("Deletes the entry for <Account> from the database. The account"); user.SendNotice("will automatically released ingame."); user.SendNotice("Example: /msg {0} Jail Del myAccount", Kernel.Instance.Network.Nickname); return; } case "edit": { if (!m_SphereAuth.IsStaff(user) || (m_SphereAuth.GetStaffPriv(user) < AccountPriv.GM)) { user.SendNotice("No help is available for this command."); return; } user.SendNotice("/msg {0} Jail Edit <Account> <Length> [<Reason>]", Kernel.Instance.Network.Nickname); user.SendNotice("Edits the entry for <Account> in the database, exchanging the"); user.SendNotice("entry's length to <Length> hours."); user.SendNotice("If [<Reason>] is provided then this will also be amended."); user.SendNotice("The 'Jailed By' property of the jail entry will be amended to "); user.SendNotice("indicate that the entry has been amended by another staff"); user.SendNotice("member if that is the case."); user.SendNotice("Example: /msg {0} Jail Edit myAccount 24", Kernel.Instance.Network.Nickname); user.SendNotice(" /msg {0} Jail Edit myAccount 24 Jailed for bug abuse.", Kernel.Instance.Network.Nickname); return; } case "save": { if (!m_SphereAuth.IsStaff(user) || (m_SphereAuth.GetStaffPriv(user) < AccountPriv.Admin)) { user.SendNotice("No help is available for this command."); return; } user.SendNotice("/msg {0} Jail Save", Kernel.Instance.Network.Nickname); user.SendNotice("Forces the Jail Database to be saved immediately. Unsaved jail"); user.SendNotice("entries will result in players not being released if the Bot"); user.SendNotice("is restarted."); user.SendNotice("Example: /msg {0} Jail Save", Kernel.Instance.Network.Nickname); return; } case "list": { user.SendNotice("/msg {0} Jail List", Kernel.Instance.Network.Nickname); user.SendNotice("Displays a list of all the currently jailed accounts, along with"); user.SendNotice("their release dates. For more information on a jail entry, use"); user.SendNotice("Jail Info"); user.SendNotice("Example: /msg {0} Jail List", Kernel.Instance.Network.Nickname); return; } case "info": { user.SendNotice("/msg {0} Jail Info <Account>", Kernel.Instance.Network.Nickname); user.SendNotice("Displays information on <Account>'s jail entry."); user.SendNotice("Example: /msg {0} Jail Info myAccount", Kernel.Instance.Network.Nickname); return; } default: { user.SendNotice("No help is available for this command."); return; } } } default: { user.SendNotice("Unknown Command '{0}'", args[0]); user.SendNotice("Following commands are available to you"); user.SendNotice("Use 'Jail Help <command>' for more information"); user.SendNotice("------------------------------------------------"); user.SendNotice("Jail Info Displays jail entry information"); user.SendNotice("Jail List Displays full list of jailed accounts."); if (m_SphereAuth.IsStaff(user)) { user.SendNotice("Jail Add Jails an account."); if (m_SphereAuth.GetStaffPriv(user) < AccountPriv.GM) return; user.SendNotice("Jail Del Releases an account from jail."); user.SendNotice("Jail Edit Edits an account entry."); if (m_SphereAuth.GetStaffPriv(user) >= AccountPriv.Admin) user.SendNotice("Jail Save Forces the Jail Database to be saved."); } return; } } } #endregion #region Ban Commands [PrivateCommand("ban")] private void BanCommand(NetworkUser user, string[] args) { if (this.m_BanSystem == null) { user.SendMessage("The Ban System is disabled and your command cannot be processed."); return; } if (args.Length <= 0) { user.SendNotice("Incorrect Usage. (Ban <command> [<arguments>])"); user.SendNotice("Following commands are available to you"); user.SendNotice("Use 'Ban Help <command>' for more information"); user.SendNotice("------------------------------------------------"); user.SendNotice("Ban Info Displays ban entry information"); user.SendNotice("Ban List Displays full list of banned accounts."); if (m_SphereAuth.IsStaff(user)) { user.SendNotice("Ban Add Bans an account."); if (m_SphereAuth.GetStaffPriv(user) < AccountPriv.GM) return; user.SendNotice("Ban Edit Edits a ban entry."); if (m_SphereAuth.GetStaffPriv(user) < AccountPriv.Admin) return; user.SendNotice("Ban Del Unbans an account."); user.SendNotice("Ban Save Forces the Ban Database to be saved."); } return; } switch (args[0].ToLower()) { case "add": { if (!m_SphereAuth.IsStaff(user)) { user.SendNotice("You cannot use this command."); return; } if (args.Length < 2) { user.SendNotice("Incorrect Arguments: 'Ban Add <Account> [<Reason>]'"); return; } if (m_BanSystem.IsBanned(args[1])) { user.SendNotice("Account '{0}' is already banned!", args[1]); return; } string banargs = ""; for (int i = 2; i < args.Length; i++) banargs += " " + args[i]; if (m_BanSystem.Ban(args[1], null, user.Nickname, banargs.Trim())) user.SendNotice("'{0}' banned!", args[1]); else user.SendNotice("Unable to ban '{0}'", args[1]); return; } case "del": { if (!m_SphereAuth.IsStaff(user) || (m_SphereAuth.GetStaffPriv(user) < AccountPriv.Admin)) { user.SendNotice("You cannot use this command."); return; } if (args.Length < 2) { user.SendNotice("Incorrect Arguments: 'Ban Del <Account>'"); return; } if (!m_BanSystem.IsBanned(args[1])) { user.SendNotice("Account '{0}' wasn't banned!", args[1]); return; } if (m_BanSystem.UnBan(args[1], user.Nickname)) user.SendNotice("'{0}' unbanned!", args[1]); else user.SendNotice("Unable to unban '{0}'", args[1]); return; } case "edit": { if (!m_SphereAuth.IsStaff(user) || (m_SphereAuth.GetStaffPriv(user) < AccountPriv.GM)) { user.SendNotice("You cannot use this command."); return; } if (args.Length < 3) { user.SendNotice("Incorrect Arguments: 'Ban Edit <Account> <Reason>'"); return; } if (!m_BanSystem.IsBanned(args[1])) { user.SendNotice("Account '{0}' wasn't banned!", args[1]);... [truncated message content] |