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: ...@@ -107,13 +107,13 @@ while True:
107 for pid, pl in players.items(): 107 for pid, pl in players.items():
108 # send each player a message to tell them about the diconnected 108 # send each player a message to tell them about the diconnected
109 # player 109 # player
110 if players[id]["name"] != None: 110 if players[pid]["name"] != None:
111 mud.send_message(pid, "{} quit the game".format( 111 mud.send_message(pid, "{} quit the game".format(
112 players[id]["name"])) 112 players[pid]["name"]))
113 else:
114 save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
115 113
116 # remove the player's entry in the player dictionary 114 # remove the player's entry in the player dictionary
115 if players[id]["name"] != None:
116 utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
117 del(players[id]) 117 del(players[id])
118 118
119 # go through any new commands sent from players 119 # go through any new commands sent from players
...@@ -130,6 +130,14 @@ while True: ...@@ -130,6 +130,14 @@ while True:
130 if command.strip() == '' or command is None: 130 if command.strip() == '' or command is None:
131 mud.send_message(id, "Invalid Name") 131 mud.send_message(id, "Invalid Name")
132 continue 132 continue
133 already_logged_in = False
134 for pid, pl in players.items():
135 if players[pid]["name"] == command:
136 mud.send_message(id, "{} is already logged in.".format(command))
137 mud.disconnect_player(id)
138 already_logged_in = True
139 if already_logged_in:
140 continue
133 loaded_player = utils.load_object_from_file("players/{}.json".format(command)) 141 loaded_player = utils.load_object_from_file("players/{}.json".format(command))
134 if loaded_player is None: 142 if loaded_player is None:
135 players[id]["name"] = command 143 players[id]["name"] = command
......