libfchat 0.1.4 → 0.1.5
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 +52 -3
- data/lib/libfchat/version.rb +1 -1
- metadata +1 -1
data/lib/libfchat/fchat.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# This file contains an object designed for writing bots/clients for fchat
|
2
|
+
|
1
3
|
module Libfchat
|
2
4
|
begin
|
3
5
|
require 'rubygems'
|
@@ -17,11 +19,18 @@ module Libfchat
|
|
17
19
|
attr_reader :version
|
18
20
|
attr_reader :clientname
|
19
21
|
|
22
|
+
##
|
23
|
+
# Initialize the object with the name and version.
|
24
|
+
# Default to just identifying as the library
|
25
|
+
|
20
26
|
def initialize(clientname="libfchat-ruby by Jippen Faddoul ( http://github.com/jippen/libfchat-ruby )",version=Libfchat::VERSION)
|
21
27
|
@clientname = clientname
|
22
28
|
@version = version
|
23
29
|
end
|
24
30
|
|
31
|
+
##
|
32
|
+
# Login to fchat as a specific user, and start the event machine
|
33
|
+
|
25
34
|
def login(server,account,password,character,timeout=30)
|
26
35
|
webapi = Libfchat::WebAPI.new
|
27
36
|
@ticket = webapi.get_ticket(account,password)
|
@@ -31,16 +40,56 @@ module Libfchat
|
|
31
40
|
self.http.errback { puts "Could not connect to " + server }
|
32
41
|
self.http.callback {
|
33
42
|
puts "Websocket connected"
|
34
|
-
self.
|
43
|
+
self.send_IDN(account,character,ticket)
|
35
44
|
}
|
36
45
|
|
37
46
|
self.http.stream { |msg|
|
38
|
-
puts "
|
47
|
+
puts "#{msg[0,3]}: #{msg[4,-1]}"
|
48
|
+
self.send(msg[0,3].upcase,MultiJson.load(msg[4,-1]))
|
39
49
|
}
|
40
50
|
}
|
41
51
|
end
|
42
52
|
|
43
|
-
|
53
|
+
##
|
54
|
+
# Some method_missing magic to make ruby handle just throwing around
|
55
|
+
# commands that may or may not exist.
|
56
|
+
|
57
|
+
def method_missing(method_name, *args, &block)
|
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
|
64
|
+
end
|
65
|
+
|
66
|
+
# ====================================================== #
|
67
|
+
# All commands that can be sent by a client have helpers #
|
68
|
+
# ====================================================== #
|
69
|
+
|
70
|
+
##
|
71
|
+
# Performs an account ban against a characters account.
|
72
|
+
# *This command requires chat op or higher.*
|
73
|
+
|
74
|
+
def send_ACB(character)
|
75
|
+
json = { :character => character }
|
76
|
+
self.http.send( "ACB " + MultiJSON.dump(json) )
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Adds a character to the chat operator list.
|
81
|
+
# *This command is admin only.*
|
82
|
+
|
83
|
+
def send_AOP(character)
|
84
|
+
json = { :character => character }
|
85
|
+
self.http.send( "AOP " + MultiJSON.dump(json) )
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# This command is used to identify with the server.
|
90
|
+
# NOTE: If you send any commands before identifying, you will be disconnected.
|
91
|
+
|
92
|
+
def send_IDN(account,character,ticket,cname=@clientname,cversion=@version,method="ticket")
|
44
93
|
# Initial identification with the server
|
45
94
|
json = {:account => account,
|
46
95
|
:character => character,
|
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.1.
|
5
|
+
VERSION = "0.1.5" unless defined?(::Libfchat::VERSION)
|
6
6
|
end
|