def handle_existing_pass(player, command): player_db = lookup_player(player.name) if player_db is None: print_to_player(player, PrintArg.UNABLE_TO_RETRIEVE_CHAR) player.wait_state = PlayerWaitStates.THEIR_NAME return 1 pid = player_db.id # clear pnames if this fails, cause failures are being logged # again, what if not check_player_pass(player_db, command): print_to_player(player, PrintArg.INCORRECT_PASSWORD) player.name = '' player.wait_state = PlayerWaitStates.THEIR_NAME return 1 roomResult = lookup_room(player.coords) if roomResult is None: assert adjust_player_location(player, 0) == 0 player.id = pid print_room_to_player(player, roomResult) reset_player_state(player) player.connected = True print("Player name " + player.name + " connected on socket " + str( player.socket_num)) return 0
def do_info_cmd(player, info): if info.subtype == InfoRequest.INFO_ROOM: roomResult = lookup_room(player.coords) print_room_to_player(player, roomResult.results()) if info.subtype == InfoRequest.INFO_COMMANDS: print_to_player(player, PrintArg.PLAYER_SHOW_COMMANDS) if info.subtype == InfoRequest.INFO_PLAYERS: print_to_player(player, PrintArg.LISTPLAYERS) if info.subtype == InfoRequest.INFO_MAP: print("ADD ME")
def alter_room_name(player, command): if command is not None and command[0] is not 'y': print_to_player(player, PrintArg.PRINT_EXITING_CMD_WAIT) reset() result = adjust_room_name(player) if result == 0: print_to_player(player, PrintArg.PRINT_ADJUSTMENT_SUCCESSFUL) elif result == 1: print_to_player(player, PrintArg.PRINT_COULDNT_ADJUST_ROOM) elif result == 2: print_to_player(player, PrintArg.PRINT_INSUFFICIENT_PERMISSIONS) reset(player) roomResult = lookup_room(player.coords) print_room_to_player(player, roomResult)
def alter_room_desc(player, command): if command is not None and command[0] is not 'y': print_to_player(player, PrintArg.PRINT_EXITING_CMD_WAIT) src.players.PlayerManagement.reset_player_state(player) result = adjust_room_desc(player) if result == 0: print_to_player(player, PrintArg.PRINT_ADJUSTMENT_SUCCESSFUL) elif result is 1: print_to_player(player, PrintArg.PRINT_COULDNT_ADJUST_ROOM) elif result is 2: print_to_player(player, PrintArg.PRINT_INSUFFICIENT_PERMISSIONS) reset(player) roomResult = lookup_room(player.coords) print_room_to_player(player, roomResult)
def remove_players_from_room(coords, target_room, players_in_room): from src.io.OutputBuilder import print_to_player, print_room_to_player from src.players.PlayerManagement import get_player_by_id, adjust_player_location queryResult = players_in_room(target_room.rid) for i in range(0, len(queryResult.results)): if queryResult.results[i].id == 0: break player = get_player_by_id(queryResult.results[i].id) if not player.coords.x == coords.x and player.coords.y == coords.y and player.coords.z == coords.z: continue print_to_player(player, OutputBuilder.PrintArg.PRINT_REMOVED_FROM_ROOM) room = lookup_room(coords) adjust_player_location(player, room.rid) room = lookup_room(player.coords) print_room_to_player(player, room) return 0
def handle_room_creation(player, command): if command is not None and command[0] is not 'y': print_to_player(player, PrintArg.PRINT_EXITING_CMD_WAIT) reset(player) dest_coords = src.players.PlayerMovement.calc_coords_from_playerloc_and_dir( player) roomResult = lookup_room(dest_coords) if roomResult.id > 0: print_to_player(player, PrintArg.PRINT_ROOM_ALREADY_EXISTS) reset(player) return # check here for their perms # print_to_player(player, PRINT_INSUFFICIENT_PERMISSIONS) rconfig = RoomBlueprint() rconfig.name = "NULL SPACE" rconfig.coords = dest_coords rconfig.desc = "It is pitch black. You are likely to be eaten by a null character." rconfig.owner = player.name rconfig.flags = "none" existing = lookup_room(player.coords) new = insert_room(rconfig) if new is None: print_to_player(player, PrintArg.PRINT_ROOM_CREATION_FAILURE) return print_to_player(player, PrintArg.PRINT_ROOM_CREATION_SUCCESS) info = get_command_info(player.store) link_rooms(info.subtype, existing, new) existing = lookup_room(player.coords) print_room_to_player(player, existing) reset(player)
def handle_new_pass(player, command): from src.io.OutputBuilder import print_to_player, PrintArg, print_room_to_player if command != player.store or len(command) != len(player.store): print_to_player(player, PrintArg.MISMATCH_PW_SET) player.wait_state = PlayerWaitStates.THEIR_NAME player.store = '' return 1 print_to_player(player, PrintArg.ATTEMPT_CREATE_USR) if insert_player(player, command) == -1: print_to_player(player, PrintArg.PLAYER_CREATION_FAILED) shutdown_socket(player) return 1 reset_player_state(player) roomResult = lookup_room_by_id(0) print_room_to_player(player, roomResult) print("Player name " + player.name + " connected on socket " + str( player.socket_num)) return 0
def do_movement_cmd(player, info): direction = Movement.DIR_NOT origin = player.coords destination = {0} if info.subtype == Movement.DIR_NORTH: direction = Movement.DIR_NORTH destination.y = origin.y + 1 elif info.subtype == Movement.DIR_EAST: direction = Movement.DIR_EAST destination.x = origin.x + 1 elif info.subtype == Movement.DIR_SOUTH: direction = Movement.DIR_SOUTH destination.y = origin.y - 1 elif info.subtype == Movement.DIR_WEST: direction = Movement.DIR_WEST destination.x = origin.x - 1 elif info.subtype == Movement.DIR_DOWN: direction = Movement.DIR_DOWN destination.z = origin.z - 1 elif info.subtype == Movement.DIR_UP: direction = Movement.DIR_UP destination.z = origin.z + 1 elif info.subtype == Movement.DIR_NORTHWEST: direction = Movement.DIR_NORTHWEST destination.x = origin.x - 1 destination.y = origin.y + 1 elif info.subtype == Movement.DIR_NORTHEAST: direction = Movement.DIR_NORTHEAST destination.x = origin.x + 1 destination.y = origin.y + 1 elif info.subtype == Movement.DIR_SOUTHWEST: direction = Movement.DIR_SOUTHWEST destination.x = origin.x - 1 destination.y = origin.y - 1 elif info.subtype == Movement.DIR_SOUTHEAST: direction = Movement.DIR_SOUTHEAST destination.x = origin.x + 1 destination.y = origin.y - 1 dest_room = lookup_room(destination) if dest_room is None: print("oh no") # do something rv = lookup_room_exits(origin, dest_room) if rv == -1: print_to_player(player, PrintArg.PRINT_INVAL_DIR) return elif rv == -2: # send them back to origin room, somewhere they shouldn't be destination.x = 0 destination.y = 0 destination.z = 0 print_to_player(player, PrintArg.PRINT_INVAL_DIR) # check me else: print_to_player(player, direction) adjust_player_location(player, dest_room.id) print_room_to_player(player, dest_room)