Class: KAG::Gather::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/kag/gather/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQueue

Returns a new instance of Queue.



7
8
9
# File 'lib/kag/gather/queue.rb', line 7

def initialize
  self.players = {}
end

Instance Attribute Details

#playersObject

Returns the value of attribute players.



5
6
7
# File 'lib/kag/gather/queue.rb', line 5

def players
  @players
end

Instance Method Details

#add(user) ⇒ Object



11
12
13
14
15
# File 'lib/kag/gather/queue.rb', line 11

def add(user)
  return false unless user.authname and !user.authname.to_s.empty?
  self.players[user.authname.to_sym] = user
  true
end

#check_for_afk(gather) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kag/gather/queue.rb', line 48

def check_for_afk(gather)
  max_idle = (KAG::Config.instance[:idle][:max] or 1800)
  max_idle = max_idle.to_i
  begin
    self.players.each do |authname,user|
      user.refresh
      if user.idle > max_idle
        self.remove(user)
        gather.send_channels_msg "Removed #{user.authname} from queue (#{KAG::Gather::Match.type_as_string}) for being idle too long [#{self.length}]"
      end
    end
  rescue Exception => e
    puts e.message
    puts e.backtrace.join("\n")
    false
  end
end

#has_player?(user) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/kag/gather/queue.rb', line 35

def has_player?(user)
  return false unless user.authname and !user.authname.to_s.empty?
  self.players.has_key?(user.authname.to_sym)
end

#lengthObject



40
41
42
# File 'lib/kag/gather/queue.rb', line 40

def length
  self.players.length
end

#listObject



27
28
29
30
31
32
33
# File 'lib/kag/gather/queue.rb', line 27

def list
  m = []
  self.players.each do |authname,user|
    m << user.authname
  end
  m.join(", ")
end

#remove(user) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/kag/gather/queue.rb', line 17

def remove(user)
  return false unless user.authname and !user.authname.to_s.empty?
  if has_player?(user)
    self.players.delete(user.authname.to_sym)
    true
  else
    false
  end
end

#resetObject



44
45
46
# File 'lib/kag/gather/queue.rb', line 44

def reset
  self.players = {}
end