Changeset 130 for binary-improvements/7dtd-server-fixes
- Timestamp:
- Aug 26, 2014, 4:41:47 PM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes
- Files:
-
- 5 added
- 18 edited
- 6 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
r128 r130 9 9 <OutputType>Library</OutputType> 10 10 <AssemblyName>7dtd-server-fixes</AssemblyName> 11 <RootNamespace>AllocsFixes</RootNamespace> 11 12 </PropertyGroup> 12 13 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> … … 44 45 <Compile Include="src\AssemblyInfo.cs" /> 45 46 <Compile Include="src\AllocsTelnetConnection.cs" /> 46 <Compile Include="src\TelnetCommands\GetTime.cs" />47 <Compile Include="src\TelnetCommands\ListPlayersExtended.cs" />48 <Compile Include="src\TelnetCommands\GetGamePrefs.cs" />49 <Compile Include="src\TelnetCommands\SayToPlayer.cs" />50 47 <Compile Include="src\AllocsLogFunctions.cs" /> 51 <Compile Include="src\TelnetCommands\SetTimeReal.cs" />52 48 <Compile Include="src\AdminToolsStuff.cs" /> 53 <Compile Include="src\TelnetCommands\ShowInventory.cs" />54 49 <Compile Include="src\PlayerDataStuff.cs" /> 55 50 <Compile Include="src\CommandExtensions.cs" /> 56 51 <Compile Include="src\CommonMappingFunctions.cs" /> 57 52 <Compile Include="src\ConsoleOutputSeparator.cs" /> 58 <Compile Include="src\TelnetCommands\PrivateMassageConnections.cs" /> 59 <Compile Include="src\TelnetCommands\Reply.cs" /> 60 <Compile Include="src\TelnetCommands\Kill.cs" /> 61 <Compile Include="src\TelnetCommands\ListLandProtection.cs" /> 62 <Compile Include="src\TelnetCommands\RemoveLandProtection.cs" /> 63 <Compile Include="src\TelnetCommands\Version.cs" /> 64 <Compile Include="src\TelnetCommands\RenderMap.cs" /> 65 <Compile Include="src\TelnetCommands\CreativeMenu.cs" /> 66 <Compile Include="src\TelnetCommands\Give.cs" /> 67 <Compile Include="src\TelnetCommands\ListItems.cs" /> 68 <Compile Include="src\MapRendering.cs" /> 53 <Compile Include="src\MapRendering\MapRendering.cs" /> 54 <Compile Include="src\MapRendering\MapRenderBlockBuffer.cs" /> 55 <Compile Include="src\MapRendering\Constants.cs" /> 56 <Compile Include="src\CustomCommands\GetTime.cs" /> 57 <Compile Include="src\CustomCommands\ListPlayersExtended.cs" /> 58 <Compile Include="src\CustomCommands\GetGamePrefs.cs" /> 59 <Compile Include="src\CustomCommands\SayToPlayer.cs" /> 60 <Compile Include="src\CustomCommands\SetTimeReal.cs" /> 61 <Compile Include="src\CustomCommands\ShowInventory.cs" /> 62 <Compile Include="src\CustomCommands\PrivateMassageConnections.cs" /> 63 <Compile Include="src\CustomCommands\Reply.cs" /> 64 <Compile Include="src\CustomCommands\Kill.cs" /> 65 <Compile Include="src\CustomCommands\ListLandProtection.cs" /> 66 <Compile Include="src\CustomCommands\RemoveLandProtection.cs" /> 67 <Compile Include="src\CustomCommands\Version.cs" /> 68 <Compile Include="src\CustomCommands\RenderMap.cs" /> 69 <Compile Include="src\CustomCommands\CreativeMenu.cs" /> 70 <Compile Include="src\CustomCommands\Give.cs" /> 71 <Compile Include="src\CustomCommands\ListItems.cs" /> 69 72 </ItemGroup> 70 73 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 71 74 <ItemGroup> 72 75 <Folder Include="src\" /> 73 <Folder Include="src\TelnetCommands\" /> 76 <Folder Include="src\MapRendering\" /> 77 <Folder Include="src\CustomCommands\" /> 74 78 </ItemGroup> 75 79 </Project> -
binary-improvements/7dtd-server-fixes/src/AdminToolsStuff.cs
r128 r130 2 2 using System.Collections.Generic; 3 3 4 public class AdminToolsStuff 4 namespace AllocsFixes 5 5 { 6 public static string[] GetAllowedCommandsList (AdminTools admTools, string _steamID)6 public class AdminToolsStuff 7 7 { 8 List<string> allowed = new List<string> (); 8 public static string[] GetAllowedCommandsList (AdminTools admTools, string _steamID) 9 { 10 List<string> allowed = new List<string> (); 9 11 10 try { 11 AdminToolsClientInfo tmpInfo = admTools.GetClientCommandInfo (_steamID); 12 if (tmpInfo.SteamID == null || tmpInfo.SteamID.Length == 0) 13 { 14 tmpInfo.PermissionLevel = 1000; 12 try { 13 AdminToolsClientInfo tmpInfo = admTools.GetClientCommandInfo (_steamID); 14 if (tmpInfo.SteamID == null || tmpInfo.SteamID.Length == 0) { 15 tmpInfo.PermissionLevel = 1000; 16 } 17 18 List<AdminToolsCommandPermissions> perms = admTools.commandPermissions; 19 ConsoleSdtd console = CommonMappingFunctions.GetGameManager ().m_GUIConsole; 20 21 foreach (AdminToolsCommandPermissions atcp in perms) { 22 if (tmpInfo.SteamID != null && tmpInfo.SteamID.Length > 0) { 23 if ((atcp.PermissionLevel >= tmpInfo.PermissionLevel) || (atcp.PermissionLevel >= 1000)) { 24 addAllowed (console, allowed, atcp.Command); 25 } 26 } else { 27 if (atcp.PermissionLevel >= 1000) { 28 addAllowed (console, allowed, atcp.Command); 29 } 30 } 31 } 32 33 if (tmpInfo.PermissionLevel <= 0) { 34 List<ConsoleCommand> commands = console.commands; 35 foreach (ConsoleCommand c in commands) { 36 if (!allowed.Contains (c.Names () [0])) { 37 if (!hasPermissionLevel (admTools, c.Names () [0])) { 38 addAllowed (console, allowed, c.Names () [0]); 39 } 40 } 41 } 42 } 43 44 } catch (Exception e) { 45 Log.Out ("Error in GetAllowedCommandsList: " + e); 15 46 } 16 47 48 49 return allowed.ToArray (); 50 } 51 52 private static bool hasPermissionLevel (AdminTools admTools, string cmd) 53 { 17 54 List<AdminToolsCommandPermissions> perms = admTools.commandPermissions; 18 ConsoleSdtd console = CommonMappingFunctions.GetGameManager ().m_GUIConsole;19 55 20 56 foreach (AdminToolsCommandPermissions atcp in perms) { 21 if (tmpInfo.SteamID != null && tmpInfo.SteamID.Length > 0) { 22 if ((atcp.PermissionLevel >= tmpInfo.PermissionLevel) || (atcp.PermissionLevel >= 1000)) { 23 addAllowed (console, allowed, atcp.Command); 24 } 25 } else { 26 if (atcp.PermissionLevel >= 1000) { 27 addAllowed (console, allowed, atcp.Command); 57 foreach (string ccName in getAlternativeNames(cmd)) { 58 if (atcp.Command.ToLower ().Equals (ccName)) { 59 return true; 28 60 } 29 61 } 30 62 } 31 32 if (tmpInfo.PermissionLevel <= 0) { 33 List<ConsoleCommand> commands = console.commands; 34 foreach (ConsoleCommand c in commands) { 35 if (!allowed.Contains (c.Names () [0])) { 36 if (!hasPermissionLevel (admTools, c.Names () [0])) { 37 addAllowed (console, allowed, c.Names () [0]); 38 } 39 } 40 } 41 } 42 43 } catch (Exception e) { 44 Log.Out ("Error in GetAllowedCommandsList: " + e); 63 return false; 45 64 } 46 65 47 48 return allowed.ToArray (); 49 } 50 51 private static bool hasPermissionLevel (AdminTools admTools, string cmd) 52 { 53 List<AdminToolsCommandPermissions> perms = admTools.commandPermissions; 54 55 foreach (AdminToolsCommandPermissions atcp in perms) { 66 private static void addAllowed (ConsoleSdtd console, List<string> list, string cmd) 67 { 56 68 foreach (string ccName in getAlternativeNames(cmd)) { 57 if ( atcp.Command.ToLower ().Equals (ccName)) {58 return true;69 if (!list.Contains (ccName)) { 70 list.Add (ccName); 59 71 } 60 72 } 61 73 } 62 return false;63 }64 74 65 private static void addAllowed (ConsoleSdtd console, List<string> list, string cmd) 66 { 67 foreach (string ccName in getAlternativeNames(cmd)) { 68 if (!list.Contains (ccName)) { 69 list.Add (ccName); 75 private static string[] getAlternativeNames (string cmd) 76 { 77 ConsoleCommand cc = CommonMappingFunctions.GetGameManager ().m_GUIConsole.getCommand (cmd); 78 if (cc != null) { 79 return cc.Names (); 80 } else { 81 return new string[]{cmd}; 70 82 } 71 83 } 72 84 } 73 74 private static string[] getAlternativeNames (string cmd)75 {76 ConsoleCommand cc = CommonMappingFunctions.GetGameManager ().m_GUIConsole.getCommand (cmd);77 if (cc != null) {78 return cc.Names ();79 } else {80 return new string[]{cmd};81 }82 }83 85 } 84 -
binary-improvements/7dtd-server-fixes/src/AllocsLogFunctions.cs
r107 r130 3 3 using UnityEngine; 4 4 5 public class AllocsLogFunctions5 namespace AllocsFixes 6 6 { 7 public static void RequestToSpawnPlayer (GameManager manager, int _clientId, string _name, string _playerClassname, string _skinTexture, int _chunkViewDim)7 public class AllocsLogFunctions 8 8 { 9 try { 10 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromClientID (_clientId); 11 int entityId = CommonMappingFunctions.GetEntityID (ci); 12 EntityPlayer ep = CommonMappingFunctions.GetEntityPlayer (ci); 9 public static void RequestToSpawnPlayer (GameManager manager, int _clientId, string _name, string _playerClassname, string _skinTexture, int _chunkViewDim) 10 { 11 try { 12 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromClientID (_clientId); 13 int entityId = CommonMappingFunctions.GetEntityID (ci); 14 EntityPlayer ep = CommonMappingFunctions.GetEntityPlayer (ci); 13 15 14 string ip = ci.networkPlayer.ipAddress;15 string name = string.Empty;16 string ip = ci.networkPlayer.ipAddress; 17 string name = string.Empty; 16 18 17 if (ep != null)18 name = ep.EntityName;19 if (ep != null) 20 name = ep.EntityName; 19 21 20 Log.Out ("Player connected, clientid=" + _clientId + 21 ", entityid=" + entityId + 22 ", name=" + name + 23 ", steamid=" + CommonMappingFunctions.GetSteamID (ci) + 24 ", ip=" + ip 25 ); 26 } catch (Exception e) { 27 Log.Out ("Error in RequestToSpawnPlayer: " + e); 22 Log.Out ("Player connected, clientid=" + _clientId + 23 ", entityid=" + entityId + 24 ", name=" + name + 25 ", steamid=" + CommonMappingFunctions.GetSteamID (ci) + 26 ", ip=" + ip 27 ); 28 } catch (Exception e) { 29 Log.Out ("Error in RequestToSpawnPlayer: " + e); 30 } 28 31 } 29 32 } -
binary-improvements/7dtd-server-fixes/src/AllocsNetTelnetServer.cs
r115 r130 7 7 using System.Threading; 8 8 9 public class AllocsNetTelnetServer 9 namespace AllocsFixes 10 10 { 11 private static ConsoleSdtd console = null; 12 private static Thread telnetThread = null; 13 private static TcpListener listener = null; 14 private static bool closed = false; 15 private static bool authEnabled = false; 16 private static List<AllocsTelnetConnection> connections = new List<AllocsTelnetConnection> (); 11 public class AllocsNetTelnetServer 12 { 13 private static Thread telnetThread = null; 14 private static TcpListener listener = null; 15 private static bool closed = false; 16 private static bool authEnabled = false; 17 private static List<AllocsTelnetConnection> connections = new List<AllocsTelnetConnection> (); 17 18 18 public static void init (int port) 19 { 20 try { 21 Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly ().GetName ().Version); 22 authEnabled = GamePrefs.GetString (EnumGamePrefs.TelnetPassword).Length != 0; 23 if (authEnabled) 24 listener = new TcpListener (IPAddress.Any, port); 25 else 26 listener = new TcpListener (IPAddress.Loopback, port); 27 telnetThread = ThreadMaster.Create ("thread Allocs TelnetListenThread", new ThreadStart (telnetListenThread)); 28 telnetThread.Start (); 29 Log.Out ("Started Allocs NetTelnetServer thread on " + port); 30 } catch (Exception e) { 31 Log.Out ("Error in AllocsTelnetServer.init: " + e); 19 public static void init (int port) 20 { 21 try { 22 Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly ().GetName ().Version); 23 authEnabled = GamePrefs.GetString (EnumGamePrefs.TelnetPassword).Length != 0; 24 if (authEnabled) 25 listener = new TcpListener (IPAddress.Any, port); 26 else 27 listener = new TcpListener (IPAddress.Loopback, port); 28 telnetThread = ThreadMaster.Create ("thread Allocs TelnetListenThread", new ThreadStart (telnetListenThread)); 29 telnetThread.Start (); 30 Log.Out ("Started Allocs NetTelnetServer thread on " + port); 31 } catch (Exception e) { 32 Log.Out ("Error in AllocsTelnetServer.init: " + e); 33 } 32 34 } 33 }34 35 35 private static void telnetListenThread () 36 { 37 try { 38 Log.Out ("Started thread_Allocs_TelnetListenThread()"); 39 listener.Start (); 40 while (!closed) { 41 Thread.Sleep (10); 42 if (listener.Pending ()) { 43 AllocsTelnetConnection c = new AllocsTelnetConnection (listener.AcceptTcpClient (), authEnabled); 44 connections.Add (c); 45 Log.Out ("Telnet connection from: " + c.GetEndPoint ()); 46 if (authEnabled) { 47 c.WriteLine ("Please enter password:"); 48 } else { 49 LoginMessage (c); 36 private static void telnetListenThread () 37 { 38 try { 39 Log.Out ("Started thread_Allocs_TelnetListenThread()"); 40 listener.Start (); 41 while (!closed) { 42 Thread.Sleep (10); 43 if (listener.Pending ()) { 44 AllocsTelnetConnection c = new AllocsTelnetConnection (listener.AcceptTcpClient (), authEnabled); 45 connections.Add (c); 46 Log.Out ("Telnet connection from: " + c.GetEndPoint ()); 47 if (authEnabled) { 48 c.WriteLine ("Please enter password:"); 49 } else { 50 LoginMessage (c); 51 } 52 } 53 54 foreach (AllocsTelnetConnection c in connections) { 55 if (c.IsClosed ()) { 56 c.Close (); 57 connections.Remove (c); 58 break; 59 } 60 if (c.Read ()) { 61 string line = lineCorrecter (c.GetLine ()); 62 if (!c.IsAuthenticated ()) { 63 if (line.Equals (GamePrefs.GetString (EnumGamePrefs.TelnetPassword))) { 64 c.SetAuthenticated (); 65 c.WriteLine ("Logon successful."); 66 c.WriteLine (string.Empty); 67 c.WriteLine (string.Empty); 68 c.WriteLine (string.Empty); 69 LoginMessage (c); 70 } else { 71 c.WriteLine ("Password incorrect, please enter password:"); 72 } 73 } else { 74 if (line.ToLower ().Equals ("exit")) { 75 Log.Out ("Telnet connection closed by client: " + c.GetEndPoint ()); 76 c.Close (); 77 connections.Remove (c); 78 break; 79 } 80 Log.Out ("Telnet executed \"" + line + "\" from: " + c.GetEndPoint ()); 81 ConsoleOutputSeparator.QueueTelnetCommand (line, c); 82 } 83 } 50 84 } 51 85 } 86 Log.Out ("Exited thread_Allocs_TelnetListenThread()"); 87 ThreadMaster.Remove (Thread.CurrentThread.Name); 88 } catch (Exception ex) { 89 Log.Out ("Error in Allocs telnetListenThread: " + ex.Message); 90 Log.Out ("Stack Trace: " + ex.StackTrace); 91 } 92 } 52 93 94 private static void LoginMessage (AllocsTelnetConnection c) 95 { 96 c.WriteLine ("*** Connected with 7DTD server."); 97 c.WriteLine ("*** Dedicated server only build"); 98 c.WriteLine ("*** Allocs server fixes loaded"); 99 c.WriteLine (string.Empty); 100 c.WriteLine ("Server IP: " + 101 ((GamePrefs.GetString (EnumGamePrefs.ServerIP) != null && GamePrefs.GetString (EnumGamePrefs.ServerIP).Length != 0) ? GamePrefs.GetString (EnumGamePrefs.ServerIP) : "Any") 102 ); 103 c.WriteLine ("Server port: " + GamePrefs.GetInt (EnumGamePrefs.ServerPort)); 104 c.WriteLine ("Max players: " + GamePrefs.GetInt (EnumGamePrefs.ServerMaxPlayerCount)); 105 c.WriteLine ("Game mode: " + GamePrefs.GetString (EnumGamePrefs.GameMode)); 106 c.WriteLine ("World: " + GamePrefs.GetString (EnumGamePrefs.GameWorld)); 107 c.WriteLine ("Game name: " + GamePrefs.GetString (EnumGamePrefs.GameName)); 108 c.WriteLine ("Difficulty: " + GamePrefs.GetInt (EnumGamePrefs.GameDifficulty)); 109 c.WriteLine (string.Empty); 110 c.WriteLine ("Press 'help' to get a list of all commands. Press 'exit' to end session."); 111 c.WriteLine (string.Empty); 112 } 113 114 private static string lineCorrecter (string line) 115 { 116 string res = ""; 117 for (int i = 0; i < line.Length; i++) { 118 if (line [i] >= ' ' && line [i] != '\'' && line [i] <= '~') { 119 res += line [i]; 120 } 121 } 122 return res.Trim (); 123 } 124 125 public static void Disconnect () 126 { 127 try { 128 closed = true; 129 if (listener != null) { 130 listener.Stop (); 131 } 132 foreach (AllocsTelnetConnection c in connections) { 133 c.Close (); 134 } 135 Thread.Sleep (100); 136 } catch (Exception e) { 137 Log.Out ("Error in AllocsTelnetServer.Disconnect: " + e); 138 } 139 } 140 141 public static void SetConsole (ConsoleSdtd console) 142 { 143 } 144 145 private static void RemoveClosedConnections () 146 { 147 try { 53 148 foreach (AllocsTelnetConnection c in connections) { 54 149 if (c.IsClosed ()) { 55 150 c.Close (); 56 connections.Remove (c);57 break;58 }59 if (c.Read ()) {60 string line = lineCorrecter (c.GetLine ());61 if (!c.IsAuthenticated ()) {62 if (line.Equals (GamePrefs.GetString (EnumGamePrefs.TelnetPassword))) {63 c.SetAuthenticated ();64 c.WriteLine ("Logon successful.");65 c.WriteLine (string.Empty);66 c.WriteLine (string.Empty);67 c.WriteLine (string.Empty);68 LoginMessage (c);69 } else {70 c.WriteLine ("Password incorrect, please enter password:");71 }72 } else {73 if (line.ToLower ().Equals ("exit")) {74 Log.Out ("Telnet connection closed by client: " + c.GetEndPoint ());75 c.Close ();76 connections.Remove (c);77 break;78 }79 Log.Out ("Telnet executed \"" + line + "\" from: " + c.GetEndPoint ());80 ConsoleOutputSeparator.QueueTelnetCommand (line, c);81 }82 151 } 83 152 } 84 } 85 Log.Out ("Exited thread_Allocs_TelnetListenThread()"); 86 ThreadMaster.Remove (Thread.CurrentThread.Name); 87 } catch (Exception ex) { 88 Log.Out ("Error in Allocs telnetListenThread: " + ex.Message); 89 Log.Out ("Stack Trace: " + ex.StackTrace); 90 } 91 } 92 93 private static void LoginMessage (AllocsTelnetConnection c) 94 { 95 c.WriteLine ("*** Connected with 7DTD server."); 96 c.WriteLine ("*** Dedicated server only build"); 97 c.WriteLine ("*** Allocs server fixes loaded"); 98 c.WriteLine (string.Empty); 99 c.WriteLine ("Server IP: " + 100 ((GamePrefs.GetString (EnumGamePrefs.ServerIP) != null && GamePrefs.GetString (EnumGamePrefs.ServerIP).Length != 0) ? GamePrefs.GetString (EnumGamePrefs.ServerIP) : "Any") 101 ); 102 c.WriteLine ("Server port: " + GamePrefs.GetInt (EnumGamePrefs.ServerPort)); 103 c.WriteLine ("Max players: " + GamePrefs.GetInt (EnumGamePrefs.ServerMaxPlayerCount)); 104 c.WriteLine ("Game mode: " + GamePrefs.GetString (EnumGamePrefs.GameMode)); 105 c.WriteLine ("World: " + GamePrefs.GetString (EnumGamePrefs.GameWorld)); 106 c.WriteLine ("Game name: " + GamePrefs.GetString (EnumGamePrefs.GameName)); 107 c.WriteLine ("Difficulty: " + GamePrefs.GetInt (EnumGamePrefs.GameDifficulty)); 108 c.WriteLine (string.Empty); 109 c.WriteLine ("Press 'help' to get a list of all commands. Press 'exit' to end session."); 110 c.WriteLine (string.Empty); 111 } 112 113 private static string lineCorrecter (string line) 114 { 115 string res = ""; 116 for (int i = 0; i < line.Length; i++) { 117 if (line [i] >= ' ' && line [i] != '\'' && line [i] <= '~') { 118 res += line [i]; 153 } catch (Exception e) { 154 Log.Out ("Error in AllocsTelnetServer.RemoveClosedConnections: " + e); 119 155 } 120 156 } 121 return res.Trim ();122 }123 157 124 public static void Disconnect () 125 { 126 try { 127 closed = true; 128 if (listener != null) { 129 listener.Stop (); 158 public static void WriteToClient (string line) 159 { 160 if (line == null) { 161 return; 130 162 } 163 RemoveClosedConnections (); 131 164 foreach (AllocsTelnetConnection c in connections) { 132 c.Close (); 165 if (c.IsAuthenticated ()) 166 c.WriteLine (line); 133 167 } 134 Thread.Sleep (100);135 } catch (Exception e) {136 Log.Out ("Error in AllocsTelnetServer.Disconnect: " + e);137 168 } 138 }139 169 140 public static void SetConsole (ConsoleSdtd console) 141 { 142 Log.Out ("Telnet SetConsole called"); 143 AllocsNetTelnetServer.console = console; 144 } 145 146 private static void RemoveClosedConnections () 147 { 148 try { 170 public static void WriteToClient_Single (string line, AllocsTelnetConnection client) 171 { 172 if (line == null) { 173 return; 174 } 175 RemoveClosedConnections (); 149 176 foreach (AllocsTelnetConnection c in connections) { 150 if (c.IsClosed ()) { 151 c.Close (); 152 } 177 if (c.IsAuthenticated () && (c == client)) 178 c.WriteLine (line); 153 179 } 154 } catch (Exception e) {155 Log.Out ("Error in AllocsTelnetServer.RemoveClosedConnections: " + e);156 }157 }158 159 public static void WriteToClient (string line)160 {161 if (line == null) {162 return;163 }164 RemoveClosedConnections ();165 foreach (AllocsTelnetConnection c in connections) {166 if (c.IsAuthenticated ())167 c.WriteLine (line);168 }169 }170 171 public static void WriteToClient_Single (string line, AllocsTelnetConnection client)172 {173 if (line == null) {174 return;175 }176 RemoveClosedConnections ();177 foreach (AllocsTelnetConnection c in connections) {178 if (c.IsAuthenticated () && (c == client))179 c.WriteLine (line);180 180 } 181 181 } -
binary-improvements/7dtd-server-fixes/src/AllocsTelnetConnection.cs
r103 r130 3 3 using System.Net.Sockets; 4 4 5 namespace AllocsFixes 6 { 5 7 public class AllocsTelnetConnection 6 8 { … … 93 95 } 94 96 } 97 } -
binary-improvements/7dtd-server-fixes/src/CommandExtensions.cs
r128 r130 1 using AllocsFixes.CustomCommands; 1 2 using System; 2 3 using System.Collections.Generic; 3 4 4 public class CommandExtensions5 namespace AllocsFixes 5 6 { 6 public static void InitCommandExtensions (GameManager manager)7 public class CommandExtensions 7 8 { 8 try { 9 manager.m_GUIConsole.AddCommand (new CreativeMenu (manager.m_GUIConsole)); 10 manager.m_GUIConsole.AddCommand (new GetGamePrefs (manager.m_GUIConsole)); 11 manager.m_GUIConsole.AddCommand (new GetTime (manager.m_GUIConsole)); 12 manager.m_GUIConsole.AddCommand (new Give (manager.m_GUIConsole)); 13 manager.m_GUIConsole.AddCommand (new Kill (manager.m_GUIConsole)); 14 manager.m_GUIConsole.AddCommand (new ListItems (manager.m_GUIConsole)); 15 manager.m_GUIConsole.AddCommand (new ListLandProtection (manager.m_GUIConsole)); 16 manager.m_GUIConsole.AddCommand (new ListPlayersExtended (manager.m_GUIConsole)); 17 manager.m_GUIConsole.AddCommand (new RemoveLandProtection (manager.m_GUIConsole)); 18 manager.m_GUIConsole.AddCommand (new RenderMap (manager.m_GUIConsole)); 19 manager.m_GUIConsole.AddCommand (new Reply (manager.m_GUIConsole)); 20 manager.m_GUIConsole.AddCommand (new SayToPlayer (manager.m_GUIConsole)); 21 manager.m_GUIConsole.AddCommand (new SetTimeReal (manager.m_GUIConsole)); 22 manager.m_GUIConsole.AddCommand (new ShowInventory (manager.m_GUIConsole)); 23 manager.m_GUIConsole.AddCommand (new Version (manager.m_GUIConsole)); 24 } catch (Exception e) { 25 Log.Out ("Error registering custom commands: " + e); 9 public static void InitCommandExtensions (GameManager manager) 10 { 11 try { 12 manager.m_GUIConsole.AddCommand (new CreativeMenu (manager.m_GUIConsole)); 13 manager.m_GUIConsole.AddCommand (new GetGamePrefs (manager.m_GUIConsole)); 14 manager.m_GUIConsole.AddCommand (new GetTime (manager.m_GUIConsole)); 15 manager.m_GUIConsole.AddCommand (new Give (manager.m_GUIConsole)); 16 manager.m_GUIConsole.AddCommand (new Kill (manager.m_GUIConsole)); 17 manager.m_GUIConsole.AddCommand (new ListItems (manager.m_GUIConsole)); 18 manager.m_GUIConsole.AddCommand (new ListLandProtection (manager.m_GUIConsole)); 19 manager.m_GUIConsole.AddCommand (new ListPlayersExtended (manager.m_GUIConsole)); 20 manager.m_GUIConsole.AddCommand (new RemoveLandProtection (manager.m_GUIConsole)); 21 manager.m_GUIConsole.AddCommand (new RenderMap (manager.m_GUIConsole)); 22 manager.m_GUIConsole.AddCommand (new Reply (manager.m_GUIConsole)); 23 manager.m_GUIConsole.AddCommand (new SayToPlayer (manager.m_GUIConsole)); 24 manager.m_GUIConsole.AddCommand (new SetTimeReal (manager.m_GUIConsole)); 25 manager.m_GUIConsole.AddCommand (new ShowInventory (manager.m_GUIConsole)); 26 manager.m_GUIConsole.AddCommand (new AllocsFixes.CustomCommands.Version (manager.m_GUIConsole)); 27 } catch (Exception e) { 28 Log.Out ("Error registering custom commands: " + e); 29 } 26 30 } 27 31 } 28 32 } 29 -
binary-improvements/7dtd-server-fixes/src/CommonMappingFunctions.cs
r128 r130 4 4 using ManagedSteam.SteamTypes; 5 5 6 public class CommonMappingFunctions6 namespace AllocsFixes 7 7 { 8 public static ConnectionManager GetConnectionManager ()8 public class CommonMappingFunctions 9 9 { 10 return ConnectionManager.Instance; 11 } 10 public static ConnectionManager GetConnectionManager () 11 { 12 return ConnectionManager.Instance; 13 } 12 14 13 public static GameManager GetGameManager ()14 {15 return GetConnectionManager ().gameManager;16 }15 public static GameManager GetGameManager () 16 { 17 return GetConnectionManager ().gameManager; 18 } 17 19 18 public static string GetPlayerName (ClientInfo _ci) 19 { 20 try { 21 int entityId = GetConnectionManager ().mapClientToEntity [_ci.clientId]; 22 return GetGameManager ().World.playerEntities.dict [entityId].EntityName; 23 } catch (Exception e) { 24 Log.Out ("Error getting player name for ClientInfo: " + e); 20 public static string GetPlayerName (ClientInfo _ci) 21 { 22 try { 23 int entityId = GetConnectionManager ().mapClientToEntity [_ci.clientId]; 24 return GetGameManager ().World.playerEntities.dict [entityId].EntityName; 25 } catch (Exception e) { 26 Log.Out ("Error getting player name for ClientInfo: " + e); 27 } 28 return null; 25 29 } 26 return null;27 }28 30 29 public static EntityPlayer GetEntityPlayer (ClientInfo _ci) 30 { 31 try { 32 int entityId = GetConnectionManager ().mapClientToEntity [_ci.clientId]; 33 return GetGameManager ().World.playerEntities.dict [entityId]; 34 } catch (Exception e) { 35 Log.Out ("Error getting entity player for ClientInfo: " + e); 31 public static EntityPlayer GetEntityPlayer (ClientInfo _ci) 32 { 33 try { 34 int entityId = GetConnectionManager ().mapClientToEntity [_ci.clientId]; 35 return GetGameManager ().World.playerEntities.dict [entityId]; 36 } catch (Exception e) { 37 Log.Out ("Error getting entity player for ClientInfo: " + e); 38 } 39 return null; 36 40 } 37 return null;38 }39 41 40 public static string GetSteamID (ClientInfo _ci)41 {42 return SingletonMonoBehaviour<Authenticator>.Instance.GetPlayerId (GetPlayerName (_ci));43 }42 public static string GetSteamID (ClientInfo _ci) 43 { 44 return SingletonMonoBehaviour<Authenticator>.Instance.GetPlayerId (GetPlayerName (_ci)); 45 } 44 46 45 public static string GetSteamID (string _playerName)46 {47 return SingletonMonoBehaviour<Authenticator>.Instance.GetPlayerId (_playerName);48 }47 public static string GetSteamID (string _playerName) 48 { 49 return SingletonMonoBehaviour<Authenticator>.Instance.GetPlayerId (_playerName); 50 } 49 51 50 public static int GetClientID (ClientInfo _ci) 51 { 52 if (_ci != null) { 53 if (GetConnectionManager ().connectedClients.ContainsKey (_ci.clientId)) 54 return _ci.clientId; 52 public static int GetClientID (ClientInfo _ci) 53 { 54 if (_ci != null) { 55 if (GetConnectionManager ().connectedClients.ContainsKey (_ci.clientId)) 56 return _ci.clientId; 57 } 58 return -1; 55 59 } 56 return -1;57 }58 60 59 public static int GetEntityID (ClientInfo _ci)60 {61 try {62 ConnectionManager cm = GetConnectionManager ();61 public static int GetEntityID (ClientInfo _ci) 62 { 63 try { 64 ConnectionManager cm = GetConnectionManager (); 63 65 64 if (cm.mapClientToEntity.ContainsKey (_ci.clientId)) 65 return cm.mapClientToEntity [_ci.clientId]; 66 else 67 return -1; 68 } catch (Exception e) { 69 Log.Out ("Error getting entity ID for ClientInfo: " + e); 66 if (cm.mapClientToEntity.ContainsKey (_ci.clientId)) 67 return cm.mapClientToEntity [_ci.clientId]; 68 else 69 return -1; 70 } catch (Exception e) { 71 Log.Out ("Error getting entity ID for ClientInfo: " + e); 72 } 73 return -1; 70 74 } 71 return -1;72 }73 75 74 public static ClientInfo GetClientInfoFromEntityID (int _entityId)75 {76 try {77 ConnectionManager cm = GetConnectionManager ();76 public static ClientInfo GetClientInfoFromEntityID (int _entityId) 77 { 78 try { 79 ConnectionManager cm = GetConnectionManager (); 78 80 79 if (cm.mapClientToEntity.ContainsValue (_entityId)) { 80 foreach (KeyValuePair<int, int> kvp in cm.mapClientToEntity) { 81 if (kvp.Value == _entityId) { 82 return cm.connectedClients [kvp.Key]; 81 if (cm.mapClientToEntity.ContainsValue (_entityId)) { 82 foreach (KeyValuePair<int, int> kvp in cm.mapClientToEntity) { 83 if (kvp.Value == _entityId) { 84 return cm.connectedClients [kvp.Key]; 85 } 83 86 } 84 87 } 88 89 return null; 90 } catch (Exception e) { 91 Log.Out ("Error getting ClientInfo for entity ID: " + e); 85 92 } 93 return null; 94 } 86 95 96 public static ClientInfo GetClientInfoFromClientID (int _clientId) 97 { 98 try { 99 ConnectionManager cm = GetConnectionManager (); 100 101 if (cm.connectedClients.ContainsKey (_clientId)) 102 return cm.connectedClients [_clientId]; 103 else 104 return null; 105 } catch (Exception e) { 106 Log.Out ("Error getting ClientInfo for client ID: " + e); 107 } 87 108 return null; 88 } catch (Exception e) {89 Log.Out ("Error getting ClientInfo for entity ID: " + e);90 109 } 91 return null; 110 111 public static ClientInfo GetClientInfoFromPlayerName (string _playerName, bool ignoreColorcodes) 112 { 113 try { 114 ConnectionManager cm = GetConnectionManager (); 115 116 _playerName = _playerName.ToLower (); 117 if (ignoreColorcodes) { 118 _playerName = Regex.Replace (_playerName, "\\[[0-9a-fA-F]{6}\\]", ""); 119 } 120 foreach (ClientInfo ci in cm.connectedClients.Values) { 121 string curName = GetPlayerName (ci).ToLower (); 122 if (ignoreColorcodes) { 123 curName = Regex.Replace (curName, "\\[[0-9a-fA-F]{6}\\]", ""); 124 } 125 if (curName.Equals (_playerName)) { 126 return ci; 127 } 128 } 129 } catch (Exception e) { 130 Log.Out ("Error getting ClientInfo for player name: " + e); 131 } 132 return null; 133 } 134 135 public static ClientInfo GetClientInfoFromNameOrID (string _nameOrId, bool ignoreColorcodes) 136 { 137 try { 138 int entityId = -1; 139 if (int.TryParse (_nameOrId, out entityId)) { 140 ClientInfo ci = GetClientInfoFromEntityID (entityId); 141 if (ci != null) 142 return ci; 143 } 144 145 return GetClientInfoFromPlayerName (_nameOrId, ignoreColorcodes); 146 } catch (Exception e) { 147 Log.Out ("Error getting ClientInfo for entity ID or player name: " + e); 148 } 149 return null; 150 } 151 152 public static ClientInfo GetClientInfoFromSteamID (string _steamId) 153 { 154 try { 155 Dictionary<string, object> uToID = Authenticator.Instance.usersToIDs; 156 foreach (KeyValuePair<string, object> kvp in uToID) { 157 string curId = string.Empty + ((SteamID)kvp.Value).AsUInt64; 158 if (curId.Equals (_steamId)) { 159 return GetClientInfoFromPlayerName (kvp.Key, false); 160 } 161 } 162 } catch (Exception e) { 163 Log.Out ("Error getting ClientInfo for steam ID: " + e); 164 } 165 return null; 166 } 167 92 168 } 93 94 public static ClientInfo GetClientInfoFromClientID (int _clientId)95 {96 try {97 ConnectionManager cm = GetConnectionManager ();98 99 if (cm.connectedClients.ContainsKey (_clientId))100 return cm.connectedClients [_clientId];101 else102 return null;103 } catch (Exception e) {104 Log.Out ("Error getting ClientInfo for client ID: " + e);105 }106 return null;107 }108 109 public static ClientInfo GetClientInfoFromPlayerName (string _playerName, bool ignoreColorcodes)110 {111 try {112 ConnectionManager cm = GetConnectionManager ();113 114 _playerName = _playerName.ToLower ();115 if (ignoreColorcodes) {116 _playerName = Regex.Replace (_playerName, "\\[[0-9a-fA-F]{6}\\]", "");117 }118 foreach (ClientInfo ci in cm.connectedClients.Values) {119 string curName = GetPlayerName (ci).ToLower ();120 if (ignoreColorcodes) {121 curName = Regex.Replace (curName, "\\[[0-9a-fA-F]{6}\\]", "");122 }123 if (curName.Equals (_playerName)) {124 return ci;125 }126 }127 } catch (Exception e) {128 Log.Out ("Error getting ClientInfo for player name: " + e);129 }130 return null;131 }132 133 public static ClientInfo GetClientInfoFromNameOrID (string _nameOrId, bool ignoreColorcodes)134 {135 try {136 int entityId = -1;137 if (int.TryParse (_nameOrId, out entityId)) {138 ClientInfo ci = GetClientInfoFromEntityID (entityId);139 if (ci != null)140 return ci;141 }142 143 return GetClientInfoFromPlayerName (_nameOrId, ignoreColorcodes);144 } catch (Exception e) {145 Log.Out ("Error getting ClientInfo for entity ID or player name: " + e);146 }147 return null;148 }149 150 public static ClientInfo GetClientInfoFromSteamID (string _steamId)151 {152 try {153 Dictionary<string, object> uToID = Authenticator.Instance.usersToIDs;154 foreach (KeyValuePair<string, object> kvp in uToID) {155 string curId = string.Empty + ((SteamID)kvp.Value).AsUInt64;156 if (curId.Equals (_steamId)) {157 return GetClientInfoFromPlayerName (kvp.Key, false);158 }159 }160 } catch (Exception e) {161 Log.Out ("Error getting ClientInfo for steam ID: " + e);162 }163 return null;164 }165 166 169 } 167 -
binary-improvements/7dtd-server-fixes/src/ConsoleOutputSeparator.cs
r115 r130 4 4 using UnityEngine; 5 5 6 public class ConsoleOutputSeparator 6 namespace AllocsFixes 7 7 { 8 public struct AllocsTelnetCommand8 public class ConsoleOutputSeparator 9 9 { 10 public string command; 11 public AllocsTelnetConnection client; 10 public struct AllocsTelnetCommand 11 { 12 public string command; 13 public AllocsTelnetConnection client; 12 14 13 public AllocsTelnetCommand (string _cmd, AllocsTelnetConnection _client) 14 { 15 command = _cmd; 16 client = _client; 17 } 18 } 19 20 private static List<AllocsTelnetCommand> telnetCommandQueue = new List<AllocsTelnetCommand> (); 21 private static bool isCurrentCommandFromClient = false; 22 private static AllocsTelnetConnection issuerOfCurrentTelnetCommand; 23 24 public static void C_ExecuteCmdFromClient (ConsoleSdtd console, NetworkPlayer _networkPlayer, string _playerID, string _command) 25 { 26 Log.Out ("Executed command \"" + _command + "\" from player \"" + _playerID + "\""); 27 28 object obj = telnetCommandQueue; 29 Monitor.Enter (obj); 30 try { 31 isCurrentCommandFromClient = true; 32 console.issuerOfCurrentClientCommand = _networkPlayer; 33 console.ExecuteClientCmdInternal (_playerID, _command); 34 isCurrentCommandFromClient = false; 35 } finally { 36 Monitor.Exit (obj); 15 public AllocsTelnetCommand (string _cmd, AllocsTelnetConnection _client) 16 { 17 command = _cmd; 18 client = _client; 19 } 37 20 } 38 21 39 } 22 private static List<AllocsTelnetCommand> telnetCommandQueue = new List<AllocsTelnetCommand> (); 23 private static bool isCurrentCommandFromClient = false; 24 private static AllocsTelnetConnection issuerOfCurrentTelnetCommand; 40 25 41 public static void C_SendResult (ConsoleSdtd console, string _line) 42 { 43 if (isCurrentCommandFromClient) { 44 console.gameManager.GetRPCNetworkView ().RPC ("RPC_Console", console.issuerOfCurrentClientCommand, new object[] 26 public static void C_ExecuteCmdFromClient (ConsoleSdtd console, NetworkPlayer _networkPlayer, string _playerID, string _command) 27 { 28 Log.Out ("Executed command \"" + _command + "\" from player \"" + _playerID + "\""); 29 30 object obj = telnetCommandQueue; 31 Monitor.Enter (obj); 32 try { 33 isCurrentCommandFromClient = true; 34 console.issuerOfCurrentClientCommand = _networkPlayer; 35 console.ExecuteClientCmdInternal (_playerID, _command); 36 isCurrentCommandFromClient = false; 37 } finally { 38 Monitor.Exit (obj); 39 } 40 41 } 42 43 public static void C_SendResult (ConsoleSdtd console, string _line) 44 { 45 if (isCurrentCommandFromClient) { 46 console.gameManager.GetRPCNetworkView ().RPC ("RPC_Console", console.issuerOfCurrentClientCommand, new object[] 45 47 { 46 48 _line, 47 49 false 48 50 } 49 ); 50 } else { 51 if (console.telnetServer != null && issuerOfCurrentTelnetCommand != null) 52 AllocsNetTelnetServer.WriteToClient_Single (_line, issuerOfCurrentTelnetCommand); 53 else if (ControlPanel.IsStarted ()) 54 ControlPanel.AddTextToOutputBuffer (_line); 51 ); 52 } else { 53 if (console.telnetServer != null && issuerOfCurrentTelnetCommand != null) 54 AllocsNetTelnetServer.WriteToClient_Single (_line, issuerOfCurrentTelnetCommand); 55 else if (ControlPanel.IsStarted ()) 56 ControlPanel.AddTextToOutputBuffer (_line); 57 } 55 58 } 56 }57 59 58 public static void C_Run (ConsoleSdtd console) 59 { 60 if (telnetCommandQueue.Count > 0) { 60 public static void C_Run (ConsoleSdtd console) 61 { 62 if (telnetCommandQueue.Count > 0) { 63 object obj = telnetCommandQueue; 64 Monitor.Enter (obj); 65 try { 66 issuerOfCurrentTelnetCommand = telnetCommandQueue [0].client; 67 console.ExecuteRemoteCmdInternal (telnetCommandQueue [0].command, false); 68 telnetCommandQueue.RemoveAt (0); 69 issuerOfCurrentTelnetCommand = null; 70 } finally { 71 Monitor.Exit (obj); 72 } 73 } 74 } 75 76 public static void QueueTelnetCommand (string _line, AllocsTelnetConnection _con) 77 { 61 78 object obj = telnetCommandQueue; 62 79 Monitor.Enter (obj); 63 80 try { 64 issuerOfCurrentTelnetCommand = telnetCommandQueue [0].client; 65 console.ExecuteRemoteCmdInternal (telnetCommandQueue [0].command, false); 66 telnetCommandQueue.RemoveAt (0); 67 issuerOfCurrentTelnetCommand = null; 81 telnetCommandQueue.Add (new AllocsTelnetCommand (_line, _con)); 68 82 } finally { 69 83 Monitor.Exit (obj); … … 71 85 } 72 86 } 73 74 public static void QueueTelnetCommand (string _line, AllocsTelnetConnection _con)75 {76 object obj = telnetCommandQueue;77 Monitor.Enter (obj);78 try {79 telnetCommandQueue.Add (new AllocsTelnetCommand (_line, _con));80 } finally {81 Monitor.Exit (obj);82 }83 }84 87 } 85 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/CreativeMenu.cs
r128 r130 2 2 using System.Collections.Generic; 3 3 4 public class CreativeMenu : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 public CreativeMenu (ConsoleSdtd cons) : base(cons)6 public class CreativeMenu : ConsoleCommand 7 7 { 8 } 8 public CreativeMenu (ConsoleSdtd cons) : base(cons) 9 { 10 } 9 11 10 public override string Description ()11 {12 return "enable/disable creative menu";13 }12 public override string Description () 13 { 14 return "enable/disable creative menu"; 15 } 14 16 15 public override string[] Names ()16 {17 return new string[] { "creativemenu", "cm" };18 }17 public override string[] Names () 18 { 19 return new string[] { "creativemenu", "cm" }; 20 } 19 21 20 public override void Run (string[] _params) 21 { 22 try { 23 if (_params.Length != 1) { 24 m_Console.SendResult ("Usage: creativemenu <0/1>"); 25 return; 22 public override void Run (string[] _params) 23 { 24 try { 25 if (_params.Length != 1) { 26 m_Console.SendResult ("Usage: creativemenu <0/1>"); 27 return; 28 } 29 30 GameStats.Set (EnumGameStats.IsCreativeMenuEnabled, _params [0].Equals ("1")); 31 32 m_Console.SendResult ("Set creative menu to " + _params [0].Equals ("1")); 33 } catch (Exception e) { 34 Log.Out ("Error in CreativeMenu.Run: " + e); 26 35 } 27 28 GameStats.Set (EnumGameStats.IsCreativeMenuEnabled, _params [0].Equals ("1"));29 30 m_Console.SendResult ("Set creative menu to " + _params [0].Equals ("1"));31 } catch (Exception e) {32 Log.Out ("Error in CreativeMenu.Run: " + e);33 36 } 34 37 } 35 38 } 36 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/GetGamePrefs.cs
r107 r130 2 2 using System.Collections.Generic; 3 3 4 public class GetGamePrefs : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 private string[] forbiddenPrefs = new string[] { 6 public class GetGamePrefs : ConsoleCommand 7 { 8 private string[] forbiddenPrefs = new string[] { 7 9 "telnet", 8 10 "adminfilename", … … 14 16 }; 15 17 16 private bool prefAccessAllowed (EnumGamePrefs gp) 17 { 18 string gpName = gp.ToString ().ToLower (); 19 foreach (string s in forbiddenPrefs) { 20 if (gpName.Contains (s)) { 21 return false; 18 private bool prefAccessAllowed (EnumGamePrefs gp) 19 { 20 string gpName = gp.ToString ().ToLower (); 21 foreach (string s in forbiddenPrefs) { 22 if (gpName.Contains (s)) { 23 return false; 24 } 22 25 } 26 return true; 23 27 } 24 return true;25 }26 28 27 public GetGamePrefs (ConsoleSdtd cons) : base(cons)28 {29 }29 public GetGamePrefs (ConsoleSdtd cons) : base(cons) 30 { 31 } 30 32 31 public override string Description ()32 {33 return "gets a game pref";34 }33 public override string Description () 34 { 35 return "gets a game pref"; 36 } 35 37 36 public override string[] Names ()37 {38 return new string[]38 public override string[] Names () 39 { 40 return new string[] 39 41 { 40 42 "getgamepref", 41 43 "gg" 42 44 }; 43 }45 } 44 46 45 public override void Run (string[] _params)46 {47 try {48 EnumGamePrefs enumGamePrefs = EnumGamePrefs.Last;47 public override void Run (string[] _params) 48 { 49 try { 50 EnumGamePrefs enumGamePrefs = EnumGamePrefs.Last; 49 51 50 if (_params.Length > 0) { 51 try { 52 enumGamePrefs = (EnumGamePrefs)((int)Enum.Parse (typeof(EnumGamePrefs), _params [0])); 53 } catch (Exception) { 52 if (_params.Length > 0) { 53 try { 54 enumGamePrefs = (EnumGamePrefs)((int)Enum.Parse (typeof(EnumGamePrefs), _params [0])); 55 } catch (Exception) { 56 } 54 57 } 55 }56 58 57 if (enumGamePrefs == EnumGamePrefs.Last) { 58 SortedList<string, string> sortedList = new SortedList<string, string> (); 59 foreach (EnumGamePrefs gp in Enum.GetValues(typeof(EnumGamePrefs))) { 60 if ((_params.Length == 0) || (gp.ToString ().ToLower ().Contains (_params [0].ToLower ()))) { 61 if (prefAccessAllowed (gp)) { 62 sortedList.Add (gp.ToString (), string.Format ("{0} = {1}", gp.ToString (), GamePrefs.GetObject (gp))); 59 if (enumGamePrefs == EnumGamePrefs.Last) { 60 SortedList<string, string> sortedList = new SortedList<string, string> (); 61 foreach (EnumGamePrefs gp in Enum.GetValues(typeof(EnumGamePrefs))) { 62 if ((_params.Length == 0) || (gp.ToString ().ToLower ().Contains (_params [0].ToLower ()))) { 63 if (prefAccessAllowed (gp)) { 64 sortedList.Add (gp.ToString (), string.Format ("{0} = {1}", gp.ToString (), GamePrefs.GetObject (gp))); 65 } 63 66 } 64 67 } 68 foreach (string s in sortedList.Keys) { 69 m_Console.SendResult (sortedList [s]); 70 } 71 } else { 72 if (prefAccessAllowed (enumGamePrefs)) 73 m_Console.SendResult (string.Format ("{0} = {1}", enumGamePrefs, GamePrefs.GetObject (enumGamePrefs))); 74 else 75 m_Console.SendResult ("Access to requested preference is forbidden"); 65 76 } 66 foreach (string s in sortedList.Keys) { 67 m_Console.SendResult (sortedList [s]); 68 } 69 } else { 70 if (prefAccessAllowed (enumGamePrefs)) 71 m_Console.SendResult (string.Format ("{0} = {1}", enumGamePrefs, GamePrefs.GetObject (enumGamePrefs))); 72 else 73 m_Console.SendResult ("Access to requested preference is forbidden"); 77 } catch (Exception e) { 78 Log.Out ("Error in GetGamePrefs.Run: " + e); 74 79 } 75 } catch (Exception e) {76 Log.Out ("Error in GetGamePrefs.Run: " + e);77 80 } 78 81 } 79 82 } 80 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/GetTime.cs
r107 r130 1 1 using System; 2 2 3 public class GetTime : ConsoleCommand 3 namespace AllocsFixes.CustomCommands 4 4 { 5 public GetTime (ConsoleSdtd cons) : base(cons)5 public class GetTime : ConsoleCommand 6 6 { 7 } 7 public GetTime (ConsoleSdtd cons) : base(cons) 8 { 9 } 8 10 9 public override string Description ()10 {11 return "retrieves current ingame time";12 }11 public override string Description () 12 { 13 return "retrieves current ingame time"; 14 } 13 15 14 public override string[] Names ()15 {16 return new string[] { "gettime", "gt" };17 }16 public override string[] Names () 17 { 18 return new string[] { "gettime", "gt" }; 19 } 18 20 19 public override void Run (string[] _params) 20 { 21 try { 22 ulong time = this.m_Console.gameManager.World.gameTime; 23 int day = (int)(time / 24000) + 1; 24 int hour = (int)(time % 24000) / 1000 + 8; 25 if (hour > 23) { 26 day++; 27 hour -= 24; 21 public override void Run (string[] _params) 22 { 23 try { 24 ulong time = this.m_Console.gameManager.World.gameTime; 25 int day = (int)(time / 24000) + 1; 26 int hour = (int)(time % 24000) / 1000 + 8; 27 if (hour > 23) { 28 day++; 29 hour -= 24; 30 } 31 int min = (int)(time % 1000) * 60 / 1000; 32 m_Console.SendResult (String.Format ("Day {0}, {1:00}:{2:00} ", day, hour, min)); 33 } catch (Exception e) { 34 Log.Out ("Error in GetTime.Run: " + e); 28 35 } 29 int min = (int)(time % 1000) * 60 / 1000;30 m_Console.SendResult (String.Format ("Day {0}, {1:00}:{2:00} ", day, hour, min));31 } catch (Exception e) {32 Log.Out ("Error in GetTime.Run: " + e);33 36 } 34 37 } 35 38 } 36 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/Give.cs
r128 r130 3 3 using UnityEngine; 4 4 5 public class Give : ConsoleCommand 5 namespace AllocsFixes.CustomCommands 6 6 { 7 public Give (ConsoleSdtd cons) : base(cons)7 public class Give : ConsoleCommand 8 8 { 9 } 9 public Give (ConsoleSdtd cons) : base(cons) 10 { 11 } 10 12 11 public override string Description ()12 {13 return "give an item to a player (entity id or name)";14 }13 public override string Description () 14 { 15 return "give an item to a player (entity id or name)"; 16 } 15 17 16 public override string[] Names ()17 {18 return new string[] { "give", string.Empty };19 }18 public override string[] Names () 19 { 20 return new string[] { "give", string.Empty }; 21 } 20 22 21 public override void Run (string[] _params) 22 { 23 try { 24 if (_params.Length != 3) { 25 m_Console.SendResult ("Usage: give <playername|entityid> <itemname> <amount>"); 26 return; 23 public override void Run (string[] _params) 24 { 25 try { 26 if (_params.Length != 3) { 27 m_Console.SendResult ("Usage: give <playername|entityid> <itemname> <amount>"); 28 return; 29 } 30 31 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], false); 32 33 if (ci == null) { 34 m_Console.SendResult ("Playername or entity id not found."); 35 return; 36 } 37 38 ItemBase item = null; 39 40 foreach (ItemBase ib in ItemBase.list) { 41 if (ib.name != null && ib.name.ToLower ().Equals (_params [1].ToLower ())) { 42 item = ib; 43 break; 44 } 45 } 46 47 if (item == null) { 48 m_Console.SendResult ("Item not found."); 49 return; 50 } 51 52 int n = int.MinValue; 53 if (!int.TryParse (_params [2], out n) || n <= 0) { 54 m_Console.SendResult ("Amount is not an integer or not greater than zero."); 55 return; 56 } 57 58 EntityPlayer p = CommonMappingFunctions.GetEntityPlayer (ci); 59 CommonMappingFunctions.GetGameManager ().DropEntityItemServer (item.itemID, n, p.GetPosition (), Vector3.zero, Vector3.zero, 50, CommonMappingFunctions.GetEntityID (ci)); 60 61 m_Console.SendResult ("Dropped item"); 62 } catch (Exception e) { 63 Log.Out ("Error in Give.Run: " + e); 27 64 } 28 29 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], false);30 31 if (ci == null) {32 m_Console.SendResult ("Playername or entity id not found.");33 return;34 }35 36 ItemBase item = null;37 38 foreach (ItemBase ib in ItemBase.list) {39 if (ib.name != null && ib.name.ToLower().Equals(_params[1].ToLower())) {40 item = ib;41 break;42 }43 }44 45 if (item == null) {46 m_Console.SendResult ("Item not found.");47 return;48 }49 50 int n = int.MinValue;51 if (!int.TryParse (_params [2], out n) || n <= 0) {52 m_Console.SendResult ("Amount is not an integer or not greater than zero.");53 return;54 }55 56 EntityPlayer p = CommonMappingFunctions.GetEntityPlayer (ci);57 CommonMappingFunctions.GetGameManager().DropEntityItemServer(item.itemID, n, p.GetPosition(), Vector3.zero, Vector3.zero, 50, CommonMappingFunctions.GetEntityID(ci));58 59 m_Console.SendResult ("Dropped item");60 } catch (Exception e) {61 Log.Out ("Error in Give.Run: " + e);62 65 } 63 66 } 64 67 } 65 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/Kill.cs
r117 r130 2 2 using System.Collections.Generic; 3 3 4 public class Kill : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 public Kill (ConsoleSdtd cons) : base(cons)6 public class Kill : ConsoleCommand 7 7 { 8 } 8 public Kill (ConsoleSdtd cons) : base(cons) 9 { 10 } 9 11 10 public override string Description ()11 {12 return "kill a given player (entity id or name)";13 }12 public override string Description () 13 { 14 return "kill a given player (entity id or name)"; 15 } 14 16 15 public override string[] Names ()16 {17 return new string[] { "kill", string.Empty };18 }17 public override string[] Names () 18 { 19 return new string[] { "kill", string.Empty }; 20 } 19 21 20 public override void Run (string[] _params) 21 { 22 try { 23 if (_params.Length != 1) { 24 m_Console.SendResult ("Usage: kill <playername|entityid>"); 25 return; 22 public override void Run (string[] _params) 23 { 24 try { 25 if (_params.Length != 1) { 26 m_Console.SendResult ("Usage: kill <playername|entityid>"); 27 return; 28 } 29 30 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], false); 31 32 if (ci == null) { 33 m_Console.SendResult ("Playername or entity id not found."); 34 return; 35 } 36 37 EntityPlayer p = CommonMappingFunctions.GetEntityPlayer (ci); 38 p.DamageEntity (new DamageSource (EnumDamageSourceType.Bullet), 9999); 39 m_Console.SendResult ("Killed player " + _params [0]); 40 } catch (Exception e) { 41 Log.Out ("Error in Kill.Run: " + e); 26 42 } 27 28 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], false);29 30 if (ci == null) {31 m_Console.SendResult ("Playername or entity id not found.");32 return;33 }34 35 EntityPlayer p = CommonMappingFunctions.GetEntityPlayer (ci);36 p.DamageEntity(new DamageSource(EnumDamageSourceType.Bullet), 9999);37 m_Console.SendResult ("Killed player " + _params [0]);38 } catch (Exception e) {39 Log.Out ("Error in Kill.Run: " + e);40 43 } 41 44 } 42 45 } 43 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/ListItems.cs
r128 r130 2 2 using System.Collections.Generic; 3 3 4 public class ListItems : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 public ListItems (ConsoleSdtd cons) : base(cons)6 public class ListItems : ConsoleCommand 7 7 { 8 } 8 public ListItems (ConsoleSdtd cons) : base(cons) 9 { 10 } 9 11 10 public override string Description ()11 {12 return "lists all items that contain the given substring";13 }12 public override string Description () 13 { 14 return "lists all items that contain the given substring"; 15 } 14 16 15 public override string[] Names ()16 {17 return new string[] { "listitems", "li" };18 }17 public override string[] Names () 18 { 19 return new string[] { "listitems", "li" }; 20 } 19 21 20 public override void Run (string[] _params) 21 { 22 try { 23 if (_params.Length != 1 || _params[0].Length == 0) { 24 m_Console.SendResult ("Usage: listitems <searchString>"); 25 return; 22 public override void Run (string[] _params) 23 { 24 try { 25 if (_params.Length != 1 || _params [0].Length == 0) { 26 m_Console.SendResult ("Usage: listitems <searchString>"); 27 return; 28 } 29 30 int n = 0; 31 foreach (ItemBase ib in ItemBase.list) { 32 if (ib.name != null && ib.name.ToLower ().Contains (_params [0].ToLower ())) { 33 m_Console.SendResult (" " + ib.name); 34 n++; 35 } 36 } 37 38 m_Console.SendResult ("Listed " + n + " matching items."); 39 } catch (Exception e) { 40 Log.Out ("Error in ListItems.Run: " + e); 26 41 } 27 28 int n = 0;29 foreach (ItemBase ib in ItemBase.list) {30 if (ib.name != null && ib.name.ToLower().Contains(_params[0].ToLower())) {31 m_Console.SendResult (" " + ib.name);32 n++;33 }34 }35 36 m_Console.SendResult ("Listed " + n + " matching items.");37 } catch (Exception e) {38 Log.Out ("Error in ListItems.Run: " + e);39 42 } 40 43 } 41 44 } 42 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/ListLandProtection.cs
r113 r130 2 2 using System.Collections.Generic; 3 3 4 public class ListLandProtection : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 public ListLandProtection (ConsoleSdtd cons) : base(cons)6 public class ListLandProtection : ConsoleCommand 7 7 { 8 } 8 public ListLandProtection (ConsoleSdtd cons) : base(cons) 9 { 10 } 9 11 10 public override string Description ()11 {12 return "lists all land protection blocks and owners";13 }12 public override string Description () 13 { 14 return "lists all land protection blocks and owners"; 15 } 14 16 15 public override string[] Names ()16 {17 return new string[] { "listlandprotection", "llp" };18 }17 public override string[] Names () 18 { 19 return new string[] { "listlandprotection", "llp" }; 20 } 19 21 20 public override void Run (string[] _params)21 {22 try {23 World w = CommonMappingFunctions.GetGameManager ().World;24 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager().GetPersistentPlayerList();22 public override void Run (string[] _params) 23 { 24 try { 25 World w = CommonMappingFunctions.GetGameManager ().World; 26 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList (); 25 27 26 Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner; 27 if (d != null) { 28 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>>(); 29 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) { 30 if (!owners.ContainsKey(kvp.Value)) { 31 owners.Add(kvp.Value, new List<Vector3i>()); 28 Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner; 29 if (d != null) { 30 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> (); 31 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) { 32 if (!owners.ContainsKey (kvp.Value)) { 33 owners.Add (kvp.Value, new List<Vector3i> ()); 34 } 35 owners [kvp.Value].Add (kvp.Key); 32 36 } 33 owners[kvp.Value].Add(kvp.Key); 37 38 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 39 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromEntityID (kvp.Key.EntityId); 40 string name = string.Empty; 41 if (ci != null) { 42 name = CommonMappingFunctions.GetPlayerName (ci); 43 } 44 name += " (" + kvp.Key.PlayerId + ")"; 45 46 m_Console.SendResult (String.Format ("Player \"{0}\" (protected: {1}, current hardness multiplier: {2}):", name, w.LandClaimIsActive (kvp.Key), w.LandClaimPower (kvp.Key))); 47 foreach (Vector3i v in kvp.Value) { 48 m_Console.SendResult (" (" + v.ToString () + ")"); 49 } 50 } 34 51 } 35 52 36 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 37 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromEntityID(kvp.Key.EntityId); 38 string name = string.Empty; 39 if (ci != null) { 40 name = CommonMappingFunctions.GetPlayerName(ci); 41 } 42 name += " (" + kvp.Key.PlayerId + ")"; 43 44 m_Console.SendResult (String.Format("Player \"{0}\" (protected: {1}, current hardness multiplier: {2}):", name, w.LandClaimIsActive(kvp.Key), w.LandClaimPower(kvp.Key))); 45 foreach (Vector3i v in kvp.Value) { 46 m_Console.SendResult(" (" + v.ToString() + ")"); 47 } 48 } 53 m_Console.SendResult ("Total of " + d.Count + " keystones in the game"); 54 } catch (Exception e) { 55 Log.Out ("Error in ListLandProtection.Run: " + e); 49 56 } 50 51 m_Console.SendResult ("Total of " + d.Count + " keystones in the game");52 } catch (Exception e) {53 Log.Out ("Error in ListLandProtection.Run: " + e);54 57 } 55 58 } -
binary-improvements/7dtd-server-fixes/src/CustomCommands/ListPlayersExtended.cs
r117 r130 2 2 using System.Collections.Generic; 3 3 4 public class ListPlayersExtended : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 public ListPlayersExtended (ConsoleSdtd cons) : base(cons)6 public class ListPlayersExtended : ConsoleCommand 7 7 { 8 } 8 public ListPlayersExtended (ConsoleSdtd cons) : base(cons) 9 { 10 } 9 11 10 public override string Description ()11 {12 return "lists all players with extended attributes";13 }12 public override string Description () 13 { 14 return "lists all players with extended attributes"; 15 } 14 16 15 public override string[] Names ()16 {17 return new string[] { "listplayersextended", "lpe" };18 }17 public override string[] Names () 18 { 19 return new string[] { "listplayersextended", "lpe" }; 20 } 19 21 20 public override void Run (string[] _params)21 {22 try {23 World w = CommonMappingFunctions.GetGameManager ().World;24 int num = 0;25 foreach (KeyValuePair<int, EntityPlayer> current in w.playerEntities.dict) {26 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromEntityID (current.Key);27 string ip = string.Empty;28 if (ci != null) {29 ip = ci.networkPlayer.ipAddress;30 }31 m_Console.SendResult (string.Concat (new object[]22 public override void Run (string[] _params) 23 { 24 try { 25 World w = CommonMappingFunctions.GetGameManager ().World; 26 int num = 0; 27 foreach (KeyValuePair<int, EntityPlayer> current in w.playerEntities.dict) { 28 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromEntityID (current.Key); 29 string ip = string.Empty; 30 if (ci != null) { 31 ip = ci.networkPlayer.ipAddress; 32 } 33 m_Console.SendResult (string.Concat (new object[] 32 34 { 33 35 string.Empty, … … 60 62 current.Value.pingToServer 61 63 } 62 ) 63 ); 64 ) 65 ); 66 } 67 m_Console.SendResult ("Total of " + w.playerEntities.list.Count + " in the game"); 68 } catch (Exception e) { 69 Log.Out ("Error in ListPlayersExtended.Run: " + e); 64 70 } 65 m_Console.SendResult ("Total of " + w.playerEntities.list.Count + " in the game");66 } catch (Exception e) {67 Log.Out ("Error in ListPlayersExtended.Run: " + e);68 71 } 69 72 } 70 73 } 71 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/PrivateMassageConnections.cs
r112 r130 2 2 using System.Collections.Generic; 3 3 4 public class PrivateMassageConnections4 namespace AllocsFixes.CustomCommands 5 5 { 6 private static Dictionary<ClientInfo, ClientInfo> senderOfLastPM = new Dictionary<ClientInfo, ClientInfo>(); 6 public class PrivateMassageConnections 7 { 8 private static Dictionary<ClientInfo, ClientInfo> senderOfLastPM = new Dictionary<ClientInfo, ClientInfo> (); 7 9 8 public static void SetLastPMSender(ClientInfo _sender, ClientInfo _receiver) { 9 if (senderOfLastPM.ContainsKey(_receiver)) 10 senderOfLastPM[_receiver] = _sender; 11 else 12 senderOfLastPM.Add(_receiver, _sender); 13 } 10 public static void SetLastPMSender (ClientInfo _sender, ClientInfo _receiver) 11 { 12 if (senderOfLastPM.ContainsKey (_receiver)) 13 senderOfLastPM [_receiver] = _sender; 14 else 15 senderOfLastPM.Add (_receiver, _sender); 16 } 14 17 15 public static ClientInfo GetLastPMSenderForPlayer(ClientInfo _player) { 16 if (senderOfLastPM.ContainsKey(_player)) 17 return senderOfLastPM[_player]; 18 return null; 18 public static ClientInfo GetLastPMSenderForPlayer (ClientInfo _player) 19 { 20 if (senderOfLastPM.ContainsKey (_player)) 21 return senderOfLastPM [_player]; 22 return null; 23 } 19 24 } 20 25 } 21 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/RemoveLandProtection.cs
r123 r130 2 2 using System.Collections.Generic; 3 3 4 public class RemoveLandProtection : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 public RemoveLandProtection (ConsoleSdtd cons) : base(cons)6 public class RemoveLandProtection : ConsoleCommand 7 7 { 8 } 8 public RemoveLandProtection (ConsoleSdtd cons) : base(cons) 9 { 10 } 9 11 10 public override string Description ()11 {12 return "removes the association of a land protection block to the owner";13 }12 public override string Description () 13 { 14 return "removes the association of a land protection block to the owner"; 15 } 14 16 15 public override string[] Names ()16 {17 return new string[] { "removelandprotection", "rlp" };18 }17 public override string[] Names () 18 { 19 return new string[] { "removelandprotection", "rlp" }; 20 } 19 21 20 private void removeById (string _id)21 {22 try {23 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();22 private void removeById (string _id) 23 { 24 try { 25 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList (); 24 26 25 if (_id.Length < 1 || !ppl.Players.ContainsKey(_id)) { 26 m_Console.SendResult ("Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones."); 27 return; 27 if (_id.Length < 1 || !ppl.Players.ContainsKey (_id)) { 28 m_Console.SendResult ("Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones."); 29 return; 30 } 31 if (ppl.Players [_id].LPBlocks == null || ppl.Players [_id].LPBlocks.Count == 0) { 32 m_Console.SendResult ("Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones."); 33 return; 34 } 35 36 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 37 foreach (Vector3i pos in ppl.Players[_id].LPBlocks) { 38 BlockChangeInfo bci = new BlockChangeInfo (pos, 0, true); 39 changes.Add (bci); 40 } 41 CommonMappingFunctions.GetGameManager ().SetBlocksRPC (changes); 42 43 m_Console.SendResult ("#" + changes.Count + " Land protection blocks for player \"" + _id + "\" removed"); 44 } catch (Exception e) { 45 Log.Out ("Error in RemoveLandProtection.removeById: " + e); 28 46 } 29 if (ppl.Players[_id].LPBlocks == null || ppl.Players[_id].LPBlocks.Count == 0) { 30 m_Console.SendResult ("Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones."); 31 return; 47 } 48 49 private void removeByPosition (string[] _coords) 50 { 51 try { 52 int x = int.MinValue; 53 int.TryParse (_coords [0], out x); 54 int y = int.MinValue; 55 int.TryParse (_coords [1], out y); 56 int z = int.MinValue; 57 int.TryParse (_coords [2], out z); 58 59 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) { 60 m_Console.SendResult ("At least one of the given coordinates is not a valid integer"); 61 return; 62 } 63 64 Vector3i v = new Vector3i (x, y, z); 65 66 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList (); 67 68 Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner; 69 if (d == null || !d.ContainsKey (v)) { 70 m_Console.SendResult ("No land protection block at the given position or not a valid position. Use \"listlandprotection\" to get a list of keystones."); 71 return; 72 } 73 74 BlockChangeInfo bci = new BlockChangeInfo (v, 0, true); 75 76 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 77 changes.Add (bci); 78 79 CommonMappingFunctions.GetGameManager ().SetBlocksRPC (changes); 80 81 m_Console.SendResult ("Land protection block at (" + v.ToString () + ") removed"); 82 } catch (Exception e) { 83 Log.Out ("Error in RemoveLandProtection.removeByPosition: " + e); 32 84 } 85 } 33 86 34 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 35 foreach (Vector3i pos in ppl.Players[_id].LPBlocks) { 36 BlockChangeInfo bci = new BlockChangeInfo (pos, 0, true); 37 changes.Add (bci); 87 public override void Run (string[] _params) 88 { 89 try { 90 if (_params.Length == 1) { 91 removeById (_params [0]); 92 } else if (_params.Length == 3) { 93 removeByPosition (_params); 94 } else { 95 m_Console.SendResult ("Usage: removelandprotection <x> <y> <z> OR removelandprotection <steamid>"); 96 } 97 } catch (Exception e) { 98 Log.Out ("Error in RemoveLandProtection.Run: " + e); 38 99 } 39 CommonMappingFunctions.GetGameManager ().SetBlocksRPC (changes);40 41 m_Console.SendResult ("#"+changes.Count + " Land protection blocks for player \"" + _id + "\" removed");42 } catch (Exception e) {43 Log.Out ("Error in RemoveLandProtection.removeById: " + e);44 }45 }46 47 private void removeByPosition (string[] _coords)48 {49 try {50 int x = int.MinValue;51 int.TryParse (_coords [0], out x);52 int y = int.MinValue;53 int.TryParse (_coords [1], out y);54 int z = int.MinValue;55 int.TryParse (_coords [2], out z);56 57 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {58 m_Console.SendResult ("At least one of the given coordinates is not a valid integer");59 return;60 }61 62 Vector3i v = new Vector3i (x, y, z);63 64 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();65 66 Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;67 if (d == null || !d.ContainsKey (v)) {68 m_Console.SendResult ("No land protection block at the given position or not a valid position. Use \"listlandprotection\" to get a list of keystones.");69 return;70 }71 72 BlockChangeInfo bci = new BlockChangeInfo (v, 0, true);73 74 List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();75 changes.Add (bci);76 77 CommonMappingFunctions.GetGameManager ().SetBlocksRPC (changes);78 79 m_Console.SendResult ("Land protection block at (" + v.ToString () + ") removed");80 } catch (Exception e) {81 Log.Out ("Error in RemoveLandProtection.removeByPosition: " + e);82 }83 }84 85 public override void Run (string[] _params)86 {87 try {88 if (_params.Length == 1) {89 removeById (_params [0]);90 } else if (_params.Length == 3) {91 removeByPosition (_params);92 } else {93 m_Console.SendResult ("Usage: removelandprotection <x> <y> <z> OR removelandprotection <steamid>");94 }95 } catch (Exception e) {96 Log.Out ("Error in RemoveLandProtection.Run: " + e);97 100 } 98 101 } -
binary-improvements/7dtd-server-fixes/src/CustomCommands/Reply.cs
r112 r130 2 2 using System.Collections.Generic; 3 3 4 public class Reply : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 public Reply (ConsoleSdtd cons) : base(cons)6 public class Reply : ConsoleCommand 7 7 { 8 } 8 public Reply (ConsoleSdtd cons) : base(cons) 9 { 10 } 9 11 10 public override string Description ()11 {12 return "send a message to the player who last sent you a PM";13 }12 public override string Description () 13 { 14 return "send a message to the player who last sent you a PM"; 15 } 14 16 15 public override string[] Names ()16 {17 return new string[] { "reply", "re" };18 }17 public override string[] Names () 18 { 19 return new string[] { "reply", "re" }; 20 } 19 21 20 private void SendMessage (ClientInfo _receiver, ClientInfo _sender, string _message)21 {22 PrivateMassageConnections.SetLastPMSender (_sender, _receiver);23 string senderName = CommonMappingFunctions.GetPlayerName (_sender);22 private void SendMessage (ClientInfo _receiver, ClientInfo _sender, string _message) 23 { 24 PrivateMassageConnections.SetLastPMSender (_sender, _receiver); 25 string senderName = CommonMappingFunctions.GetPlayerName (_sender); 24 26 25 CommonMappingFunctions.GetConnectionManager ().networkView.RPC ("RPC_ChatMessage", _receiver.networkPlayer,27 CommonMappingFunctions.GetConnectionManager ().networkView.RPC ("RPC_ChatMessage", _receiver.networkPlayer, 26 28 new object[] { 27 29 _message, … … 30 32 true 31 33 } 32 ); 33 string receiverName = CommonMappingFunctions.GetPlayerName (_receiver); 34 m_Console.SendResult ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + senderName + "\""); 35 } 36 37 private void RunInternal (ClientInfo _sender, string[] _params) 38 { 39 if (_params.Length < 1) { 40 m_Console.SendResult ("Usage: reply <message>"); 41 return; 34 ); 35 string receiverName = CommonMappingFunctions.GetPlayerName (_receiver); 36 m_Console.SendResult ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + senderName + "\""); 42 37 } 43 38 44 string message = _params [0]; 45 for (int i = 1; i < _params.Length; i++) { 46 message += " " + _params [i]; 39 private void RunInternal (ClientInfo _sender, string[] _params) 40 { 41 if (_params.Length < 1) { 42 m_Console.SendResult ("Usage: reply <message>"); 43 return; 44 } 45 46 string message = _params [0]; 47 for (int i = 1; i < _params.Length; i++) { 48 message += " " + _params [i]; 49 } 50 51 ClientInfo receiver = PrivateMassageConnections.GetLastPMSenderForPlayer (_sender); 52 if (receiver != null && CommonMappingFunctions.GetClientID (receiver) >= 0) { 53 SendMessage (receiver, _sender, message); 54 } else { 55 if (receiver != null) { 56 m_Console.SendResult ("The sender of the PM you last received is currently not online."); 57 } else { 58 m_Console.SendResult ("You have not received a PM so far."); 59 } 60 } 47 61 } 48 62 49 ClientInfo receiver = PrivateMassageConnections.GetLastPMSenderForPlayer (_sender);50 if (receiver != null && CommonMappingFunctions.GetClientID (receiver) >= 0){51 SendMessage (receiver, _sender, message);52 } else {53 if (receiver != null) {54 m_Console.SendResult ("The sender of the PM you last received is currently not online.");55 } else{56 m_Console.SendResult ("You have not received a PM so far.");63 public override void ExecuteRemote (string _sender, string[] _params) 64 { 65 try { 66 m_Console.SendResult (string.Format ("{0} executing remote command '{1}' {2}", _sender, this.Names () [0], string.Join (" ", _params))); 67 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromSteamID (_sender); 68 RunInternal (ci, _params); 69 } catch (Exception e) { 70 Log.Out ("Error in Reply.ExecuteRemote: " + e); 57 71 } 58 72 } 59 }60 73 61 public override void ExecuteRemote (string _sender, string[] _params) 62 { 63 try { 64 m_Console.SendResult (string.Format ("{0} executing remote command '{1}' {2}", _sender, this.Names () [0], string.Join (" ", _params))); 65 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromSteamID (_sender); 66 RunInternal (ci, _params); 67 } catch (Exception e) { 68 Log.Out ("Error in Reply.ExecuteRemote: " + e); 74 public override void Run (string[] _params) 75 { 76 Log.Out ("Command \"reply\" can only be used on clients!"); 69 77 } 70 78 } 71 72 public override void Run (string[] _params)73 {74 Log.Out ("Command \"reply\" can only be used on clients!");75 }76 79 } 77 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/SayToPlayer.cs
r111 r130 2 2 using System.Collections.Generic; 3 3 4 public class SayToPlayer : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 public SayToPlayer (ConsoleSdtd cons) : base(cons)6 public class SayToPlayer : ConsoleCommand 7 7 { 8 } 8 public SayToPlayer (ConsoleSdtd cons) : base(cons) 9 { 10 } 9 11 10 public override string Description ()11 {12 return "send a message to a single player";13 }12 public override string Description () 13 { 14 return "send a message to a single player"; 15 } 14 16 15 public override string[] Names ()16 {17 return new string[] { "sayplayer", "pm" };18 }17 public override string[] Names () 18 { 19 return new string[] { "sayplayer", "pm" }; 20 } 19 21 20 private void SendMessage (ClientInfo _receiver, ClientInfo _sender, string _message)21 {22 string senderName;23 if (_sender != null) {24 PrivateMassageConnections.SetLastPMSender(_sender, _receiver);25 senderName = CommonMappingFunctions.GetPlayerName (_sender);26 } else {27 senderName = "Server";28 }29 CommonMappingFunctions.GetConnectionManager ().networkView.RPC ("RPC_ChatMessage", _receiver.networkPlayer,22 private void SendMessage (ClientInfo _receiver, ClientInfo _sender, string _message) 23 { 24 string senderName; 25 if (_sender != null) { 26 PrivateMassageConnections.SetLastPMSender (_sender, _receiver); 27 senderName = CommonMappingFunctions.GetPlayerName (_sender); 28 } else { 29 senderName = "Server"; 30 } 31 CommonMappingFunctions.GetConnectionManager ().networkView.RPC ("RPC_ChatMessage", _receiver.networkPlayer, 30 32 new object[] { 31 33 _message, … … 34 36 true 35 37 } 36 ); 37 string receiverName = CommonMappingFunctions.GetPlayerName (_receiver); 38 m_Console.SendResult ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + senderName + "\""); 39 } 40 41 private void RunInternal (ClientInfo _sender, string[] _params) 42 { 43 if (_params.Length < 2) { 44 m_Console.SendResult ("Usage: sayplayer <playername|entityid> <message>"); 45 return; 38 ); 39 string receiverName = CommonMappingFunctions.GetPlayerName (_receiver); 40 m_Console.SendResult ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + senderName + "\""); 46 41 } 47 42 48 string message = _params [1]; 49 for (int i = 2; i < _params.Length; i++) { 50 message += " " + _params [i]; 43 private void RunInternal (ClientInfo _sender, string[] _params) 44 { 45 if (_params.Length < 2) { 46 m_Console.SendResult ("Usage: sayplayer <playername|entityid> <message>"); 47 return; 48 } 49 50 string message = _params [1]; 51 for (int i = 2; i < _params.Length; i++) { 52 message += " " + _params [i]; 53 } 54 55 ClientInfo receiver = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], true); 56 if (receiver != null) { 57 SendMessage (receiver, _sender, message); 58 } else { 59 m_Console.SendResult ("Playername or entity ID not found."); 60 } 51 61 } 52 62 53 ClientInfo receiver = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], true); 54 if (receiver != null) { 55 SendMessage (receiver, _sender, message); 56 } else { 57 m_Console.SendResult ("Playername or entity ID not found."); 63 public override void ExecuteRemote (string _sender, string[] _params) 64 { 65 try { 66 this.m_Console.SendResult (string.Format ("{0} executing remote command '{1}' {2}", _sender, this.Names () [0], string.Join (" ", _params))); 67 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromSteamID (_sender); 68 RunInternal (ci, _params); 69 } catch (Exception e) { 70 Log.Out ("Error in SayToPlayer.ExecuteRemote: " + e); 71 } 58 72 } 59 }60 73 61 public override void ExecuteRemote (string _sender, string[] _params) 62 { 63 try { 64 this.m_Console.SendResult (string.Format ("{0} executing remote command '{1}' {2}", _sender, this.Names () [0], string.Join (" ", _params))); 65 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromSteamID (_sender); 66 RunInternal (ci, _params); 67 } catch (Exception e) { 68 Log.Out ("Error in SayToPlayer.ExecuteRemote: " + e); 69 } 70 } 71 72 public override void Run (string[] _params) 73 { 74 try { 75 RunInternal (null, _params); 76 } catch (Exception e) { 77 Log.Out ("Error in SayToPlayer.Run: " + e); 74 public override void Run (string[] _params) 75 { 76 try { 77 RunInternal (null, _params); 78 } catch (Exception e) { 79 Log.Out ("Error in SayToPlayer.Run: " + e); 80 } 78 81 } 79 82 } 80 83 } 81 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/SetTimeReal.cs
r107 r130 1 1 using System; 2 2 3 public class SetTimeReal : ConsoleCommand 3 namespace AllocsFixes.CustomCommands 4 4 { 5 public SetTimeReal (ConsoleSdtd cons) : base(cons)5 public class SetTimeReal : ConsoleCommand 6 6 { 7 } 7 public SetTimeReal (ConsoleSdtd cons) : base(cons) 8 { 9 } 8 10 9 public override string Description ()10 {11 return "set current ingame time, params: <day> <hour> <min>";12 }11 public override string Description () 12 { 13 return "set current ingame time, params: <day> <hour> <min>"; 14 } 13 15 14 public override string[] Names ()15 {16 return new string[] { "settimereal", "str" };17 }16 public override string[] Names () 17 { 18 return new string[] { "settimereal", "str" }; 19 } 18 20 19 public override void Run (string[] _params) 20 { 21 try { 22 if (_params.Length != 3) { 23 m_Console.SendResult ("Usage: settimereal <day> <hour> <min>"); 24 return; 21 public override void Run (string[] _params) 22 { 23 try { 24 if (_params.Length != 3) { 25 m_Console.SendResult ("Usage: settimereal <day> <hour> <min>"); 26 return; 27 } 28 29 int day, hour, min; 30 if (!int.TryParse (_params [0], out day)) { 31 m_Console.SendResult ("Could not parse day number \"" + _params [0] + "\""); 32 return; 33 } 34 if (day < 1) { 35 m_Console.SendResult ("Day must be >= 1"); 36 return; 37 } 38 if (!int.TryParse (_params [1], out hour)) { 39 m_Console.SendResult ("Could not parse hour \"" + _params [1] + "\""); 40 return; 41 } 42 if (hour > 23) { 43 m_Console.SendResult ("Hour must be <= 23"); 44 return; 45 } 46 if (!int.TryParse (_params [2], out min)) { 47 m_Console.SendResult ("Could not parse minute \"" + _params [2] + "\""); 48 return; 49 } 50 if (min > 59) { 51 m_Console.SendResult ("Minute must be <= 59"); 52 return; 53 } 54 if ((day < 1) || (hour < 8 && day < 1)) { 55 m_Console.SendResult ("Time may not be prior to day 1, 8:00"); 56 return; 57 } 58 59 ulong time = ((ulong)(day - 1) * 24000) + ((ulong)hour * 1000) + ((ulong)min * 1000 / 60) - 8000; 60 m_Console.gameManager.World.gameTime = time; 61 m_Console.SendResult (String.Format ("Set time to Day {0}, {1:00}:{2:00} = {3}", day, hour, min, time)); 62 } catch (Exception e) { 63 Log.Out ("Error in SetTimeReal.Run: " + e); 25 64 } 26 27 int day, hour, min;28 if (!int.TryParse (_params [0], out day)) {29 m_Console.SendResult ("Could not parse day number \"" + _params [0] + "\"");30 return;31 }32 if (day < 1) {33 m_Console.SendResult ("Day must be >= 1");34 return;35 }36 if (!int.TryParse (_params [1], out hour)) {37 m_Console.SendResult ("Could not parse hour \"" + _params [1] + "\"");38 return;39 }40 if (hour > 23) {41 m_Console.SendResult ("Hour must be <= 23");42 return;43 }44 if (!int.TryParse (_params [2], out min)) {45 m_Console.SendResult ("Could not parse minute \"" + _params [2] + "\"");46 return;47 }48 if (min > 59) {49 m_Console.SendResult ("Minute must be <= 59");50 return;51 }52 if ((day < 1) || (hour < 8 && day < 1)) {53 m_Console.SendResult ("Time may not be prior to day 1, 8:00");54 return;55 }56 57 ulong time = ((ulong)(day - 1) * 24000) + ((ulong)hour * 1000) + ((ulong)min * 1000 / 60) - 8000;58 m_Console.gameManager.World.gameTime = time;59 m_Console.SendResult (String.Format ("Set time to Day {0}, {1:00}:{2:00} = {3}", day, hour, min, time));60 } catch (Exception e) {61 Log.Out ("Error in SetTimeReal.Run: " + e);62 65 } 63 66 } 64 67 } 65 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/ShowInventory.cs
r107 r130 2 2 using System.Collections.Generic; 3 3 4 public class ShowInventory : ConsoleCommand 4 namespace AllocsFixes.CustomCommands 5 5 { 6 private GameManager manager; 6 public class ShowInventory : ConsoleCommand 7 { 8 private GameManager manager; 7 9 8 public ShowInventory (ConsoleSdtd cons) : base(cons)9 {10 manager = m_Console.gameManager;11 }10 public ShowInventory (ConsoleSdtd cons) : base(cons) 11 { 12 manager = m_Console.gameManager; 13 } 12 14 13 public override string Description ()14 {15 return "list inventory of a given player (entity id or name)";16 }15 public override string Description () 16 { 17 return "list inventory of a given player (entity id or name)"; 18 } 17 19 18 public override string[] Names ()19 {20 return new string[] { "showinventory", "si" };21 }20 public override string[] Names () 21 { 22 return new string[] { "showinventory", "si" }; 23 } 22 24 23 public override void Run (string[] _params)24 {25 try {26 if (_params.Length < 1) {27 m_Console.SendResult ("Usage: showinventory <playername|entityid>");28 return;29 }25 public override void Run (string[] _params) 26 { 27 try { 28 if (_params.Length < 1) { 29 m_Console.SendResult ("Usage: showinventory <playername|entityid>"); 30 return; 31 } 30 32 31 int entityId = -1;32 PlayerDataStuff.PlayerItems items = null;33 if (int.TryParse (_params [0], out entityId)) {34 items = PlayerDataStuff.GetPlayerItems (entityId);35 }33 int entityId = -1; 34 PlayerDataStuff.PlayerItems items = null; 35 if (int.TryParse (_params [0], out entityId)) { 36 items = PlayerDataStuff.GetPlayerItems (entityId); 37 } 36 38 37 if (items == null) { 38 string playerName = _params [0].ToLower (); 39 foreach (KeyValuePair<int, EntityPlayer> kvp in manager.World.playerEntities.dict) { 40 if (kvp.Value.EntityName.ToLower ().Equals (playerName)) { 41 entityId = kvp.Key; 42 break; 39 if (items == null) { 40 string playerName = _params [0].ToLower (); 41 foreach (KeyValuePair<int, EntityPlayer> kvp in manager.World.playerEntities.dict) { 42 if (kvp.Value.EntityName.ToLower ().Equals (playerName)) { 43 entityId = kvp.Key; 44 break; 45 } 43 46 } 44 47 } 48 items = PlayerDataStuff.GetPlayerItems (entityId); 49 50 if (items == null) { 51 m_Console.SendResult ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s)."); 52 return; 53 } 54 55 m_Console.SendResult ("Belt of player:"); 56 foreach (KeyValuePair<string, int> kvp in items.belt) { 57 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key)); 58 } 59 m_Console.SendResult (string.Empty); 60 m_Console.SendResult ("Bagpack of player:"); 61 foreach (KeyValuePair<string, int> kvp in items.bag) { 62 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key)); 63 } 64 m_Console.SendResult (string.Empty); 65 } catch (Exception e) { 66 Log.Out ("Error in ShowInventory.Run: " + e); 45 67 } 46 items = PlayerDataStuff.GetPlayerItems (entityId);47 48 if (items == null) {49 m_Console.SendResult ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s).");50 return;51 }52 53 m_Console.SendResult ("Belt of player:");54 foreach (KeyValuePair<string, int> kvp in items.belt) {55 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));56 }57 m_Console.SendResult (string.Empty);58 m_Console.SendResult ("Bagpack of player:");59 foreach (KeyValuePair<string, int> kvp in items.bag) {60 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));61 }62 m_Console.SendResult (string.Empty);63 } catch (Exception e) {64 Log.Out ("Error in ShowInventory.Run: " + e);65 68 } 66 69 } 67 70 } 68 -
binary-improvements/7dtd-server-fixes/src/CustomCommands/Version.cs
r114 r130 3 3 using System.Reflection; 4 4 5 public class Version : ConsoleCommand 5 namespace AllocsFixes.CustomCommands 6 6 { 7 public Version (ConsoleSdtd cons) : base(cons)7 public class Version : ConsoleCommand 8 8 { 9 } 9 public Version (ConsoleSdtd cons) : base(cons) 10 { 11 } 10 12 11 public override string Description ()12 {13 return "get the currently running version of the server fixes";14 }13 public override string Description () 14 { 15 return "get the currently running version of the server fixes"; 16 } 15 17 16 public override string[] Names ()17 {18 return new string[] { "version", string.Empty };19 }18 public override string[] Names () 19 { 20 return new string[] { "version", string.Empty }; 21 } 20 22 21 public override void Run (string[] _params) 22 { 23 try { 24 m_Console.SendResult ("Server fixes version: " + Assembly.GetExecutingAssembly ().GetName ().Version); 25 } catch (Exception e) { 26 Log.Out ("Error in Version.Run: " + e); 23 public override void Run (string[] _params) 24 { 25 try { 26 m_Console.SendResult ("Server fixes version: " + Assembly.GetExecutingAssembly ().GetName ().Version); 27 } catch (Exception e) { 28 Log.Out ("Error in Version.Run: " + e); 29 } 27 30 } 28 31 } 29 32 } 30 -
binary-improvements/7dtd-server-fixes/src/PlayerDataStuff.cs
r128 r130 2 2 using System.Collections.Generic; 3 3 4 public class PlayerDataStuff 4 namespace AllocsFixes 5 5 { 6 public class Player Items6 public class PlayerDataStuff 7 7 { 8 public SortedList<string, int> belt = new SortedList<string, int> (); 9 public SortedList<string, int> bag = new SortedList<string, int> (); 8 public class PlayerItems 9 { 10 public SortedList<string, int> belt = new SortedList<string, int> (); 11 public SortedList<string, int> bag = new SortedList<string, int> (); 10 12 11 public PlayerItems (InventoryField[] _belt, InventoryField[] _bag) 12 { 13 foreach (InventoryField item in _belt) { 14 if (item.count > 0) { 15 string name = getInvFieldName (item); 16 if (belt.ContainsKey (name)) { 17 belt [name] += item.count; 18 } else { 19 belt.Add (name, item.count); 13 public PlayerItems (InventoryField[] _belt, InventoryField[] _bag) 14 { 15 foreach (InventoryField item in _belt) { 16 if (item.count > 0) { 17 string name = getInvFieldName (item); 18 if (belt.ContainsKey (name)) { 19 belt [name] += item.count; 20 } else { 21 belt.Add (name, item.count); 22 } 23 } 24 } 25 26 foreach (InventoryField item in _bag) { 27 if (item.count > 0) { 28 string name = getInvFieldName (item); 29 if (bag.ContainsKey (name)) { 30 bag [name] += item.count; 31 } else { 32 bag.Add (name, item.count); 33 } 20 34 } 21 35 } 22 36 } 37 }; 23 38 24 foreach (InventoryField item in _bag) { 25 if (item.count > 0) { 26 string name = getInvFieldName (item); 27 if (bag.ContainsKey (name)) { 28 bag [name] += item.count; 29 } else { 30 bag.Add (name, item.count); 31 } 39 private static Dictionary<int, PlayerItems> itemsPerEntityId = new Dictionary<int, PlayerItems> (); 40 41 public static PlayerItems GetPlayerItems (int entityId) 42 { 43 if (itemsPerEntityId.ContainsKey (entityId)) 44 return itemsPerEntityId [entityId]; 45 else 46 return null; 47 } 48 49 public static void GM_SavePlayerData (GameManager manager, int _clientId, PlayerDataFile _playerDataFile) 50 { 51 try { 52 int entityId = CommonMappingFunctions.GetEntityID (CommonMappingFunctions.GetClientInfoFromClientID (_clientId)); 53 if (entityId >= 0) { 54 Log.Out ("Saving playerData for entity id: " + entityId); 55 56 if (itemsPerEntityId.ContainsKey (entityId)) 57 itemsPerEntityId.Remove (entityId); 58 itemsPerEntityId.Add (entityId, new PlayerItems (_playerDataFile.inventory, _playerDataFile.bag)); 32 59 } 60 } catch (Exception e) { 61 Log.Out ("Error in GM_SavePlayerData: " + e); 33 62 } 34 }35 };36 37 private static Dictionary<int, PlayerItems> itemsPerEntityId = new Dictionary<int, PlayerItems> ();38 39 public static PlayerItems GetPlayerItems (int entityId)40 {41 if (itemsPerEntityId.ContainsKey (entityId))42 return itemsPerEntityId [entityId];43 else44 return null;45 }46 47 public static void GM_SavePlayerData (GameManager manager, int _clientId, PlayerDataFile _playerDataFile)48 {49 try {50 int entityId = CommonMappingFunctions.GetEntityID (CommonMappingFunctions.GetClientInfoFromClientID (_clientId));51 if (entityId >= 0) {52 Log.Out ("Saving playerData for entity id: " + entityId);53 54 if (itemsPerEntityId.ContainsKey (entityId))55 itemsPerEntityId.Remove (entityId);56 itemsPerEntityId.Add (entityId, new PlayerItems (_playerDataFile.inventory, _playerDataFile.bag));57 }58 } catch (Exception e) {59 Log.Out ("Error in GM_SavePlayerData: " + e);60 }61 63 62 64 // Log.Out ("Inventory of player:"); … … 71 73 // printItem (item, i); 72 74 // } 73 }75 } 74 76 75 private static string getInvFieldName (InventoryField item) 76 { 77 ItemBase iBase = ItemBase.list [item.itemValue.type]; 78 string name = iBase.name; 79 if (iBase.IsBlock ()) { 80 ItemBlock iBlock = (ItemBlock)iBase; 81 name = iBlock.GetItemName (item.itemValue); 82 } 83 return name; 84 } 85 86 private static void printItem (InventoryField item, int slot) 87 { 88 if (item.count > 0) { 77 private static string getInvFieldName (InventoryField item) 78 { 89 79 ItemBase iBase = ItemBase.list [item.itemValue.type]; 90 80 string name = iBase.name; … … 93 83 name = iBlock.GetItemName (item.itemValue); 94 84 } 95 Log.Out (string.Format ("Slot {0:00}: {1:00} * {2}, blockinst={3}, meta={4}, type={5}, usetimes={6}", 96 slot, item.count, name, item.itemValue.blockinst, item.itemValue.meta, item.itemValue.type, item.itemValue.usetimes)); 85 return name; 86 } 87 88 private static void printItem (InventoryField item, int slot) 89 { 90 if (item.count > 0) { 91 ItemBase iBase = ItemBase.list [item.itemValue.type]; 92 string name = iBase.name; 93 if (iBase.IsBlock ()) { 94 ItemBlock iBlock = (ItemBlock)iBase; 95 name = iBlock.GetItemName (item.itemValue); 96 } 97 Log.Out (string.Format ("Slot {0:00}: {1:00} * {2}, blockinst={3}, meta={4}, type={5}, usetimes={6}", 98 slot, item.count, name, item.itemValue.blockinst, item.itemValue.meta, item.itemValue.type, item.itemValue.usetimes) 99 ); 100 } 97 101 } 98 102 } 99 103 } 100
Note:
See TracChangeset
for help on using the changeset viewer.