Skip to content

Commit 994206c

Browse files
committed
Fix connect to remote 2.0 servers (used to only work in local)
1 parent 875ce6b commit 994206c

File tree

13 files changed

+362
-107
lines changed

13 files changed

+362
-107
lines changed

Gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6+
7+
gemspec

Gemfile.lock

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
PATH
2+
remote: .
3+
specs:
4+
wired (0.0.2)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
bindata (2.4.4)
10+
deep_clone (0.0.1)
11+
diff-lcs (1.3)
12+
little-plugger (1.1.4)
13+
logging (1.8.2)
14+
little-plugger (>= 1.1.3)
15+
multi_json (>= 1.8.4)
16+
mini_portile2 (2.4.0)
17+
multi_json (1.13.1)
18+
nokogiri (1.10.3)
19+
mini_portile2 (~> 2.4.0)
20+
openssl (2.1.2)
21+
pr-zlib (1.0.6)
22+
rspec (2.99.0)
23+
rspec-core (~> 2.99.0)
24+
rspec-expectations (~> 2.99.0)
25+
rspec-mocks (~> 2.99.0)
26+
rspec-core (2.99.2)
27+
rspec-expectations (2.99.2)
28+
diff-lcs (>= 1.1.3, < 2.0)
29+
rspec-mocks (2.99.4)
30+
timers (1.1.0)
31+
zlib (1.0.0)
32+
33+
PLATFORMS
34+
ruby
35+
36+
DEPENDENCIES
37+
bindata (~> 2.4.4)
38+
deep_clone (~> 0.0.1)
39+
logging (~> 1.8, >= 1.8.1)
40+
nokogiri (~> 1.5, >= 1.5.5)
41+
openssl (~> 2.1.2)
42+
pr-zlib (~> 1.0.6)
43+
rspec (~> 2.13, >= 2.13.0)
44+
timers (~> 1.1, >= 1.1.0)
45+
wired!
46+
zlib (~> 1.0.0)
47+
48+
BUNDLED WITH
49+
1.17.3

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ And run:
8888

8989
Have a look to `bin/rwire` code, rspec test cases and the source code for more examples.
9090

91+
## RWire example
92+
93+
bin/rwire connect example.org:4875 -l admin -p ********
94+
9195
## Contribute
9296

9397
Of course, every contributions are welcome, do not hesitate to commit pull-requests.

bin/rwire

+28-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env ruby
2-
32
require 'curses'
4-
require "./lib/wired"
3+
require './lib/wired'
54
require 'thor'
65

76

@@ -64,6 +63,18 @@ class Window
6463
message.add_parameter("wired.chat.id", 1)
6564
message.add_parameter("wired.chat.topic.topic", reststring)
6665

66+
elsif string.start_with? "/nick"
67+
@client.nick = reststring
68+
@client.set_nick
69+
70+
elsif string.start_with? "/status"
71+
@client.status = reststring
72+
@client.set_status
73+
74+
elsif string.start_with? "/icon"
75+
@client.icon = reststring
76+
@client.set_icon
77+
6778
end
6879
else
6980
message = Wired::Message.new(:name => "wired.chat.send_say", :spec => @client.spec)
@@ -84,7 +95,7 @@ class Window
8495
def draw_text_field
8596
setpos(divider_line, 0)
8697
attron(color_pair(COLOR_WHITE) | A_NORMAL) do
87-
addstr("#" * cols)
98+
addstr("_" * cols)
8899
end
89100

90101
cursor_to_input_line
@@ -122,23 +133,26 @@ end
122133

123134

124135
class RWire < Thor
125-
desc "connect <hostname:port> <username> <password>", "Connect to a Wired 2.0 server"
136+
desc "connect <hostname> [OPTIONS]", "Connect to a Wired 2.0 server"
126137
long_desc <<-LONGDESC
127138
RWire is a lightweight Wired 2.0 client written in Ruby.
128139
129-
With --nick option, you can specify your user nickname in the public chat.
130-
131-
With --status option, you can specify your user status in the public chat.
132-
133140
Copyright © 2015, Rafaël Warnault <[email protected]>. All rights reserved.
134141
LONGDESC
135142

136143

