Skip to content

Commit 4656f43

Browse files
committed
Merge branch 'master' into engine_blade
2 parents 6b85e8f + 9ad3291 commit 4656f43

File tree

22 files changed

+195
-273
lines changed

22 files changed

+195
-273
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{1,40}|(__.*__))$
4646
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
4747

4848
# Variable names that are always ok
49-
good-names=x,y,z,a,b,c,d,e,f,g,h,x1,y1,z1,x2,y2,z2,p1,p2,source-python,fget,create_global_pointers_from_file,create_function_typedefs_from_file,MuzzleFlashStyle,WeaponID,WeaponType,WeaponSlot,WeaponInfo,BaseClient
49+
good-names=x,y,z,a,b,c,d,e,f,g,h,x1,y1,z1,x2,y2,z2,p1,p2,source-python,fget,create_global_pointers_from_file,create_function_typedefs_from_file,MuzzleFlashStyle,WeaponID,WeaponType,WeaponSlot,WeaponInfo,BaseClient,BaseEntityOutput
5050

5151

5252
[REPORTS]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[virtual_function]
2+
3+
[[add_upgrade]]
4+
offset_linux = 425
5+
offset_windows = 424
6+
arguments = INT
7+
8+
[[has_upgrade]]
9+
offset_linux = 428
10+
offset_windows = 427
11+
arguments = INT
12+
13+
[[is_dual_wielding]]
14+
offset_linux = 412
15+
offset_windows = 411
16+
return_type = BOOL
17+
18+
[[is_weapon_upgraded]]
19+
offset_linux = 411
20+
offset_windows = 410
21+
return_type = BOOL
22+
23+
[[remove_all_upgrades]]
24+
offset_linux = 427
25+
offset_windows = 426
26+
27+
[[remove_upgrade]]
28+
offset_linux = 426
29+
offset_windows = 425
30+
arguments = INT
31+
32+
33+
[property]
34+
35+
is_dual_wielding = m_isDualWielding
36+
upgrade_bits = m_upgradeBitVec
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[property]
2+
3+
upgraded_ammo = m_nUpgradedPrimaryAmmoLoaded

addons/source-python/packages/source-python/commands/auth.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# Source.Python Imports
99
# Auth
1010
from auth.manager import auth_manager
11+
# Players
12+
from players.helpers import playerinfo_from_index
1113
# Hooks
1214
from hooks.exceptions import except_hooks
1315

@@ -38,7 +40,8 @@ def __call__(self, *args):
3840

3941
# Is the player authorized?
4042
if not auth_manager.is_player_authorized(
41-
args[0], self.level, self.permission, self.flag):
43+
playerinfo_from_index(args[1]), self.level, self.permission,
44+
self.flag):
4245

4346
# Is there fail callback?
4447
if self.fail_callback is not None:

addons/source-python/packages/source-python/commands/manager.py

Lines changed: 42 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -2,190 +2,75 @@
22

33
"""Provides a base class for registering commands and filters."""
44

5-
# =============================================================================
6-
# >> IMPORTS
7-
# =============================================================================
8-
# Source.Python Imports
9-
# Commands
10-
from commands import CommandReturn
11-
# Hooks
12-
from hooks.exceptions import except_hooks
13-
145

156
# =============================================================================
167
# >> CLASSES
178
# =============================================================================
18-
class _BaseCommandManager(dict):
9+
class _BaseCommandManager(object):
1910

2011
"""Class used to (un)register commands."""
2112

22-
# Store the base attributes
23-
_use_args = True
24-
_callback_manager = None
13+
# Can be set to a class that acts like a proxy for commands. It will be
14+
# registered instead of a callback. If the command was issued, the
15+
# callback manager will be called and it's its responsibility to call the
16+
# actual callback.
17+
_callback_proxy = None
2518

26-
def register_commands(self, names, callback, *args, **kwargs):
27-
"""Register the given commands to the given callback."""
19+
def __init__(self):
20+
"""Initialize the command manager."""
21+
# This will store all created callback proxies
22+
self._callback_proxies = []
23+
24+
def _prepare_command_names(self, names):
25+
"""Validate and prepare the given command names.
26+
27+
The given argument can be a string, list or tuple. A TypeError is
28+
raised if it does not meet the requirements.
29+
"""
2830
# Was a single command name given?
2931
if isinstance(names, str):
30-
31-
# Store the command as a list
3232
names = [names]
3333

3434
# Are the names of a proper iterable type?
3535
if not isinstance(names, (list, tuple)):
36-
37-
# Raise an error
3836
raise TypeError(
3937
'{0} commands must be passed as a list, tuple, or string,'
4038
' not "{1}"'.format(type(self).__name__, type(names).__name__))
4139

42-
# Is there a specified callback manager for this class?
43-
if self._callback_manager is not None:
44-
45-
# Get the callback manager's instance for the given callback
46-
callback = self._callback_manager(callback, *args, **kwargs)
47-
48-
# Loop through the given names
49-
for name in names:
40+
return names
5041

51-
# Is the command already registered?
52-
if name not in self:
42+
def _get_command_proxy(self, callback):
43+
"""Return the command proxy for the given callback.
5344
54-
# Are the arguments supposed to be used
55-
# when getting the command instance?
56-
if self._use_args:
45+
Raise a ValueError when the proxy wasn't found.
46+
"""
47+
for proxy in self._callback_proxies:
48+
if proxy.callback is callback:
49+
return proxy
5750

58-
# Get the command using the arguments
59-
command = self._get_command(name, *args)
51+
raise ValueError('Unable to find a proxy for the given callback.')
6052

61-
# Are the arguments not supposed to be used?
62-
else:
63-
64-
# Get the command without the arguments
65-
command = self._get_command(name)
53+
def register_commands(self, names, callback, *args, **kwargs):
54+
"""Register the given commands to the given callback."""
55+
names = self._prepare_command_names(names)
6656

67-
# Add the command to the dictionary
68-
self[name] = _CallbackList(command)
57+
if self._callback_proxy is not None:
58+
# Create a new callback proxy for this callback
59+
callback = self._callback_proxy(callback, *args, **kwargs)
60+
self._callback_proxies.append(callback)
6961

70-
# Add the callback to the command's list of callbacks
71-
self[name].append(callback)
62+
# Register all command names
63+
for name in names:
64+
self._get_command(name, *args).add_callback(callback)
7265

7366
def unregister_commands(self, names, callback):
7467
"""Unregister the given commands from the given callback."""
75-
# Was a single command name given?
76-
if isinstance(names, str):
77-
78-
# Store the command as a list
79-
names = [names]
80-
81-
# Are the names of a proper iterable type?
82-
if not isinstance(names, (list, tuple)):
68+
names = self._prepare_command_names(names)
8369

84-
# Raise an error
85-
raise TypeError(
86-
'{0} commands must be passed as a list, tuple, or string,'
87-
' not "{1}"'.format(type(self).__name__, type(names).__name__))
70+
if self._callback_proxy is not None:
71+
callback = self._get_command_proxy(callback)
72+
self._callback_proxies.remove(callback)
8873

