warchat 0.0.3 → 0.0.4

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.
@@ -0,0 +1,57 @@
1
+ = Warchat
2
+
3
+ This project aims to create a simple ruby interface for connecting to Blizzard's Mobile Guild Chat.
4
+
5
+ = Features
6
+
7
+ At the moment there is only a very basic set of features, but the main hurdle of
8
+ authenticating with the mobile armory server is mostly solved.
9
+
10
+ * SRP authentication
11
+ * Guild Chat
12
+ * Officer Chat
13
+ * Whispers
14
+ * Presence notifications
15
+
16
+ = Simple Usage example
17
+
18
+ This is a simple chat client that will let you talk in guild chat and receive messages.
19
+
20
+ require 'rubygems'
21
+ require 'warchat'
22
+
23
+ USERNAME = ''
24
+ PASSWORD = ''
25
+ CHARACTER_NAME = ''
26
+ CHARACTER_REALM = ''
27
+
28
+ client = Warchat::Chat::Client.new
29
+
30
+ client.on_establish = Proc.new do |response|
31
+ client.character_name = CHARACTER_NAME
32
+ client.character_realm = CHARACTER_REALM
33
+ client.login
34
+ end
35
+
36
+ client.on_message = Proc.new do |message|
37
+ case message.type
38
+ when Warchat::Chat::Message::CHAT_MSG_TYPE_GUILD_CHAT
39
+ puts "[Guild] #{message.character_name}: #{message.body}"
40
+ when Warchat::Chat::Message::CHAT_MSG_TYPE_GUILD_MOTD
41
+ puts "MOTD: #{message.body}"
42
+ when Warchat::Chat::Message::CHAT_MSG_TYPE_OFFICER_CHAT
43
+ puts "[Officer] #{message.character_name}: #{message.body}"
44
+ when Warchat::Chat::Message::CHAT_MSG_TYPE_WHISPER
45
+ puts "[Whisper] #{message.character_name}: #{message.body}"
46
+ end
47
+ end
48
+
49
+ begin
50
+ client.start(USERNAME,PASSWORD)
51
+ loop do
52
+ msg = gets.chomp
53
+ client.message msg,Warchat::Chat::Message::CHAT_MSG_TYPE_GUILD_CHAT
54
+ end
55
+ rescue Interrupt => e
56
+ client.close
57
+ end
@@ -4,4 +4,4 @@ require 'andand'
4
4
  module Warchat
5
5
  end
6
6
 
7
- [['*.rb'],['network','*.rb'],['srp','*.rb'],['chat','*.rb']].each do |p| Dir.glob(File.join(File.expand_path('../wow_chat',__FILE__)),*p).each &method(:require) end
7
+ [['*.rb'],['network','*.rb'],['srp','*.rb'],['chat','*.rb']].each do |p| Dir.glob(File.join(File.expand_path('../warchat',__FILE__),*p)).each &method(:require) end
@@ -1,4 +1,5 @@
1
- module Warchat module Chat
1
+ module Warchat
2
+ module Chat
2
3
  module ChatResponse
3
4
  def presence?
4
5
  chat_type == 'wow_presence'
@@ -62,17 +62,21 @@ module Warchat
62
62
  on_message.andand.call(message)
63
63
  send("on_message_#{message.type}".to_sym).andand.call(message)
64
64
  elsif response.presence?
65
- puts
66
65
  on_presence.andand.call(Presence.new(response))
67
66
  else
68
67
  puts "unhandled chat type: #{response.chat_type}"
69
68
  end
70
69
  end
71
70
 
72
- def close
71
+ def close_nonblock
73
72
  request = Warchat::Network::Request.new("/chat-logout",:chatSessionId=>@chat_session_id)
74
73
  session.send_request(request)
75
74
  end
75
+
76
+ def close
77
+ close_nonblock
78
+ sleep(0.1) until session.is_closed?
79
+ end
76
80
 
77
81
  def keep_alive
78
82
  request = Warchat::Network::Request("/ah-mail")
@@ -12,7 +12,7 @@ module Warchat
12
12
  CHAT_MSG_TYPE_OFFICER_CHAT = "officer_chat"
13
13
  CHAT_MSG_TYPE_WHISPER = "whisper"
14
14
 
15
- attr_reader :type,:body,:from_type,:character_id
15
+ attr_reader :type,:body,:from_type,:character_id,:from
16
16
 
17
17
  def initialize response
18
18
  @type = response["messageType"]
@@ -21,7 +21,6 @@ module Warchat
21
21
  if @from
22
22
  @from_type = from["chatIdType"]
23
23
  @character_id = from["characterId"]
24
- @character_name = from['characterName']
25
24
  end
26
25
  end
27
26
 
@@ -38,7 +38,7 @@ module Warchat
38
38
  @closed = true
39
39
  @socket.close
40
40
  end
41
- [@request_thread,@response_thread].each &:join
41
+ ([@request_thread,@response_thread]-[Thread.current]).each &:join
42
42
  end
43
43
 
44
44
  def is_closed?
@@ -42,7 +42,11 @@ module Warchat
42
42
  end
43
43
 
44
44
  def close reason=''
45
- @connection.andand.close reason
45
+ @connection.close reason
46
+ end
47
+
48
+ def is_closed?
49
+ @connection.is_closed?
46
50
  end
47
51
 
48
52
  def send_request request
@@ -1,3 +1,3 @@
1
1
  module Warchat
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Zachary Gavin
@@ -60,6 +60,7 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - .gitignore
62
62
  - Gemfile
63
+ - README.rdoc
63
64
  - Rakefile
64
65
  - lib/warchat.rb
65
66
  - lib/warchat/byte_string.rb