To start a new discussion, join us on Discord. The DontCamp.com read-only forum archives are below.

DontCamp.com
No, but really, you should join us on Discord.

DontCamp Code
Goto page Previous  1, 2, 3
 
   DontCamp.com Forum Index -> Community Discussion and News
View previous topic :: View next topic  
Author Message
DogShxtTaco
CH Administrator


Joined: 19 Apr 2004
Posts: 8201
Location: Cary, NC

PostPosted: Fri Apr 28, 2006 8:48 am    Post subject:

I think that all of that is possible, and currently being done by chunks of the dc_ass.py code. I have to head to work, but one of us can walk you through that. I'm fairly sure that restrictions in the python modules that bf2 uses prevent us from being able to execute OS files, but there are way around that, if I remember correctly.

Here's the code:
http://dontcamp.com/code/?file=dc_ass.py
Butter
CH Administrator


Joined: 18 Apr 2004
Posts: 7520
Location: New York, NY

PostPosted: Fri Apr 28, 2006 10:14 am    Post subject:

This is dc_irs.py with an added !report command that will log the chatline and the playername of the person that said it to 'logfile' in the bf2 directory. Dst is right that there is not enough standard python library support in BF2 to spawn a new process. The only work around we've used was to manually create an HTTP request using the socket module so we can call a PHP script. Kinda awkward...

You can see the addition I made in that if, elif, else section near the bottom. That's where I add whatever commands this script will be handling.

Code:
import bf2
import host
import re
from dc_debug import decho
 
# for the time command
import time
 
 
def init():
    decho('dc_irs: initializing DontCamp.com In-game Report System', 2)
    host.registerHandler('ChatMessage', onChatMessage, 1)
   
def onChatMessage(player_id, text, channel, flags):
   
    # pull the potential prefix off the text line
    text = text.replace("HUD_TEXT_CHAT_TEAM", "")
    text = text.replace("HUD_TEXT_CHAT_SQUAD", "")
    text = text.replace("*\xA71DEAD\xA70*", "")
   
    # unless the first character is ! don't do anything
    if text[0:1] == "!":
        decho("dc_irs: the first character of %s was !" % text, 5)
 
        # grab the parts of the chatline I need with a REGEX
        pattern = re.compile(r'!(\w*) ?(.*)')
        matches = pattern.findall(text)
        command = matches[0][0]
        decho("dc_irs: command = %s" % command, 5) 
 
        # grab a parameter, if any
        if matches[0][1] != "":
            parameter = matches[0][1]
            decho("dc_irs: parameter = %s" % parameter, 5)
        else:
            parameter = None
            decho("dc_irs: no parameter given", 5)

        # this is where you would setup each command
        if command == "nextmap":
            decho('The next map is %s' % host.rcon_invoke('maplist.list').splitlines()[int(host.rcon_invoke('admin.nextLevel').strip())].split()[1].strip('"').replace('_', ' ').title(), 1)
        elif command == "time":
            decho('The time is: %s' % time.strftime('%H:%M %p %Z'), 1)
        elif command == "report":
            try:
                fh = open('logfile', 'a')
                fh.write('%s: %s\n' % (bf2.PlayerManager.Player(player_id).getName(), parameter))
                fh.close()
                decho('dc_irs: logfile augmented', 1)
            # it would be nice to handle the open() failure and parameter = None exceptions separately, but I'd have to go look up how
            except:
                decho('dc_irs: There was an error writing to the logfile', 1)
        else:
            decho('ERROR: invalid command', 1)

_________________
EDT sucks.
Gramps



Joined: 27 Apr 2006
Posts: 3

PostPosted: Tue May 02, 2006 8:24 am    Post subject:

Thx for the help guys!

But i haven't been able to make it work.

I guess that __init__.py should contain:
import dc_irs
dc_irs.init()

Hmm...
What if i run modmanager and bf2cc?
Is there another way i should implemnt it then?
Or is it not even doable then?

Or am i just stupid?
Wink
Butter
CH Administrator


Joined: 18 Apr 2004
Posts: 7520
Location: New York, NY

PostPosted: Tue May 02, 2006 8:28 am    Post subject:

We've not ever tried to get our stuff to work with MM and BF2CC. Do you have dc_debug installed as well? Most our scrtips require it. And you'll definitely need to have those lines you mentioned in the __init__.py file.
_________________
EDT sucks.
Gramps



Joined: 27 Apr 2006
Posts: 3

PostPosted: Tue May 02, 2006 9:13 am    Post subject:

I do get the feeling that you think Bf2cc *ux Bigtime...
Wink

I installed the dc_debug.
I also put a # in front of Deco since i didn't need that code atm anyway.

Still didn't work.
I checked around a little and it seems like you have to "convert" the code to "modmanagerstyle".

Well, thanks a lot guys! Now you gave me some trouble i Have to solve!!
Grr.
Wink

Actually, you been a great help trying to help me out.
Thx
Butter
CH Administrator


Joined: 18 Apr 2004
Posts: 7520
Location: New York, NY

PostPosted: Tue May 02, 2006 9:21 am    Post subject:

You're welcome. I do think MM sucks because our code works without it, and their code breaks our code. That's just their code being a jerk ass. I've not used BF2CC in a long time, but the last time I did, I was dissatified. We run a linux server and I don't like running .NET daemons in linux.
_________________
EDT sucks.
Butter
CH Administrator


Joined: 18 Apr 2004
Posts: 7520
Location: New York, NY

PostPosted: Fri Jan 02, 2015 7:17 pm    Post subject:

All our released code has been moved to this github repo: https://github.com/jpwoodbu/dontcamp_bf2

Since this code is rather old and only applies to BF2, I'm going to edit this thread to no longer be an announcement.
_________________
EDT sucks.
DogShxtTaco
CH Administrator


Joined: 19 Apr 2004
Posts: 8201
Location: Cary, NC

PostPosted: Mon Jan 05, 2015 12:32 am    Post subject:

https://github.com/dontcamp ^^