Layout server control msg structure
Thus closed #5 By deciding to support server as well. This is rebranding from teeworlds-client to teeworlds_network And thus also including a bunch of file renames
This commit is contained in:
parent
3a39d3f9f8
commit
6c005497d4
|
@ -1,5 +1,5 @@
|
|||
# teeworlds-client
|
||||
A teeworlds 0.7 client library written in ruby
|
||||
# teeworlds_network
|
||||
A teeworlds 0.7 client & server library written in ruby
|
||||
|
||||
## Sample
|
||||
|
||||
|
@ -11,7 +11,7 @@ Also properly disconnect when the program is killed gracefully.
|
|||
For more sample usages checkout the [examples/](examples/) folder.
|
||||
|
||||
```ruby
|
||||
require_relative 'lib/teeworlds-client'
|
||||
require_relative 'lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new(verbose: false)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'lib/teeworlds-client'
|
||||
require_relative 'lib/teeworlds_client'
|
||||
|
||||
args = { verbose: false, ip: nil, port: nil }
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
# Print all incoming chat messages to stdout
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new(verbose: false)
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
# Prints out all network traffic
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new(verbose: true)
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
# Chat spamming client
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new(verbose: true)
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
# Set custom skin and other player infos
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new(verbose: true)
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#
|
||||
# Then connect to localhost and write !ping in the chat
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new(verbose: false)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new(verbose: false)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../lib/teeworlds-client'
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new(verbose: false)
|
||||
|
||||
|
|
|
@ -7,4 +7,8 @@ class NetAddr
|
|||
@ip = ip
|
||||
@port = port
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{@ip}:#{@port}"
|
||||
end
|
||||
end
|
||||
|
|
1
lib/teeworlds-client.rb → lib/teeworlds_client.rb
Executable file → Normal file
1
lib/teeworlds-client.rb → lib/teeworlds_client.rb
Executable file → Normal file
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'socket'
|
4
lib/teeworlds_network.rb
Normal file
4
lib/teeworlds_network.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'teeworlds_server'
|
||||
require_relative 'teeworlds_client'
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'socket'
|
||||
|
@ -47,6 +46,9 @@ class TeeworldsServer
|
|||
puts "got ctrl msg: #{msg}"
|
||||
case msg
|
||||
when NET_CTRLMSG_TOKEN then on_ctrl_token(packet)
|
||||
when NET_CTRLMSG_CONNECT then on_ctrl_connect(packet)
|
||||
when NET_CTRLMSG_KEEPALIVE then on_ctrl_keep_alive(packet)
|
||||
when NET_CTRLMSG_CLOSE then on_ctrl_close(packet)
|
||||
else
|
||||
puts "Uknown control message #{msg}"
|
||||
exit(1)
|
||||
|
@ -65,6 +67,18 @@ class TeeworldsServer
|
|||
send_ctrl_with_token(packet.addr, token)
|
||||
end
|
||||
|
||||
def on_ctrl_keep_alive(packet)
|
||||
puts "Got keep alive from #{packet.addr}" if @verbose
|
||||
end
|
||||
|
||||
def on_ctrl_close(packet)
|
||||
puts "Client closed the connection #{packet.addr}"
|
||||
end
|
||||
|
||||
def on_ctrl_connect(packet)
|
||||
puts "Got connect from #{packet.addr}"
|
||||
end
|
||||
|
||||
def on_packet(packet)
|
||||
# process connless packets data
|
||||
if packet.flags_control
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'lib/srv'
|
||||
require_relative 'lib/teeworlds_server'
|
||||
|
||||
srv = TeeworldsServer.new(verbose: false)
|
||||
srv.run('127.0.0.1', 8303)
|
|
@ -3,12 +3,12 @@
|
|||
require 'rake'
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'teeworlds-client'
|
||||
s.name = 'teeworlds_network'
|
||||
s.version = '0.0.1'
|
||||
s.summary = 'teeworlds 0.7 network protocol (client)'
|
||||
s.summary = 'teeworlds 0.7 network protocol (client and server)'
|
||||
s.description = <<-DESC
|
||||
A library wrapping the network protocol of the game teeworlds.
|
||||
Supported protocol version 0.7 and only the client side.
|
||||
Only supporting the version 0.7 of the teeworlds protocol.
|
||||
DESC
|
||||
s.authors = ['ChillerDragon']
|
||||
s.email = 'ChillerDragon@gmail.com'
|
||||
|
@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|||
s.required_ruby_version = '>= 3.1.2'
|
||||
s.add_dependency 'huffman_tw', '~> 0.0.1'
|
||||
s.add_dependency 'rspec', '~> 3.9.0'
|
||||
s.homepage = 'https://github.com/ChillerDragon/teeworlds-client'
|
||||
s.homepage = 'https://github.com/ChillerDragon/teeworlds_network'
|
||||
s.license = 'Unlicense'
|
||||
s.metadata['rubygems_mfa_required'] = 'true'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue