Changeset 13 for tabled.py

Show
Ignore:
Timestamp:
02/03/08 18:29:26 (4 years ago)
Author:
mike
Message:

Added some actioN

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tabled.py

    r12 r13  
    11""" 
    2 usage: tabled.py <gamename> 
     2usage: tabled.py <port> 
    33""" 
    44import sys 
     
    3232        try: 
    3333            decoded = cjson.decode(line) 
    34             if "method" not in decoded: 
     34            if decoded == None or "method" not in decoded: 
    3535                self.sendString( cjson.encode( 
    3636                    protocol.MakeError(101,"Messages must contain methods")) ) 
     
    5757                    d.addCallback(self.sendMessage) 
    5858                    self.table.addPlayer(decoded, d) 
     59            elif method == "action": 
     60                value =  decoded["value"] 
     61                if value != None: value = float(value) 
     62                self.table.action(self.id, decoded["action"],value) 
    5963            else: 
    6064                self.sendString( cjson.encode(protocol.MakeError(102,"Unknown Method")) ) 
     
    7781        sys.exit(0) 
    7882 
    79     gamename =  sys.argv[1] 
     83    port = int(sys.argv[1]) 
    8084 
    8185    factory = Factory() 
     
    8387 
    8488    # 8007 is the port you want to run under. Choose something >1024 
    85     reactor.listenTCP(8007, factory) 
     89    reactor.listenTCP(port, factory) 
     90    print "Listening on localhost:%d" % port 
    8691    reactor.run() 
    8792