DISQUS

DISQUS Hello! Gareth Jones is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Replacing Python on a Battlefield 2 server

Started by garethj · 1 year ago

Lately I’ve been doing some work (I promise it is real work) with Battlefield 2. The server part of the game has a cut-down version of Python built in so that you can interact with it, modifying aspects of the game and reacting to events etc. More details on this can be found on this [...] ... Continue reading »

13 comments

  • Hmm. I'm not really into games, but I'd still fancy a job where they crop as "work"!
  • It's a hard life I know... :)
  • So is this running in a stable manner for you? I have some url calls I would like to make in the game and this would be a welcome help.
  • Hey Cal. Yes this works fine for me - let me know if I can help at all.
  • Well that is great news. Have you been able to get url calls working properly? I don't know much about python, but recoding our in game management system has been a fun experience. Right now, I'd like to use a url call to allow admins to register their keyhash via a php page and get a success or fail notification in game.
  • I have the alternative version of Python running correctly doing what I need but I'm not sure what you mean by URL calls - is this the kind of thing you're after: http://www.python.org/doc/lib/module-httplib.html?
  • Yep. Requests for webpages in the existing python return garbage results so far. I'd like to be able to have a python script call a webpage, parse the results, then display the results in game.
  • Something like this should do the job:

    import urllib
    webPageHandle = urllib.urlopen('http://blog.garethj.com/')
    webPageContents = webpage.read()

    Then obviously you'll have to parse webPageContents for the information you need and use the BF2 API to send that into the game. This page looks like a good tutorial if you need more help: http://www.voidspace.org.uk/python/articles/url...

    Hope that's useful :)
  • Yes. Thank you.

    Originally I wanted to use post methods, but I now think a simple get is more efficent for my level of coding. It also means that I can use the standard python lib that comes with bf2.

    I appreciate the help.
  • I tried your method and when the server starts it crashes with "Import Error:" and flashes back to shell. I am using python2.4 and have changed the usr/lib/python2.5 to usr/lib64/python2.4 any clues?
  • What exactly have you changed? Have you replaced (or linked) the libdice_py.so in the Battlefield directory with your own and editing the __init__.py? If that's all done, there might be an issue with replacing a 32-bit Python with a 64-bit one (which is what your directory names suggest) so that could be the cause.
  • I 1. Replace the Battlefield 2 Python library (e.g. ‘bf2/bin/ia-32/libdice_py.so’) with the version of your choice. I just linked to my locally installed version ‘/usr/lib/libpython2.5.so’.
    2. Replace the Python library path at runtime to use the new libraries, e.g. edit ‘bf2/python/bf2/__init__.py’ and putting the equivalent of ’sys.path = ['/usr/lib/python2.5/', '/usr/lib/python2.5/lib-dynload/', 'python', 'mods/bf2/python', 'admin']‘ after the ‘import sys’ line.

    Is what I did, but I did substitute my version for 2.5. I used locate to find the directories for python. I run the 64 bit version of bf2.exe so I figured 64bit libs would be a proper replacement.
  • So sounds like you've done everything correctly. I assume you've kept the relative locations in the sys.path such as 'python', 'mods/bd2/python' and 'admin' as these are battlefield specific libraries it will try to load? Failing that, try the 32 bit version - maybe BF2 always runs a 32bit Python regardless of which version the game is running.

Add New Comment

Returning? Login