Raised This Month: $51 Target: $400
 12% 

unloading plugins, playerinfo and cvars


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
disq
Junior Member
Join Date: Dec 2004
Old 02-24-2005 , 23:41   unloading plugins, playerinfo and cvars
Reply With Quote #1

Hi,

I'm having some problems on my serverplugin and i need some help. here are the issues:

1. When i unload my plugin via plugin_unload, it's CON_COMMANDS and cvar are still in place. Is there something I should do in MyPlugin::Unload() to unregister the concommands/cvars? (also the plugin might be still running, i didn't check that)

2. The code below is from the function that is called on plugin load, to populate a struct array "serverPlayers[]" with the currently connected player information. It is called in MyPlugin::Load() so you can unload/load a new version while the map is running and players connected. But it's crashing, take a look:

Code:
for(int i=0;i<65;i++) 
{ 
edict_t *pEntity = engine->EntityOfEntIndex(i); 
if (!pEntity || pEntity->IsFree()) continue; 

IPlayerInfo *playerinfo=playerinfomanager->GetPlayerInfo(pEntity); 
if (!playerinfo) continue; 

//crashes right here! 
if (!playerinfo->IsConnected()) continue; 

// <insert code that fills serverPlayers[i] 's members with player's info> 

}
I'm not a big fan of saving playerList/maxClients that are passed to serverActivate, because it won't be called if the plugin is loaded after the server initialization. My plugin needs to be loadable/unloadable any time (so I can develop without disturbing the server crowd)

3. The code seems to crash if i register more than one CVAR, but i'm still investigating that. Code is like this:

Code:
static ConVar myp_cvar1("myp_cvar1", "", FCVAR_PLUGIN | FCVAR_PROTECTED, "first cvar"); 
static ConVar myp_cvar2("myp_cvar2", 1, FCVAR_PLUGIN | FCVAR_PROTECTED, "second cvar"); //crash here!

Any suggestions?

I'm developing this plugin on Linux. (it took some effort to get it to compile already :p )
It's currently in testing on two of my servers without these three features and it's running without any problems for a few days now.

Thanks.
disq is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 02-25-2005 , 08:30  
Reply With Quote #2

1) I have implemented a convar / concommand removing code for SourceMod.
From the devlog:
Quote:
So, we need a method to remove any command from the command list. HL2 stores the commands in a linked list; it only stores the first one, and every command maintains its pointer to the next command. Note that there is no pointer to the previous command. New commands get added at the beginning of the list.

So, we have two cases:
1) The command we want to remove is NOT at the beginning of the list
In this case, we go through the list, until we find the command we want to remove. We set the previous command’s next pointer to our next pointer, and that’s all.
2) The command we want to remove IS at the beginning of the list
In this case, we have to modify the engine’s internal command list pointer. We don’t have direct access to it, so we need to use a workaround. What I have used is a command that is always registered (that’s why I gave it the name “eternal command"). It has a method, called BringToTop, that unregisters itself from the list and reregisters again. So, when you want to remove a command that is at the beginning, you call g_EternalCommand.BringToTop(), and then you do the same as in 1 (except more simple, as you only have to set g_EternalCommand’s next pointer to your next pointer).
If you want to see the source, click here.
Check the destructor of CCmdHook and the CAlwaysRegisterableCommand class (both are at the beginning of the file).

2)
Code:
if (!pEntity || pEntity->IsFree())
I have experienced a problem with this test. On my listenserver, it told me that all players are valid. This is actually reliable:
Code:
if (!pEntity || pEntity->IsFree() || !pEntity->GetUnknown() || !pEntity->GetUnknown()->GetBaseEntity())
( taken from here; CRFGeneral::AddAllPlayers())

Umm... No idea about 3 ;o
__________________
hello, i am pm
PM is offline
disq
Junior Member
Join Date: Dec 2004
Old 02-25-2005 , 09:56  
Reply With Quote #3

#3, apparently the second argument i was passing had to be a string. so, changed it from 1 to "1" and it works now. doh.

#2. it still doesn't filter out the necessary indexes. still crashing.

#1. I investigated more, the clientcommands doesn't work or the plugin doesn't get called. so it's ok there. heck, what was valve thinking. updates breaking interfaces, globally-defined cvars/plugins. i don't like this "native" serverplugin support, metamod was a lot better.

maybe, i should just set g_plugin to NULL in the destructor code, and make checks in every console command. i'll see if it works.
disq is offline
disq
Junior Member
Join Date: Dec 2004
Old 02-25-2005 , 10:10  
Reply With Quote #4

destructor doesn't get called on plugin onload.. (that's why the commands still work after unloading, without a crash.. g_plugin remains valid) i added a global bool to check if it's unloaded (sets it to true on plugin::load and false on plugin::unload) and con_commands validate them.

now i also have to unregister the cvars
disq is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 02-25-2005 , 11:21  
Reply With Quote #5

#2: Hmm, may be that the playerinfomanager is returning invalid stuff, that happens i.e. in the steam id validated callback. Not sure though, the method I posted was filtering everything reliably for me (it is also used in the gamedll)

#1: The reason why I had the code in the destructor was that I was calling delete hook; to remove it - just place the code to any function.
__________________
hello, i am pm
PM is offline
disq
Junior Member
Join Date: Dec 2004
Old 02-25-2005 , 12:32  
Reply With Quote #6

#2: the thing is the routine is called on myplugin::load and it always crashes. no players on the server, crash. players on the server, crash.

#1: i meant my destructor, referring to my previous message. your solution is too complicated for a simple plugin like mine
disq is offline
fysh
Senior Member
Join Date: Oct 2004
Old 02-25-2005 , 17:35  
Reply With Quote #7

Whenever I unload my plugin and then upgrade it and try to load it again the server crashes. Is there something I need to do besides removing console commands(including CVars)?
fysh is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 02-26-2005 , 04:16  
Reply With Quote #8

I'll probably disable unloading SourceMod if it will cause problems
__________________
hello, i am pm
PM is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode