|
18 | 18 | # ============================================================================= |
19 | 19 | # Source.Python Imports |
20 | 20 | # Players |
| 21 | +from _players._helpers import address_from_playerinfo |
21 | 22 | from _players._helpers import baseentity_from_playerinfo |
22 | 23 | from _players._helpers import baseentity_from_userid |
23 | 24 | from _players._helpers import basehandle_from_playerinfo |
|
27 | 28 | from _players._helpers import index_from_playerinfo |
28 | 29 | from _players._helpers import index_from_userid |
29 | 30 | from _players._helpers import index_from_name |
| 31 | +from _players._helpers import index_from_steamid |
| 32 | +from _players._helpers import index_from_uniqueid |
30 | 33 | from _players._helpers import inthandle_from_playerinfo |
31 | 34 | from _players._helpers import inthandle_from_userid |
32 | 35 | from _players._helpers import playerinfo_from_baseentity |
|
45 | 48 | from _players._helpers import userid_from_inthandle |
46 | 49 | from _players._helpers import userid_from_playerinfo |
47 | 50 | from _players._helpers import userid_from_pointer |
| 51 | +from _players._helpers import uniqueid_from_index |
| 52 | +from _players._helpers import uniqueid_from_playerinfo |
48 | 53 |
|
49 | 54 |
|
50 | 55 | # ============================================================================= |
|
84 | 89 | 'userid_from_playerinfo', |
85 | 90 | 'userid_from_pointer', |
86 | 91 | ) |
87 | | - |
88 | | - |
89 | | -# ============================================================================= |
90 | | -# >> OTHER HELPER FUNCTIONS |
91 | | -# ============================================================================= |
92 | | -def index_from_steamid(steamid): |
93 | | - """Return an index from the given SteamID. |
94 | | -
|
95 | | - :param str steamid: The SteamID to get the index of. |
96 | | - :rtype: int |
97 | | - """ |
98 | | - # Loop through all players on the server |
99 | | - for edict in PlayerGenerator(): |
100 | | - |
101 | | - # Get the PlayerInfo instance of the player... |
102 | | - playerinfo = playerinfo_from_edict(edict) |
103 | | - |
104 | | - # Is the current player's SteamID the same as the one given? |
105 | | - if playerinfo.steamid == steamid: |
106 | | - |
107 | | - # Return the index of the current player |
108 | | - return index_from_playerinfo(playerinfo) |
109 | | - |
110 | | - raise ValueError( |
111 | | - 'Conversion from "SteamID" ({}) to "Index" failed.'.format(steamid)) |
112 | | - |
113 | | - |
114 | | -def index_from_uniqueid(uniqueid): |
115 | | - """Return an index from the given UniqueID. |
116 | | -
|
117 | | - :param str uniqueid: The UniqueID to get the index of. |
118 | | - :rtype: int |
119 | | - """ |
120 | | - # Loop through all players on the server |
121 | | - for edict in PlayerGenerator(): |
122 | | - |
123 | | - # Get the PlayerInfo instance of the player... |
124 | | - playerinfo = playerinfo_from_edict(edict) |
125 | | - |
126 | | - # Is the current player's UniqueID the same as the one given? |
127 | | - if uniqueid_from_playerinfo(playerinfo) == uniqueid: |
128 | | - |
129 | | - # Return the index of the current player |
130 | | - return index_from_playerinfo(playerinfo) |
131 | | - |
132 | | - raise ValueError( |
133 | | - 'Conversion from "UniqueID" ({}) to "Index" failed.'.format(uniqueid)) |
134 | | - |
135 | | - |
136 | | -def uniqueid_from_playerinfo(playerinfo): |
137 | | - """Return the UniqueID for the given player. |
138 | | -
|
139 | | - :param PlayerInfo playerinfo: The PlayerInfo |
140 | | - instance to get the UniqueID from. |
141 | | - :return: The UniqueID of the player. E.g. 'BOT_STAN' or 'STEAM_0:0:12345' |
142 | | - :rtype: str |
143 | | - """ |
144 | | - # Is the player a Bot? |
145 | | - if playerinfo.is_fake_client() or 'BOT' in playerinfo.steamid: |
146 | | - |
147 | | - # Return the bot's UniqueID |
148 | | - return 'BOT_{0}'.format(playerinfo.name) |
149 | | - |
150 | | - # Get the player's SteamID |
151 | | - steamid = playerinfo.steamid |
152 | | - |
153 | | - # Is this a Lan SteamID? |
154 | | - if 'LAN' in steamid: |
155 | | - |
156 | | - # Get the player's IP address |
157 | | - address = address_from_playerinfo(playerinfo) |
158 | | - |
159 | | - # Return the Lan player's ID |
160 | | - return 'LAN_{0}'.format('_'.join(address.split(':')[0].split('.'))) |
161 | | - |
162 | | - # Return the player's SteamID |
163 | | - return steamid |
164 | | - |
165 | | - |
166 | | -def uniqueid_from_index(index): |
167 | | - """Return the UniqueID for the given player index. |
168 | | -
|
169 | | - :param int index: The player index to get the UniqueID from. |
170 | | - :return: The UniqueID of the player. E.g. 'BOT_STAN' or 'STEAM_0:0:12345' |
171 | | - :rtype: str |
172 | | - """ |
173 | | - return uniqueid_from_playerinfo(playerinfo_from_index(index)) |
174 | | - |
175 | | - |
176 | | -def address_from_playerinfo(playerinfo): |
177 | | - """Return the IP address for the given player. |
178 | | -
|
179 | | - If the player is a bot, an empty string will be returned. |
180 | | -
|
181 | | - :param PlayerInfo playerinfo: The PlayerInfo |
182 | | - instance to get the UniqueID from. |
183 | | - :return: The IP address. E.g. '127.0.0.1:27015' |
184 | | - :rtype: str |
185 | | - """ |
186 | | - # Is the player a bot? |
187 | | - if playerinfo.is_fake_client() or 'BOT' in playerinfo.steamid: |
188 | | - |
189 | | - # Return an empty string, since using <netinfo>.address crashes |
190 | | - # with bots |
191 | | - return '' |
192 | | - |
193 | | - # Get the player's index |
194 | | - index = index_from_playerinfo(playerinfo) |
195 | | - |
196 | | - # Get the player's NetInfo instance |
197 | | - netinfo = engine_server.get_player_net_info(index) |
198 | | - |
199 | | - # Return the player's IP Address |
200 | | - return netinfo.address |
0 commit comments