class RuneRb::World::YAMLFileLoader
Public Instance Methods
check_login(session)
click to toggle source
# File app/world/world.rb, line 145 def check_login(session) # Check password validity unless validate_credentials(session.username, session.password) return LoginResult.new(3, nil) end existing = WORLD.players.find(nil) {|p| p.name.eql?(session.username)} if existing == nil # no existing user with this name, new login return LoginResult.new(2, RuneRb::Model::Player.new(session)) else # existing user = already logged in return LoginResult.new(5, nil) end end
decode_container(container, arr)
click to toggle source
# File app/world/world.rb, line 250 def decode_container(container, arr) arr.each_with_index {|val, i| container.set i, (val[0] == -1 ? nil : RuneRb::Item::Item.new(val[0], val[1])) } end
decode_skills(skills, data)
click to toggle source
# File app/world/world.rb, line 234 def decode_skills(skills, data) data.each_with_index {|val, i| skills.set_skill RuneRb::Player::Skills::SKILLS[i], val[0], val[1], false } end
default_profile(player)
click to toggle source
# File app/world/world.rb, line 256 def default_profile(player) player.location = RuneRb::Model::Location.new(3232, 3232, 0) player.rights = :admin end
encode_container(container)
click to toggle source
# File app/world/world.rb, line 240 def encode_container(container) arr = Array.new(container.capacity, [-1, -1]) container.items.each_with_index {|val, i| arr[i] = [val.id, val.count] unless val == nil } arr end
encode_skills(skills)
click to toggle source
# File app/world/world.rb, line 228 def encode_skills(skills) RuneRb::Player::Skills::SKILLS.inject([]){|arr, sk| arr << [skills.skills[sk], skills.exps[sk]] } end
load_profile(player)
click to toggle source
# File app/world/world.rb, line 162 def load_profile(player) begin key = RuneRb::Misc::NameUtils.format_name_protocol(player.name) profile = if FileTest.exists?("./data/profiles/#{key}.yaml") YAML::load(File.open("./data/profiles/#{key}.yaml")) else nil end PROFILE_LOG.info "Retrieving profile: #{key}" if profile == nil default_profile(player) else player.rights = RuneRb::World::RIGHTS[2] #RuneRb::World::RIGHTS[profile.rights] || :player player.members = profile.member player.appearance.set_look profile.appearance decode_container(player.equipment, profile.equipment) decode_container(player.inventory, profile.inventory) decode_container(player.bank, profile.bank) decode_skills(player.skills, profile.skills) player.varp.friends = profile.friends player.varp.ignores = profile.ignores player.location = RuneRb::Model::Location.new(profile.x, profile.y, profile.z) player.settings = profile.settings || {} end rescue Exception => e PROFILE_LOG.error "Unable to load profile" PROFILE_LOG.error e return false end return true end
save_profile(player)
click to toggle source
# File app/world/world.rb, line 198 def save_profile(player) key = RuneRb::Misc::NameUtils.format_name_protocol(player.name) PROFILE_LOG.info "Storing profile: #{key}" profile = Profile.new profile.hash = player.name_long profile.banned = false profile.member = player.members #profile.rights = RuneRb::World::RIGHTS.index(player.rights) profile.x = player.location.x profile.y = player.location.y profile.z = player.location.z profile.appearance = player.appearance.get_look profile.skills = encode_skills(player.skills) profile.equipment = encode_container(player.equipment) profile.inventory = encode_container(player.inventory) profile.bank = encode_container(player.bank) profile.friends = player.varp.friends profile.ignores = player.varp.ignores profile.settings = player.settings File.open("./data/profiles/#{key}.yaml", "w" ) do |out| YAML.dump(profile, out) out.flush end true end
validate_credentials(username, password)
click to toggle source
# File app/world/world.rb, line 262 def validate_credentials(username, password) true end