- Timestamp:
- Aug 26, 2014, 4:41:47 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.