17133446 by Barry

prevent dupe players, fixed entered game message.

1 parent 83e4eec5
Showing 1 changed file with 12 additions and 4 deletions
......@@ -107,13 +107,13 @@ while True:
for pid, pl in players.items():
# send each player a message to tell them about the diconnected
# player
if players[id]["name"] != None:
if players[pid]["name"] != None:
mud.send_message(pid, "{} quit the game".format(
players[id]["name"]))
else:
save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
players[pid]["name"]))
# remove the player's entry in the player dictionary
if players[id]["name"] != None:
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
del(players[id])
# go through any new commands sent from players
......@@ -130,6 +130,14 @@ while True:
if command.strip() == '' or command is None:
mud.send_message(id, "Invalid Name")
continue
already_logged_in = False
for pid, pl in players.items():
if players[pid]["name"] == command:
mud.send_message(id, "{} is already logged in.".format(command))
mud.disconnect_player(id)
already_logged_in = True
if already_logged_in:
continue
loaded_player = utils.load_object_from_file("players/{}.json".format(command))
if loaded_player is None:
players[id]["name"] = command
......