Skip to content

Commit

Permalink
Generate server hooks docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Feb 21, 2024
1 parent a789574 commit 0d52e58
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 4 deletions.
26 changes: 26 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,29 @@ Version v0.0.6
[#send_input(input = {})](classes/TeeworldsClient.md#send_input)

[#on_tick(&block)](classes/TeeworldsClient.md#on_tick)

### [TeeworldsServer](classes/TeeworldsServer.md)

[#on_tick(&block)](classes/TeeworldsServer.md#on_tick)

[#on_client_drop(&block)](classes/TeeworldsServer.md#on_client_drop)

[#on_input(&block)](classes/TeeworldsServer.md#on_input)

[#on_enter_game(&block)](classes/TeeworldsServer.md#on_enter_game)

[#on_start_info(&block)](classes/TeeworldsServer.md#on_start_info)

[#on_ready(&block)](classes/TeeworldsServer.md#on_ready)

[#on_info(&block)](classes/TeeworldsServer.md#on_info)

[#on_emote(&block)](classes/TeeworldsServer.md#on_emote)

[#on_shutdown(&block)](classes/TeeworldsServer.md#on_shutdown)

[#on_rcon_cmd(&block)](classes/TeeworldsServer.md#on_rcon_cmd)

[#on_rcon_auth(&block)](classes/TeeworldsServer.md#on_rcon_auth)

[#on_chat(&block)](classes/TeeworldsServer.md#on_chat)
207 changes: 207 additions & 0 deletions docs/classes/TeeworldsServer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# TeeworldsServer

### <a name="on_tick"></a> #on_tick(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

context.message is nil because there is no message payload.

**Example:**
```ruby
server = TeeworldsServer.new

server.on_tick do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_client_drop"></a> #on_client_drop(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

context.message is a [SvClientDrop](../classes/messages/SvClientDrop.md)

**Example:**
```ruby
server = TeeworldsServer.new

server.on_client_drop do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_input"></a> #on_input(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

TODO: generated documentation

**Example:**
```ruby
server = TeeworldsServer.new

server.on_input do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_enter_game"></a> #on_enter_game(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

TODO: generated documentation

**Example:**
```ruby
server = TeeworldsServer.new

server.on_enter_game do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_start_info"></a> #on_start_info(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

TODO: generated documentation

**Example:**
```ruby
server = TeeworldsServer.new

server.on_start_info do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_ready"></a> #on_ready(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

TODO: generated documentation

**Example:**
```ruby
server = TeeworldsServer.new

server.on_ready do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_info"></a> #on_info(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

TODO: generated documentation

**Example:**
```ruby
server = TeeworldsServer.new

server.on_info do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_emote"></a> #on_emote(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

TODO: generated documentation

**Example:**
```ruby
server = TeeworldsServer.new

server.on_emote do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_shutdown"></a> #on_shutdown(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

TODO: generated documentation

**Example:**
```ruby
server = TeeworldsServer.new

server.on_shutdown do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_rcon_cmd"></a> #on_rcon_cmd(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

TODO: generated documentation

**Example:**
```ruby
server = TeeworldsServer.new

server.on_rcon_cmd do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_rcon_auth"></a> #on_rcon_auth(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

TODO: generated documentation

**Example:**
```ruby
server = TeeworldsServer.new

server.on_rcon_auth do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```

### <a name="on_chat"></a> #on_chat(&block)

**Parameter: block [Block |[context](../classes/Context.md)|]**

context.message is nil because there is no message payload.

**Example:**
```ruby
server = TeeworldsServer.new

server.on_chat do |context|
# TODO: generated documentation
end

server.run('127.0.0.1', 8377)
```


4 changes: 2 additions & 2 deletions lib/game_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def call_hook(hook_sym, context, optional = nil)

def on_emoticon(chunk, _packet)
msg = ClEmoticon.new(chunk.data[1..])
return if call_hook(:emote, Context.new(msg, chunk:, packet:)).nil?
call_hook(:emote, Context.new(msg, chunk:, packet:)).nil?
end

def on_info(chunk, packet)
Expand Down Expand Up @@ -145,7 +145,7 @@ def on_input(chunk, packet)
return if call_hook(:input, Context.new(msg, chunk:, packet:)).nil?

dir = msg.direction
puts "#{packet.client.player.id} tried to move #{dir}" unless dir.zero?
puts "#{packet.client.player.id} tried to move #{dir}" unless dir.zero?
end

def on_client_drop(client, reason = nil)
Expand Down
3 changes: 2 additions & 1 deletion lib/messages/cl_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#
# Client -> Server
class ClInput
attr_accessor :ack_game_tick, :prediction_tick, :size, :direction, :target_x, :target_y, :jump, :fire, :hook, :player_flags, :wanted_weapon, :next_weapon, :prev_weapon, :ping
attr_accessor :ack_game_tick, :prediction_tick, :size, :direction, :target_x, :target_y, :jump, :fire, :hook,
:player_flags, :wanted_weapon, :next_weapon, :prev_weapon, :ping

def initialize(hash_or_raw)
if hash_or_raw.instance_of?(Hash)
Expand Down
8 changes: 7 additions & 1 deletion scripts/hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,13 @@ function check_file() {
fi
}

if check_file TeeworldsClient lib/teeworlds_client.rb # || check_file TeeworldsServer lib/teeworlds_server.rb
echo "[*] client"
if check_file TeeworldsClient lib/teeworlds_client.rb
then
exit 1
fi
echo "[*] server"
if check_file TeeworldsServer lib/teeworlds_server.rb
then
exit 1
fi

0 comments on commit 0d52e58

Please sign in to comment.