warchat 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -3
- data/lib/warchat.rb +1 -0
- data/lib/warchat/byte_string.rb +1 -0
- data/lib/warchat/chat/chat_response.rb +1 -0
- data/lib/warchat/chat/client.rb +6 -4
- data/lib/warchat/chat/message.rb +1 -0
- data/lib/warchat/chat/presence.rb +1 -0
- data/lib/warchat/network/binary_reader.rb +6 -3
- data/lib/warchat/network/binary_writer.rb +2 -1
- data/lib/warchat/network/connection.rb +1 -1
- data/lib/warchat/network/request.rb +4 -1
- data/lib/warchat/network/response.rb +1 -0
- data/lib/warchat/network/session.rb +1 -0
- data/lib/warchat/srp/client.rb +25 -15
- data/lib/warchat/timer.rb +1 -0
- data/lib/warchat/version.rb +2 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -29,9 +29,7 @@ This is a simple chat client that will let you talk in guild chat and receive me
|
|
29
29
|
client = Warchat::Chat::Client.new
|
30
30
|
|
31
31
|
client.on_establish = Proc.new do |response|
|
32
|
-
client.
|
33
|
-
client.character_realm = CHARACTER_REALM
|
34
|
-
client.login
|
32
|
+
client.login CHARACTER_NAME,CHARACTER_REALM
|
35
33
|
end
|
36
34
|
|
37
35
|
client.on_message = Proc.new do |message|
|
data/lib/warchat.rb
CHANGED
data/lib/warchat/byte_string.rb
CHANGED
data/lib/warchat/chat/client.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
1
2
|
module Warchat
|
2
3
|
module Chat
|
3
4
|
class Warchat::Chat::Client
|
4
5
|
attr_accessor :on_message,:on_presence,:on_logout,:on_fail,:on_establish
|
5
6
|
attr_accessor :on_message_afk,:on_message_dnd,:on_message_guild_chat,:on_message_motd,:on_message_officer_chat,:on_message_whisper,:on_chat_logout
|
6
|
-
attr_accessor :character_name,:character_realm
|
7
7
|
|
8
8
|
attr_reader :session
|
9
9
|
|
@@ -16,6 +16,7 @@ module Warchat
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def start username, password
|
19
|
+
[username,password].each do |s| s.respond_to? :force_encoding and s.force_encoding(__ENCODING__) end
|
19
20
|
self.session.start(username,password)
|
20
21
|
end
|
21
22
|
|
@@ -32,7 +33,8 @@ module Warchat
|
|
32
33
|
send(m,response) if respond_to? m
|
33
34
|
end
|
34
35
|
|
35
|
-
def login
|
36
|
+
def login character_name,character_realm
|
37
|
+
[character_name,character_realm].each do |s| s.respond_to? :force_encoding and s.force_encoding(__ENCODING__) end
|
36
38
|
request = Warchat::Network::Request.new("/chat-login",:options=>{:mature_filter=>'false'},:n=>character_name,:r=>character_realm)
|
37
39
|
session.send_request(request)
|
38
40
|
@timer = Warchat::Timer.new(30,&method(:keep_alive))
|
@@ -55,11 +57,11 @@ module Warchat
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def chat response
|
58
|
-
response.extend(ChatResponse)
|
60
|
+
response.extend(Warchat::Chat::ChatResponse)
|
59
61
|
if response.ack?
|
60
62
|
|
61
63
|
elsif response.message?
|
62
|
-
message = Message.new(response)
|
64
|
+
message = Warchat::Chat::Message.new(response)
|
63
65
|
[on_message,send("on_message_#{message.type}".to_sym)].compact.each do |m| m.call(message) end
|
64
66
|
elsif response.presence?
|
65
67
|
on_presence and on_presence.call(Presence.new(response))
|
data/lib/warchat/chat/message.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
1
2
|
module Warchat
|
2
3
|
module Network
|
3
4
|
class BinaryReader
|
@@ -11,11 +12,13 @@ module Warchat
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def substream l
|
14
|
-
@socket.read
|
15
|
+
sub = @socket.read(l)
|
16
|
+
sub << @socket.read(l-sub.length) until sub.length >= l
|
17
|
+
sub
|
15
18
|
end
|
16
19
|
|
17
20
|
def byte
|
18
|
-
substream
|
21
|
+
substream(1)
|
19
22
|
end
|
20
23
|
|
21
24
|
def string
|
@@ -23,7 +26,7 @@ module Warchat
|
|
23
26
|
end
|
24
27
|
|
25
28
|
def array
|
26
|
-
(1..(int_32)).map
|
29
|
+
(1..(int_32)).map(&method(:parse_next))
|
27
30
|
end
|
28
31
|
|
29
32
|
def hash
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
1
2
|
module Warchat
|
2
3
|
module Network
|
3
4
|
class Request < Hash
|
@@ -30,7 +31,8 @@ module Warchat
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def stream socket
|
33
|
-
|
34
|
+
str_socket = StringSocket.new
|
35
|
+
writer = BinaryWriter.new str_socket
|
34
36
|
writer.string(target)
|
35
37
|
writer.int_32(@id)
|
36
38
|
each do |k,v|
|
@@ -50,6 +52,7 @@ module Warchat
|
|
50
52
|
writer.byte 0xFF
|
51
53
|
end
|
52
54
|
writer.byte 0xFF
|
55
|
+
socket.print(str_socket.value)
|
53
56
|
end
|
54
57
|
|
55
58
|
def inspect
|
data/lib/warchat/srp/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
1
2
|
require 'digest'
|
2
3
|
require 'openssl'
|
3
4
|
|
@@ -13,7 +14,7 @@ module Warchat
|
|
13
14
|
HASH_SIZE = 32
|
14
15
|
SESSION_KEY_SIZE = HASH_SIZE * 2
|
15
16
|
|
16
|
-
attr_reader :b,:b_bytes
|
17
|
+
attr_reader :b,:b_bytes,:salt,:user,:password
|
17
18
|
|
18
19
|
def modpow(a, n, m)
|
19
20
|
r = 1
|
@@ -21,12 +22,12 @@ module Warchat
|
|
21
22
|
r = r * a % m if n[0] == 1
|
22
23
|
n >>= 1
|
23
24
|
return r if n == 0
|
24
|
-
a = a
|
25
|
+
a = (a ** 2) % m
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
def pack_int int
|
29
|
-
Warchat::ByteString.new
|
30
|
+
Warchat::ByteString.new([int.to_s(16).reverse].pack('h*'))
|
30
31
|
end
|
31
32
|
|
32
33
|
def unpack_int str
|
@@ -34,11 +35,15 @@ module Warchat
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def digest_int s
|
37
|
-
unpack_int(
|
38
|
+
unpack_int(digest_str(s))
|
39
|
+
end
|
40
|
+
|
41
|
+
def digest_str s
|
42
|
+
Digest::SHA2.digest(s).tap do |s| s.respond_to? :force_encoding and s.force_encoding(__ENCODING__) end
|
38
43
|
end
|
39
44
|
|
40
45
|
def adjust_size str,length
|
41
|
-
str[0..(length-1)].ljust(length,"\000")
|
46
|
+
Warchat::ByteString.new str[0..(length-1)].ljust(length,"\000")
|
42
47
|
end
|
43
48
|
|
44
49
|
def random_crypt
|
@@ -48,14 +53,14 @@ module Warchat
|
|
48
53
|
def hN_xor_hG
|
49
54
|
# xor H(N) and H(G)
|
50
55
|
return @hN_xor_hG if @hN_xor_hG
|
51
|
-
hN =
|
52
|
-
hG =
|
56
|
+
hN = digest_str(pack_int(MODULUS)).unpack('C*')
|
57
|
+
hG = digest_str(pack_int(G)).unpack('C*')
|
53
58
|
|
54
|
-
|
59
|
+
tmp = []
|
55
60
|
|
56
|
-
HASH_SIZE.times do |i|
|
61
|
+
HASH_SIZE.times do |i| tmp[i] = (hN[i] ^ hG[i]) end
|
57
62
|
|
58
|
-
@hN_xor_hG
|
63
|
+
@hN_xor_hG = tmp.pack('C*')
|
59
64
|
end
|
60
65
|
|
61
66
|
def a
|
@@ -77,7 +82,7 @@ module Warchat
|
|
77
82
|
|
78
83
|
def x
|
79
84
|
# H(salt | H(userHash | : | sessionPassword))
|
80
|
-
@x ||= digest_int(@salt+
|
85
|
+
@x ||= digest_int(@salt+digest_str(@user+":"+@password))
|
81
86
|
end
|
82
87
|
|
83
88
|
def s
|
@@ -92,13 +97,18 @@ module Warchat
|
|
92
97
|
|
93
98
|
def auth1_proof user, password, salt, b_bytes
|
94
99
|
@b = unpack_int b_bytes
|
100
|
+
|
95
101
|
@b_bytes = adjust_size(b_bytes,MODULUS_SIZE)
|
96
102
|
@salt = adjust_size(salt,SALT_SIZE)
|
97
103
|
@user = user
|
98
104
|
@password = password
|
99
105
|
|
100
|
-
|
101
|
-
|
106
|
+
proof
|
107
|
+
end
|
108
|
+
|
109
|
+
def proof
|
110
|
+
# hash this to generate client proof, H(H(N) xor H(G) | H(userHash) | salt | A | B | K)
|
111
|
+
Warchat::ByteString.new digest_str(hN_xor_hG+digest_str(user)+salt+a_bytes+b_bytes+session_key)
|
102
112
|
end
|
103
113
|
|
104
114
|
def session_key
|
@@ -116,7 +126,7 @@ module Warchat
|
|
116
126
|
temp << s_bytes[i*2+offset]
|
117
127
|
end
|
118
128
|
|
119
|
-
hash =
|
129
|
+
hash = digest_str(temp)
|
120
130
|
HASH_SIZE.times do |i|
|
121
131
|
@session_key[i*2] = hash[i]
|
122
132
|
end
|
@@ -126,7 +136,7 @@ module Warchat
|
|
126
136
|
temp << s_bytes[i*2+offset+1]
|
127
137
|
end
|
128
138
|
|
129
|
-
hash =
|
139
|
+
hash = digest_str(temp)
|
130
140
|
HASH_SIZE.times do |i|
|
131
141
|
@session_key[i*2+1] = hash[i]
|
132
142
|
end
|
data/lib/warchat/timer.rb
CHANGED
data/lib/warchat/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zachary Gavin
|