Page 1 of 2

Auto Loading Plugin

Posted: Thu Sep 01, 2016 10:09 am
by Kill
Hello, hope everyone is alright!

Is it going to be implemented anytime or is it going to remain the same?

Been using SourceMod, I really like the way it autoloads plugin, would love to see it here too!

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 10:32 am
by iPlayer
cfg/autoexec.cfg:

Code: Select all

sp plugin load myplugin

Add as many lines as you need

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 10:41 am
by Kill
iPlayer wrote:cfg/autoexec.cfg:

Code: Select all

sp plugin load myplugin

Add as many lines as you need



I already now that :) Thanks. But I'm talking about autoloading them, by SP itself, without additional stuff.

IMO, addng that to autoexec isn't really autoloading.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 11:01 am
by L'In20Cible

Syntax: Select all

# ../addons/source-python/plugins/autoload/autoload.py

"""Automatically load installed plugins."""

# ============================================================================
# >> IMPORTS
# ============================================================================
# Source.Python Imports
# Core
from core.manager import core_plugin_manager
# Listeners
from listeners import OnLevelInit
# Paths
from paths import PLUGIN_PATH


# ============================================================================
# >> LOAD/UNLOAD
# ============================================================================
def load():
"""Called when this plugin is loaded."""
# Autoload all plugins
autoload_plugins()


# ============================================================================
# >> HELPER FUNCTIONS
# ============================================================================
def autoload_plugins():
"""Autoload all plugins."""
# Loop through all plugins' directories
for directory in PLUGIN_PATH.dirs():

# Get the name of the plugin
name = directory.basename()

# Skip ourself/private plugins (ignore __pycache__, etc)
if name == 'autoload' or name.startswith('__'):
continue

# Is the plugin already loaded?
if core_plugin_manager.is_loaded(name):
continue

# Attempt to load the current plugin
core_plugin_manager[name]


# ============================================================================
# >> LISTENERS
# ============================================================================
@OnLevelInit
def on_level_init(map_name):
"""Called when a new map gets initialized."""
# Autoload all plugins
autoload_plugins()

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 12:39 pm
by satoon101
I'm pretty sure there was already a topic about this, but I cannot seem to find it. But, no, this will never be included in SP. You can use a plugin like the one in L'In20Cible's post to do this for you. Just add his plugin to your server and add sp plugin load autoload (or whatever you end up calling it) to your autoexec.cfg if you want this functionality.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 12:43 pm
by iPlayer
I'd like to point out the path that L'In20Cible has specified in the header of the file:

Code: Select all

../addons/source-python/plugins/autoload.py

Does putting a .py file directly to the plugins folder (instead of making it a package) make the plugin load without sp plugin load or it's just a mistake?


More on topic: I personally prefer enabling/disabling plugins by simply commenting or uncommenting the corresponding entries in autoexec.cfg, rather than moving files back and forth.