137-
option :nick, :type => :string, :default => "RWire Client", :banner => "<nick>"
138-
option :status, :type => :string, :default => "Red Ruby", :banner => "<status>"
144+
method_option :login, :aliases => "-l", :type => :string, :desc => "User login", :banner => "<login>", :default => "guest"
145+
method_option :password, :aliases => "-p", :type => :string, :desc => "User password", :banner => "<password>"
146+
method_option :port, :aliases => "-P", :type => :string, :desc => "Server port", :banner => "<port>", :default => "4871"
147+
method_option :nick, :aliases => "-n", :type => :string, :desc => "User nickname", :banner => "<nick>", :default => "RWire Client"
148+
method_option :status, :aliases => "-s", :type => :string, :desc => "User status", :banner => "<status>"
149+
method_option :icon, :aliases => "-i", :type => :string, :desc => "User icon", :banner => "/path/to/image"
139150

151+
def connect(hostname)
152+
login = options[:login] || "guest"
153+
password = options[:password] || ""
154+
port = options[:port] || "4871"
140155

141-
def connect(hostname, login="guest", password="")
142156
# Logging setup (remove stdout and add rwire.log file)
143157
Wired::Log.remove_appenders Logging.appenders.stdout
144158
Wired::Log.add_appenders Logging.appenders.file('log/rwire.log')
@@ -148,10 +162,10 @@ class RWire < Thor
148162
spec = Wired::Spec.new
149163

150164
# Create a Wired Url object pointing to "localhost"
151-
url = Wired::Url.new "wired://admin@localhost"
165+
url = Wired::Url.new "wired://#{login}:#{password}@#{hostname}:#{port}"
152166

153167
# Create a Client object against the specification
154-
client = Wired::Client.new spec
168+
client = Wired::Client.new(spec, options)
155169

156170
# Handle interupt properly
157171
#Kernel.trap("INT") { client.disconnect }
@@ -164,7 +178,7 @@ class RWire < Thor
164178

165179
begin
166180
window.start
167-
rescue Interrupt
181+
rescue Interrupt => e
168182
client.disconnect
169183
warn "\nYou have been disconnected from #{client.server.name}"
170184
exit 1

database.sqlite3

116 KB
Binary file not shown.

lib/wired.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require_relative 'wired/cipher'
22
require_relative 'wired/client'
3+
require_relative 'wired/icon'
34
require_relative 'wired/logger'
45
require_relative 'wired/message'
56
require_relative 'wired/server'

lib/wired/client.rb

+58-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def initialize(spec, options = {})
2323
@spec = spec
2424
@nick = options[:nick] || "Ruby Wired Client"
2525
@status = options[:status] || "Ruby version " + RUBY_VERSION
26+
@icon = options[:icon] || nil
2627
@options = options
2728
@listeners = []
2829
@users = []
@@ -45,7 +46,7 @@ def connect(url, listener = nil)
4546

4647
@socket = Wired::Socket.new(@url.hostname, @spec, options)
4748
if @socket.connect
48-
if client_info and login
49+
if client_info and set_user and login
4950
if listener
5051
@listeners << listener
5152
listen
@@ -95,8 +96,40 @@ def join_chat(chat_id)
9596

9697

9798

98-
def destroy
99+
def set_nick
100+
message = Wired::Message.new(:spec => @spec, :name => "wired.user.set_nick")
101+
message.add_parameter("wired.user.nick", @nick)
99102

103+
send_message message
104+
message = @socket.read
105+
end
106+
107+
108+
def set_status
109+
message = Wired::Message.new(:spec => @spec, :name => "wired.user.set_status")
110+
message.add_parameter("wired.user.status", @status)
111+
112+
send_message message
113+
message = @socket.read
114+
end
115+
116+
117+
def set_icon
118+
new_icon = nil
119+
120+
if @icon != nil
121+
new_icon = Wired::Icon.new path: options[:icon]
122+
else
123+
new_icon = Wired::Icon.new string: $default_icon
124+
end
125+
126+
Wired::Log.info new_icon.string
127+
128+
message = Wired::Message.new(:spec => @spec, :name => "wired.user.set_icon")
129+
message.add_parameter("wired.user.icon", new_icon.to_bin)
130+
131+
send_message message
132+
message = @socket.read
100133
end
101134

102135

@@ -256,16 +289,19 @@ def client_info
256289
message = Wired::Message.new(:spec => @spec, :name => "wired.client_info")
257290

