diff --git a/mudserver.py b/mudserver.py index 14f1efb..53178c1 100644 --- a/mudserver.py +++ b/mudserver.py @@ -135,29 +135,14 @@ def get_new_players(self): entered the game since the last call to 'update'. Each item in the list is a player id number. """ - retval = [] - # go through all the events in the main list - for ev in self._events: - # if the event is a new player occurence, add the info to the list - if ev[0] == self._EVENT_NEW_PLAYER: - retval.append(ev[1]) - # return the info list - return retval + return [ev[1] for ev in self._events if ev[0] == self._EVENT_NEW_PLAYER] def get_disconnected_players(self): """Returns a list containing info on any players that have left the game since the last call to 'update'. Each item in the list is a player id number. """ - retval = [] - # go through all the events in the main list - for ev in self._events: - # if the event is a player disconnect occurence, add the info to - # the list - if ev[0] == self._EVENT_PLAYER_LEFT: - retval.append(ev[1]) - # return the info list - return retval + return [ev[1] for ev in self._events if ev[0] == self._EVENT_PLAYER_LEFT] def get_commands(self): """Returns a list containing any commands sent from players @@ -167,14 +152,7 @@ def get_commands(self): they typed), and another string containing the text after the command """ - retval = [] - # go through all the events in the main list - for ev in self._events: - # if the event is a command occurence, add the info to the list - if ev[0] == self._EVENT_COMMAND: - retval.append((ev[1], ev[2], ev[3])) - # return the info list - return retval + return [(ev[1], ev[2], ev[3]) for ev in self._events if ev[0] == self._EVENT_COMMAND] def send_message(self, to, message): """Sends the text in the 'message' parameter to the player with @@ -183,7 +161,7 @@ def send_message(self, to, message): """ # we make sure to put a newline on the end so the client receives the # message on its own line - self._attempt_send(to, message+"\n\r") + self._attempt_send(to, message + "\n\r") def shutdown(self): """Closes down the server, disconnecting all clients and diff --git a/simplemud.py b/simplemud.py index 0dbfabd..8ea0735 100755 --- a/simplemud.py +++ b/simplemud.py @@ -154,15 +154,8 @@ # send the player back the description of their current room mud.send_message(id, rm["description"]) - playershere = [] - # go through every player in the game - for pid, pl in players.items(): - # if they're in the same room as the player - if players[pid]["room"] == players[id]["room"]: - # ... and they have a name to be shown - if players[pid]["name"] is not None: - # add their name to the list - playershere.append(players[pid]["name"]) + # make list of every player with a name that's in the same room as the current player + playershere = [players[pid]["name"] for pid, pl in players.items() if players[pid]["room"] == players[id]["room"] and players[pid]["name"] is not None] # send player a message containing the list of players in the room mud.send_message(id, "Players here: {}".format(