89-
# Loop through all given names
74+
# Unregister all command names
9075
for name in names:
91-
92-
# Is the command registered?
93-
if name not in self:
94-
95-
# Raise an error
96-
raise KeyError('Command "{0}" not registered'.format(name))
97-
98-
# Is there a specified callback manager for this class?
99-
if self._callback_manager is not None:
100-
101-
# Loop through each callback in the command's list
102-
for registered_callback in self[name]:
103-
104-
# Is the current callback an
105-
# instance for the given callback?
106-
if registered_callback.callback == callback:
107-
108-
# Set the callback's instance to the current callback
109-
callback = registered_callback
110-
111-
# Break the loop
112-
break
113-
114-
# Remove the callback from the command's list
115-
self[name].remove(callback)
116-
117-
# Are there any more callbacks registered to the command?
118-
if not self[name]:
119-
120-
# Remove the callback from the command's callback
121-
self[name].command.remove_callback(self[name])
122-
123-
# Remove the command from the dictionary
124-
del self[name]
125-
126-
127-
class _CallbackList(list):
128-
129-
"""List class used to store."""
130-
131-
def __init__(self, command):
132-
"""Register the instance to the command."""
133-
# Initialize the list
134-
super(_CallbackList, self).__init__()
135-
136-
# Store the command
137-
self.command = command
138-
139-
# Add the instance to the command's callback list
140-
self.command.add_callback(self)
141-
142-
def __call__(self, *args):
143-
"""Call all callbacks for the command."""
144-
# Loop through each callback in the list
145-
for callback in self:
146-
147-
# Use try/except to continue the loop in case of an error
148-
try:
149-
150-
# Call the callback and get its return value
151-
return_value = callback(*args)
152-
153-
# Was an error encountered?
154-
except:
155-
156-
# Print the exception to the console
157-
except_hooks.print_exception()
158-
159-
# Was no error encountered?
160-
else:
161-
162-
# Does the command need blocked?
163-
if not (return_value is None or return_value):
164-
165-
# Block the command
166-
return CommandReturn.BLOCK
167-
168-
# Allow the command to continue
169-
return CommandReturn.CONTINUE
170-
171-
def append(self, callback):
172-
"""Add a callback to the list."""
173-
# Is the callback already in the list?
174-
if callback in self:
175-
176-
# Raise an error
177-
raise ValueError('Callback already registered to command')
178-
179-
# Add the callback to the list
180-
super(_CallbackList, self).append(callback)
181-
182-
def remove(self, callback):
183-
"""Remove a callback from the list."""
184-
# Is the callback in the list?
185-
if callback not in self:
186-
187-
# Raise an error
188-
raise ValueError('Callback not registered to command')
189-
190-
# Remove the callback from the list
191-
super(_CallbackList, self).remove(callback)
76+
self._get_command(name).remove_callback(callback)

addons/source-python/packages/source-python/commands/player.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@ class _PlayerCommandManager(_BaseCommandManager):
1818

1919
"""Base class used to (un)register client/say commands."""
2020

21-
# Store the base attributes
22-
_use_args = False
23-
_callback_manager = _AuthCallback
21+
_callback_proxy = _AuthCallback

addons/source-python/packages/source-python/engines/precache.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ class _PrecacheBase(AutoUnload):
5151
# or not the path was added to the downloadables
5252
_downloads = None
5353

54-
def __init__(self, path, download=False):
54+
def __init__(self, path, preload=False, download=False):
5555
"""Add the file to downloadables if download is True."""
5656
# Save the path that should be precached
5757
self._path = path
5858

59+
# Save whether the the file should be preloaded
60+
self._preload = preload
61+
5962
# Get the calling module
6063
caller = getmodule(stack()[1][0])
6164

@@ -101,7 +104,7 @@ def path(self):
101104

102105
def _precache(self):
103106
"""Precache the path."""
104-
self._precache_method(self._path)
107+
self._precache_method(self._path, self._preload)
105108

106109
def _server_spawn(self, game_event):
107110
"""Precache the object on map change."""

addons/source-python/packages/source-python/listeners/_entity_output.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@
2424
from _listeners import _ListenerManager
2525

2626

27-
# =============================================================================
28-
# >> ALL DECLARATION
29-
# =============================================================================
30-
__all__ = ('entity_output_listener_manager',
31-
)
32-
33-
3427
# =============================================================================
3528
# >> GLOBAL VARIABLES
3629
# =============================================================================

addons/source-python/packages/source-python/net_channel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
__all__ = ('NetChannel',
3030
'NetChannelHandler',
3131
'NetChannelInfo',
32+
'NetFlow',
3233
'NetMessage',
3334
)
3435

addons/source-python/packages/source-python/players/voice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
# =============================================================================
3232
# >> ALL DECLARATION
3333
# =============================================================================
34-
__all__ = ('voice_server',
35-
'mute_manager',
34+
__all__ = ('mute_manager',
35+
'voice_server',
3636
)
3737

3838

src/core/modules/commands/commands.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class CCommandExt
6969
const char* szValue = command.GetCommandString();
7070
return PyUnicode_DecodeUTF8(szValue, strlen(szValue), "ignore");
7171
}
72+
73+
static bool Tokenize(CCommand& command, const char* szCommand)
74+
{
75+
return command.Tokenize(szCommand);
76+
}
7277
};
7378

7479

0 commit comments

Comments
 (0)