Class: Weskit::MP::Worker
- Extended by:
- Forwardable
- Defined in:
- lib/weskit/mp/worker.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
Instance Method Summary collapse
- #connect_and(&operate) ⇒ Object
-
#initialize(nickname) ⇒ Worker
constructor
A new instance of Worker.
- #login ⇒ Object
- #verify_response(element) ⇒ Object
Constructor Details
#initialize(nickname) ⇒ Worker
Returns a new instance of Worker.
16 17 18 19 |
# File 'lib/weskit/mp/worker.rb', line 16 def initialize nickname @connection = Connection.new self @nickname = nickname end |
Instance Attribute Details
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
7 8 9 |
# File 'lib/weskit/mp/worker.rb', line 7 def debug @debug end |
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
7 8 9 |
# File 'lib/weskit/mp/worker.rb', line 7 def nickname @nickname end |
Instance Method Details
#connect_and(&operate) ⇒ Object
10 11 12 13 14 |
# File 'lib/weskit/mp/worker.rb', line 10 def connect_and &operate @connection.open do instance_eval &operate end end |
#login ⇒ Object
21 22 23 24 25 |
# File 'lib/weskit/mp/worker.rb', line 21 def login 'login', {:selective_ping => 1, :username => @nickname} read ; verify_response :mustlogin read ; verify_response :join_lobby end |
#verify_response(element) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/weskit/mp/worker.rb', line 27 def verify_response element element = @connection.buffer.find(element).first unless element raise Errors::ResponseError, "Server send node other than '#{element}'" end end |