source: binary-improvements/7dtd-server-fixes/src/CommonMappingFunctions.cs@ 219

Last change on this file since 219 was 213, checked in by alloc, 10 years ago

fixes

File size: 3.0 KB
RevLine 
[107]1using System;
2using System.Collections.Generic;
[111]3using System.Text.RegularExpressions;
[203]4using Steamworks;
[107]5
[130]6namespace 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 {
17 return GetConnectionManager ().gameManager;
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 {
[213]27 return GetGameManager ().World.playerEntities.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}
Note: See TracBrowser for help on using the repository browser.