[bfprog] Digest Configuration Variables - Update
Andrew Armstrong
andrewa at bigpond.net.au
Tue Jul 26 16:40:53 PDT 2005
Thanks for that.
Im thinking due to the way the multiple server configurations are setup, ill
just have to include the 'read config data' (parseConfig) function in my own
script, unless I can specify how to import a specific file.
For example, I dont just have default.py and default.cfg - They are called
server1.py and server1.cfg (and they work together).
Is it possible to do the following in server1.py for example:
import myscript
myscript.init(1)
Then in myscript.py:
def init(servernum)
from (server + servernum) import options
... Then use the options array
I dont see that working though :)
Alternativly, I can just place the parseConfig code in my script and re-read
it again on initilization (when init() is called) and maintain the array
myself, this seems the best solution.
One issue I have with that solution though is, how can I access variables
between the functions (Eg, I create the options array again in init(), how
can I then access it (from within the same python file, myscript.py) in
another function? Im talking about global variables.
So in:
def init(servernum)
# Setup the options array here
def anotherfunction()
# I can access the options array that I created in init() earlier
Any ideas?
Thankyou for the help so far.
- Andrew
----- Original Message -----
From: "Forrest Thiessen" <thiessen at cyberscapearena.com>
To: "Battlefield Programming" <bfprog at lists.matureasskickers.net>
Sent: Wednesday, July 27, 2005 12:07 AM
Subject: Re: [bfprog] Digest Configuration Variables - Update
> Yes; because the admin directory is in sys.path, you can import
> default.py by saying:
> import default
> Then everything in default.py's namespace is available to you, as long
> as you qualify it with "default." at the beginning. For example, if you
> want to check the value of an "xyzzy" option that you set in
> default.cfg, you could access it as
> default.options['xyzzy']
>
> Alternately, if the options dictionary is the only thing you're after,
> it might be easier to instead import just the dictionary with:
> from default import options
> Then you can access the xyzzy option as:
> options['xyzzy']
> without any need to qualify it.
>
> --Forrest (aka "Woody")
>
>
> Andrew Armstrong wrote:
>
> > Unfortunatly I cannot work like this either, since I need to support
> > multiple gameservers running off the same installation (which
> > currently works fine).
> >
> > In default.py the parseConfig() function currently parses all: "key =
> > value" lines in default.cfg and places them into the options array.
> >
> > Eg, in admin/default.cfg there is:
> > password = email
> >
> > And then I can access it (in default.PY) via:
> > options['password']
> >
> > I can add new lines/configuration options to the default.cfg file -
> > this would be ideal.
> >
> > However, how do I go about *retrieving* the options array from another
> > py script?
> >
> > Ive tried:
> >
> > import bf2
> > import host
> > from bf2 import g_debug
> >
> > def init():
> > print "Got password of " + options['password']
> >
> > However it does not seem to print anything/know what options is.
> >
> > Basically the question comes down to: How do I access the options
> > array (originally declared/used in default.py) from another python file?
> >
> > Im assuming I have to import it somehow?
> >
> > Cheers,
> > Andrew
> >
> > ----- Original Message ----- From: "Brandon" <brandon at bf2cc.com>
> > To: <bfprog at lists.matureasskickers.net>
> > Sent: Tuesday, July 26, 2005 9:09 AM
> > Subject: [bfprog] RE: BFProg Digest Configuration Variables
> >
> >
> >> See the default.py script for an example. It's in the "def
> >> parseConfig()"
> >> function.
> >>
> >> -----Original Message-----
> >> From: bfprog-bounces at lists.matureasskickers.net
> >> [mailto:bfprog-bounces at lists.matureasskickers.net] On Behalf Of
> >> bfprog-request at lists.matureasskickers.net
> >> Sent: Monday, July 25, 2005 3:00 PM
> >> To: bfprog at lists.matureasskickers.net
> >> Subject: BFProg Digest, Vol 2, Issue 14
> >>
> >> Send BFProg mailing list submissions to
> >> bfprog at lists.matureasskickers.net
> >>
> >> To subscribe or unsubscribe via the World Wide Web, visit
> >> http://lists.matureasskickers.net/mailman/listinfo/bfprog
> >> or, via email, send a message with subject or body 'help' to
> >> bfprog-request at lists.matureasskickers.net
> >>
> >> You can reach the person managing the list at
> >> bfprog-owner at lists.matureasskickers.net
> >>
> >> When replying, please edit your Subject line so it is more specific
> >> than "Re: Contents of BFProg digest..."
> >>
> >>
> >> Today's Topics:
> >>
> >> 1. Configuration Variables? (Andrew Armstrong)
> >> 2. Re: Unregistering Handlers (Einar S. Ids?)
> >> 3. registerhandler, last param is for? (Giel van Schijndel)
> >> 4. Re: Unregistering Handlers (Forrest Thiessen)
> >> 5. Re: Configuration Variables? (Forrest Thiessen)
> >>
> >>
> >> ----------------------------------------------------------------------
> >>
> >> Message: 1
> >> Date: Mon, 25 Jul 2005 14:45:39 +1000
> >> From: "Andrew Armstrong" <andrewa at bigpond.net.au>
> >> Subject: [bfprog] Configuration Variables?
> >> To: <bfprog at lists.matureasskickers.net>
> >> Message-ID: <002001c590d3$b4ff5a20$a600a8c0 at plasma>
> >> Content-Type: text/plain; charset="iso-8859-1"
> >>
> >> Hey,
> >>
> >> For the love of gawd, help me! :)
> >>
> >> I have been working on a script file that will reject people who dont
> >> meet a
> >> minimum rank. This works as intended.
> >>
> >> However, I *do not want* to have to hard code the 'min required rank'
> >> variable in the python script - this is not acceptable (multiple
> >> configs etc
> >> among other things).
> >>
> >> I want to be able to say in the server config file put:
> >>
> >> sv.minrank = 1
> >>
> >> Just as an example.
> >>
> >> And then retrieve it in my script via:
> >>
> >> if (playersrank < (getSetting('sv.minrank'))
> >> ... kick em
> >>
> >> Once again, jsut an example (getSetting() is made up).
> >>
> >> Surely theres an easy way to make such variables accessable?
> >>
> >> Trying to figure this out is driving me insane - Any help would be
> >> appreciated!
> >>
> >> Cheers,
> >> Andrew
> >> -------------- next part --------------
> >> An HTML attachment was scrubbed...
> >> URL:
> >>
http://lists.matureasskickers.net/pipermail/bfprog/attachments/20050725/eb21
> >>
> >> 5cfb/attachment-0001.html
> >>
> >> ------------------------------
> >>
> >> Message: 2
> >> Date: Mon, 25 Jul 2005 11:17:56 +0200
> >> From: "Einar S. Ids?" <esi at itk.ntnu.no>
> >> Subject: Re: [bfprog] Unregistering Handlers
> >> To: Battlefield Programming <bfprog at lists.matureasskickers.net>
> >> Message-ID: <42E4AE44.1030300 at itk.ntnu.no>
> >> Content-Type: text/plain; charset=ISO-8859-1
> >>
> >> Ah, that is really cool! I didn't know you could split a "function
> >> object" into parts like this and "cancel" individual parts - good idea!
> >> I'll just pretend it was my suggestion that led you to this solution,
> >> which should ensure my happines for the rest of the day ;)
> >>
> >> Einar
> >>
> >>> I eventually figured out a byzantine way around the problem, at least
> >>> for my purposes:
> >>>
> >>>
> >>
http://bf2.fun-o-matic.org/index.php/Cookbook:Dynamically_Changing_an_Event_
> >>
> >> Handler
> >>
> >>> The method I came up with recognizes that I can't do anything about
the
> >>> original handler function object, but I *can* swap out the code object
> >>> inside of it. It doesn't result in the handler becoming unregistered,
> >>> but what I was really after was a way to replace a standard handler
> >>> with
> >>> one of my own, anyway, so this fits the bill.
> >>
> >>
> >>
> >> ------------------------------
> >>
> >> Message: 3
> >> Date: Mon, 25 Jul 2005 14:28:44 +0200
> >> From: Giel van Schijndel <giel at kingofdos.com>
> >> Subject: [bfprog] registerhandler, last param is for?
> >> To: bfprog-list <bfprog at lists.matureasskickers.net>
> >> Message-ID: <42E4DAFC.2060209 at kingofdos.com>
> >> Content-Type: text/plain; charset="us-ascii"
> >>
> >> An HTML attachment was scrubbed...
> >> URL:
> >>
http://lists.matureasskickers.net/pipermail/bfprog/attachments/20050725/0ebc
> >>
> >> 6003/attachment-0001.html
> >>
> >> ------------------------------
> >>
> >> Message: 4
> >> Date: Mon, 25 Jul 2005 08:49:22 -0600
> >> From: Forrest Thiessen <thiessen at cyberscapearena.com>
> >> Subject: Re: [bfprog] Unregistering Handlers
> >> To: Battlefield Programming <bfprog at lists.matureasskickers.net>
> >> Message-ID: <42E4FBF2.1060106 at cyberscapearena.com>
> >> Content-Type: text/plain; charset=ISO-8859-1
> >>
> >> If you're happy, I'm happy! Enjoy the rest of your day! ;-)
> >>
> >> --Forrest
> >>
> >>
> >> Einar S. Idsx wrote:
> >>
> >>> Ah, that is really cool! I didn't know you could split a "function
> >>> object" into parts like this and "cancel" individual parts - good
idea!
> >>> I'll just pretend it was my suggestion that led you to this solution,
> >>> which should ensure my happines for the rest of the day ;)
> >>>
> >>> Einar
> >>>
> >>>
> >>>
> >>>> I eventually figured out a byzantine way around the problem, at least
> >>>> for my purposes:
> >>>>
> >>>>
http://bf2.fun-o-matic.org/index.php/Cookbook:Dynamically_Changing_an_Even
> >>>>
> >>>
> >> t_Handler
> >>
> >>>> The method I came up with recognizes that I can't do anything about
> >>>> the
> >>>> original handler function object, but I *can* swap out the code
object
> >>>> inside of it. It doesn't result in the handler becoming unregistered,
> >>>> but what I was really after was a way to replace a standard handler
> >>>> with
> >>>> one of my own, anyway, so this fits the bill.
> >>>>
> >>>>
> >>> _______________________________________________
> >>> BFProg mailing list
> >>> BFProg at lists.matureasskickers.net
> >>> http://lists.matureasskickers.net/mailman/listinfo/bfprog
> >>>
> >>>
> >>
> >>
> >> ------------------------------
> >>
> >> Message: 5
> >> Date: Mon, 25 Jul 2005 09:06:12 -0600
> >> From: Forrest Thiessen <thiessen at cyberscapearena.com>
> >> Subject: Re: [bfprog] Configuration Variables?
> >> To: Battlefield Programming <bfprog at lists.matureasskickers.net>
> >> Message-ID: <42E4FFE4.4040608 at cyberscapearena.com>
> >> Content-Type: text/plain; charset=ISO-8859-1
> >>
> >> There's a function in the wiki "cookbook" section that accesses
> >> configuration variables:
> >>
> >>
http://bf2.fun-o-matic.org/index.php/Cookbook:Finding_the_Value_of_a_Server_
> >>
> >> Configuration_Variable
> >>
> >> It works great on standard config variables built into BF2. However,
> >> the second part of your question is about putting your own custom
> >> variables into the main BF2 .con files, and I have *not* found a way to
> >> get that to work, yet. I tried adding a line to ServerSettings.con,
for
> >> example, that said "sv.forrest 1". When I try retrieving the value of
> >> sv.forrest, I get an error--something like "unknown variable" (it might
> >> be slightly different--I don't remember the exact wording of the
error).
> >>
> >> You can always make your own .con file, and read and parse it during
> >> game startup, but I understand why you'd prefer to use the existing
> >> configuration mechanism.
> >>
> >> --Forrest (aka "Woody")
> >>
> >>
> >> Andrew Armstrong wrote:
> >>
> >>> Hey,
> >>>
> >>> For the love of gawd, help me! :)
> >>>
> >>> I have been working on a script file that will reject people who dont
> >>> meet a minimum rank. This works as intended.
> >>>
> >>> However, I *do not want* to have to hard code the 'min required rank'
> >>> variable in the python script - this is not acceptable (multiple
> >>> configs etc among other things).
> >>>
> >>> I want to be able to say in the server config file put:
> >>>
> >>> sv.minrank = 1
> >>>
> >>> Just as an example.
> >>>
> >>> And then retrieve it in my script via:
> >>>
> >>> if (playersrank < (getSetting('sv.minrank'))
> >>> ... kick em
> >>>
> >>> Once again, jsut an example (getSetting() is made up).
> >>>
> >>> Surely theres an easy way to make such variables accessable?
> >>>
> >>> Trying to figure this out is driving me insane - Any help would be
> >>> appreciated!
> >>>
> >>> Cheers,
> >>> Andrew
> >>>
>
>>> ------------------------------------------------------------------------
> >>>
> >>>
> >>> _______________________________________________
> >>> BFProg mailing list
> >>> BFProg at lists.matureasskickers.net
> >>> http://lists.matureasskickers.net/mailman/listinfo/bfprog
> >>>
> >>>
> >>
> >>
> >> ------------------------------
> >>
> >> _______________________________________________
> >> BFProg mailing list
> >> BFProg at lists.matureasskickers.net
> >> http://lists.matureasskickers.net/mailman/listinfo/bfprog
> >>
> >>
> >> End of BFProg Digest, Vol 2, Issue 14
> >> *************************************
> >>
> >>
> >> _______________________________________________
> >> BFProg mailing list
> >> BFProg at lists.matureasskickers.net
> >> http://lists.matureasskickers.net/mailman/listinfo/bfprog
> >
> >
> > _______________________________________________
> > BFProg mailing list
> > BFProg at lists.matureasskickers.net
> > http://lists.matureasskickers.net/mailman/listinfo/bfprog
>
> _______________________________________________
> BFProg mailing list
> BFProg at lists.matureasskickers.net
> http://lists.matureasskickers.net/mailman/listinfo/bfprog
More information about the BFProg
mailing list