From 2486bc9993e43abaaacea0f7473000fd48657f45 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Mon, 9 Mar 2015 15:11:09 -0500 Subject: [PATCH] added pm command fixed connections not incrementing fixed formatting of ban response added ability of multiple instances running --- Admin/App.config | 6 ++--- Admin/Command.cs | 13 +++++++++- Admin/Connection.cs | 20 +++++++++++----- Admin/Database.cs | 2 +- Admin/IW4M ADMIN.csproj | 25 ++++++++++++------- Admin/Main.cs | 41 +++++++++++++++++++++++++------- Admin/Player.cs | 2 +- Admin/Properties/AssemblyInfo.cs | 2 +- Admin/Server.cs | 10 ++++---- Admin/version.txt | 1 + 10 files changed, 88 insertions(+), 34 deletions(-) create mode 100644 Admin/version.txt diff --git a/Admin/App.config b/Admin/App.config index d3d299647..fe52a9bf4 100644 --- a/Admin/App.config +++ b/Admin/App.config @@ -1,6 +1,6 @@ - - - + + + diff --git a/Admin/Command.cs b/Admin/Command.cs index 938dafddc..dc7860afa 100644 --- a/Admin/Command.cs +++ b/Admin/Command.cs @@ -171,7 +171,7 @@ namespace IW4MAdmin if (E.Origin.getLevel() > E.Target.getLevel()) { E.Target.Ban(Message, E.Origin); - E.Origin.Tell("Successfully banned ^5" + E.Target.getName() + " (^7" + E.Target.getID()); + E.Origin.Tell(String.Format("Sucessfully banned ^5{0} ^7({1})", E.Target.getName(), E.Target.getID())); } else E.Origin.Tell("You cannot ban " + E.Target.getName()); @@ -431,4 +431,15 @@ namespace IW4MAdmin } } + + class PrivateMessage : Command + { + public PrivateMessage(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { } + + public override void Execute(Event E) + { + E.Target.Tell("^1" + E.Origin.getName() + " ^3[PM]^7 - " + E.Data); + E.Origin.Tell("Sucessfully sent message"); + } + } } diff --git a/Admin/Connection.cs b/Admin/Connection.cs index fa1ce8df4..3c5a3dacd 100644 --- a/Admin/Connection.cs +++ b/Admin/Connection.cs @@ -17,14 +17,22 @@ namespace IW4MAdmin public String Read() { - WebResponse Resp = ConnectionHandle.GetResponse(); - StreamReader data_in = new StreamReader(Resp.GetResponseStream()); - String result = data_in.ReadToEnd(); + try + { + WebResponse Resp = ConnectionHandle.GetResponse(); + StreamReader data_in = new StreamReader(Resp.GetResponseStream()); + String result = data_in.ReadToEnd(); - data_in.Close(); - Resp.Close(); + data_in.Close(); + Resp.Close(); - return result; + return result; + } + + catch (System.Net.WebException E) + { + return null; + } } private String Location; diff --git a/Admin/Database.cs b/Admin/Database.cs index 1f78e5181..fa34fd99b 100644 --- a/Admin/Database.cs +++ b/Admin/Database.cs @@ -37,7 +37,7 @@ namespace IW4MAdmin if (Result != null && Result.Rows.Count > 0) { DataRow ResponseRow = Result.Rows[0]; - return new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), cNum, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), ResponseRow["LastOffense"].ToString(), ((int)ResponseRow["Connections"] + 1)); + return new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), cNum, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), ResponseRow["LastOffense"].ToString(), (int)ResponseRow["Connections"]); } else diff --git a/Admin/IW4M ADMIN.csproj b/Admin/IW4M ADMIN.csproj index 6f3703c5a..4878af297 100644 --- a/Admin/IW4M ADMIN.csproj +++ b/Admin/IW4M ADMIN.csproj @@ -13,7 +13,7 @@ 512 true - ftp://raidmax.org/IW4M/Admin/ + ftp://raidmax.org/ true Web true @@ -22,14 +22,14 @@ Days false false - true + false http://raidmax.org/IW4M/Admin/ IW4M Administration RaidMax LLC true publish.htm - 3 - 0.1.0.%2a + 4 + 0.2.0.%2a false true true @@ -109,11 +109,20 @@ + - - - - + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/Admin/Main.cs b/Admin/Main.cs index 00074a2c0..6da523153 100644 --- a/Admin/Main.cs +++ b/Admin/Main.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading; namespace IW4MAdmin { @@ -9,20 +10,26 @@ namespace IW4MAdmin static String IP; static int Port; static String RCON; + static double Version = 0.2; static void Main(string[] args) { Console.WriteLine("====================================================="); - Console.WriteLine(" IW4M ADMIN v"); + Console.WriteLine(" IW4M ADMIN"); Console.WriteLine(" by RaidMax "); + String latestVer = checkUpdate(); + if (latestVer != null) + Console.WriteLine(" Version " + Version + " (latest " + latestVer + ")"); + else + Console.WriteLine(" Version " + Version + " (unable to retrieve latest)"); Console.WriteLine("====================================================="); + file Config = new file("config\\servers.cfg"); - String[] SV_CONF = Config.getParameters(3); - double Version = 0.1; + String[] SV_CONF = Config.readAll(); - if (SV_CONF == null || SV_CONF.Length != 3) + if (SV_CONF == null || SV_CONF.Length < 1) { setupConfig(); SV_CONF = new file("config\\servers.cfg").getParameters(3); @@ -31,11 +38,23 @@ namespace IW4MAdmin if (Config.getSize() > 0 && SV_CONF != null) { - Console.WriteLine("Starting admin on port " + SV_CONF[1]); + foreach (String S in SV_CONF) + { + if (S.Length < 1) + continue; - Server IW4M; - IW4M = new Server(SV_CONF[0], Convert.ToInt32(SV_CONF[1]), SV_CONF[2]); - IW4M.Monitor(); + String[] sv = S.Split(':'); + + Console.WriteLine("Starting admin on port " + sv[1]); + + Server IW4M; + IW4M = new Server(sv[0], Convert.ToInt32(sv[1]), sv[2]); + + //Threading seems best here + Thread monitorThread = new Thread(new ThreadStart(IW4M.Monitor)); + monitorThread.Start(); + } + } else { @@ -58,5 +77,11 @@ namespace IW4MAdmin Config.Write(IP + ":" + Port + ":" + RCON); Console.WriteLine("Great! Let's go ahead and start 'er up."); } + + static String checkUpdate() + { + Connection Ver = new Connection("http://raidmax.org/IW4M/Admin/version.txt"); + return Ver.Read(); + } } } diff --git a/Admin/Player.cs b/Admin/Player.cs index dd375d390..4434d8102 100644 --- a/Admin/Player.cs +++ b/Admin/Player.cs @@ -36,7 +36,7 @@ namespace IW4MAdmin Level = l; dbID = cind; LastOffense = lo; - Connections = con; + Connections = con + 1; Warnings = 0; } diff --git a/Admin/Properties/AssemblyInfo.cs b/Admin/Properties/AssemblyInfo.cs index 7fb6d6e90..b52354359 100644 --- a/Admin/Properties/AssemblyInfo.cs +++ b/Admin/Properties/AssemblyInfo.cs @@ -33,5 +33,5 @@ using System.Resources; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.*")] +[assembly: AssemblyVersion("0.1.*")] [assembly: NeutralResourcesLanguageAttribute("en")] diff --git a/Admin/Server.cs b/Admin/Server.cs index 706f08a73..3b491381c 100644 --- a/Admin/Server.cs +++ b/Admin/Server.cs @@ -22,7 +22,7 @@ namespace IW4MAdmin logFile = new file("admin_" + port + ".log", true); Log = new Log(logFile, Log.Level.Production); players = new List(new Player[18]); - DB = new Database(port + ".dll"); + DB = new Database("clients.dll"); Bans = DB.getBans(); owner = DB.getOwner(); maps = new List(); @@ -113,7 +113,7 @@ namespace IW4MAdmin } catch (Exception E) { - Log.Write("Unable to add player - " + E.Message, Log.Level.Debug); + Log.Write("Unable to add player " + P.getName() + " - " + E.Message, Log.Level.Debug); return false; } } @@ -254,9 +254,9 @@ namespace IW4MAdmin { if (!intializeBasics()) { - Log.Write("Shutting due to uncorrectable errors (check log)" + logPath, Log.Level.Production); + Log.Write("Stopping " + Port + " due to uncorrectable errors (check log)" + logPath, Log.Level.Production); Utilities.Wait(10); - Environment.Exit(-1); + return; } //Handles new rcon requests in a fashionable manner @@ -717,7 +717,7 @@ namespace IW4MAdmin commands.Add(new MapCMD("map", "change to specified map. syntax: !map", "m", Player.Permission.Administrator, 1, false)); commands.Add(new Find("find", "find player in database. syntax: !find ", "f", Player.Permission.Administrator, 1, false)); commands.Add(new Rules("rules", "list server rules. syntax: !rules", "r", Player.Permission.User, 0, false)); - + commands.Add(new PrivateMessage("privatemessage", "send message to other player. syntax: !pm ", "pm", Player.Permission.User, 2, true)); /* commands.Add(new commands { command = "stats", desc = "view your server stats.", requiredPer = 0 }); commands.Add(new commands { command = "speed", desc = "change player speed. syntax: !speed ", requiredPer = 3 }); diff --git a/Admin/version.txt b/Admin/version.txt new file mode 100644 index 000000000..d55bea3a0 --- /dev/null +++ b/Admin/version.txt @@ -0,0 +1 @@ +0.2 \ No newline at end of file