[Bobbot-cvs] Plugins/Sphere SphereConfig.cs,1.6,1.7 SpherePlugin.cs,1.22,1.23
Status: Alpha
Brought to you by:
iainmckay
From: Mr S. C. <mrs...@us...> - 2005-07-17 21:09:04
|
Update of /cvsroot/bobbot/Plugins/Sphere In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24008/Sphere Modified Files: SphereConfig.cs SpherePlugin.cs Log Message: - Added Accounting.AccountsReader for reading accounts directly from a Sphere Accounts File - Added Accounting.MultiAccountSearch for finding accounts with matching IPs or Passwords. - Added more log messages to find with 'log list' - Added ability o disable Jail and Bans systems by placing '-1' as their database file paths. - Updated Messages from sphere console. Index: SpherePlugin.cs =================================================================== RCS file: /cvsroot/bobbot/Plugins/Sphere/SpherePlugin.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** SpherePlugin.cs 26 Feb 2005 22:41:38 -0000 1.22 --- SpherePlugin.cs 17 Jul 2005 21:08:55 -0000 1.23 *************** *** 1,3 **** ! #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.Configuration; 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 Bot.Other.Sphere; using Bot.Other.Sphere.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 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_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 = ""; if (File.Exists("peak.txt")) { StreamReader 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(); } 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_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.RegisterHandler(typeof(HouseKillingMessage)); m_Server.RegisterHandler(typeof(PlayerJailedMessage)); m_Server.RegisterHandler(typeof(PlayerReleasedMessage)); m_Server.RegisterHandler(typeof(SkillNukeMessage)); Bot.Core.Kernel.Instance.Network.Welcome += new WelcomeReplyEventHandler(OnNetworkWelcome); 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); m_JailSystem = new JailSystem(this, m_Config.JailDatabase); 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_Timer.Interval == 1) { m_Timer.Stop(); m_Timer.Interval = m_Config.ResyncPeriod; m_Timer.Start(); } } private void OnClientConnected(object sender, ClientConnectedEventArgs args) --- 1,3 ---- ! #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 Bot.Other.Sphere; using Bot.Other.Sphere.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) *************** *** 7,17 **** if (args.Message.ClientCount > m_ClientPeak) m_ClientPeak = args.Message.ClientCount; - } #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("!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 > 50) { chan.SendMessage("The specified message is too long. You cannot use more than 50 characters."); return; } m_Server.WriteLine("var.lothbot_target={0}", args[0]); m_Server.WriteLine("uid.{0}.respondtoplayer {1}", m_LothBotUid, message.Trim()); } [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 (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 (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]); return; } string banargs = ""; for (int i = 2; i < args.Length; i++) banargs += " " + args[i]; if (m_BanSystem.EditBan(args[1], user.Nickname, banargs.Trim())) user.SendNotice("'{0}'s ban entry is edited!", args[1]); else user.SendNotice("Unable to edit ban entry '{0}'!", args[1]); return; } case "list": { if (m_BanSystem.BannedAccounts <= 0) { user.SendNotice("No Accounts are Banned!"); return; } foreach (BanEntry entry in m_BanSystem.GetBanEntryList()) { user.SendNotice("Account: {0}", entry.Account); } return; } case "info": { if (args.Length < 2) { user.SendNotice("Incorrect Arguments: 'Ban Info <Account>'"); return; } BanEntry entry = m_BanSystem.GetBanEntry(args[1]); if (entry != null) { user.SendNotice("Account: {0}", entry.Account); user.SendNotice("Character: {0}", entry.Character); user.SendNotice("Banned By: {0}", entry.BannedBy); user.SendNotice("Ban Date: {0}", entry.BannedOn); user.SendNotice("Reason: {0}", entry.Reason); } else user.SendNotice("Account '{0}' Not Banned!", 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_BanSystem.SaveDatabase()) user.SendNotice("Database Saved Successfully."); else user.SendNotice("Database Failed to Save!"); return; } case "help": { if (args.Length < 2) { user.SendNotice("Incorrect Arguments: 'Ban 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} Ban Add <Account> [<Reason>]", Kernel.Instance.Network.Nickname); user.SendNotice("Adds a new ban database entry for <Account>. The account will"); user.SendNotice("automatically be banned ingame."); 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} Ban Add myAccount", Kernel.Instance.Network.Nickname); user.SendNotice(" /msg {0} Ban Add myAccount Banned for injection abuse.", Kernel.Instance.Network.Nickname); return; } case "del": { 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} Ban Del <Account>", Kernel.Instance.Network.Nickname); user.SendNotice("Deletes the entry for <Account> from the database. The account"); user.SendNotice("will automatically be unbanned ingame."); user.SendNotice("Example: /msg {0} Ban 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} Ban Edit <Account> <Reason>", Kernel.Instance.Network.Nickname); user.SendNotice("Edits the entry for <Account> in the database, exchanging the."); user.SendNotice("current Reason to <Reason>."); user.SendNotice("The 'Banned By' property of the ban 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(" /msg {0} Ban Edit myAccount Banned for injection 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} Ban Save", Kernel.Instance.Network.Nickname); user.SendNotice("Forces the Ban Database to be saved immediately. Unsaved ban"); user.SendNotice("entries will result in players not being released if the Bot"); user.SendNotice("is restarted."); user.SendNotice("Example: /msg {0} Ban Save", Kernel.Instance.Network.Nickname); return; } case "list": { user.SendNotice("/msg {0} Ban List", Kernel.Instance.Network.Nickname); user.SendNotice("Displays a list of all the currently banned accounts, along with"); user.SendNotice("their release dates. For more information on a ban entry, use"); user.SendNotice("Ban Info"); user.SendNotice("Example: /msg {0} Ban List", Kernel.Instance.Network.Nickname); return; } case "info": { user.SendNotice("/msg {0} Ban Info <Account>", Kernel.Instance.Network.Nickname); user.SendNotice("Displays information on <Account>'s ban entry."); user.SendNotice("Example: /msg {0} Ban 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 '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; } } } #endregion #region Page Commands /* [AllowCondition("LothStaff", AccountPriv.Counselor, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!pages")] private void PagesCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (!m_Server.IsConnected) { chan.SendMessage("Not Connected To Server"); return; } int pages = (int)m_Server.GetProperty("GMPAGES", typeof(int)); if (pages <= 0) { user.SendNotice("There are no pages to list!"); return; } user.SendNotice("Pages: {0}", pages); for (int i = 0; i < pages; i++) { user.SendNotice( "{0}. Time=\"{1} minutes ago\" Account=\"{2}\" Reason=\"{3}\"", (i + 1), (Int32.Parse((string)m_Server.GetProperty(String.Format("GMPAGE.{0}.TIME", i)), System.Globalization.NumberStyles.HexNumber) / 60), (string)m_Server.GetProperty(String.Format("GMPAGE.{0}.ACCOUNT", i)), (string)m_Server.GetProperty(String.Format("GMPAGE.{0}.REASON", i)) ); } } [AllowCondition("LothStaff", AccountPriv.Counselor, AllowConditionUsage.GreaterThanOrEqual, AllowConditionTarget.User)] [AllowCondition("StaffChannel", true, AllowConditionUsage.Equals, AllowConditionTarget.Channel)] [ChannelCommand("!page delete")] private void PageCommand(NetworkChannel chan, NetworkUser user, string[] args) { if (!m_Server.IsConnected) { chan.SendMessage("Not Connected To Server"); return; } if (args.Length <= 0) { PagesCommand(chan, user, args); return; } int page; try {page = Int32.Parse(args[0]) - 1; } catch { return; } if (page < 0) { chan.SendMe... [truncated message content] |