Changeset 103 for binary-improvements/7dtd-server-fixes/src/TelnetCommands
- Timestamp:
- Jul 24, 2014, 3:25:58 PM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src/TelnetCommands
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/TelnetCommands/GetGamePrefs.cs
r91 r103 45 45 public override void Run (string[] _params) 46 46 { 47 EnumGamePrefs enumGamePrefs = EnumGamePrefs.Last; 47 try { 48 EnumGamePrefs enumGamePrefs = EnumGamePrefs.Last; 48 49 49 if (_params.Length > 0) { 50 try { 51 enumGamePrefs = (EnumGamePrefs)((int)Enum.Parse (typeof(EnumGamePrefs), _params [0])); 52 } catch (Exception) { 50 if (_params.Length > 0) { 51 try { 52 enumGamePrefs = (EnumGamePrefs)((int)Enum.Parse (typeof(EnumGamePrefs), _params [0])); 53 } catch (Exception) { 54 } 53 55 } 54 }55 56 56 if (enumGamePrefs == EnumGamePrefs.Last) { 57 SortedList<string, string> sortedList = new SortedList<string, string> (); 58 foreach (EnumGamePrefs gp in Enum.GetValues(typeof(EnumGamePrefs))) { 59 if ((_params.Length == 0) || (gp.ToString ().ToLower ().Contains (_params [0].ToLower ()))) { 60 if (prefAccessAllowed (gp)) { 61 sortedList.Add (gp.ToString (), string.Format ("{0} = {1}", gp.ToString (), GamePrefs.GetObject (gp))); 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))); 63 } 62 64 } 63 65 } 66 foreach (string s in sortedList.Keys) { 67 m_Console.md000a (sortedList [s]); 68 } 69 } else { 70 if (prefAccessAllowed (enumGamePrefs)) 71 m_Console.md000a (string.Format ("{0} = {1}", enumGamePrefs, GamePrefs.GetObject (enumGamePrefs))); 72 else 73 m_Console.md000a ("Access to requested preference is forbidden"); 64 74 } 65 foreach (string s in sortedList.Keys) { 66 m_Console.md000a (sortedList [s]); 67 } 68 } else { 69 if (prefAccessAllowed (enumGamePrefs)) 70 m_Console.md000a (string.Format ("{0} = {1}", enumGamePrefs, GamePrefs.GetObject (enumGamePrefs))); 71 else 72 m_Console.md000a ("Access to requested preference is forbidden"); 75 } catch (Exception e) { 76 Log.Out ("Error in GetGamePrefs.Run: " + e); 73 77 } 74 78 } -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/GetTime.cs
r84 r103 19 19 public override void Run (string[] _params) 20 20 { 21 ulong time = this.m_Console.gameManager.World.gameTime; 22 int day = (int)(time / 24000) + 1; 23 int hour = (int)(time % 24000) / 1000 + 8; 24 if (hour > 23) { 25 day++; 26 hour -= 24; 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; 28 } 29 int min = (int)(time % 1000) * 60 / 1000; 30 m_Console.md000a (String.Format ("Day {0}, {1:00}:{2:00} ", day, hour, min)); 31 } catch (Exception e) { 32 Log.Out ("Error in GetTime.Run: " + e); 27 33 } 28 int min = (int)(time % 1000) * 60 / 1000;29 m_Console.md000a (String.Format ("Day {0}, {1:00}:{2:00} ", day, hour, min));30 34 } 31 35 } -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/ListPlayersExtended.cs
r91 r103 4 4 public class ListPlayersExtended : ConsoleCommand 5 5 { 6 public ListPlayersExtended(ConsoleSdtd cons) : base(cons) { 6 public ListPlayersExtended (ConsoleSdtd cons) : base(cons) 7 { 7 8 } 8 9 … … 12 13 } 13 14 14 public override string[] Names () { 15 public override string[] Names () 16 { 15 17 return new string[] { "listplayersextended", "lpe" }; 16 18 } … … 18 20 public override void Run (string[] _params) 19 21 { 20 World w = this.m_Console.gameManager.World; 21 int num = 0; 22 foreach (KeyValuePair<int, EntityPlayer> current in w.playerEntities.dict) 23 { 24 int clientId = -1; 25 Dictionary<int,int> d = this.m_Console.gameManager.connectionManager.mapClientToEntity; 26 foreach (KeyValuePair<int, int> mapping in d) { 27 if (mapping.Value == current.Value.fd0087) { 28 clientId = mapping.Key; 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; 29 30 } 30 } 31 string ip = string.Empty; 32 if (clientId >= 0) { 33 ip = this.m_Console.gameManager.connectionManager.connectedClients [clientId].networkPlayer.ipAddress; 34 } 35 m_Console.md000a (string.Concat (new object[] 31 m_Console.md000a (string.Concat (new object[] 36 32 { 37 33 string.Empty, … … 58 54 current.Value.Score, 59 55 ", steamid=", 60 SingletonMonoBehaviour<Authenticator>.Instance.GetPlayerId (current.Value.EntityName),56 CommonMappingFunctions.GetSteamID (ci), 61 57 ", ip=", 62 58 ip, 63 59 ", ping=", 64 60 current.Value.pingToServer 65 })); 61 } 62 ) 63 ); 64 } 65 m_Console.md000a ("Total of " + w.playerEntities.list.Count + " in the game"); 66 } catch (Exception e) { 67 Log.Out ("Error in ListPlayersExtended.Run: " + e); 66 68 } 67 m_Console.md000a ("Total of " + w.playerEntities.list.Count + " in the game");68 69 } 69 70 } -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/SayToPlayer.cs
r83 r103 4 4 public class SayToPlayer : ConsoleCommand 5 5 { 6 private GameManager manager;7 8 6 public SayToPlayer (ConsoleSdtd cons) : base(cons) 9 7 { 10 manager = m_Console.gameManager;11 8 } 12 9 … … 18 15 public override string[] Names () 19 16 { 20 return new string[] { "sayplayer", string.Empty};17 return new string[] { "sayplayer", "pm" }; 21 18 } 22 19 23 public override void Run (string[] _params) 20 private void SendMessage (ClientInfo _receiver, string _sender, string _message) 21 { 22 CommonMappingFunctions.GetConnectionManager ().networkView.RPC ("RPC_ChatMessage", _receiver.networkPlayer, 23 new object[] { _message, -1, _sender + " (PM)", true }); 24 string receiverName = CommonMappingFunctions.GetPlayerName (_receiver); 25 m_Console.md000a ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + _sender + "\""); 26 } 27 28 private void RunInternal (string _sender, string[] _params) 24 29 { 25 30 if (_params.Length < 2) { … … 33 38 } 34 39 35 int entityId = -1; 36 if (int.TryParse (_params [0], out entityId)) { 37 foreach (KeyValuePair<int, int> kvp in manager.connectionManager.mapClientToEntity) { 38 if (kvp.Value == entityId) { 39 int clientid = kvp.Key; 40 ClientInfo ci = manager.connectionManager.connectedClients[clientid]; 41 if (ci != null) { 42 manager.connectionManager.networkView.RPC ("RPC_ChatMessage", ci.networkPlayer, new object[] { 43 message, 44 -1, 45 "Server (private)", 46 true 47 } 48 ); 49 m_Console.md000a ("Message sent"); 50 return; 51 } 52 } 40 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0]); 41 if (ci != null) { 42 SendMessage (ci, _sender, message); 43 } else { 44 m_Console.md000a ("Playername or entity ID not found."); 45 } 46 } 47 48 public override void ExecuteRemote (string _sender, string[] _params) 49 { 50 try { 51 this.m_Console.md000a (string.Format ("{0} executing remote command '{1}' {2}", _sender, this.Names () [0], string.Join (" ", _params))); 52 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromSteamID (_sender); 53 if (ci != null) { 54 _sender = CommonMappingFunctions.GetPlayerName (ci); 53 55 } 54 m_Console.md000a ("Entity ID not found."); 55 } else { 56 string destPlayerName = _params [0].ToLower (); 57 foreach (ClientInfo ci in manager.connectionManager.connectedClients.Values) { 58 Dictionary<int,int> d = manager.connectionManager.mapClientToEntity; 59 if (d.ContainsKey (ci.clientId)) { 60 entityId = d [ci.clientId]; 61 string curName = manager.World.playerEntities.dict [entityId].EntityName; 62 if (curName.ToLower ().Equals (destPlayerName)) { 63 manager.connectionManager.networkView.RPC ("RPC_ChatMessage", ci.networkPlayer, new object[] { 64 message, 65 -1, 66 "Server (private)", 67 true 68 } 69 ); 70 m_Console.md000a ("Message sent"); 71 return; 72 } 73 } 74 } 75 m_Console.md000a ("Playername not found."); 56 RunInternal (_sender, _params); 57 } catch (Exception e) { 58 Log.Out ("Error in SayToPlayer.ExecuteRemote: " + e); 59 } 60 } 61 62 public override void Run (string[] _params) 63 { 64 try { 65 RunInternal ("Server", _params); 66 } catch (Exception e) { 67 Log.Out ("Error in SayToPlayer.Run: " + e); 76 68 } 77 69 } -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/SetTimeReal.cs
r84 r103 19 19 public override void Run (string[] _params) 20 20 { 21 if (_params.Length != 3) { 22 m_Console.md000a ("Usage: settimereal <day> <hour> <min>"); 23 return; 21 try { 22 if (_params.Length != 3) { 23 m_Console.md000a ("Usage: settimereal <day> <hour> <min>"); 24 return; 25 } 26 27 int day, hour, min; 28 if (!int.TryParse (_params [0], out day)) { 29 m_Console.md000a ("Could not parse day number \"" + _params [0] + "\""); 30 return; 31 } 32 if (day < 1) { 33 m_Console.md000a ("Day must be >= 1"); 34 return; 35 } 36 if (!int.TryParse (_params [1], out hour)) { 37 m_Console.md000a ("Could not parse hour \"" + _params [1] + "\""); 38 return; 39 } 40 if (hour > 23) { 41 m_Console.md000a ("Hour must be <= 23"); 42 return; 43 } 44 if (!int.TryParse (_params [2], out min)) { 45 m_Console.md000a ("Could not parse minute \"" + _params [2] + "\""); 46 return; 47 } 48 if (min > 59) { 49 m_Console.md000a ("Minute must be <= 59"); 50 return; 51 } 52 if ((day < 1) || (hour < 8 && day < 1)) { 53 m_Console.md000a ("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.md000a (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); 24 62 } 25 26 int day, hour, min;27 if (!int.TryParse (_params [0], out day)) {28 m_Console.md000a ("Could not parse day number \"" + _params [0] + "\"");29 return;30 }31 if (day < 1) {32 m_Console.md000a ("Day must be >= 1");33 return;34 }35 if (!int.TryParse (_params [1], out hour)) {36 m_Console.md000a ("Could not parse hour \"" + _params [1] + "\"");37 return;38 }39 if (hour > 23) {40 m_Console.md000a ("Hour must be <= 23");41 return;42 }43 if (!int.TryParse (_params [2], out min)) {44 m_Console.md000a ("Could not parse minute \"" + _params [2] + "\"");45 return;46 }47 if (min > 59) {48 m_Console.md000a ("Minute must be <= 59");49 return;50 }51 if ((day < 1) || (hour < 8 && day < 1)) {52 m_Console.md000a ("Time may not be prior to day 1, 8:00");53 return;54 }55 56 ulong time = ((ulong)(day-1) * 24000) + ((ulong)hour * 1000) + ((ulong)min * 1000 / 60) - 8000;57 this.m_Console.gameManager.World.gameTime = time;58 m_Console.md000a (String.Format ("Set time to Day {0}, {1:00}:{2:00} = {3}", day, hour, min, time));59 63 } 60 64 } -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/ShowInventory.cs
r93 r103 23 23 public override void Run (string[] _params) 24 24 { 25 if (_params.Length < 1) { 26 m_Console.md000a ("Usage: showinventory <playername|entityid>"); 27 return; 28 } 25 try { 26 if (_params.Length < 1) { 27 m_Console.md000a ("Usage: showinventory <playername|entityid>"); 28 return; 29 } 29 30 30 int entityId = -1;31 PlayerDataStuff.PlayerItems items = null;32 if (int.TryParse (_params [0], out entityId)) {33 items = PlayerDataStuff.GetPlayerItems (entityId);34 }31 int entityId = -1; 32 PlayerDataStuff.PlayerItems items = null; 33 if (int.TryParse (_params [0], out entityId)) { 34 items = PlayerDataStuff.GetPlayerItems (entityId); 35 } 35 36 36 if (items == null) { 37 string playerName = _params [0].ToLower (); 38 foreach (KeyValuePair<int, EntityPlayer> kvp in manager.World.playerEntities.dict) { 39 if (kvp.Value.EntityName.ToLower ().Equals (playerName)) { 40 entityId = kvp.Key; 41 break; 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; 43 } 42 44 } 43 45 } 46 items = PlayerDataStuff.GetPlayerItems (entityId); 47 48 if (items == null) { 49 m_Console.md000a ("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.md000a ("Belt of player:"); 54 foreach (KeyValuePair<string, int> kvp in items.belt) { 55 m_Console.md000a (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key)); 56 } 57 m_Console.md000a (string.Empty); 58 m_Console.md000a ("Bagpack of player:"); 59 foreach (KeyValuePair<string, int> kvp in items.bag) { 60 m_Console.md000a (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key)); 61 } 62 m_Console.md000a (string.Empty); 63 } catch (Exception e) { 64 Log.Out ("Error in ShowInventory.Run: " + e); 44 65 } 45 items = PlayerDataStuff.GetPlayerItems (entityId);46 47 if (items == null) {48 m_Console.md000a ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s).");49 return;50 }51 52 m_Console.md000a ("Belt of player:");53 foreach (KeyValuePair<string, int> kvp in items.belt) {54 m_Console.md000a (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));55 }56 m_Console.md000a (string.Empty);57 m_Console.md000a ("Bagpack of player:");58 foreach (KeyValuePair<string, int> kvp in items.bag) {59 m_Console.md000a (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));60 }61 m_Console.md000a (string.Empty);62 66 } 63 67 }
Note:
See TracChangeset
for help on using the changeset viewer.