libfchat 0.1.5 → 0.2.0
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/lib/libfchat/fchat.rb +53 -34
- data/lib/libfchat/version.rb +1 -1
- metadata +4 -4
data/lib/libfchat/fchat.rb
CHANGED
@@ -7,14 +7,14 @@ module Libfchat
|
|
7
7
|
#I don't actually NEED rubygems, unless on 1.8
|
8
8
|
end
|
9
9
|
require 'multi_json'
|
10
|
+
require 'faye/websocket'
|
10
11
|
require 'eventmachine'
|
11
|
-
require 'em-http-request'
|
12
12
|
require 'libfchat/version'
|
13
13
|
require 'libfchat/webapi'
|
14
14
|
|
15
15
|
class Fchat
|
16
16
|
attr_reader :ticket
|
17
|
-
attr_accessor :
|
17
|
+
attr_accessor :websocket
|
18
18
|
|
19
19
|
attr_reader :version
|
20
20
|
attr_reader :clientname
|
@@ -28,6 +28,21 @@ module Libfchat
|
|
28
28
|
@version = version
|
29
29
|
end
|
30
30
|
|
31
|
+
##
|
32
|
+
# Some method_missing magic to make ruby handle just throwing around
|
33
|
+
# commands that may or may not exist.
|
34
|
+
|
35
|
+
def method_missing(method_name, *args, &block)
|
36
|
+
puts "Method_missing: #{method_name}"
|
37
|
+
# Try to handle all three-letter strings
|
38
|
+
puts "Trying to parse |#{method_name.to_s[0,3]}|"
|
39
|
+
if method_name.to_s[0,3] == method_name.to_s
|
40
|
+
puts "Dunno how to handle #{method_name.to_s}"
|
41
|
+
else
|
42
|
+
#super(method_name,*args,&block)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
31
46
|
##
|
32
47
|
# Login to fchat as a specific user, and start the event machine
|
33
48
|
|
@@ -35,34 +50,32 @@ module Libfchat
|
|
35
50
|
webapi = Libfchat::WebAPI.new
|
36
51
|
@ticket = webapi.get_ticket(account,password)
|
37
52
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
53
|
+
EM.run {
|
54
|
+
@websocket = Faye::WebSocket::Client.new(server)
|
55
|
+
|
56
|
+
@websocket.onopen = lambda do |event|
|
42
57
|
puts "Websocket connected"
|
43
|
-
self.
|
44
|
-
|
58
|
+
self.send('IDN',account,character,ticket)
|
59
|
+
puts "Authentication sent"
|
60
|
+
end
|
61
|
+
|
62
|
+
@websocket.onclose = lambda do |event|
|
63
|
+
@websocket = nil
|
64
|
+
end
|
45
65
|
|
46
|
-
|
47
|
-
puts "
|
48
|
-
|
49
|
-
}
|
66
|
+
@websocket.onmessage = lambda do |event|
|
67
|
+
puts "<< #{event.data}"
|
68
|
+
end
|
50
69
|
}
|
51
70
|
end
|
52
71
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
# Try to handle all three-letter strings
|
59
|
-
if method_name.to_s[0,3] == method_name.to_s
|
60
|
-
puts "Dunno how to handle #{method_name.to_s}"
|
61
|
-
else
|
62
|
-
super(method_name,*args,&block)
|
63
|
-
end
|
72
|
+
def send_message(type,json)
|
73
|
+
jsonstr = ::MultiJson.dump(json)
|
74
|
+
msg = "#{type} #{jsonstr}"
|
75
|
+
puts ">> #{msg}"
|
76
|
+
@websocket.send(msg)
|
64
77
|
end
|
65
|
-
|
78
|
+
|
66
79
|
# ====================================================== #
|
67
80
|
# All commands that can be sent by a client have helpers #
|
68
81
|
# ====================================================== #
|
@@ -71,33 +84,39 @@ module Libfchat
|
|
71
84
|
# Performs an account ban against a characters account.
|
72
85
|
# *This command requires chat op or higher.*
|
73
86
|
|
74
|
-
def
|
87
|
+
def ACB(character)
|
75
88
|
json = { :character => character }
|
76
|
-
self.
|
89
|
+
self.send('send_message','ACB',json)
|
77
90
|
end
|
78
91
|
|
79
92
|
##
|
80
93
|
# Adds a character to the chat operator list.
|
81
94
|
# *This command is admin only.*
|
82
95
|
|
83
|
-
def
|
96
|
+
def AOP(character)
|
84
97
|
json = { :character => character }
|
85
|
-
self.
|
98
|
+
self.send('send_message','AOP',json)
|
86
99
|
end
|
87
100
|
|
88
101
|
##
|
89
102
|
# This command is used to identify with the server.
|
90
|
-
# NOTE: If you send any commands before identifying, you will be
|
91
|
-
|
92
|
-
|
103
|
+
# NOTE: If you send any commands before identifying, you will be
|
104
|
+
# disconnected.
|
105
|
+
|
106
|
+
def IDN(account,
|
107
|
+
character,
|
108
|
+
ticket,
|
109
|
+
cname=@clientname,
|
110
|
+
cversion=@version,
|
111
|
+
method="ticket")
|
93
112
|
# Initial identification with the server
|
94
113
|
json = {:account => account,
|
95
114
|
:character => character,
|
96
|
-
:ticket => ticket,
|
115
|
+
:ticket => ticket['ticket'],
|
97
116
|
:cname => cname,
|
98
117
|
:cversion => cversion,
|
99
|
-
:method => ticket}
|
100
|
-
self.
|
118
|
+
:method => 'ticket'}
|
119
|
+
self.send('send_message','IDN',json)
|
101
120
|
end
|
102
121
|
|
103
122
|
|
data/lib/libfchat/version.rb
CHANGED
@@ -2,5 +2,5 @@ module Libfchat
|
|
2
2
|
# We're doing this because we might write tests that deal
|
3
3
|
# with other versions of Libfchat and we are unsure how to
|
4
4
|
# handle this better.
|
5
|
-
VERSION = "0.
|
5
|
+
VERSION = "0.2.0" unless defined?(::Libfchat::VERSION)
|
6
6
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libfchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -60,13 +60,13 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.3.6
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: faye-websocket
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 0.4.6
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
77
|
+
version: 0.4.6
|
78
78
|
description: A library for connecting to F-chat ( http://f-list.net )
|
79
79
|
email: cheetahmorph@gmail.com
|
80
80
|
executables: []
|