| Class | MUES::User |
| In: |
lib/mues/user.rb
(CVS)
|
| Parent: | MUES::StorableObject |
A user connection class for the MUES::Engine. A user object is an abstraction which contains the data describing a connected user and methods for interacting with that data, but does not contain any IO functionality itself. That task is delegated to a MUES::IOEventStream object which is joined with the user object at activation time. Activation is the process of associating a user object with a particular IO connection and a "command shell" after the user has provided valid authentication. The command shell is an instance of MUES::CommandShell (or a derivative) which the user can use to perform tasks in the MUES such as creating new characters, assuming the roles of existing characters, creating macros, etc.
| SVNRev | = | %q$Rev: 1215 $ | SVN Revision | |
| SVNId | = | %q$Id: user.rb 1215 2004-06-14 06:02:09Z deveiant $ | SVN Id | |
| SVNURL | = | %q$URL: svn+ssh://deveiate.org/usr/local/svn/MUES/trunk/lib/mues/user.rb $ | SVN URL |
| username | -> | login |
| cryptedPass | [R] | The user‘s encrypted password |
| emailAddress | [RW] | The player‘s email address |
| firstLoginTick | [R] | Tick number of the user‘s first login |
| flags | [RW] | Bitflags for the user (currently unused) |
| ioEventStream | [R] | The IOEventStream object belonging to this user |
| lastHost | [RW] | The host the user last logged in from |
| lastLoginDate | [RW] | The Date the user last logged in |
| preferences | [RW] | Hash of preferences for the user |
| realname | [RW] | The real name of the player |
| remoteHost | [R] | The name/IP of the host the user is connected from |
| timeCreated | [R] | Date from when the user was created |
| username | [RW] | The username of the user |
Return a MUES::Questionnaire IOEventFilter object suitable for insertion into a user‘s IOEventStream to query for altering an attribute of a user.
# File lib/mues/user.rb, line 121 def self::getAttributeQuestionnaire(user, attribute) question = CreateUserQuestions.find {|question| question[:name] == attribute } raise RuntimeError, "Can't build a questionnaire for '%s': No question with that name." % attribute if question.nil? question[:question] = ("Currently: %s\n" % user.send(attribute.intern)) + question[:question] qnaire = Questionnaire::new( "Change #{attribute}", question ) {|qnaire| MUES::ServerFunctions::unregisterUser( user ) user.send("#{attribute}=", qnaire.answers[attribute.intern]) MUES::ServerFunctions::registerUser( user ) qnaire.message "Changed '%s' for %s to '%s'\n\n" % [ attribute, user.login.capitalize, user.send(attribute.intern) ] } qnaire.debugLevel = 5 return qnaire end
Return a MUES::Questionnaire IOEventFilter object suitable for insertion into a user‘s IOEventStream to query for the information necessary to create a new user.
# File lib/mues/user.rb, line 78 def self::getCreationQuestionnaire qnaire = Questionnaire::new( "Create User", *CreateUserQuestions ) {|qnaire| user = MUES::User::new( qnaire.answers ) MUES::ServerFunctions::registerUser( user ) qnaire.message( "\nUser '%s' created.\n" % user.login.capitalize ) } qnaire.debugLevel = 5 return qnaire end
Return a MUES::Questionnaire IOEventFilter object suitable for insertion into a user‘s IOEventStream to query for a new password.
# File lib/mues/user.rb, line 92 def self::getPasswordQuestionnaire( user, isOther ) questions = nil # If we're changing another user's password, don't prompt for the # old password if isOther questions = ChangePasswordQuestions[1..-1] else questions = ChangePasswordQuestions end name = "Changing %s's password" % user.login.capitalize qnaire = Questionnaire::new( name, *questions ) {|qnaire| user.password = qnaire.answers[:newPassword] qnaire.message( "Password changed.\n\n" ) } # Add the user to the support data so the questionnaire's validators # can get at it qnaire.debugLevel = 5 qnaire.supportData[:user] = user return qnaire end
Create a new user object with the hash of attributes specified. The valid attributes are:
# File lib/mues/user.rb, line 163 def initialize( attributes={} ) checkResponse( attributes, '[]', '[]=', 'has_key?' ) super() @remoteHost = nil @stream = nil @activated = false @username = attributes[:username] || 'guest' @realname = attributes[:realname] || 'Guest User' @emailAddress = attributes[:emailAddress] || 'guestAccount@localhost' @lastLoginDate = attributes[:lastLoginDate] @lastHost = attributes[:lastHost] @timeCreated = Time.now @firstLoginTick = 0 @flags = 0 @preferences = {} @cryptedPass = '*' self.password = attributes[:password] if attributes.has_key?( :password ) end
Comparison operator — compares usernames.
# File lib/mues/user.rb, line 259 def <=>( otherUser ) @username <=> otherUser.username end
Activate the user, set up their environment with the given stream, and output the specified ‘message of the day’, if given.
# File lib/mues/user.rb, line 280 def activate( stream ) # Set the stream @stream = stream @stream.unpause @activated = true self.log.debug "Activating %p" % self registerHandlerForEvents( self, MUES::OutputEvent ) #MUES::TickEvent ) return [] end
Returns true if the engine has activated this user object
# File lib/mues/user.rb, line 234 def activated? @activated end
Deactivate our IOEventStream and prepare to be destroyed
# File lib/mues/user.rb, line 294 def deactivate results = [] # Unregister all our handlers unregisterHandlerForEvents( self ) # Shut down the IO event stream @activated = false results.replace @stream.shutdown if @stream results.flatten! # Return any events that need dispatching debugMsg 1, "Returning %d result events from deactivation." % results.length return results end
Lull the user for storage (MUES::StorableObject interface).
# File lib/mues/user.rb, line 341 def lull!( objStore ) @remoteHost = nil @stream = nil @activated = false # :FIXME: This should probably be 'super' instead. Needs # investigation, though. return true end
Reset the user‘s password to ((|newPassword|)). The password will be encrypted before being stored.
# File lib/mues/user.rb, line 266 def password=( newPassword ) newPassword = newPassword.to_s @cryptedPass = Digest::MD5::hexdigest( newPassword ) end
Returns true if the specified password matches the user‘s.
# File lib/mues/user.rb, line 273 def passwordMatches?( pass ) return Digest::MD5::hexdigest( pass ) == @cryptedPass end
Reconnect with the client connection from another io stream
# File lib/mues/user.rb, line 313 def reconnect( stream ) checkType( stream, MUES::IOEventStream ) results = [] stream.pause newFilter = stream.removeFiltersOfType( MUES::OutputFilter )[0] raise RuntimeError, "Cannot reconnect from a stream with no OutputFilter" unless newFilter newFilter.puts( "Reconnecting..." ) stream.unpause # Get the current stream's socket output filter/s and flush 'em # before closing it and replacing it with the new one. @stream.pause results.replace @stream.stopFiltersOfType( MUES::OutputFilter ) {|filter| filter.puts( "[Reconnect from #{newFilter.remoteHost}]" ) newFilter.sortPosition = filter.sortPosition } @stream.addFilters( newFilter ) @stream.addEvents( MUES::InputEvent.new("") ) @stream.unpause return results end
Sets the remote IP that the client is connected from, and sets the user‘s ‘lastHost’ attribute.
# File lib/mues/user.rb, line 241 def remoteHost=( newIp ) checkType( newIp, ::String ) @remoteHost = @lastHost = newIp end
Returns a stringified version of the user object
# File lib/mues/user.rb, line 249 def to_s "%s - %s <%s>" % [ @realname, @username.capitalize, @emailAddress ] end