Changeset 121
Legend:
- Unmodified
- Added
- Removed
-
adventure/adventuremuc.py
r118 r121 27 27 28 28 def add_world(self, filename): 29 """ 30 Adding new world in mud instance 31 """ 29 32 print 'Adding world from "%s"...' % filename 30 33 world = World(self, filename) … … 33 36 34 37 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)) 36 43 self.send(stanza) 37 44 38 def handle_iq(self, _, iq): 45 def handle_iq(self, _, iq_): 46 """ 47 Handle iq stanza 48 """ 39 49 #print "iq: from #{iq.from} type #{iq.type} to #{iq.to}: #{iq.queryns}" 40 50 … … 90 100 91 101 def handle_presence(self, _, pres): 102 """ 103 Handle presence stanza 104 """ 92 105 print 'presence: from %s type %s to %s' % (pres.getFrom(), 93 106 pres.getType(), … … 98 111 self.worlds[world].handle_presence(pres) 99 112 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.') 101 116 self.send(answer) 102 117 return True 103 118 104 119 def handle_message(self, _, msg): 120 """ 121 Handle message stanza 122 """ 105 123 print 'message: from %s type %s to %s: %s' % (msg.getFrom(), 106 124 msg.getType(), … … 112 130 self.worlds[world].handle_message(msg) 113 131 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.') 115 135 self.send(answer) 116 136 return True … … 122 142 print 'Syntax: ./adventuremuc.py <JID> <Password> <Host> <Port>' 123 143 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') 126 146 while 1: 127 muc.Process(10)147 MUD.Process(10) -
adventure/cave.xml
r103 r121 3 3 <place name='cave_1'> 4 4 <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" /> 7 7 </place> 8 8 9 9 <place name="cave_2"> 10 10 <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" /> 12 12 </place> 13 13 14 14 <place name="cave_3"> 15 15 <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" /> 18 18 </place> 19 19 … … 21 21 <description>There is a fire, and a stupid rat... 22 22 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" /> 24 24 </place> 25 25 -
adventure/player.py
r120 r121 30 30 if thing != self: 31 31 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_)) 33 34 else: 34 35 self.send_message(None, '%s spawns' % thing.name) 35 36 36 def on_leave(self, thing, to ):37 def on_leave(self, thing, to_): 37 38 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_)) 40 42 else: 41 43 self.send_message(None, '%s disintegrates' % thing.name) -
adventure/thing.py
r120 r121 11 11 self.aliases = (name,) # Noms alternatifs 12 12 self.actions = list() 13 self.presence = None14 self. UID= 013 self.presences = None 14 self.uid = 0 15 15 self.place = None 16 16 self.enters = list() 17 17 self.leaves = list() 18 19 def jid(self): 20 return None 18 self.jid = None # useful ? 21 19 22 20 def presence(self): 23 xe= None21 pres = None 24 22 #for pres in each_element('presence'): 25 # xe= Presence(node=pres)23 # pres = Presence(node=pres) 26 24 #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')) 28 26 #else: 29 # xe.add(Jabber::MUC::XMUCUser.new).add(Jabber::MUC::XMUCUserItem.new('owner', 'moderator'))30 return xe27 # pres.add(Jabber::MUC::XMUCUser.new).add(Jabber::MUC::XMUCUserItem.new('owner', 'moderator')) 28 return pres 31 29 32 30 def see(self, place): … … 38 36 def send_message_to_place(self, fromresource, text): 39 37 for thing in self.world.each_element('thing'): 40 if thing.place == place:38 if thing.place == self.place: 41 39 thing.send_message(fromresource, text) 42 40 43 41 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_]) 46 44 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_]) 50 48 51 49 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) 54 72 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) 76 74 77 75 … … 79 77 80 78 class Action: 81 def _ init__(self, name, parent):79 def __init__(self, name, parent): 82 80 self.name = name 83 81 self.parent = parent 84 82 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 15 15 doc = xml_parse(filename) 16 16 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') 20 20 get_elements = doc.documentElement.getElementsByTagName 21 21 places = get_elements('place') 22 22 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) 25 26 self.places[place_obj.name] = place_obj 26 27 gos = place.getElementsByTagName('go') … … 30 31 #things = get_elements('thing') 31 32 #for thing in things: 32 33 33 34 34 35 … … 106 107 msg.setType('normal') 107 108 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()) 109 112 self.send(None, msg) 110 113 return True … … 113 116 player = None 114 117 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): 116 120 player = thing 117 121 118 122 # 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 121 127 self.send(thing.name, answer) 122 128 return True 123 129 124 130 # 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): 126 133 answer = None 127 134 if len(pres.getTo().getResource()) > 1: … … 138 145 self.things[player.name] = player 139 146 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.') 141 149 # Or broadcast updated presence 142 150 else: … … 158 166 player = None 159 167 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): 161 170 player = thing 162 171 … … 172 181 def command(self, player, text): 173 182 if text == '?': 174 player.send_message( None, '(Command) who')183 player.send_message('Help!', '(Command) who') 175 184 place = self.place(player.place) 176 185 if place: 177 186 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) 179 188 for thing in self.each_thing_by_place(player.place): 180 189 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)) 182 193 return True 183 194 else: … … 189 200 what = '' 190 201 if cmd == 'go': 202 print what 191 203 oldplace = self.place(player.place) 192 204 newplace = None … … 205 217 for thing in self.things.values(): 206 218 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)) 208 222 return True 209 223 else:
