| [107] | 1 | using System; | 
|---|
|  | 2 | using System.Collections.Generic; | 
|---|
| [111] | 3 | using System.Text.RegularExpressions; | 
|---|
| [203] | 4 | using Steamworks; | 
|---|
| [107] | 5 |  | 
|---|
| [130] | 6 | namespace AllocsFixes | 
|---|
| [107] | 7 | { | 
|---|
| [130] | 8 | public class CommonMappingFunctions | 
|---|
| [107] | 9 | { | 
|---|
| [130] | 10 | public static ConnectionManager GetConnectionManager () | 
|---|
|  | 11 | { | 
|---|
|  | 12 | return ConnectionManager.Instance; | 
|---|
|  | 13 | } | 
|---|
| [107] | 14 |  | 
|---|
| [130] | 15 | public static GameManager GetGameManager () | 
|---|
|  | 16 | { | 
|---|
| [224] | 17 | return GameManager.Instance; | 
|---|
| [130] | 18 | } | 
|---|
| [107] | 19 |  | 
|---|
| [130] | 20 | public static string GetPlayerName (ClientInfo _ci) | 
|---|
|  | 21 | { | 
|---|
| [213] | 22 | return _ci.playerName; | 
|---|
| [107] | 23 | } | 
|---|
|  | 24 |  | 
|---|
| [130] | 25 | public static EntityPlayer GetEntityPlayer (ClientInfo _ci) | 
|---|
|  | 26 | { | 
|---|
| [224] | 27 | return GetGameManager ().World.Players.dict [_ci.entityId]; | 
|---|
| [107] | 28 | } | 
|---|
|  | 29 |  | 
|---|
| [130] | 30 | public static string GetSteamID (ClientInfo _ci) | 
|---|
|  | 31 | { | 
|---|
| [213] | 32 | return _ci.playerId; | 
|---|
| [130] | 33 | } | 
|---|
| [107] | 34 |  | 
|---|
| [130] | 35 | public static int GetClientID (ClientInfo _ci) | 
|---|
|  | 36 | { | 
|---|
| [213] | 37 | return _ci.clientId; | 
|---|
| [110] | 38 | } | 
|---|
| [107] | 39 |  | 
|---|
| [130] | 40 | public static int GetEntityID (ClientInfo _ci) | 
|---|
|  | 41 | { | 
|---|
| [213] | 42 | return _ci.entityId; | 
|---|
| [107] | 43 | } | 
|---|
|  | 44 |  | 
|---|
| [130] | 45 | public static ClientInfo GetClientInfoFromEntityID (int _entityId) | 
|---|
|  | 46 | { | 
|---|
|  | 47 | try { | 
|---|
|  | 48 | ConnectionManager cm = GetConnectionManager (); | 
|---|
| [107] | 49 |  | 
|---|
| [213] | 50 | return cm.GetClientInfoForEntityId (_entityId); | 
|---|
| [130] | 51 | } catch (Exception e) { | 
|---|
|  | 52 | Log.Out ("Error getting ClientInfo for entity ID: " + e); | 
|---|
| [107] | 53 | } | 
|---|
|  | 54 | return null; | 
|---|
|  | 55 | } | 
|---|
|  | 56 |  | 
|---|
| [130] | 57 | public static ClientInfo GetClientInfoFromClientID (int _clientId) | 
|---|
|  | 58 | { | 
|---|
|  | 59 | try { | 
|---|
|  | 60 | ConnectionManager cm = GetConnectionManager (); | 
|---|
| [107] | 61 |  | 
|---|
| [130] | 62 | if (cm.connectedClients.ContainsKey (_clientId)) | 
|---|
|  | 63 | return cm.connectedClients [_clientId]; | 
|---|
|  | 64 | else | 
|---|
|  | 65 | return null; | 
|---|
|  | 66 | } catch (Exception e) { | 
|---|
|  | 67 | Log.Out ("Error getting ClientInfo for client ID: " + e); | 
|---|
|  | 68 | } | 
|---|
|  | 69 | return null; | 
|---|
| [107] | 70 | } | 
|---|
|  | 71 |  | 
|---|
| [130] | 72 | public static ClientInfo GetClientInfoFromPlayerName (string _playerName, bool ignoreColorcodes) | 
|---|
|  | 73 | { | 
|---|
|  | 74 | try { | 
|---|
|  | 75 | ConnectionManager cm = GetConnectionManager (); | 
|---|
| [107] | 76 |  | 
|---|
| [130] | 77 | _playerName = _playerName.ToLower (); | 
|---|
| [111] | 78 | if (ignoreColorcodes) { | 
|---|
| [130] | 79 | _playerName = Regex.Replace (_playerName, "\\[[0-9a-fA-F]{6}\\]", ""); | 
|---|
| [111] | 80 | } | 
|---|
| [130] | 81 | foreach (ClientInfo ci in cm.connectedClients.Values) { | 
|---|
|  | 82 | string curName = GetPlayerName (ci).ToLower (); | 
|---|
|  | 83 | if (ignoreColorcodes) { | 
|---|
|  | 84 | curName = Regex.Replace (curName, "\\[[0-9a-fA-F]{6}\\]", ""); | 
|---|
|  | 85 | } | 
|---|
|  | 86 | if (curName.Equals (_playerName)) { | 
|---|
|  | 87 | return ci; | 
|---|
|  | 88 | } | 
|---|
| [107] | 89 | } | 
|---|
| [130] | 90 | } catch (Exception e) { | 
|---|
|  | 91 | Log.Out ("Error getting ClientInfo for player name: " + e); | 
|---|
| [107] | 92 | } | 
|---|
| [130] | 93 | return null; | 
|---|
| [107] | 94 | } | 
|---|
|  | 95 |  | 
|---|
| [130] | 96 | public static ClientInfo GetClientInfoFromNameOrID (string _nameOrId, bool ignoreColorcodes) | 
|---|
|  | 97 | { | 
|---|
|  | 98 | try { | 
|---|
| [144] | 99 | long tempLong; | 
|---|
|  | 100 | if (_nameOrId.Length == 17 && long.TryParse (_nameOrId, out tempLong)) { | 
|---|
|  | 101 | return GetClientInfoFromSteamID (_nameOrId); | 
|---|
|  | 102 | } else { | 
|---|
|  | 103 | int entityId = -1; | 
|---|
|  | 104 | if (int.TryParse (_nameOrId, out entityId)) { | 
|---|
|  | 105 | ClientInfo ci = GetClientInfoFromEntityID (entityId); | 
|---|
|  | 106 | if (ci != null) | 
|---|
|  | 107 | return ci; | 
|---|
|  | 108 | } | 
|---|
|  | 109 |  | 
|---|
|  | 110 | return GetClientInfoFromPlayerName (_nameOrId, ignoreColorcodes); | 
|---|
| [130] | 111 | } | 
|---|
|  | 112 | } catch (Exception e) { | 
|---|
| [144] | 113 | Log.Out ("Error getting ClientInfo for steam ID / entity ID / player name \"" + _nameOrId + "\": " + e); | 
|---|
| [107] | 114 | } | 
|---|
| [130] | 115 | return null; | 
|---|
| [107] | 116 | } | 
|---|
|  | 117 |  | 
|---|
| [130] | 118 | public static ClientInfo GetClientInfoFromSteamID (string _steamId) | 
|---|
|  | 119 | { | 
|---|
| [213] | 120 | return GetConnectionManager ().GetClientInfoForPlayerId (_steamId); | 
|---|
| [107] | 121 | } | 
|---|
| [130] | 122 |  | 
|---|
| [107] | 123 | } | 
|---|
|  | 124 | } | 
|---|