Server Help

Misc User Apps - Python Bot?

cycad - Fri Jan 29, 2010 2:05 pm
Post subject: Python Bot?
Just kidding, this topic isn't really a question.

I wrote a Python bot core for the sake of learning a little about Python. It logs in over the Subspace protocol and then sits there printing out the events it receives. I only created a couple of events but it could be extended if there's any interest.

I broke down the Game Stack and the Core Stack into 2 classes, so the core stack can be reused, say, for connecting to the biller. It handles reliability and cluster packets.

If you have interest in writing a core or want to have a fun way to learn Python then this might be useful to you. I didn't write it as a production solution (there isn't really a problem to be solved;) but I hope at least 1 person can find this useful or learn something from it.

Here's an example:
Code: Show/Hide

#!/usr/bin/env python

from SubspaceGameStack import *

if __name__ == '__main__':
   stack = SubspaceGameStack(False)
   stack.connectToServer('127.0.0.1', 7900, 'username', 'password*smodpassword', '#master')
   
   connected = True
   while connected:
      event = stack.waitForEvent()
      if event.type == EVENT_TICK:
         #lets not be too noisy
         #print 'EVENT_TICK'
         pass
      if event.type == EVENT_ENTER:
         print 'EVENT_ENTER'
         print "Player Joined:", event.name
      elif event.type == EVENT_LEAVE:
         print 'EVENT_LEAVE'
         print 'Player with PID %04X left' % event.pid
      elif event.type == EVENT_MESSAGE:
         print 'EVENT_MESSAGE'
         print 'Type:%d Text:%s' % (event.message_type, event.message)
      elif event.type == EVENT_DISCONNECT:
         print 'EVENT_DISCONNECT'
         connected = False
      elif event.type == EVENT_LOGIN:
         print 'EVENT_LOGIN'


And some output:
Code: Show/Hide

EVENT_LOGIN
EVENT_ENTER
Player Joined: Bot-EG-Public-2
EVENT_ENTER
Player Joined: Bot-PubSup-2
EVENT_ENTER
Player Joined: supers bro1
EVENT_ENTER
Player Joined: Conceptronic
EVENT_ENTER
Player Joined: Leap
EVENT_ENTER
Player Joined: Skype
EVENT_ENTER
Player Joined: Ummagumma
EVENT_ENTER
Player Joined: Scooby!
EVENT_ENTER
Player Joined: H0ST
EVENT_ENTER
Player Joined: SupaFlyTNT
EVENT_ENTER
Player Joined: Luft
EVENT_ENTER
Player Joined: apex
EVENT_ENTER
Player Joined: Emergen-C
EVENT_ENTER
Player Joined: King of Borg
EVENT_ENTER
Player Joined: AyhA
EVENT_ENTER
Player Joined: trodd21
EVENT_ENTER
Player Joined: Azn_Street_Hooker
EVENT_ENTER
Player Joined: droog
EVENT_ENTER
Player Joined: WarHunter
EVENT_ENTER
Player Joined: Jugulate$6
EVENT_ENTER
Player Joined: Vengren
EVENT_ENTER
Player Joined: SLAP ~ HAPPY
EVENT_ENTER
Player Joined: su-34
EVENT_ENTER
Player Joined: final ride
EVENT_ENTER
Player Joined: G]-[()ST
EVENT_ENTER
Player Joined: zombie
EVENT_ENTER
Player Joined: coldielox
EVENT_ENTER
Player Joined: oDb
EVENT_ENTER
Player Joined: Duckie
EVENT_ENTER
Player Joined: BulletiN
EVENT_ENTER
Player Joined: Gilthaniel
EVENT_ENTER
Player Joined: stoned i am
EVENT_ENTER
Player Joined: leen
EVENT_ENTER
Player Joined: ritzand
EVENT_ENTER
Player Joined: aquabox
EVENT_MESSAGE
Type:0 Text:This arena is Continuum-only. Please get Continuum client from http://www.subspace.net to play here
EVENT_MESSAGE
Type:0 Text:Welcome to Extreme Games - Visit our website at www.extreme-games.net


You can message me in SS if you have any questions. Have fun.
divine.216 - Sun Jan 31, 2010 11:01 pm
Post subject:
I haven't played with it yet; but wonderful stuff. Thanks for this.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group