# # file:: cmd_last.rb # This source code copyright (C) 2009 Craig Smith # All rights reserved. # # Released under the terms of the TeensyMUD Public License # See LICENSE file for additional information. # module Cmd bindtextdomain("cmd") # Shows the last # of ppl to login def cmd_last(args) cnt = nil case args when "", nil cnt = 10 when /(\d+)/ cnt = $1.to_i else sendto _("Usage: @last <number of users>") return end if cnt ppl = Hash.new world.all_characters.each do |oid| plyr = get_object(oid) if plyr.acctid log.info "DEBUG: #{plyr.name} HAS ACCTID #{plyr.acctid}" acct = get_object(plyr.acctid) if acct.logged_in log.info "DEBUG: has LOGGED_IN" ppl[acct.logged_in] = acct end end end printed = 0 msg = _("Last %{cnt} logged on.\n" % {:cnt => cnt}) ppl.sort.each do |time, plyr| newmsg << "#{time} - #{acct.name}" if plyr.account.logged_out newmsg << " (#{acct.logged_out})" else newmsg << " (online)" end newmsg << "\n" msg << newmsg if printed < cnt printed += 1 end add_event(id, id, :show, msg) end end end