Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactors, and fixed challenge sometimes breaking

  • Loading branch information...
commit 4cf5807acda7555536cc066e88174192a8ab8664 1 parent 48f0d24
@asterite asterite authored
View
12 lib/msn/challenge.rb
@@ -12,7 +12,7 @@ def challenge(challenge, product_key = ProductKey, product_id = ProductId)
md5array = new_hash_parts.map { |n| n & F }
chlstring = "#{challenge}#{product_id}"
- chlstring = "#{chlstring}#{'0' * (chlstring.length % 8)}"
+ chlstring = "#{chlstring}#{'0' * (8 - chlstring.length % 8)}"
chlstring_array = chlstring.scan(/.{4}/)
chlstring_array.map! { |str| str.bytes.map { |b| b.to_s(16) }.reverse.join.to_i(16) }
@@ -39,15 +39,5 @@ def challenge(challenge, product_key = ProductKey, product_id = ProductId)
new_hash_parts.map { |x| x.to_s(16).scan(/.{2}/).reverse.join }.join
end
-
- def split_in_chunks(string, length)
- array = []
- i = 0
- while i < string.length
- array.push string[i ... i + length]
- i += length
- end
- array
- end
end
end
View
3  lib/msn/messenger.rb
@@ -37,7 +37,8 @@ def add_contact(email, display_name = email)
end
def remove_contact(email)
- @notification_server.rem "AL", email
+ username, domain = email.split '@', 2
+ @notification_server.send_payload_command "RML", %Q(<ml><d n="#{domain}"><c n="#{username}" t="1" l="1" /></d></ml>)
end
def on_ready(&handler)
View
8 lib/msn/notification_server.rb
@@ -74,14 +74,6 @@ def login_to_nexus(policy, nonce)
nexus = Msn::Nexus.new policy, nonce
token, return_value = nexus.login messenger.username, messenger.password
- first_msg = true
- on_event('MSG') do
- if first_msg
- first_msg = false
- messenger.ready
- end
- end
-
on_event('RNG') do |header|
switchboard = create_switchboard header[5], header[2]
switchboard.ans username_guid, header[4], header[1]
View
12 lib/msn/protocol.rb
@@ -16,7 +16,7 @@ def receive_line(line)
answer_challenge pieces[2]
when 'RNG'
handle_event pieces
- when 'MSG', 'NOT', 'GCF'
+ when 'MSG', 'NOT', 'GCF', 'ADL', 'RML'
@header = pieces
size = pieces.last.to_i
@@ -50,9 +50,7 @@ def handle_event(header, data = nil)
end
def answer_challenge(challenge_string)
- payload = Msn::Challenge.challenge(challenge_string)
-
- send_command_internal "QRY #{@trid} #{Msn::Challenge::ProductId} 32\r\n#{payload}"
+ send_payload_command "QRY", Msn::Challenge::ProductId, Msn::Challenge.challenge(challenge_string)
end
def send_command(command, *args)
@@ -64,6 +62,12 @@ def send_command(command, *args)
Fiber.yield
end
+ def send_payload_command(command, *args)
+ payload = args.pop
+ args.push payload.length
+ send_command_internal "#{command} #{@trid} #{args.join ' '}\r\n#{payload}"
+ end
+
def send_command_internal(text)
puts ">> #{text}" if Msn::Messenger.debug
send_data text
View
5 lib/msn/switchboard.rb
@@ -17,10 +17,7 @@ def initialize(messenger)
end
def send_message(text)
- header = "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nUser-Agent: pidgin/2.10.5devel\r\nX-MMS-IM-Format: FN=Segoe%20UI; EF=; CO=0; PF=0; RL=0\r\n\r\n#{text}"
- message = "MSG #{@trid} N #{header.length}\r\n#{header}"
-
- send_command_internal message
+ send_payload_command "MSG", "N", "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nUser-Agent: pidgin/2.10.5devel\r\nX-MMS-IM-Format: FN=Segoe%20UI; EF=; CO=0; PF=0; RL=0\r\n\r\n#{text}"
end
end
View
4 spec/msn/challenge_spec.rb
@@ -8,4 +8,8 @@
it "replies to challenge for MSNP15" do
Challenge.challenge("11533365622852247127").should eq("f086d1ded067186deca8dba2231602cf")
end
+
+ it "replies to longer challenge" do
+ Challenge.challenge("237191752526424888127371168").should eq("65b6b623c649c25629af048d34066040")
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.