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

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

fixes

File size: 3.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text.RegularExpressions;
4using Steamworks;
5
6namespace AllocsFixes
7{
8 public class CommonMappingFunctions
9 {
10 public static ConnectionManager GetConnectionManager ()
11 {
12 return ConnectionManager.Instance;
13 }
14
15 public static GameManager GetGameManager ()
16 {
17 return GetConnectionManager ().gameManager;
18 }
19
20 public static string GetPlayerName (ClientInfo _ci)
21 {
22 return _ci.playerName;
23 }
24
25 public static EntityPlayer GetEntityPlayer (ClientInfo _ci)
26 {
27 return GetGameManager ().World.playerEntities.dict [_ci.entityId];
28 }
29
30 public static string GetSteamID (ClientInfo _ci)
31 {
32 return _ci.playerId;
33 }
34
35 public static int GetClientID (ClientInfo _ci)
36 {
37 return _ci.clientId;
38 }
39
40 public static int GetEntityID (ClientInfo _ci)
41 {
42 return _ci.entityId;
43 }
44
45 public static ClientInfo GetClientInfoFromEntityID (int _entityId)
46 {
47 try {
48 ConnectionManager cm = GetConnectionManager ();
49
50 return cm.GetClientInfoForEntityId (_entityId);
51 } catch (Exception e) {
52 Log.Out ("Error getting ClientInfo for entity ID: " + e);
53 }
54 return null;
55 }
56
57 public static ClientInfo GetClientInfoFromClientID (int _clientId)
58 {
59 try {
60 ConnectionManager cm = GetConnectionManager ();
61
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;
70 }
71
72 public static ClientInfo GetClientInfoFromPlayerName (string _playerName, bool ignoreColorcodes)
73 {
74 try {
75 ConnectionManager cm = GetConnectionManager ();
76
77 _playerName = _playerName.ToLower ();
78 if (ignoreColorcodes) {
79 _playerName = Regex.Replace (_playerName, "\\[[0-9a-fA-F]{6}\\]", "");
80 }
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 }
89 }
90 } catch (Exception e) {
91 Log.Out ("Error getting ClientInfo for player name: " + e);
92 }
93 return null;
94 }
95
96 public static ClientInfo GetClientInfoFromNameOrID (string _nameOrId, bool ignoreColorcodes)
97 {
98 try {
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);
111 }
112 } catch (Exception e) {
113 Log.Out ("Error getting ClientInfo for steam ID / entity ID / player name \"" + _nameOrId + "\": " + e);
114 }
115 return null;
116 }
117
118 public static ClientInfo GetClientInfoFromSteamID (string _steamId)
119 {
120 return GetConnectionManager ().GetClientInfoForPlayerId (_steamId);
121 }
122
123 }
124}
Note: See TracBrowser for help on using the repository browser.