class Rsrb::World::PlayerFileLoader
Public Class Methods
new()
click to toggle source
# File lib/rsrb/world/loader.rb, line 5 def initialize init_loggers end
Public Instance Methods
decode_container(container, arr)
click to toggle source
# File lib/rsrb/world/loader.rb, line 103 def decode_container(container, arr) arr.each_with_index do |val, i| container.set i, (val[0] == -1 ? nil : Rsrb::Item::Item.new(val[0], val[1])) end end
decode_skills(skills, data)
click to toggle source
# File lib/rsrb/world/loader.rb, line 87 def decode_skills(skills, data) data.each_with_index do |val, i| skills.set_skill Rsrb::Player::Skills::SKILLS[i], val[0], val[1], false end end
default_profile(player)
click to toggle source
# File lib/rsrb/world/loader.rb, line 109 def default_profile(player) player.location = Rsrb::Model::Location.new(3232, 3232, 0) player.rights = :player end
encode_container(container)
click to toggle source
# File lib/rsrb/world/loader.rb, line 93 def encode_container(container) arr = Array.new(container.capacity, [-1, -1]) container.items.each_with_index do |val, i| arr[i] = [val.id, val.count] unless val.nil? end arr end
encode_skills(skills)
click to toggle source
# File lib/rsrb/world/loader.rb, line 81 def encode_skills(skills) Rsrb::Player::Skills::SKILLS.inject([]) do |arr, sk| arr << [skills.skills[sk], skills.exps[sk]] end end
load_profile(player)
click to toggle source
# File lib/rsrb/world/loader.rb, line 21 def load_profile(player) begin key = Rsrb::Misc::NameUtils.format_name_protocol(player.name) if File.exists?("assets/profiles/#{key}.yaml") log "Retrieving profile for #{key}" profile = Psych.load_file("assets/profiles/#{key}.yaml") player.rights = Rsrb::World::Constants::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 = Rsrb::Model::Location.new(profile.x, profile.y, profile.z) player.settings = profile.settings || {} else log! "Creating new profile for #{key}" default_profile(player) end player rescue StandardError => e err "Unable to load profile for #{e}", e end end
save_profile(player)
click to toggle source
# File lib/rsrb/world/loader.rb, line 51 def save_profile(player) key = Rsrb::Misc::NameUtils.format_name_protocol(player.name) log "Storing profile for #{key}" profile = Profile.new profile.hash = player.name_long profile.banned = false profile.member = player.members profile.rights = Rsrb::World::Constants::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("assets/profiles/#{key}.yaml", 'w' ) do |out| YAML.dump(profile, out) out.flush end true end
validate_credentials(credentials)
click to toggle source
Attempts to validate the provided credentials.
# File lib/rsrb/world/loader.rb, line 11 def validate_credentials(credentials) log! "Validating #{credentials}" ## # credentials[:password] == db[:PROFILES].where(username: credentials[:username]).get(:password) # TODO: Temp @credentials = credentials log "Validated #{credentials}" true end