Page 1 of 2
server init
Posted: Wed Nov 15, 2017 2:38 pm
by Speed0x
why is source python accepting scriptloading, before the server has fully initiated its native modules? ( e.g. autoexec with sp load) wouldnt it make sense to wait at least until e.g. steam gives its server_live callback? if there is any, ofc.... im just assuming steam communicates with the server somehow...
if there already is some listener for that im sorry... maybe someone can mention it again.. thanks guys
Re: server init
Posted: Wed Nov 15, 2017 2:46 pm
by Ayuto
Why not? There are some situations in which you might want to load a plugin quite early (e.g. if you want to block some server console messages).
Also, I wouldn't rely on Steam. What if your server doesn't has access to the Steam servers or the Steam servers are simply down?
If you are experiencing any issues, you can always delay-load your plugin with "sp delay 3 sp plugin load xyz".
Re: server init
Posted: Wed Nov 15, 2017 2:53 pm
by Speed0x
you might have misinterpreted my concern.. im looking for a way to identify when the server has fully loaded its native modules. its probably the same function as steam users when calling "server_live".... i dont have a problem if source python wants to keep it this way, im just asking if there is a way for me to manually get access for this or if i have to delay the entire load ( which i find unreliable )
thanks for helping
Re: server init
Posted: Wed Nov 15, 2017 2:58 pm
by L'In20Cible
I think you are looking for the
OnServerActivate listener or
server_spawn event.
Re: server init
Posted: Wed Nov 15, 2017 3:03 pm
by Speed0x
yeah will try that thanks.
just a quick note to answer @Ayuto : a user could potentially crash his server when accessing a native module via sp too early... im not sure whether console prints are more important than that.. but ill try to implement a custom load now with the serveractivate event for my code... thanks both of you
Re: server init
Posted: Wed Nov 15, 2017 3:07 pm
by L'In20Cible
I really don't understand what you are referring to by "native module", could you elaborate which modules exactly? The game binaries? They are the ones loading Source.Python so everything that is not related to the game-play (entities, stringtables, etc.) should be accessible when loading your plugins via the autoexec.cfg.
Re: server init
Posted: Wed Nov 15, 2017 3:20 pm
by Speed0x
interesting, you are saying that its exactly the other way around, but i never said that source python was loading "the game binaries".. i said source python "accesses" them too early.... ( which presupposes the binaries being loaded first ;) )
i could post a crashdump (.mdmp) if that helps? last time i tested, my server crashed when i was precaching too early with sp. ( limit reached i think) i also had other errors, but i can't recall them now, without recreating the situation and looking into it..
Re: server init
Posted: Wed Nov 15, 2017 4:02 pm
by L'In20Cible
Like I said in my post, stringtables are not allocated yet. Also, they are freed and re-allocated every map so you should NEVER pre-cache anything in global scope/or load function. You should instead use the
engines.precache module that will ensure to refresh the indexes every map for you.
Re: server init
Posted: Wed Nov 15, 2017 4:17 pm
by Speed0x
i have no idea what your advice to me is now...
i said
"last time i tested, my server crashed when i was precaching too early with sp"
and you are saying
"Like I said" ... "You should instead use the engines.precache module that will ensure to refresh the indexes every map for you."
Re: server init
Posted: Wed Nov 15, 2017 4:22 pm
by L'In20Cible
In my previous post, I mentioned that stringtables cannot be accessed unless a map is loaded because they are related to the game-play and they are not initialized at this point. I assumed that you was pre-caching using the direct engine_server calls, which I'm unsure if they have the proper checks to prevent accessing the tables if they are not allocated which would result into a crash. However, the engines.precache module is offering classes that ensure a map is loaded before pre-caching any strings and also ensure that the indexes carried by your objects are always the one for the current allocated table. Could you post/try to reproduce the code that was causing the crashes? So we could figure it out better.
Re: server init
Posted: Wed Nov 15, 2017 4:34 pm
by Speed0x
using this:
Syntax: Select all
from engines.server import engine_server
engine_server.precache_decal
crashes on the first precache for me.
sp info output
Code: Select all
Date : 2017-11-15 16:33:24.392091
OS : Windows-7-6.1.7601-SP1
Game : csgo
SP version : 582
Re: server init
Posted: Wed Nov 15, 2017 4:37 pm
by L'In20Cible
Thanks, I was able to reproduce the crashes as well. Will add checks to ensure it doesn't crash but you should really use the Decal class (same usage for Model and Generic classes):
Syntax: Select all
from engines.precache import Decal
my_decal = Decal('some/decal.vmt')
def some_function():
print(f'{my_decal.path} currently has the index {my_decal.index}')
These classes ensure that the indexes are always up-to-date so you don't have to worry about anything.
Re: server init
Posted: Wed Nov 15, 2017 4:44 pm
by Speed0x
thanks. theres a problem. with your workaround i dont get index from the Decal() class. it only suppresses any scriptload errors.
my goal really is to only start loading my script when the server is fully ready. i will just implement a server_ready listener loader.
btw, whats a workaround for engines.server.server ?
example code:
Syntax: Select all
from engines.server import server
print(server.map_name)
Re: server init
Posted: Wed Nov 15, 2017 4:52 pm
by L'In20Cible
Yes, checking against the map name is a workaround as it will only returns an empty string when no map has been loaded at all. However, since "server" relies on a signature/symbol, I would rather recommend using:
Syntax: Select all
from engines.server import global_vars
global_vars.map_name
Re: server init
Posted: Wed Nov 15, 2017 4:55 pm
by L'In20Cible
Speed0x wrote:thanks. theres a problem. with your workaround i dont get index from the Decal() class. it only suppresses any scriptload errors.
Which is not really a "problem" because you don't need indexes if there is no map loaded because you cannot network any effects unless there is players and no players can connect if there is no map.
Speed0x wrote:my goal really is to only start loading my script when the server is fully ready. i will just implement a server_ready listener loader.
This is really unnecessary, but do as you will.

