# go through any newly connected players for id in mud.get_new_players(): # add the new player to the dictionary, noting that they've not been # named yet. # The dictionary key is the player's id number. Start them off in the # 'Tavern' room. # Try adding more player stats - level, gold, inventory, etc players[id] = { "name": None, "room": "Tavern", } # send the new player a prompt for their name mud.send_message(id, "What is your name?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in players: continue # go through all the players in the game for pid, pl in players.items(): # send each player a message to tell them about the diconnected # player mud.send_message(pid, "{} quit the game".format(players[id]["name"]))
# go through any newly connected players while mud.events_new_player: player_id = mud.events_new_player.popleft() # add the new player to the dictionary, noting that they've not been # named yet. # The dictionary key is the player's id number. We set their room to # None initially until they have entered a name # Try adding more player stats - level, gold, inventory, etc players[player_id] = { "name": None, "room": None, } # send the new player a prompt for their name mud.send_message(player_id, "What is your name?") # go through any recently disconnected players while mud.events_player_left: player_id = mud.events_player_left.popleft() # if for any reason the player isn't in the player map, skip them and # move on to the next one if player_id not in players: continue # go through all the players in the game for pid, pl in players.items(): # send each player a message to tell them about the disconnected # player mud.send_message(pid, "{} quit the game".format(
show_timing(previous_timing, "resting") # go through any new commands sent from players for id, command, params in mud.get_commands(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in players: continue if command.lower() == "startover" and \ players[id]['exAttribute0'] is not None and \ players[id]['authenticated'] is None: if not os.path.isfile(".disableRegistrations"): players[id]['idleStart'] = int(time.time()) mud.send_message( id, "<f220>Ok, Starting character creation " + "from the beginning!\n") players[id]['exAttribute0'] = 1000 if command.lower() == "exit" and \ players[id]['exAttribute0'] is not None and \ players[id]['authenticated'] is None: players[id]['idleStart'] = int(time.time()) mud.send_message(id, "<f220>Ok, leaving the character creation.\n") players[id]['exAttribute0'] = None mud.send_message( id, "<f15>What is your username?<r>\n<f246>Type " + "'<f253>new<r><f246>' to create a character.\n\n") id_str = str(id) log("Player ID " + id_str + " has aborted character creation.", "info")
continue # if the player hasn't given their name yet, use this first command as # their name and move them to the starting room. if players[id]["name"] is None: welcomeNewPlayer(id, command) # each of the possible commands is handled below. Try adding new # commands to the game! # 'help' command elif command == "help": printHelp(id) # 'say' command elif command == "say": cmdSay(id, params) # 'look' command elif command == "look" or command == "l": cmdLook(id) # 'go' command elif command == "go": cmdGo(id, params) # some other, unrecognised command else: # send back an 'unknown command' message mud.send_message(id, f"Unknown command '{command}'")
corpses[len(corpses)] = { 'room': players[pid]['room'], 'name': str(players[pid]['name'] + '`s corpse'), 'inv': players[pid]['inv'], 'died': int(time.time()), 'TTL': players[pid]['corpseTTL'], 'owner': 1 } # Clear player's inventory, it stays on the corpse # This is bugged, causing errors when picking up things after death # players[pid]['inv'] = '' players[pid]['isInCombat'] = 0 players[pid]['lastRoom'] = players[pid]['room'] players[pid]['room'] = '$rid=666$' fightsCopy = deepcopy(fights) for (fight, pl) in fightsCopy.items(): if fightsCopy[fight]['s1id'] == pid or fightsCopy[fight]['s2id'] == pid: del fights[fight] for (pid2, pl) in list(players.items()): if players[pid2]['authenticated'] is not None \ and players[pid2]['room'] == players[pid]['lastRoom'] \ and players[pid2]['name'] != players[pid]['name']: mud.send_message(pid2, '<u><f32>{}<r> <f124>has been killed.'.format(players[pid]['name'])) players[pid]['lastRoom'] = None mud.send_message(pid, '<b88><f158>Oh dear! You have died!') # Add Player Death event (ID:666) to eventSchedule addToScheduler(666, pid, eventSchedule, scriptedEventsDB) players[pid]['hp'] = 4 # Handle Fights for (fid, pl) in list(fights.items()): # PC -> PC if fights[fid]['s1type'] == 'pc' and fights[fid]['s2type'] == 'pc': if players[fights[fid]['s1id']]['room'] == players[fights[fid]['s2id']]['room']: if int(time.time()) >= players[fights[fid]['s1id']]['lastCombatAction'] + 10 - players[fights[fid]['s1id']]['agi']: if players[fights[fid]['s2id']]['isAttackable'] == 1:
while True: # calling update for uptodate information mud.update() # go through any newly connected players for id in mud.get_new_players(): # adding the new player to the dictionary with their name and room empty players[id] = { "name": None, "room": None, } # ask the new player for their name mud.send_message(id, "What is your name?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if player not present continue the loop if id not in players: continue # go through all the players in the game for pid, pl in players.items(): # send each player a message to tell them about the diconnected player mud.send_message(pid, "{} quit the game".format(players[id]["name"])) # remove the player's entry
# go through any newly connected players for id in mud.get_new_players(): # add the new player to the dictionary, noting that they've not been # named yet. # The dictionary key is the player's id number. Start them off in the # 'Tavern' room. # Try adding more player stats - level, gold, inventory, etc players[id] = { "name": None, "room": "Tavern", } # send the new player a prompt for their name mud.send_message(id, "What is your name?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in players: continue # go through all the players in the game for pid, pl in players.items(): # send each player a message to tell them about the diconnected player mud.send_message(pid, "%s quit the game" % players[id]["name"]) # remove the player's entry in the player dictionary del (players[id])
# go through any newly connected players for id in mud.get_new_players(): # add the new player to the dictionary, noting that they've not been # named yet. # The dictionary key is the player's id number. We set their room to # None initially until they have entered a name # Try adding more player stats - level, gold, inventory, etc players[id] = { "name": None, "room": None, } # send the new player a prompt for their name mud.send_message(id, "What is your name?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in players: continue # go through all the players in the game for pid, pl in players.items(): # send each player a message to tell them about the diconnected # player mud.send_message(pid, "{} quit the game".format( players[id]["name"]))
class MudServerWorker(threading.Thread): def __init__(self, q, *args, **kwargs): self.keep_running = True imported_lib = import_files(**import_paths) library.store_lib(imported_lib) self.start_location = Location( "Starting Location", "This is the default starting location.") if "Marston Basement" in library.locations: self.start_location = library.locations["Marston Basement"] super().__init__(*args, **kwargs) # Cannot call mud.shutdown() here because it will try to call the sockets in run on the final go through def shutdown(self): self.keep_running = False def run(self): logging.info("Starting server.") self.mud = MudServer() library.store_server(self.mud) logging.info("Server started successfully.") # main game loop. We loop forever (i.e. until the program is terminated) while self.keep_running: try: server_command = self.q.get(block=False) if server_command is not None: if server_command.command_type == ServerCommandEnum.BROADCAST_MESSAGE: self.mud.send_message_to_all(server_command.params) elif server_command.command_type == ServerCommandEnum.GET_PLAYERS: logging.info("Players: ") for player in control.Player.player_ids.values(): logging.info(str(player)) except Exception: pass # 'update' must be called in the loop to keep the game running and give # us up-to-date information self.mud.update() # handle events on the server_queue while (len(self.mud.server_queue) > 0): event = self.mud.server_queue.popleft() logging.info(event) id = event.id if event.type is EventType.PLAYER_JOIN: logging.info("Player %s joined." % event.id) # notifying the player of their class, creating the character self.mud.send_message(id, "Welcome to MuddySwamp!") PlayerClass = library.random_class.get() self.mud.send_message(id, "You are a(n) %s" % PlayerClass) self.mud.send_message(id, "What is your name?") # creating a controler (a 'Player'), then giving that Player control of a new character # of whatever class the player is new_player = control.Player(event.id) new_character = PlayerClass() new_player.assume_control(new_character) elif event.type is EventType.MESSAGE_RECEIVED: # log the message logging.debug("Event message: " + event.message) control.Player.send_command(id, event.message) elif event.type is EventType.PLAYER_DISCONNECT: # logging data of the player player = control.Player.player_ids[id] logging.info("%s left" % player) if player.receiver is not None: pass #self.mud.send_message_to_all("%s quit the game" % player.receiver) control.Player.remove_player(id) # temporary: move this to a better place later for id, msg in control.Player.receive_messages(): self.mud.send_message(id, msg) # Shut down the mud instance after the while loop finishes self.mud.shutdown()
# go through any newly connected players for id in mud.get_new_players(): # add the new player to the dictionary, noting that they've not been # named yet. The dictionary key is the player's id number. We set their # room to None initially until they have entered a name # Try adding more player stats - level, gold, inventory, etc players[id] = { "name": None, "money": data["defaults"]["money"], "inventory": [], "room": None, } # send the new player a prompt for their name mud.send_message(id, "What is your username?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in players: continue # go through all the players in the game for pid, pl in players.items(): # send each player a message to tell them about the diconnected # player mud.send_message(pid, "{} quit the game".format(players[id]["name"])) # remove the player's entry in the player dictionary del (players[id]) # go through any new commands sent from players
# add the new player to the dictionary, noting that they've not been # named yet. # The dictionary key is the player's id number. We set their room to # None initially until they have entered a name # Try adding more player stats - level, gold, inventory, etc players[id] = { "name": None, "room": None, "level": 1, "hp": 50, "inventory": [items.PlainBread()], "gold": 5 } # send the new player a prompt for their name mud.send_message(id, "|-----------------|") mud.send_message(id, "| Zomb1e Survival |") mud.send_message(id, "|-----------------|\n") mud.send_message(id, "What is your name?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in players: continue # go through all the players in the game for pid, pl in players.items(): # send each player a message to tell them about the diconnected # player
# 'update' must be called in the loop to keep the game running and give # us up-to-date information mud.update() # go through any newly connected players for id in mud.get_new_players(): # add the new player to the dictionary, noting that they've not been # named yet. # The dictionary key is the player's id number. Start them off in the # 'Tavern' room. # Try adding more player stats - level, gold, inventory, etc active_players[id] = {"name": "temp", "room": "temp", "inventory": []} # send the new player a prompt for their name mud.send_message(id, "What is your name?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in active_players: continue # go through all the players in the game for pid in active_players: # send each player a message to tell them about the disconnected player mud.send_message(pid, "%s quit the game" % active_players[id]["name"])
# go through any newly connected players for id in mud.get_new_players(): # add the new player to the dictionary, noting that they've not been # named yet. # The dictionary key is the player's id number. Start them off in the # 'Tavern' room. # Try adding more player stats - level, gold, inventory, etc players[id] = { "name": None, "room": "Tavern", } # send the new player a prompt for their name mud.send_message(id,"What is your name?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in players: continue # go through all the players in the game for pid,pl in players.items(): # send each player a message to tell them about the diconnected player mud.send_message(pid,"%s quit the game" % players[id]["name"]) # remove the player's entry in the player dictionary
"room": None, "credits": 100, "inventory": ["xp booster", "watermelon", "xp booster"], "npcChosen": "", "xp": 0, "level": 1, "maxHp": 15, "hp": 15, "atk": 3, "def": 1, "spd": 7, "currentAttackTime": 0, } # send the new player a prompt for their name mud.send_message(id, "What is your name?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in players: continue # go through all the players in the game for pid, pl in players.items(): # send each player a message to tell them about the diconnected # player mud.send_message(pid, "{} quit the game".format(players[id]["name"]))
# add the new player to the dictionary, noting that they've not been # named yet. # The dictionary key is the player's id number. We set their room to # None initially until they have entered a name # Try adding more player stats - level, gold, inventory, etc players[id] = { "name": None, "room": None, "health": 100, "sabateur": 'No', "temp": np.random.randint(979, 987) / 10, } # send the new player a prompt for their name mud.send_message(id, "What is your name?") # go through any recently disconnected players for id in mud.get_disconnected_players(): # if for any reason the player isn't in the player map, skip them and # move on to the next one if id not in players: continue # go through all the players in the game for pid, pl in players.items(): # send each player a message to tell them about the diconnected # player mud.send_message(pid, "{} quit the game".format(players[id]["name"]))