Call chunks messages (closed #6)
This commit is contained in:
parent
aadb67f39c
commit
6cad2f6bbc
|
@ -21,14 +21,16 @@ client.connect('localhost', 8303, detach: true)
|
|||
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
TODO: generated documentation
|
||||
context.message is a [MaplistEntryAdd](../classes/messages/MaplistEntryAdd.md)
|
||||
|
||||
**Example:**
|
||||
```ruby
|
||||
client = TeeworldsClient.new
|
||||
|
||||
client.on_maplist_entry_add do |context|
|
||||
# TODO: generated documentation
|
||||
# print all map names the server
|
||||
# sends to the client
|
||||
puts context.message.name
|
||||
end
|
||||
|
||||
client.connect('localhost', 8303, detach: true)
|
||||
|
@ -38,14 +40,16 @@ client.connect('localhost', 8303, detach: true)
|
|||
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
TODO: generated documentation
|
||||
context.message is a [MaplistEntryRem](../classes/messages/MaplistEntryRem.md)
|
||||
|
||||
**Example:**
|
||||
```ruby
|
||||
client = TeeworldsClient.new
|
||||
|
||||
client.on_rcon_cmd_rem do |context|
|
||||
# TODO: generated documentation
|
||||
client.on_maplist_entry_rem do |context|
|
||||
# print all map names the server
|
||||
# sends to the client
|
||||
puts context.message.name
|
||||
end
|
||||
|
||||
client.connect('localhost', 8303, detach: true)
|
||||
|
|
5
docs/v0.0.1/classes/messages/MaplistEntryAdd.md
Normal file
5
docs/v0.0.1/classes/messages/MaplistEntryAdd.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# MaplistEntryAdd
|
||||
|
||||
Server -> Client
|
||||
|
||||
### @name [String]
|
5
docs/v0.0.1/classes/messages/MaplistEntryRem.md
Normal file
5
docs/v0.0.1/classes/messages/MaplistEntryRem.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# MaplistEntryRem
|
||||
|
||||
Server -> Client
|
||||
|
||||
### @name [String]
|
17
examples/10_maplist.rb
Executable file
17
examples/10_maplist.rb
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new
|
||||
|
||||
client.on_connected do |_|
|
||||
client.rcon_auth(password: 'rcon')
|
||||
end
|
||||
|
||||
client.on_maplist_entry_add do |ctx|
|
||||
puts ctx.message.name
|
||||
end
|
||||
|
||||
# connect and block main thread
|
||||
client.connect('localhost', 8303, detach: false)
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
class Context
|
||||
attr_reader :old_data
|
||||
attr_accessor :data, :todo_rename_this
|
||||
attr_accessor :data, :message
|
||||
|
||||
def initialize(todo_rename_this, keys = {})
|
||||
@todo_rename_this = todo_rename_this # the obj holding the parsed chunk
|
||||
def initialize(message, keys = {})
|
||||
@message = message # the obj holding the parsed chunk
|
||||
@cancel = false
|
||||
@old_data = keys
|
||||
@data = keys
|
||||
|
|
|
@ -52,35 +52,27 @@ class GameClient
|
|||
end
|
||||
|
||||
def on_rcon_cmd_add(chunk)
|
||||
todo_rename_this = RconCmdAdd.new(chunk.data[1..])
|
||||
context = Context.new(todo_rename_this)
|
||||
return if call_hook(:rcon_cmd_add, context).nil?
|
||||
|
||||
p context.todo_rename_this
|
||||
message = RconCmdAdd.new(chunk.data[1..])
|
||||
context = Context.new(message)
|
||||
call_hook(:rcon_cmd_add, context)
|
||||
end
|
||||
|
||||
def on_rcon_cmd_rem(chunk)
|
||||
todo_rename_this = RconCmdRem.new(chunk.data[1..])
|
||||
context = Context.new(todo_rename_this)
|
||||
return if call_hook(:rcon_cmd_rem, context).nil?
|
||||
|
||||
p context.todo_rename_this
|
||||
message = RconCmdRem.new(chunk.data[1..])
|
||||
context = Context.new(message)
|
||||
call_hook(:rcon_cmd_rem, context)
|
||||
end
|
||||
|
||||
def on_maplist_entry_add(chunk)
|
||||
todo_rename_this = MaplistEntryAdd.new(chunk.data[1..])
|
||||
context = Context.new(todo_rename_this)
|
||||
return if call_hook(:maplist_entry_add, context).nil?
|
||||
|
||||
p context.todo_rename_this
|
||||
message = MaplistEntryAdd.new(chunk.data[1..])
|
||||
context = Context.new(message)
|
||||
call_hook(:maplist_entry_add, context)
|
||||
end
|
||||
|
||||
def on_maplist_entry_rem(chunk)
|
||||
todo_rename_this = MaplistEntryRem.new(chunk.data[1..])
|
||||
context = Context.new(todo_rename_this)
|
||||
return if call_hook(:maplist_entry_rem, context).nil?
|
||||
|
||||
p context.todo_rename_this
|
||||
message = MaplistEntryRem.new(chunk.data[1..])
|
||||
context = Context.new(message)
|
||||
call_hook(:maplist_entry_rem, context)
|
||||
end
|
||||
|
||||
def on_client_info(chunk)
|
||||
|
@ -113,20 +105,20 @@ class GameClient
|
|||
end
|
||||
|
||||
def on_input_timing(chunk)
|
||||
todo_rename_this = InputTiming.new(chunk.data[1..])
|
||||
context = Context.new(todo_rename_this, chunk:)
|
||||
message = InputTiming.new(chunk.data[1..])
|
||||
context = Context.new(message, chunk:)
|
||||
call_hook(:input_timing, context)
|
||||
end
|
||||
|
||||
def on_client_drop(chunk)
|
||||
todo_rename_this = SvClientDrop.new(chunk.data[1..])
|
||||
message = SvClientDrop.new(chunk.data[1..])
|
||||
context = Context.new(
|
||||
nil,
|
||||
player: @players[todo_rename_this.client_id],
|
||||
player: @players[message.client_id],
|
||||
chunk:,
|
||||
client_id: todo_rename_this.client_id,
|
||||
reason: todo_rename_this.reason,
|
||||
silent: todo_rename_this.silent?
|
||||
client_id: message.client_id,
|
||||
reason: message.reason,
|
||||
silent: message.silent?
|
||||
)
|
||||
return if call_hook(:client_drop, context).nil?
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ class GameServer
|
|||
end
|
||||
|
||||
def on_emoticon(chunk, _packet)
|
||||
todo_rename_this = ClEmoticon.new(chunk.data[1..])
|
||||
p todo_rename_this
|
||||
message = ClEmoticon.new(chunk.data[1..])
|
||||
p message
|
||||
end
|
||||
|
||||
def on_info(chunk, packet)
|
||||
|
|
Loading…
Reference in a new issue