module Nova::Starbound::DefaultBehavior::Passwordable

Handles passwords with the default behavior.

Attributes

password[W]

The current password. If it’s nil, any password works; if it’s an empty string, no password works; and if it’s a string, only passwords matching that string works.

@return [nil, String]

Public Class Methods

included(reciever) click to toggle source

When this is included by {DefaultBehavior}, define the packets nessicary for password management.

@return [void]

# File lib/nova/starbound/default_behavior/passwordable.rb, line 68
def self.included(reciever)
  reciever.handle :packet => :password
end

Public Instance Methods

authenticated?() click to toggle source

Whether or not it was authenticated.

@return [Boolean]

# File lib/nova/starbound/default_behavior/passwordable.rb, line 40
def authenticated?
  @authenticated
end
check_password(pass) click to toggle source

Checks to see if the given password is valid. If it is, it sets authenticated to true. Otherwise, sets it to false.

@param pass [String] the password to check. @return [Boolean]

# File lib/nova/starbound/default_behavior/passwordable.rb, line 33
def check_password(pass)
  @authenticated = valid_password? pass
end
valid_password?(pass) click to toggle source

Checks to see if the given password is valid. Returns false if it isn’t, true if it is.

@param pass [String] the password to check. @return [Boolean]

# File lib/nova/starbound/default_behavior/passwordable.rb, line 20
def valid_password?(pass)
  if password.nil? || (pass == password && password != "")
    true
  else
    false
  end
end

Private Instance Methods

handle_packet_password(packet, proto) click to toggle source

Handles the password packet, by checking the password. If it matches, it returns an “OK” packet. Otherwise, it returns a “FAIL” packet.

@param packet [Protocol::Packet] the packet that the client sent. @param proto [Protocol] the protocol used to communicate

with the client.

@return [void]

# File lib/nova/starbound/default_behavior/passwordable.rb, line 54
def handle_packet_password(packet, proto)
  if reciever.check_password packet.body
    proto.respond_to packet, :password, "OK"
  else
    proto.respond_to packet, :password, "FAIL"
  end
end