Re: [hlcoders] Examples of uses for IEngine->ServerInsertCommand()
I'm pretty sure the command queue works the same as most of these games since Quake. All 'exec' does is place all of the lines into the command queue in the proper order. Then the command handler will take each command independently off of the queue. At that point, they're not a 'block' or anything, they're just individual commands that happen to be placed in the queue in a sequence. When any individual command is processed, it can still insert commands at the front of the queue and have it execute before the (former) next command is scheduled to do so. This is almost certainly why an 'exec' or 'alias' within a cfg file happens before continuing with other lines in the .cfg file-- they pretty much always insert their looked-up lines into the front of the queue (these built-in commands are basically a limited form of 'variable expansion' already). In order to create other commands that can behave the same way, we need something like ServerInsertCommand() rather than one that adds to the end of the queue. So in short, I'm 95% certain that this command is exactly what the community would need for this purpose. -Mattie - Original Message - From: "Jeremy Swigart" <[EMAIL PROTECTED]> To: Sent: Friday, June 10, 2005 9:20 AM Subject: Re: [hlcoders] Examples of uses for IEngine->ServerInsertCommand() I could be wrong, but even if ServerInsertCommand() puts the script command at the front of the queue as opposed to the back, that still wouldn't be executed until the current script is finished. Sounds like really what you need is ServerCommandNow() that executes it right now, so that when the next line of the current script runs, it can be sure that the results of the script it just invoked is already done. Sounds like even with ServerInsertCommand() it is gonna be a pain to get the ordering right. On 6/10/05, Mattie Casper <[EMAIL PROTECTED]> wrote: Thanks for the suggestion, but, as you may have guessed, this has been considered. ;) Yet, creating an entire scripting engine isn't the goal of EventScripts. There are lots of different scripting engines out there, and they definitely have their place for administrators who understand coding. EventScripts is trying to be the middle-ground between a structured/scoped language and the console commands they know and love. As I mentioned below, ES doesn't yet support looping and the like and may never do so--- it's not intended to be a full-powered scripting language. With EventScripts, we're trying to enhance the console commands so that even everyday normal console/rcon commands and normal autoexec.cfg/server.cfg files can take advantage of very simple logic and variable expansion. We don't need everything a scripting language can do, we just want some basic enhancements to the command console. Most of these console enhancements would be along the lines Valve was already been moving, e.g. with "setinfo" and "incrementvar". Yet, even in the case of a full blown scripting language, not having InsertCommand() means that any scripts/commands that you wished to invoke via a normal Valve cfg file would have the same ordering problem if they needed to pass commands back to the server (e.g. exec, changelevel, kickid, etc). These commands would execute *after* the current .cfg file was totally resolved and not in-place. This wouldn't be intuitive and would likely cause problems! It wouldn't be a problem if you didn't allow the console to launch scripts, but the server console is a great place for invoking things like that (especially remotely). *** TO CLARIFY, this isn't a problem just for scripting engines! *** It's a problem for ANY PLUGIN that uses console commands and needs to interact with the console. Let's say I wrote a console command "mattie_exec" that took Con_Argv(1) and passed it to exec with a different directory prefix (e.g. my mod's directory). // server.cfg mattie_exec blah.cfg exec load_plugins.cfg // end of server.cfg Now, the mattie_exec command, all it does is call engine->ServerCommand("exec matties_mod\blah.cfg\n"). In this case, the console would execute like this: 1. (contents of server.cfg added to the queue around LevelInit()) 2. mattie_exec runs (places "exec mattie_mod\blah.cfg" at end of queue) 3. exec load_plugins.cfg runs (all plugins activated, configured, etc) 4. exec mattie_mod\blah.cfg runs You see that even though the mattie_exec command was placed in a certain order in the cfg file, it's irrelevant. Any server commands those commands rely upon cannot be activated until after the entire .cfg file has been processed. This means that if the "load_plugins.cfg" relied upon any settings created in blah.cfg, there's no way at all to get it to work short of bypassing the plugin commands. Admittedl
Re: [hlcoders] Examples of uses for IEngine->ServerInsertCommand()
This is also something I've considered-- I was just discussing this in my forum. Obviously writing my own 'exec' (and a lot of surrounding overhead) is a way I can achieve what I want without Valve providing the appropriate mechanism. It's not terrible to force all users to use a different .cfg file system, but it's certainly not the idea behind EventScripts, or really what other plugin authors might need. Other plugin authors trying to write commands that order properly won't find very good ROI on rewriting an exec (they just have to live with it). EventScripts itself is supposed to just extend the console with a bunch of new commands -- we'd all prefer if it didn't require admins to change how they're doing things today if they want them to work. Even if they did so (as you say, I suspect a lot of users could live with it), all it takes is for them to forget and add lines to the traditional .cfg files (which a lot of rental sites provide web access to, edit-wise) and things get out of order again. Also keep in mind that people also use aliases to stack commands in groups into the command buffer. I don't have a lot of recourse in those situations other than providing my own 'alias' handler in the script preprocessor and disallowing use of the conventional one if the user wishes things to order properly. Anyway, it's certainly doable if my user base is comfortable with changing their current paradigm and I reinvent the wheel a few times, but that's definitely quite far out of line with what EventScripts was supposed to be. I.e. I just want to add powerful console commands that should work fine in any server.cfg, autoexec.cfg. I know I have to move 'out of that realm' if Valve's not able to provide the InsertCommand() API, but that won't solve the problem for any plugin but my own (unless they also re-invent the wheel to solve this). All in all, I have options, and I appreciate the suggestions (keep 'em coming, by all means!), but mostly my available options involve circumventing Valve and creating my own independent engine. I'd, of course, much rather work with them and interoperate. And to do so, I need this one easy and accessible command and it will open a world of possibility for console commands. On the platforms where EventScripts works best, already administrators are able to recreate a huge number of plugins simply using .cfg files and some popular admin plugins. See this thread for examples: http://www.sourcemod.net/forums/viewtopic.php?t=898 Thanks again for your suggestions, -Mattie - Original Message - From: "Karl "XP-Cagey" Patrick" <[EMAIL PROTECTED]> To: Sent: Saturday, June 11, 2005 8:58 AM Subject: RE: [hlcoders] Examples of uses for IEngine->ServerInsertCommand() Yet, even in the case of a full blown scripting language, not having InsertCommand() means that any scripts/commands that you wished to invoke via a normal Valve cfg file would have the same ordering problem if they needed to pass commands back to the server (e.g. exec, changelevel, kickid, etc). One solution to your problem that doesn't require an API change is instructing users to write a one-line config file that simply calls your plugin-enabled parser to run on another file. E.g. have the entire contents of autoexec.cfg be "eventscripts_exec autoexec_script.cfg\n". Once you have that arrangement, there aren't any commands that you need to preempt from the top level scripts--load and manipulate the entire autoexec_script.cfg file in memory to perform whatever transforms you need, then feed the entire transformed file to the server in a block. Delayed insertion removes the need for preemptive insertion, and as far as your end users know or care, they're still using Valve's config system. Placement of the entire config into a one-off file isn't seamless, but it's not hard for users to understand and it doesn't require much extra work or drive space. If HL2 calls two script files, say autoexec.cfg and server.cfg, at nearly the same time and they both contain a single call into a one-off, the execution order will appear to be the same to end users even if the second exec comes before or in the middle of the interpreted commands from the first file, since the effect of calling the second file would place its commands after the complete set of commands from the intial file (assuming the whole file interpret-and-stuff mechanism described above and synchronous server command execution). You really don't need out-of-order placement for variable substitution or subscript execution using this scheme--you could even support calls into other files and process them entirely in place before you begin inserting the top level file. You might want to have preemptive insertion for live evaluation of loop conditions, but that problem can
RE: [hlcoders] Examples of uses for IEngine->ServerInsertCommand()
> Yet, even in the case of a full blown scripting language, not having > InsertCommand() means that any scripts/commands that you wished to > invoke via a normal Valve cfg file would have the same ordering problem if > they needed to pass commands back to the server (e.g. exec, changelevel, > kickid, etc). One solution to your problem that doesn't require an API change is instructing users to write a one-line config file that simply calls your plugin-enabled parser to run on another file. E.g. have the entire contents of autoexec.cfg be "eventscripts_exec autoexec_script.cfg\n". Once you have that arrangement, there aren't any commands that you need to preempt from the top level scripts--load and manipulate the entire autoexec_script.cfg file in memory to perform whatever transforms you need, then feed the entire transformed file to the server in a block. Delayed insertion removes the need for preemptive insertion, and as far as your end users know or care, they're still using Valve's config system. Placement of the entire config into a one-off file isn't seamless, but it's not hard for users to understand and it doesn't require much extra work or drive space. If HL2 calls two script files, say autoexec.cfg and server.cfg, at nearly the same time and they both contain a single call into a one-off, the execution order will appear to be the same to end users even if the second exec comes before or in the middle of the interpreted commands from the first file, since the effect of calling the second file would place its commands after the complete set of commands from the intial file (assuming the whole file interpret-and-stuff mechanism described above and synchronous server command execution). You really don't need out-of-order placement for variable substitution or subscript execution using this scheme--you could even support calls into other files and process them entirely in place before you begin inserting the top level file. You might want to have preemptive insertion for live evaluation of loop conditions, but that problem can also be solved through delayed insertion - keep all commands after the evaluation statement in memory until you get back your result. Simple loop counters can be unrolled in place instantly, and I'm not sure how much complexity a configuration script really needs. My 2 cents, Karl > -Original Message- > From: [EMAIL PROTECTED] [mailto:hlcoders- > [EMAIL PROTECTED] On Behalf Of Jeremy Swigart > Sent: Friday, June 10, 2005 6:20 AM > To: hlcoders@list.valvesoftware.com > Subject: Re: [hlcoders] Examples of uses for IEngine- > >ServerInsertCommand() > > I could be wrong, but even if ServerInsertCommand() puts the script > command at the front of the queue as opposed to the back, that still > wouldn't be executed until the current script is finished. Sounds like > really what you need is ServerCommandNow() that executes it right now, > so that when the next line of the current script runs, it can be sure > that the results of the script it just invoked is already done. Sounds > like even with ServerInsertCommand() it is gonna be a pain to get the > ordering right. > > On 6/10/05, Mattie Casper <[EMAIL PROTECTED]> wrote: > > Thanks for the suggestion, but, as you may have guessed, this has been > > considered. ;) Yet, creating an entire scripting engine isn't the goal > of > > EventScripts. There are lots of different scripting engines out there, > and they > > definitely have their place for administrators who understand coding. > > EventScripts is trying to be the middle-ground between a > structured/scoped > > language and the console commands they know and love. As I mentioned > below, ES > > doesn't yet support looping and the like and may never do so--- it's not > > intended to be a full-powered scripting language. > > > > With EventScripts, we're trying to enhance the console commands so that > even > > everyday normal console/rcon commands and normal autoexec.cfg/server.cfg > files > > can take advantage of very simple logic and variable expansion. We don't > need > > everything a scripting language can do, we just want some basic > enhancements to > > the command console. Most of these console enhancements would be along > the lines > > Valve was already been moving, e.g. with "setinfo" and "incrementvar". > > > > Yet, even in the case of a full blown scripting language, not having > > InsertCommand() means that any scripts/commands that you wished to > invoke via a > > normal Valve cfg file would have the same ordering problem if they > needed to > > pass commands back to the server (e.g. exec, changelevel, kicki
Re: [hlcoders] Examples of uses for IEngine->ServerInsertCommand()
I could be wrong, but even if ServerInsertCommand() puts the script command at the front of the queue as opposed to the back, that still wouldn't be executed until the current script is finished. Sounds like really what you need is ServerCommandNow() that executes it right now, so that when the next line of the current script runs, it can be sure that the results of the script it just invoked is already done. Sounds like even with ServerInsertCommand() it is gonna be a pain to get the ordering right. On 6/10/05, Mattie Casper <[EMAIL PROTECTED]> wrote: > Thanks for the suggestion, but, as you may have guessed, this has been > considered. ;) Yet, creating an entire scripting engine isn't the goal of > EventScripts. There are lots of different scripting engines out there, and > they > definitely have their place for administrators who understand coding. > EventScripts is trying to be the middle-ground between a structured/scoped > language and the console commands they know and love. As I mentioned below, ES > doesn't yet support looping and the like and may never do so--- it's not > intended to be a full-powered scripting language. > > With EventScripts, we're trying to enhance the console commands so that even > everyday normal console/rcon commands and normal autoexec.cfg/server.cfg files > can take advantage of very simple logic and variable expansion. We don't need > everything a scripting language can do, we just want some basic enhancements > to > the command console. Most of these console enhancements would be along the > lines > Valve was already been moving, e.g. with "setinfo" and "incrementvar". > > Yet, even in the case of a full blown scripting language, not having > InsertCommand() means that any scripts/commands that you wished to invoke via > a > normal Valve cfg file would have the same ordering problem if they needed to > pass commands back to the server (e.g. exec, changelevel, kickid, etc). These > commands would execute *after* the current .cfg file was totally resolved and > not in-place. This wouldn't be intuitive and would likely cause problems! It > wouldn't be a problem if you didn't allow the console to launch scripts, but > the > server console is a great place for invoking things like that (especially > remotely). > > *** TO CLARIFY, this isn't a problem just for scripting engines! *** It's a > problem for ANY PLUGIN that uses console commands and needs to interact with > the > console. Let's say I wrote a console command "mattie_exec" that took > Con_Argv(1) > and passed it to exec with a different directory prefix (e.g. my mod's > directory). > > // server.cfg > mattie_exec blah.cfg > exec load_plugins.cfg > // end of server.cfg > > Now, the mattie_exec command, all it does is call engine->ServerCommand("exec > matties_mod\blah.cfg\n"). In this case, the console would execute like this: > > 1. (contents of server.cfg added to the queue around LevelInit()) > 2. mattie_exec runs (places "exec mattie_mod\blah.cfg" at end of queue) > 3. exec load_plugins.cfg runs (all plugins activated, configured, etc) > 4. exec mattie_mod\blah.cfg runs > > You see that even though the mattie_exec command was placed in a certain order > in the cfg file, it's irrelevant. Any server commands those commands rely upon > cannot be activated until after the entire .cfg file has been processed. This > means that if the "load_plugins.cfg" relied upon any settings created in > blah.cfg, there's no way at all to get it to work short of bypassing the > plugin > commands. > > Admittedly, this is a simple example, but it underscores the issue outside of > a > scripting context. Plugin console commands could be calling back to any number > of other console commands. We all have access to ServerCommand(), right? Well, > just like Valve, we need it's sister command in order to create proper console > commands. Sometimes we don't care about ordering, so ServerCommand() might be > appropriate, but many times ordering *will* be important. We truly need > ServerInsertCommand(), and I hope everyone can see that. > > Thanks for your help and for reading this far, > -Mattie > > - Original Message - > From: "Jeremy Swigart" <[EMAIL PROTECTED]> > To: > Sent: Friday, June 10, 2005 7:17 AM > Subject: Re: [hlcoders] Examples of uses for IEngine->ServerInsertCommand() > > > > Have you considered using a scripting language such as lua or > > gamemonkeyscript or another one that supports fake threading? > > Specifically you might be interested in their ability to execute over > >
Re: [hlcoders] Examples of uses for IEngine->ServerInsertCommand()
Thanks for the suggestion, but, as you may have guessed, this has been considered. ;) Yet, creating an entire scripting engine isn't the goal of EventScripts. There are lots of different scripting engines out there, and they definitely have their place for administrators who understand coding. EventScripts is trying to be the middle-ground between a structured/scoped language and the console commands they know and love. As I mentioned below, ES doesn't yet support looping and the like and may never do so--- it's not intended to be a full-powered scripting language. With EventScripts, we're trying to enhance the console commands so that even everyday normal console/rcon commands and normal autoexec.cfg/server.cfg files can take advantage of very simple logic and variable expansion. We don't need everything a scripting language can do, we just want some basic enhancements to the command console. Most of these console enhancements would be along the lines Valve was already been moving, e.g. with "setinfo" and "incrementvar". Yet, even in the case of a full blown scripting language, not having InsertCommand() means that any scripts/commands that you wished to invoke via a normal Valve cfg file would have the same ordering problem if they needed to pass commands back to the server (e.g. exec, changelevel, kickid, etc). These commands would execute *after* the current .cfg file was totally resolved and not in-place. This wouldn't be intuitive and would likely cause problems! It wouldn't be a problem if you didn't allow the console to launch scripts, but the server console is a great place for invoking things like that (especially remotely). *** TO CLARIFY, this isn't a problem just for scripting engines! *** It's a problem for ANY PLUGIN that uses console commands and needs to interact with the console. Let's say I wrote a console command "mattie_exec" that took Con_Argv(1) and passed it to exec with a different directory prefix (e.g. my mod's directory). // server.cfg mattie_exec blah.cfg exec load_plugins.cfg // end of server.cfg Now, the mattie_exec command, all it does is call engine->ServerCommand("exec matties_mod\blah.cfg\n"). In this case, the console would execute like this: 1. (contents of server.cfg added to the queue around LevelInit()) 2. mattie_exec runs (places "exec mattie_mod\blah.cfg" at end of queue) 3. exec load_plugins.cfg runs (all plugins activated, configured, etc) 4. exec mattie_mod\blah.cfg runs You see that even though the mattie_exec command was placed in a certain order in the cfg file, it's irrelevant. Any server commands those commands rely upon cannot be activated until after the entire .cfg file has been processed. This means that if the "load_plugins.cfg" relied upon any settings created in blah.cfg, there's no way at all to get it to work short of bypassing the plugin commands. Admittedly, this is a simple example, but it underscores the issue outside of a scripting context. Plugin console commands could be calling back to any number of other console commands. We all have access to ServerCommand(), right? Well, just like Valve, we need it's sister command in order to create proper console commands. Sometimes we don't care about ordering, so ServerCommand() might be appropriate, but many times ordering *will* be important. We truly need ServerInsertCommand(), and I hope everyone can see that. Thanks for your help and for reading this far, -Mattie ----- Original Message - From: "Jeremy Swigart" <[EMAIL PROTECTED]> To: Sent: Friday, June 10, 2005 7:17 AM Subject: Re: [hlcoders] Examples of uses for IEngine->ServerInsertCommand() Have you considered using a scripting language such as lua or gamemonkeyscript or another one that supports fake threading? Specifically you might be interested in their ability to execute over many frames, yet still be written in a top down manner. Here's an example of GMS, which I use in my bot. / server.cfg if(sv_gravity > 800) { exec("reset_grav.cfg"); echo("gravity reset"); yield(); // suspend execution of the script till the next frame, can also do sleep() commands } else { echo("gravity is fine"); } echo("this happens the frame after the gravity is reset, or right away if the exec didnt happen"); Everything you do and much more would be possible using the features of an existing scripting language, and with it you'd get the power of conditionals, tables, loops, and much more. Just an idea. J On 6/9/05, Mattie Casper <[EMAIL PROTECTED]> wrote: As promised, this email contains examples of the sorts of things that plugin authors cannot manage in Source without some method to insert commands at the beginning of the server command queue. This ability is vital for any plugin wishing to create meta cons
Re: [hlcoders] Examples of uses for IEngine->ServerInsertCommand()
Have you considered using a scripting language such as lua or gamemonkeyscript or another one that supports fake threading? Specifically you might be interested in their ability to execute over many frames, yet still be written in a top down manner. Here's an example of GMS, which I use in my bot. / server.cfg if(sv_gravity > 800) { exec("reset_grav.cfg"); echo("gravity reset"); yield(); // suspend execution of the script till the next frame, can also do sleep() commands } else { echo("gravity is fine"); } echo("this happens the frame after the gravity is reset, or right away if the exec didnt happen"); Everything you do and much more would be possible using the features of an existing scripting language, and with it you'd get the power of conditionals, tables, loops, and much more. Just an idea. J On 6/9/05, Mattie Casper <[EMAIL PROTECTED]> wrote: > > As promised, this email contains examples of the sorts of things that plugin > authors cannot manage in Source without some method to insert commands at the > beginning of the server command queue. This ability is vital for any plugin > wishing to create meta console commands. I.e. commands like alias, exec, > incrementvar, etc. > > Variable expansion -- > > EventScripts makes extensive use of variable expansion for its console > commands, and it's crippled without InsertCommand(). There's no way to arrange > for expanded commands to execute right away before the rest of a config file. > For example, let's say I added the following lines to a .cfg file (e.g. > server.cfg): > > // server.cfg > // let's say 'mypluginvar' is a variable exposed by my plugin > mypluginvar "ClanMatch" > expandvars echo *** mypluginvar equals %mypluginvar% > echo *** The above line should say "mypluginvar equals ClanMatch" > echo *** server.cfg is completely done. should see nothing else. > // end server.cfg > > So, if my plugin's 'expandvars' command expanded variables in the string > provided to it and then passed it back to the server, the only mechanism it > can > use is ServerCommand(). This will place it AFTER everything else in the queue. > As such, the output would be: > > *** The above line should say "mypluginvar equals ClanMatch" > *** server.cfg is completely done. should see nothing else. > *** mypluginvar equals ClanMatch > > This is definitely not what someone writing a .cfg file would be expecting. > They > expect the commands to go in order of writing. EventScripts supports a great > deal of variable expansion, but there's no support for intuitive ordering. > This > example is trivial compared to the complicated scripts people are creating. It > really weakens the plugin when admins can't trust that your variables will be > expanded properly in relation to other commands in the cfg file. > - > > Conditional expressions -- > - > EventScripts supports conditional expressions. These are also hindered > without > InsertCommand(). The order of execution again gets all out of phase. For > example, let's say I added the following lines to a .cfg file (e.g. > server.cfg): > > // server.cfg > // let's say my plugin exposes an "exec_if" command > exec_if sv_gravity > 800 then reset_grav.cfg > echo *** sv_gravity was set back to 800 by increase_grav.cfg > exec_if sv_gravity > 800 then something_wrong.cfg > // end of server.cfg > > In this case, the plugin command "exec_if" would test the condition > "sv_gravity > > 800" and then use, sadly, ServerCommand() to place "exec reset_grav.cfg" in > the queue where it could reset the gravity back to 800. Unfortunately, this > goes > to the very end of the queue, so the rest of the server.cfg executes first. > This > means the second conditional will STILL see sv_gravity incorrectly because it > goes through the server command queue like this: > > 1. exec_if > 2. echo > 3. exec_if > 4. exec reset_grav.cfg > 5. exec something_wrong.cfg > > #5 should never happen-- and #4 should happen before the 'echo' does. Yet we > can't do this because InsertCommand() isn't yet available to plugin writers. > - > > Loops -- > -- > EventScripts does not yet support loops, but these would also be possible if > Valve provided a way to insert commands at the beginning of the queue. Without > it, you cannot be certain that the loop lines will execute before the next > line > in a script. > -- > > Enhanced versions of alias, exec, etc > - > EventScripts doesn't do this yet, but if I wanted to create an enhanced > version > of these Valve commands, the new commands will always be deficient without > InsertCommand(). For example, if we wanted to write an optimized "exec" > command > that cached the .cfg file in memory on the first execution and then always ran > it from memory whenever called (to avoid refetches from disk):