View Source FLHook (FLHook Client v2.0.0)
FLHook is a community-managed tool for managing Freelancer game servers. Freelancer is a pretty old game that has been released in 2003 by Microsoft, but it still has a very committed community.
FLHook allows connecting via a socket to run commands on and receive events from a Freelancer Server. This library provides an Elixir client for that matter. You could use it to build web-based management interfaces or ingame chat bots, for example.
connect-to-server
Connect to Server
{:ok, client} = FLHook.Client.start_link(
host: "myserver.com",
password: "s3cret",
)
Alternatively, create your own module that you can configure in your application.
defmodule MyFLClient do
use FLHook.Client
end
Add the client to your supervision tree:
defmodule MyApp.Application do
use Application
def start(_type, _args) do
Supervisor.start_link(
[MyFLClient],
strategy: :one_for_one,
name: MyApp.Supervisor
)
end
end
In your config:
import Config
config :my_app, MyFLClient,
host: "localhost",
port: 1920,
event_mode: true,
connect_on_start: true,
backoff_interval: 1000,
connect_timeout: 5000,
password: "s3cret",
recv_timeout: 5000,
send_timeout: 5000
dispatch-command
Dispatch Command
Send a command to the server and receive the result immediately:
{:ok, result} = FLHook.cmd(client, {"addcash", ["MyUsername", 10]})
new_cash = FLHook.Result.param!(result, "cash")
IO.puts("New cash: #{new_cash} credits")
listen-to-events
Listen to Events
Let the current process receive FLHook events:
FLHook.subscribe(client)
receive do
%FLHook.Event{type: "kill", dict: dict} ->
IO.inspect(dict, label: "player killed")
end
Link to this section Summary
Functions
Sends a command to the socket and returns the result.
Sends a command to the socket and returns the result. Raises on error.
Registers the specified process as event listener.
Removes the event listener for the specified process.
Link to this section Functions
@spec cmd(FLHook.Client.client(), FLHook.Command.command()) :: {:ok, FLHook.Result.t()} | {:error, Exception.t()}
Sends a command to the socket and returns the result.
@spec cmd!(FLHook.Client.client(), FLHook.Command.command()) :: FLHook.Result.t() | no_return()
Sends a command to the socket and returns the result. Raises on error.
@spec subscribe(FLHook.Client.client(), pid()) :: :ok
Registers the specified process as event listener.
@spec unsubscribe(FLHook.Client.client(), pid()) :: :ok
Removes the event listener for the specified process.