Class: JsChat::User
- Inherits:
-
Object
- Object
- JsChat::User
- Includes:
- FloodProtection
- Defined in:
- lib/jschat/server.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#identified ⇒ Object
Returns the value of attribute identified.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#last_activity ⇒ Object
Returns the value of attribute last_activity.
-
#last_poll ⇒ Object
Returns the value of attribute last_poll.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rooms ⇒ Object
Returns the value of attribute rooms.
-
#session_length ⇒ Object
Returns the value of attribute session_length.
Class Method Summary collapse
Instance Method Summary collapse
- #change(params) ⇒ Object
-
#initialize(connection) ⇒ User
constructor
A new instance of User.
- #private_message(message) ⇒ Object
- #session_expired? ⇒ Boolean
- #to_json(*a) ⇒ Object
- #update_session_expiration ⇒ Object
Methods included from FloodProtection
#detect_flooding, #flooding?, #remove_old_activity_logs, #seen!
Constructor Details
#initialize(connection) ⇒ User
Returns a new instance of User.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jschat/server.rb', line 52 def initialize(connection) @name = nil @connection = connection @rooms = [] @last_activity = Time.now.utc @last_poll = Time.now.utc @identified = false @ip = '' @expires = nil @session_length = nil end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
49 50 51 |
# File 'lib/jschat/server.rb', line 49 def connection @connection end |
#identified ⇒ Object
Returns the value of attribute identified.
49 50 51 |
# File 'lib/jschat/server.rb', line 49 def identified @identified end |
#ip ⇒ Object
Returns the value of attribute ip.
49 50 51 |
# File 'lib/jschat/server.rb', line 49 def ip @ip end |
#last_activity ⇒ Object
Returns the value of attribute last_activity.
49 50 51 |
# File 'lib/jschat/server.rb', line 49 def last_activity @last_activity end |
#last_poll ⇒ Object
Returns the value of attribute last_poll.
49 50 51 |
# File 'lib/jschat/server.rb', line 49 def last_poll @last_poll end |
#name ⇒ Object
Returns the value of attribute name.
49 50 51 |
# File 'lib/jschat/server.rb', line 49 def name @name end |
#rooms ⇒ Object
Returns the value of attribute rooms.
49 50 51 |
# File 'lib/jschat/server.rb', line 49 def rooms @rooms end |
#session_length ⇒ Object
Returns the value of attribute session_length.
49 50 51 |
# File 'lib/jschat/server.rb', line 49 def session_length @session_length end |
Class Method Details
.valid_name?(name) ⇒ Boolean
89 90 91 |
# File 'lib/jschat/server.rb', line 89 def self.valid_name?(name) not name.match /[^[:alnum:]._\-\[\]^C]/ and name.size > 0 end |
Instance Method Details
#change(params) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/jschat/server.rb', line 98 def change(params) # Valid options for change ['name'].each do |field| if params[field] old_value = send(field) send "#{field}=", params[field] @rooms.each do |room| response = { 'change' => 'user', 'room' => room.name, 'user' => { field => { old_value => params[field] } } } room.change_notice self, response return [field, params[field]] end end end end |
#private_message(message) ⇒ Object
93 94 95 96 |
# File 'lib/jschat/server.rb', line 93 def () response = { 'display' => 'message', 'message' => } @connection.send_response response end |
#session_expired? ⇒ Boolean
64 65 66 67 |
# File 'lib/jschat/server.rb', line 64 def session_expired? return true if @expires.nil? Time.now.utc >= @expires end |
#to_json(*a) ⇒ Object
74 75 76 |
# File 'lib/jschat/server.rb', line 74 def to_json(*a) { 'name' => @name, 'last_activity' => @last_activity }.to_json(*a) end |
#update_session_expiration ⇒ Object
69 70 71 72 |
# File 'lib/jschat/server.rb', line 69 def update_session_expiration return if @session_length.nil? @expires = Time.now.utc + @session_length end |