258291
message.add_parameters({
259-
"wired.info.application.name" => "Wired Ruby",
260-
"wired.info.application.version" => "0.1",
261-
"wired.info.application.build" => "0",
262-
"wired.info.os.name" => "OSX",
263-
"wired.info.os.version" => "10.8",
264-
"wired.info.arch" => "x86_64",
265-
"wired.info.supports_rsrc" => "false"
266-
})
292+
"wired.info.application.name" => "Wired Ruby",
293+
"wired.info.application.version" => "0.1",
294+
"wired.info.application.build" => "1",
295+
"wired.info.os.name" => "macOS",
296+
"wired.info.os.version" => "10.8",
297+
"wired.info.arch" => "x86_64",
298+
"wired.info.supports_rsrc" => "false"
299+
})
300+
301+
send_message message
302+
303+
sleep 1
267304

268-
send_message message
269305
message = @socket.read
270306

271307
@server = Wired::Server.new message if message
@@ -275,6 +311,8 @@ def client_info
275311

276312

277313
def login
314+
puts "login"
315+
278316
message = Wired::Message.new(:spec => @spec, :name => "wired.send_login")
279317

280318
if @url.login && @url.login.size > 0
@@ -292,5 +330,14 @@ def login
292330
send_message message
293331
message = @socket.read
294332
end
333+
334+
335+
def set_user
336+
puts "set_user"
337+
338+
set_nick
339+
set_status
340+
set_icon
341+
end
295342
end
296343
end

lib/wired/icon.rb

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
require 'base64'
2+
3+
$default_icon = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr
4+
0AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJ
5+
qcGAAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAA
6+
Dx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0
7+
YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICA
8+
gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3Ln
9+
czLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjI
10+
j4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJv
11+
dXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR
12+
0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogIC
13+
AgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmO
14+
k9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlw
15+
dGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4
16+
KTMInWQAACCdJREFUWAntVmuMVGcZfs53bnO/7czO7D
17+
Iss7DQcsdKu1RssYXEpmpsU4mxRrGYoOkvo8SY6B9Nj
18+
YkYIjb+MobQP8ZgIcQixVagFVqX+wLCXplZd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WPIL3L51ATa+C1yWU63UYpFbsJO
65+
8zeEvcm7gCjNnO0s5/i33RFgIgaJq2cnxkfF0hX1h4r
66+
fjPzVan8rml4eVY1mEbDNtJTAZryDTTmGjSyC2fxcXM
67+
aQIwhEIlD54yn7dEKFULjaqBVsuCQSE08rgpHAp+W5j
68+
mLmTqGeKxzXbb7lwOEAs63RnctWtXheOEDSGXX64WLT
69+
bIf/j0dek0GuUSMmoaN5UUchqNW1ZGxM2j6LTgp27oC
70+
/jp35BF45eIFDWoZLhVN2DOcBXxhGePfMOVMWXq0fOM
71+
2wjmGLAvZsVOuTgNjKU8pD7vc+aX+74rbImtlgROIwp
72+
Mymr6OGnCyWRYo1KxY6/R2GvQACpRvRcrGkoVHY1RZN
73+
lbnt+LQ67jmq+ZzGazKdJ9pw3SxT2zgO7Z8WlEohHT6
74+
XKI3KinWL7M1TXe7HTEeLfDI0ASCR4B0Cl3Lbu5EPUG
75+
zYKmpqNa01FMGWbthDAoHPDv42/JH+re1jgZv/Gfxun
76+
6vgzY99sSDAb9oigmWENcRvSuEj+lPuHbqK30PcJFHV
77+
EmSV76i8JzMDULSt5AKWWUq4MYa51xnGIT4geCzA3Xr
78+
NpEuUzxm5d4s+rbh/uFYP7z9nkikXDUarUgl5NiRE/c
79+
6NB6WJfZJQRNHydZzGxyDT3PT5tpMSXUpBRtuuVJcMV
80+
UKkWd5KPloQA8QAXt3UpJYct+O7nmSqt965Ofh2TgX4
81+
k6d3UEBImrAAAAAElFTkSuQmCC"
82+
83+
module Wired
84+
class Icon
85+
attr_accessor :path
86+
attr_accessor :string
87+
88+
def initialize(options = {})
89+
@path = options[:path]
90+
@string = options[:string] || $default_icon
91+
92+
@string = Base64.strict_encode64(File.open(@path, "rb").read).to_s if @path
93+
end
94+
95+
96+
def to_b64
97+
return @string if @string
98+
return nil
99+
end
100+
101+
102+
def to_bin
103+
@string.unpack('m*')[0]
104+
end
105+
end
106+
end

0 commit comments

Comments
 (0)