You could also just load your plugin via server.cfg instead of autoexec.cfg if this is really an issue for you.
Re: server init
Posted: Wed Nov 15, 2017 4:59 pm
by Speed0x
Which is not really a "problem" because you don't need indexes if there is no map loaded because you cannot network any effects unless there is players and no players can connect if there is no map.
if you think outside the box of "does it crash? no? ok this works perfectly!!", you will see that getting indexes after precaching is needed only 1 time. thats why im trying to get the index. im not really trying to precache something, that suppresses an error of getting the index. because then i can never use the index
Re: server init
Posted: Wed Nov 15, 2017 5:03 pm
by L'In20Cible
Speed0x wrote:if you think outside the box of "does it crash? no? ok this works use it!!", you will see that getting indexes after precaching is needed only 1 time. thats why im trying to get the index. im not really trying to precache something, that suppresses an error of getting not index. because that doesnt help at all. its just a waste
Wrong. Like I mentioned above, precached strings are freed
every map change. If you do not re-precache after a new map, your index is no longer valid and will points to another string in the tables. The engine tells you, with a crash, that you cannot pre-cache anything because the tables are
not ready because there is no map loaded. Like I also mentioned, the engines.precache module
update the indexes for you every map while also ensuring that a map is loaded in order to do the pre-caching.
Re: server init
Posted: Wed Nov 15, 2017 5:41 pm
by Speed0x
you are kinda wrong, because i know that i dont reload the map and your scenario never happens.. so it doesnt help me.. :(
Re: server init
Posted: Wed Nov 15, 2017 6:06 pm
by L'In20Cible
Speed0x wrote:you are kinda wrong, because i know that i dont reload the map and your scenario never happens.. so it doesnt help me.. :(
This will be my last post because this is going nowhere. Here is some data to prove my point.
Syntax: Select all
from commands.server import ServerCommand
from engines.server import engine_server
from engines.server import global_vars
from memory import get_object_pointer
from stringtables import string_tables
model = 'models/parachute/orangebox/parachute_default.mdl'
model_index = engine_server.precache_model(model)
modelprecache_ptr = get_object_pointer(string_tables.modelprecache)
@ServerCommand('print')
def print_command(command):
print(f'Current map: {global_vars.map_name}')
print(f'\tmodel_index = {model_index} (Current: {string_tables.modelprecache[model]})')
print(f'\tmodelprecache_ptr = {modelprecache_ptr.address} (Current: {get_object_pointer(string_tables.modelprecache).address})')
Syntax: Select all
[SP] Successfully loaded plugin 'testing'.
print
Current map: de_dust2
model_index = 151 (Current: 151)
modelprecache_ptr = 69562112 (Current: 69562112)
changelevel cs_office
print
Current map: cs_office
model_index = 151 (Current: 65535)
modelprecache_ptr = 69562112 (Current: 69561600)
Re: server init
Posted: Wed Nov 15, 2017 6:12 pm
by Speed0x
you dont need to prove your point. ive already seen your point. i dont disagree with your point.
your point just doesnt help me.
just a moment ago i wanted to create a simple loader via the server_ready listener. but then you kinda told me its a useless approach, although it suits my needs at least. so idk.. mb it IS for the best, that it is your last post.. thanks anyway