Changeset 121

Show
Ignore:
Timestamp:
10/24/07 13:27:51 (3 years ago)
Author:
elghinn
Message:

* no more bugs

Location:
adventure
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • adventure/adventuremuc.py

    r118 r121  
    2727 
    2828    def add_world(self, filename): 
     29        """ 
     30        Adding new world in mud instance 
     31        """ 
    2932        print 'Adding world from "%s"...' % filename 
    3033        world = World(self, filename) 
     
    3336 
    3437    def snd(self, worldnode, worldresource, stanza): 
    35         stanza.setFrom(JID(node=worldnode, domain=self.jid.getDomain(), resource=worldresource)) 
     38        """ 
     39        Send stanza 'stanza' to 'worldresource' in world 'worldnode' 
     40        """ 
     41        stanza.setFrom(JID(node=worldnode, domain=self.jid.getDomain(), 
     42                           resource=worldresource)) 
    3643        self.send(stanza) 
    3744 
    38     def handle_iq(self, _, iq): 
     45    def handle_iq(self, _, iq_): 
     46        """ 
     47        Handle iq stanza 
     48        """ 
    3949        #print "iq: from #{iq.from} type #{iq.type} to #{iq.to}: #{iq.queryns}" 
    4050 
     
    90100 
    91101    def handle_presence(self, _, pres): 
     102        """ 
     103        Handle presence stanza 
     104        """ 
    92105        print 'presence: from %s type %s to %s' % (pres.getFrom(), 
    93106                                                   pres.getType(), 
     
    98111            self.worlds[world].handle_presence(pres) 
    99112        else: 
    100             answer = Error(pres, 'item-not-found', 'The world you are trying to reach is currently unavailable.') 
     113            answer = Error(pres, 'item-not-found', 
     114                           'The world you are trying to reach is currently ' 
     115                           'unavailable.') 
    101116            self.send(answer) 
    102117        return True 
    103118 
    104119    def handle_message(self, _, msg): 
     120        """ 
     121        Handle message stanza 
     122        """ 
    105123        print 'message: from %s type %s to %s: %s' % (msg.getFrom(), 
    106124                                                      msg.getType(), 
     
    112130            self.worlds[world].handle_message(msg) 
    113131        else: 
    114             answer = Error(msg, 'item-not-found', 'The world you are trying to reach is currently unavailable.') 
     132            answer = Error(msg, 'item-not-found', 
     133                           'The world you are trying to reach is currently ' 
     134                           'unavailable.') 
    115135            self.send(answer) 
    116136        return True 
     
    122142        print 'Syntax: ./adventuremuc.py <JID> <Password> <Host> <Port>' 
    123143        print 'See README for further help' 
    124     muc = AdventureMUC(argv[1], argv[2], argv[3], int(argv[4])) 
    125     muc.add_world('cave.xml') 
     144    MUD = AdventureMUC(argv[1], argv[2], argv[3], int(argv[4])) 
     145    MUD.add_world('cave.xml') 
    126146    while 1: 
    127         muc.Process(10) 
     147        MUD.Process(10) 
  • adventure/cave.xml

    r103 r121  
    33    <place name='cave_1'> 
    44        <description>You are in the dark, but you can hear a little sound from the East, and the wind from the West.</description> 
    5         <go spec="to the East" place="cave_2" /> 
    6         <go spec="to the West" place="cave_3" /> 
     5        <go spec="east" place="cave_2" /> 
     6        <go spec="west" place="cave_3" /> 
    77    </place> 
    88     
    99    <place name="cave_2"> 
    1010        <description>There is a strange man, lying on the floor, with a happy face.</description> 
    11         <go spec="to the West" place="cave_1" /> 
     11        <go spec="west" place="cave_1" /> 
    1212    </place> 
    1313     
    1414    <place name="cave_3"> 
    1515        <description>You can see a light ray from the North.</description> 
    16         <go spec="to the East" place="cave_1" /> 
    17         <go spec="to the North" place="cave_4" /> 
     16        <go spec="east" place="cave_1" /> 
     17        <go spec="north" place="cave_4" /> 
    1818    </place> 
    1919     
     
    2121        <description>There is a fire, and a stupid rat... 
    2222        No exit, make what you want, but please don't hurt any animal.</description> 
    23         <go spec="to the South" place="cave_3" /> 
     23        <go spec="south" place="cave_3" /> 
    2424    </place> 
    2525     
  • adventure/player.py

    r120 r121  
    3030        if thing != self: 
    3131            if from_: 
    32                 self.send_message(None, '%s enters %s coming from %s' % (thing.name, place, from_)) 
     32                self.send_message(None, '%s enters %s coming from %s' % 
     33                                  (thing.name, self.place, from_)) 
    3334            else: 
    3435                self.send_message(None, '%s spawns' % thing.name) 
    3536 
    36     def on_leave(self, thing, to): 
     37    def on_leave(self, thing, to_): 
    3738        if thing != self: 
    38             if to: 
    39                 self.send_message(None, '%s leaves %s going to %s' % (thing.name, place, to)) 
     39            if to_: 
     40                self.send_message(None, '%s leaves %s going to %s' % 
     41                                  (thing.name, self.place, to_)) 
    4042            else: 
    4143                self.send_message(None, '%s disintegrates' % thing.name) 
  • adventure/thing.py

    r120 r121  
    1111        self.aliases = (name,) # Noms alternatifs 
    1212        self.actions = list() 
    13         self.presence = None 
    14         self.UID = 0 
     13        self.presences = None 
     14        self.uid = 0 
    1515        self.place = None 
    1616        self.enters = list() 
    1717        self.leaves = list() 
    18  
    19     def jid(self): 
    20         return None 
     18        self.jid = None # useful ? 
    2119 
    2220    def presence(self): 
    23         xe = None 
     21        pres = None 
    2422        #for pres in each_element('presence'): 
    25         #    xe = Presence(node=pres) 
     23        #    pres = Presence(node=pres) 
    2624        #if isinstance(self, Player): 
    27         #    xe.add(Jabber::MUC::XMUCUser.new).add(Jabber::MUC::XMUCUserItem.new('none', 'participant')) 
     25        #    pres.add(Jabber::MUC::XMUCUser.new).add(Jabber::MUC::XMUCUserItem.new('none', 'participant')) 
    2826        #else: 
    29         #    xe.add(Jabber::MUC::XMUCUser.new).add(Jabber::MUC::XMUCUserItem.new('owner', 'moderator')) 
    30         return xe 
     27        #    pres.add(Jabber::MUC::XMUCUser.new).add(Jabber::MUC::XMUCUserItem.new('owner', 'moderator')) 
     28        return pres 
    3129 
    3230    def see(self, place): 
     
    3836    def send_message_to_place(self, fromresource, text): 
    3937        for thing in self.world.each_element('thing'): 
    40             if thing.place == place: 
     38            if thing.place == self.place: 
    4139                thing.send_message(fromresource, text) 
    4240   
    4341    def on_enter(self, thing, from_): 
    44         for c in self.enters: 
    45             self.command(thing, c, [from_]) 
     42        for command in self.enters: 
     43            self.command(thing, command, [from_]) 
    4644 
    47     def on_leave(self, thing, to): 
    48         for c in self.leaves: 
    49             self.command(thing, c, [to]) 
     45    def on_leave(self, thing, to_): 
     46        for command in self.leaves: 
     47            self.command(thing, command, [to_]) 
    5048 
    5149    def command(self, source, command, arguments): 
    52             if command.action[1]: 
    53                 text = command.action[1] 
     50        if command.action[1]: 
     51            text = command.action[1] 
     52        else: 
     53            text = '' 
     54        target = None 
     55        if command.action[2]: 
     56            for thing in self.world.each_thing_by_place(self.place): 
     57                if thing.name == command.action[2]: 
     58                    target = thing 
     59                    break 
     60        #else: 
     61        if not target: 
     62            target = self 
     63        text.replace('%self%', target.name) 
     64        text.replace('%actor%', source.name) 
     65        text.replace('%place%', self.place) 
     66        if command.action[0] == 'say' or command.action[0] == 'narration': 
     67            sender = None 
     68            if command.action[0] == 'say': 
     69                sender = self.name 
     70            if command.action[3] == 'all': 
     71                self.send_message_to_place(sender, text) 
    5472            else: 
    55                 text = '' 
    56             target = None 
    57             if command.action[2]: 
    58                 for thing in self.world.each_thing_by_place(self.place): 
    59                     if thing.name == command.action[2]: 
    60                         target = thing 
    61                         break 
    62             #else: 
    63             if not target: 
    64                 target = self 
    65             text.replace('%self%', target.name) 
    66             text.replace('%actor%', source.name) 
    67             text.replace('%place%', place) 
    68             if command.action[0] == 'say' or command.action[0] == 'narration': 
    69                 sender = None 
    70                 if command.action[0] == 'say': 
    71                     sender = self.name 
    72                 if command.action[3] == 'all': 
    73                     self.send_message_to_place(sender, text) 
    74                 else: 
    75                     source.send_message(sender, text) 
     73                source.send_message(sender, text) 
    7674 
    7775 
     
    7977 
    8078class Action: 
    81     def _init__(self, name, parent): 
     79    def __init__(self, name, parent): 
    8280        self.name = name 
    8381        self.parent = parent 
    8482        self.objects = list() # objets requis 
    85         self.expressions = list() # Expressions... Un élément si pas de "%" dans la chaîne "name", sinon : 
    86                                   # un élément par alias ( ex "use bottle on", "use whiskey on" ) 
    87         #self.xmlelement = None # Élément XML à traiter si les objets sont dans l'inventaire 
    88         self.action = list() # (("say","coucou",None,None),("destroy",None)) par exemple 
    89                              # à respecter : premier élément : nom de la commande, deuxième : texte, troisième : target 
     83        # Expressions... Un élément si pas de "%" dans la chaîne "name", sinon : 
     84        # un élément par alias ( ex "use bottle on", "use whiskey on" ) 
     85        self.expressions = list() 
     86 
     87        # Élément XML à traiter si les objets sont dans l'inventaire 
     88        #self.xmlelement = None 
     89 
     90        # (("say","coucou",None,None),("destroy",None)) par exemple 
     91        # à respecter : premier élément : nom de la commande, 
     92        #               deuxième : texte, troisième : target 
     93        self.action = list() 
  • adventure/world.py

    r119 r121  
    1515        doc = xml_parse(filename) 
    1616        doc_getAttribute = doc.documentElement.getAttribute 
    17         self.node = doc.documentElement.getAttribute('node') 
    18         self.name = doc.documentElement.getAttribute('name') 
    19         self.start = doc.documentElement.getAttribute('start') 
     17        self.node = doc_getAttribute('node') 
     18        self.name = doc_getAttribute('name') 
     19        self.start = doc_getAttribute('start') 
    2020        get_elements = doc.documentElement.getElementsByTagName 
    2121        places = get_elements('place') 
    2222        for place in places: 
    23             place_obj = Place(place.getAttribute('name'), 
    24                               place.getAttribute('description')) 
     23            place_obj = Place( 
     24                place.getAttribute('name'), 
     25                place.getElementsByTagName('description')[0].firstChild.data) 
    2526            self.places[place_obj.name] = place_obj 
    2627            gos = place.getElementsByTagName('go') 
     
    3031        #things = get_elements('thing') 
    3132        #for thing in things: 
    32              
     33 
    3334 
    3435 
     
    106107            msg.setType('normal') 
    107108            msg.setSubject('Adventure component help') 
    108             msg.setBody('You don\'t need to subscribe to my presence. Simply use your Jabber client to join the MUC or conference at %s' % pres.getTo()) 
     109            msg.setBody('You don\'t need to subscribe to my presence. ' 
     110                        'Simply use your Jabber client to join the MUC or ' 
     111                        'conference at %s' % pres.getTo()) 
    109112            self.send(None, msg) 
    110113            return True 
     
    113116        player = None 
    114117        for thing in self.things.values(): 
    115             if isinstance(thing, Player) and pres.getTo().getResource() == thing.name: 
     118            if (isinstance(thing, Player) and 
     119                pres.getTo().getResource() == thing.name): 
    116120                player = thing 
    117121 
    118122            # Disallow nick changes 
    119             if isinstance(thing, Player) and (pres.getFrom() == thing.jid) and (player != thing): 
    120                 answer = Error(pres, 'not-acceptable', 'Nickchange not allowed') #False 
     123            if (isinstance(thing, Player) and pres.getFrom() == thing.jid and 
     124                player != thing): 
     125                answer = Error(pres, 'not-acceptable', 
     126                               'Nickchange not allowed') #False 
    121127                self.send(thing.name, answer) 
    122128                return True 
    123129 
    124130        # Either nick-collission or empty nick 
    125         if player and pres.getFrom() != player.jid or len(pres.getTo().getResource()) < 2: 
     131        if (player and pres.getFrom() != player.jid or 
     132            len(pres.getTo().getResource()) < 2): 
    126133            answer = None 
    127134            if len(pres.getTo().getResource()) > 1: 
     
    138145            self.things[player.name] = player 
    139146            self.move_thing(player, self.start) 
    140             player.send_message('Help!', 'Send "?" to get a list of available commands any time.') 
     147            player.send_message('Help!', 'Send "?" to get a list of available ' 
     148                                'commands any time.') 
    141149        # Or broadcast updated presence 
    142150        else: 
     
    158166        player = None 
    159167        for thing in self.things.values(): 
    160             if isinstance(thing, Player) and not msg.getTo().getResource() and msg.getFrom() == thing.jid: 
     168            if (isinstance(thing, Player) and not msg.getTo().getResource() and 
     169                msg.getFrom() == thing.jid): 
    161170                player = thing 
    162171 
     
    172181    def command(self, player, text): 
    173182        if text == '?': 
    174             player.send_message(None, '(Command) who') 
     183            player.send_message('Help!', '(Command) who') 
    175184            place = self.place(player.place) 
    176185            if place: 
    177186                for exit_name in place.exits.keys(): 
    178                     player.send_message(None, '(Command) go %s' % exit_name) 
     187                    player.send_message('Help!', '(Command) go %s' % exit_name) 
    179188            for thing in self.each_thing_by_place(player.place): 
    180189                for c in thing.actions: 
    181                     player.send_message(None, '(Command) %s %s' % (c.expressions[0], thing.name)) 
     190                    player.send_message('Help!', 
     191                                        '(Command) %s %s' % (c.expressions[0], 
     192                                                             thing.name)) 
    182193            return True 
    183194        else: 
     
    189200                what = '' 
    190201            if cmd == 'go': 
     202                print what 
    191203                oldplace = self.place(player.place) 
    192204                newplace = None 
     
    205217                for thing in self.things.values(): 
    206218                    if isinstance(thing, Player): 
    207                         player.send_message(None, '%s is at/in %s' % (thing.name, thing.place)) 
     219                        player.send_message(None, 
     220                                            '%s is at/in %s' % (thing.name, 
     221                                                                thing.place)) 
    208222                return True 
    209223            else: