Auto Loading Plugin

All other Source.Python topics and issues.
User avatar
Kill
Member
Posts: 88
Joined: Wed Aug 31, 2016 10:05 pm

Auto Loading Plugin

Postby Kill » Thu Sep 01, 2016 10:09 am

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!
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Auto Loading Plugin

Postby iPlayer » Thu Sep 01, 2016 10:32 am

cfg/autoexec.cfg:

Code: Select all

sp plugin load myplugin

Add as many lines as you need
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
Kill
Member
Posts: 88
Joined: Wed Aug 31, 2016 10:05 pm

Re: Auto Loading Plugin

Postby Kill » Thu Sep 01, 2016 10:41 am

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.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Auto Loading Plugin

Postby L'In20Cible » Thu Sep 01, 2016 11:01 am

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()
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Auto Loading Plugin

Postby satoon101 » Thu Sep 01, 2016 12:39 pm

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.
Image
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Auto Loading Plugin

Postby iPlayer » Thu Sep 01, 2016 12:43 pm

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.
Last edited by iPlayer on Thu Sep 01, 2016 12:54 pm, edited 1 time in total.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Auto Loading Plugin

Postby Ayuto » Thu Sep 01, 2016 12:47 pm

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Auto Loading Plugin

Postby satoon101 » Thu Sep 01, 2016 12:51 pm

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.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Auto Loading Plugin

Postby satoon101 » Thu Sep 01, 2016 12:56 pm

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.
Image
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Auto Loading Plugin

Postby iPlayer » Thu Sep 01, 2016 12:56 pm

I also edited my previous post with one more point.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Auto Loading Plugin

Postby satoon101 » Thu Sep 01, 2016 1:02 pm

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).
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Auto Loading Plugin

Postby L'In20Cible » Thu Sep 01, 2016 1:13 pm

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
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Auto Loading Plugin

Postby iPlayer » Thu Sep 01, 2016 1:16 pm

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?
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Auto Loading Plugin

Postby L'In20Cible » Thu Sep 01, 2016 1:21 pm

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Auto Loading Plugin

Postby satoon101 » Thu Sep 01, 2016 1:28 pm

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.
Image
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Auto Loading Plugin

Postby iPlayer » Thu Sep 01, 2016 1:30 pm

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Auto Loading Plugin

Postby L'In20Cible » Thu Sep 01, 2016 1:38 pm

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.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Auto Loading Plugin

Postby iPlayer » Thu Sep 01, 2016 1:43 pm

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Auto Loading Plugin

Postby L'In20Cible » Thu Sep 01, 2016 1:53 pm

We could spend the day listing all the possibilities, but none of those has something to do with auto-loading plugins or not.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Auto Loading Plugin

Postby iPlayer » Thu Sep 01, 2016 1:56 pm

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 28 guests