Plus! It enables you to run multiple SRCDS instances (with different mods) from one installation folder. I don't know anybody who does that, but it's definitely supported by SRCDS as it provides servercfgfile to set different server.cfg (if I'm not mistaken), and different autoexec.cfg can be set via command line with +exec dm_autoexec.cfg.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 12:47 pm
by Ayuto
iPlayer wrote:Does putting a .py file directly to the plugins folder (instead of making it a package) make the plugin load without sp plugin load or it's just a mistake?

No, it won't load. Though, we also discussed the idea of allowing simple *.py files.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 12:51 pm
by satoon101
We have also considered adding allowing plugins to be loaded as:

Code: Select all

../addons/source-python/plugins/autoload/__init__.py


I don't remember if we ever finished that discussion though.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 12:56 pm
by satoon101
iPlayer wrote:More on topic: I personally prefer enabling/disabling plugins by simply commenting or uncommenting the corresponding entries in autoexec.cfg, rather than moving files back and forth.

Also, this is exactly on point. Not to mention, a lot of us who are developing plugins with SP tend to have test scripts that we want to use every once in awhile but not all the time. It would get very tedious to have to continuously move files from one folder to another. Whereas, adding/removing // from the autoexec.cfg, or even just loading/reloading manually on the server when we want to, is so much easier of a process.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 12:56 pm
by iPlayer
I also edited my previous post with one more point.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:02 pm
by satoon101
iPlayer wrote:Plus! It enables you to run multiple SRCDS instances (with different mods) from one installation folder. I don't know anybody who does that, but it's definitely supported by SRCDS as it provides servercfgfile to set different server.cfg (if I'm not mistaken), and different autoexec.cfg can be set via command line with +exec dm_autoexec.cfg.

Well, to that point, I use my PluginHelpers scripts to symlink SP to all my local servers and to symlink all my plugins to SP (which means they are also all on every local server). There are certainly some of them that would error if trying to load on the wrong server (ie a plugin that only supports CS:GO/CS:S could raise a NotImplementedError on TF2).

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:13 pm
by L'In20Cible
satoon101 wrote:We have also considered adding allowing plugins to be loaded as:

Code: Select all

../addons/source-python/plugins/autoload/__init__.py


I don't remember if we ever finished that discussion though.
Ayuto wrote:
iPlayer wrote:Does putting a .py file directly to the plugins folder (instead of making it a package) make the plugin load without sp plugin load or it's just a mistake?

No, it won't load. Though, we also discussed the idea of allowing simple *.py files.


viewtopic.php?p=6315#p6315

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:16 pm
by iPlayer
By "mods" I meant like GG/DM etc, but the same game. Just different config files that load different plugins. As long as your PluginHelpers scripts don't relate to the server port and don't create conflicting files, it should all be alright, shouldn't it?

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:21 pm
by L'In20Cible
One of the main reason why I'm not for auto-loading plugins, along with all the reasons given above, is the fact that any trolls could pretend to ship something (like a custom map, or models, etc.) with some malicious plugin that get automatically loaded without the server's owner conscent. Let's not forget that while "we" do know the difference between a map and a plugin, casual users may have no idea and just believe the description they got from the download page they got it from.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:28 pm
by satoon101
L'In20Cible wrote:http://forums.sourcepython.com/viewtopic.php?p=6315#p6315

Thank you! I hadn't had time to search for that.


iPlayer wrote:By "mods" I meant like GG/DM etc, but the same game. Just different config files that load different plugins. As long as your PluginHelpers scripts don't relate to the server port and don't create conflicting files, it should all be alright, shouldn't it?

Ah, ok, I misunderstood. I read mods as games. My point was that if we had autoloading, all of my plugins would attempt to be loaded when starting any of the servers, and a number of them would error or even possibly crash a server for a game it was not intended for. I get your point now. But yes, all around, autoloading is not a great idea.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:30 pm
by iPlayer
One of the main reason why I'm not for auto-loading plugins, along with all the reasons given above, is the fact that any trolls could pretend to ship something (like a custom map, or models, etc.) with some malicious plugin that get automatically loaded without the server's owner conscent. Let's not forget that while "we" do know the difference between a map and a plugin, casual users may have no idea and just believe the description they got from the download page they got it from.


Well, if one can by any means make somebody put something in their addons folder, they probably won't have any problems
a) make somebody put something in their cfg folder
b) use point_servercommand's Command input to execute sp plugin load malicious_plugin

Also, gamebanana definitely deletes the custom content (models, maps) that includes addons folder in it. That's the reason I put map data generated from VMF preprocessing into mapdata folder and not into addons/source-python/data.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:38 pm
by L'In20Cible
Indeed, there will always be a way to trick someone. But auto-loading plugins is like opening the door with a giant flashing sign that says welcome. Trolls would also need to trick them into executing that cfg, which is the same as tricking them by running the load command itself so that argument is kinda invalid to me.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:43 pm
by iPlayer
Trolls can provide autoexec.cfg. And if we're talking about maps, then map by default (not in CS:GO, though) has all rights to execute any server command as a server console.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:53 pm
by L'In20Cible
We could spend the day listing all the possibilities, but none of those has something to do with auto-loading plugins or not.

Re: Auto Loading Plugin

Posted: Thu Sep 01, 2016 1:56 pm
by iPlayer
We could, but one of my maps was banned from gamebanana for banning players I didn't like with Sourcemod.

My point is that if you allow somebody to go into your addons folder, then it doesn't matter if some autounload is turned on or off.