forked from Source-Python-Dev-Team/Source.Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
217 lines (164 loc) · 7.48 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# ../__init__.py
"""This is the main file that loads/unloads the Python portion of the plugin.
===============================================================================
Source Python
Copyright (C) 2012 Source Python Development Team. All rights reserved.
===============================================================================
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 3.0, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
As a special exception, the Source.Python Team gives you permission
to link the code of this program (as well as its derivative works) to
"Half-Life 2," the "Source Engine," and any Game MODs that run on software
by the Valve Corporation. You must obey the GNU General Public License in
all respects for all other code used. Additionally, the Source.Python
Development Team grants this exception to all derivative works.
"""
# =============================================================================
# >> LOAD & UNLOAD
# =============================================================================
def load():
"""Load Source.Python's Python side."""
setup_hooks()
setup_logging()
setup_translations()
setup_sp_command()
setup_auth()
setup_user_settings()
setup_entities_listener()
setup_versioning()
def unload():
"""Unload Source.Python's Python side."""
unload_plugins()
remove_entities_listener()
# =============================================================================
# >> HOOKS
# =============================================================================
def setup_hooks():
"""Set up hooks."""
from hooks.exceptions import except_hooks
from hooks.warnings import warning_hooks
# =============================================================================
# >> LOGGING
# =============================================================================
def setup_logging():
"""Set up logging."""
from configobj import ConfigObjError
from cvars import ConVar
# Use try/except in case the logging values are not integers
try:
# Import the core settings dictionary
from core.settings import _core_settings
# Set the logging level
ConVar('sp_logging_level').set_int(
int(_core_settings['LOG_SETTINGS']['level']))
# Set the logging areas
ConVar('sp_logging_areas').set_int(
int(_core_settings['LOG_SETTINGS']['areas']))
# Was an exception raised?
except (ValueError, ConfigObjError):
# Set the logging level to max (5)
ConVar('sp_logging_level').set_int(5)
# Set the logging area to include console, SP logs, and main log
ConVar('sp_logging_areas').set_int(7)
# Import the _sp_logger
from loggers import _sp_logger
# Log a message about the value
_sp_logger.log_message(
'[Source.Python] Plugin did not load properly ' +
'due to the following error:')
# Re-raise the error
raise
# =============================================================================
# >> TRANSLATIONS
# =============================================================================
def setup_translations():
"""Set up translations."""
# Import the Language Manager
from translations.manager import language_manager
from core.settings import _core_settings
# Set the default language
language_manager._register_default_language(
_core_settings['BASE_SETTINGS']['language'])
# =============================================================================
# >> SP COMMAND
# =============================================================================
def setup_sp_command():
"""Set up the 'sp' command."""
from core.command import _core_command
# =============================================================================
# >> AUTH
# =============================================================================
def setup_auth():
"""Set up authentification."""
from core.command import _core_command
from core.settings import _core_settings
# Get the auth providers that should be loaded
auth_providers = _core_settings['AUTH_SETTINGS']['providers'].split()
# Should any providers be loaded?
if auth_providers:
# Load the auth providers
_core_command['auth'].call_command(['load'] + auth_providers)
# =============================================================================
# >> USER_SETTINGS
# =============================================================================
def setup_user_settings():
"""Set up user settings."""
from commands.client import client_command_manager
from commands.say import say_command_manager
from settings.menu import _player_settings
from core.settings import _core_settings
# Are there any private user settings say commands?
if _core_settings['USER_SETTINGS']['private_say_commands']:
# Register the private user settings say commands
say_command_manager.register_commands(_core_settings[
'USER_SETTINGS']['private_say_commands'].split(
','), _player_settings._private_send_menu)
# Are there any public user settings say commands?
if _core_settings['USER_SETTINGS']['public_say_commands']:
# Register the public user settings say commands
say_command_manager.register_commands(_core_settings[
'USER_SETTINGS']['public_say_commands'].split(
','), _player_settings._send_menu)
# Are there any client user settings commands?
if _core_settings['USER_SETTINGS']['client_commands']:
# Register the client user settings commands
client_command_manager.register_commands(_core_settings[
'USER_SETTINGS']['client_commands'].split(
','), _player_settings._send_menu)
# =============================================================================
# >> ENTITIES LISTENER
# =============================================================================
def setup_entities_listener():
"""Set up entities listener."""
from _core import _sp_plugin
from memory.manager import manager
manager.get_global_pointer('GlobalEntityList').add_entity_listener(
_sp_plugin)
def remove_entities_listener():
"""Remove entities listener."""
from _core import _sp_plugin
from memory.manager import manager
manager.get_global_pointer('GlobalEntityList').remove_entity_listener(
_sp_plugin)
# =============================================================================
# >> PLUGINS
# =============================================================================
def unload_plugins():
"""Unload all plugins."""
from core.manager import core_plugin_manager
from core.command import _core_command
for plugin_name in core_plugin_manager:
_core_command.unload_plugin(plugin_name)
# =============================================================================
# >> VERSION
# =============================================================================
def setup_versioning():
"""Setup versioning."""
from core import version