Class: Warchat::Network::Session
- Inherits:
-
Object
- Object
- Warchat::Network::Session
- Defined in:
- lib/warchat/network/session.rb
Instance Attribute Summary collapse
-
#on_close ⇒ Object
Returns the value of attribute on_close.
-
#on_error ⇒ Object
Returns the value of attribute on_error.
-
#on_establish ⇒ Object
Returns the value of attribute on_establish.
-
#on_receive ⇒ Object
Returns the value of attribute on_receive.
Instance Method Summary collapse
- #close(reason = '') ⇒ Object
- #connection_close(reason) ⇒ Object
- #connection_receive(response) ⇒ Object
- #established? ⇒ Boolean
-
#initialize ⇒ Session
constructor
A new instance of Session.
- #is_closed? ⇒ Boolean
- #send_request(request) ⇒ Object
- #stage_1(response) ⇒ Object
- #stage_2(response) ⇒ Object
- #stage_3(response) ⇒ Object
- #start(account_name, account_password, host = "m.us.wowarmory.com", port = 8780) ⇒ Object
Constructor Details
#initialize ⇒ Session
Returns a new instance of Session.
9 10 11 12 13 14 |
# File 'lib/warchat/network/session.rb', line 9 def initialize @connection = Warchat::Network::Connection.new @connection.on_close = method(:connection_close) @connection.on_receive = method(:connection_receive) end |
Instance Attribute Details
#on_close ⇒ Object
Returns the value of attribute on_close.
6 7 8 |
# File 'lib/warchat/network/session.rb', line 6 def on_close @on_close end |
#on_error ⇒ Object
Returns the value of attribute on_error.
6 7 8 |
# File 'lib/warchat/network/session.rb', line 6 def on_error @on_error end |
#on_establish ⇒ Object
Returns the value of attribute on_establish.
6 7 8 |
# File 'lib/warchat/network/session.rb', line 6 def on_establish @on_establish end |
#on_receive ⇒ Object
Returns the value of attribute on_receive.
6 7 8 |
# File 'lib/warchat/network/session.rb', line 6 def on_receive @on_receive end |
Instance Method Details
#close(reason = '') ⇒ Object
45 46 47 |
# File 'lib/warchat/network/session.rb', line 45 def close reason='' @connection.close reason end |
#connection_close(reason) ⇒ Object
82 83 84 |
# File 'lib/warchat/network/session.rb', line 82 def connection_close reason on_close and on_close.call(reason) end |
#connection_receive(response) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/warchat/network/session.rb', line 71 def connection_receive response m = "stage_#{response['stage']}".to_sym if response.ok? respond_to? m and send(m,response) or on_receive and on_receive.call(response) else error = response["body"] Warchat.debug("error: " + error) close(error) if respond_to? m end end |
#established? ⇒ Boolean
41 42 43 |
# File 'lib/warchat/network/session.rb', line 41 def established? @established end |
#is_closed? ⇒ Boolean
49 50 51 |
# File 'lib/warchat/network/session.rb', line 49 def is_closed? @connection.is_closed? end |
#send_request(request) ⇒ Object
53 54 55 |
# File 'lib/warchat/network/session.rb', line 53 def send_request request @connection and @connection.send_request(request) end |
#stage_1(response) ⇒ Object
57 58 59 60 |
# File 'lib/warchat/network/session.rb', line 57 def stage_1 response proof = @srp.auth1_proof(response["user"], @account_password[0..15].upcase, response["salt"], response["B"]) send_request(Request.new("/authenticate2",:clientProof=>proof)) end |
#stage_2(response) ⇒ Object
62 63 64 |
# File 'lib/warchat/network/session.rb', line 62 def stage_2 response send_request(Request.new("/authenticate2",:clientProof=>Warchat::ByteString.new("\000"))) end |
#stage_3(response) ⇒ Object
66 67 68 69 |
# File 'lib/warchat/network/session.rb', line 66 def stage_3 response @established = true on_establish and on_establish.call(response) end |
#start(account_name, account_password, host = "m.us.wowarmory.com", port = 8780) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/warchat/network/session.rb', line 16 def start account_name, account_password,host="m.us.wowarmory.com",port=8780 @account_name = account_name @account_password = account_password @connection.start host,port @srp = Warchat::Srp::Client.new send_request Request.new('/authenticate1', :screenRes => "PHONE_HIGH", :device => "iPhone", :deviceSystemVersion => "4.2.1", :deviceModel => "iPhone3,1", :appV => "3.0.0", :deviceTime => Time.now.to_i, :deviceTimeZoneId => "America/New_York", :clientA => @srp.a_bytes, :appId => "Armory", :deviceId => '50862581c5dc46072050d51886cbae3149b3473c', :emailAddress => account_name, :deviceTimeZone => "-14400000", :locale => "en_US" ) end |