Browse files

implements message() to send private messages to players

handles players' connections
handles players' disconnections
handles players' chat

So we got a first alpha version that let you type !iamgod in-game and issue basic commands such as !help
  • Loading branch information...
Courgette committed Apr 30, 2011
1 parent 4a63a5f commit cd351e55840b8ea97a222196fb86f0cd465338f9
Showing with 83 additions and 12 deletions.
  1. +83 −12 b3/parsers/
@@ -22,10 +22,28 @@
__author__ = 'Courgette'
__version__ = '0.1'
* In your main config file, set log level down to 8 to see log message of
type VERBOS2. <set name="log_level">8</set>
* You can add the section below in your b3.xml in order to display the log
file on your console :
<settings name="devmode">
<set name="log2console">true</set>
import re
import json
from b3.parser import Parser
import b3
from b3.parser import Parser
from import EVT_CUSTOM
class AltitudeParser(Parser):
"""B3 parser for the Altitude game. See"""
@@ -36,6 +54,14 @@ class AltitudeParser(Parser):
## extract the time off a log line
_lineTime = re.compile(r'^{"port":[0-9]+, "time":(?P<seconds>[0-9]+),.*')
## Direct event mapping between Altitude events type and B3 event types.
## B3 event will be created with their data parameter set to the full
## altitude event object
_eventMap = {
'consoleCommandExecute' : EVT_CUSTOM,
def startup(self):
@@ -72,22 +98,27 @@ def parseLine(self, line):
## we will route the handling of that altitude_event to a method dedicated
## to an alititude event type. The method will be name after the event type
## capitalized name prefixed by 'OnAltitude'
method_name = "OnAltitude%s" % altitude_event['type'].capitalize()
## capitalized name prefixed by 'OnAltitude'.
## I.E.: type 'clientAdd' would route to 'OnAltitudeClientAdd' method
type = altitude_event['type']
method_name = "OnAltitude%s%s" % (type[:1].upper(), type[1:])
event = None
if not hasattr(self, method_name):
# no handling method for such event :(
# we fallback on creating a B3 event of type EVT_UNKNOWN
self.verbose("un-handled altitude event : %r", altitude_event)
event = self.getEvent('EVT_UNKNOWN', data=altitude_event)
if type in self._eventMap:
event =[type], data=altitude_event)
# no handling method for such event :(
# we fallback on creating a B3 event of type EVT_UNKNOWN
self.verbose2("create method %s to handle event %r", method_name, altitude_event)
event = self.getEvent('EVT_UNKNOWN', data=altitude_event)
func = getattr(self, method_name)
event = func(altitude_event)
# if we came up with a B3 event, then queue it up so it can be dispatched
# to the listening plugins
if event:
self.verbose2("event created for this log line : %s", event)
@@ -98,25 +129,65 @@ def parseLine(self, line):
# those methods are called by parseLine() and
# may return a B3 Event object
# ================================================
def OnAltitudeClientAdd(self, altitude_event):
""" handle log lines of type clientAdd
example :
## self.clients is B3 currently connected player store. We tell the client store we got a new one.
self.clients.newClient(altitude_event['player'], guid=altitude_event['vaporId'], name=altitude_event['nickname'], team=b3.TEAM_UNKNOWN)
def OnAltitudeClientRemove(self, altitude_event):
""" handle log lines of type clientRemove
example :
{"port":27276,"message":"left","time":17317434,"player":2,"reason":"Client left.","nickname":"Courgette","vaporId":"a8654321-123a-414e-c71a-123123123131","type":"clientRemove","ip":""}'
c = self.clients.getByCID(altitude_event['player'])
if c:
def OnAltitudeChat(self, altitude_event):
""" handle log lines of type clientRemove
example :
Unfortunately, there is no distinction between a normal chat and team chat
{"port":27276,"message":"test team chat","time":1167491,"player":3,"server":false,"type":"chat"}
c = self.clients.getByCID(altitude_event['player'])
if c:
if altitude_event['server'] == False:
return self.getEvent('EVT_CLIENT_SAY', data=altitude_event['message'], client=c)
return self.getEvent('EVT_CUSTOM', data=altitude_event, client=c)
# =======================================
# implement parser interface
# =======================================
def say(self, msg):
broadcast a message to all players
self.write('serverMessage %s' % self.stripColors(msg))
def message(self, client, msg):
display a message to a given player
self.write('serverWhisper %s %s' % (, self.stripColors(msg)))
# =======================================
# other methods
# =======================================
class AltitudeRcon():
"""Object that opens the Altitude command file and allows B3 to write
commands in it"""

0 comments on commit cd351e5

Please sign in to comment.