mirror of
https://github.com/amineo/t2_server_query_elixir.git
synced 2026-07-13 15:34:39 +00:00
refactor(spec): add type specs
This commit is contained in:
parent
a500fea095
commit
7392039071
3 changed files with 19 additions and 4 deletions
|
|
@ -70,7 +70,7 @@ defmodule T2ServerQuery do
|
||||||
}}
|
}}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@spec query(String.t(), integer(), integer()) :: {atom(), %T2ServerQuery.QueryResult{}}
|
@spec query(String.t(), integer(), integer()) :: {atom(), T2ServerQuery.QueryResult.t()}
|
||||||
def query(server_ip, port \\ 28_000, timeout \\ 3_500) do
|
def query(server_ip, port \\ 28_000, timeout \\ 3_500) do
|
||||||
Logger.info "query: #{server_ip}"
|
Logger.info "query: #{server_ip}"
|
||||||
case is_valid_ip?(server_ip) do
|
case is_valid_ip?(server_ip) do
|
||||||
|
|
@ -79,7 +79,7 @@ defmodule T2ServerQuery do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec handle_query(String.t(), integer(), integer()) :: {atom(), %T2ServerQuery.QueryResult{}}
|
@spec handle_query(String.t(), integer(), integer()) :: {atom(), T2ServerQuery.QueryResult.t()}
|
||||||
defp handle_query(server_ip, port, timeout) do
|
defp handle_query(server_ip, port, timeout) do
|
||||||
{:ok, socket} = :gen_udp.open(0, [:binary, {:active, false}])
|
{:ok, socket} = :gen_udp.open(0, [:binary, {:active, false}])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ defmodule T2ServerQuery.PacketParser do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec init(binary(), binary()) :: {:ok, %QueryResult{}}
|
@spec init(binary(), binary()) :: {:ok, QueryResult.t()}
|
||||||
def init(info_packet, status_packet) when is_binary(info_packet) and is_binary(status_packet) do
|
def init(info_packet, status_packet) when is_binary(info_packet) and is_binary(status_packet) do
|
||||||
|
|
||||||
info_results = info_packet
|
info_results = info_packet
|
||||||
|
|
@ -83,7 +83,7 @@ defmodule T2ServerQuery.PacketParser do
|
||||||
pack_results({:ok, status_results, info_results})
|
pack_results({:ok, status_results, info_results})
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec pack_results({:ok, map(), map()}) :: {:ok, %QueryResult{}}
|
@spec pack_results({:ok, map(), map()}) :: {:ok, QueryResult.t()}
|
||||||
defp pack_results({:ok, status_results, info_results}) do
|
defp pack_results({:ok, status_results, info_results}) do
|
||||||
results = %QueryResult{}
|
results = %QueryResult{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,21 @@ defmodule T2ServerQuery.QueryResult do
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@type t() :: %__MODULE__{
|
||||||
|
server_status: atom(),
|
||||||
|
server_name: String.t(),
|
||||||
|
game_type: String.t(),
|
||||||
|
mission_type: String.t(),
|
||||||
|
map_name: String.t(),
|
||||||
|
player_count: integer(),
|
||||||
|
max_player_count: integer(),
|
||||||
|
bot_count: integer(),
|
||||||
|
server_description: String.t(),
|
||||||
|
team_count: integer(),
|
||||||
|
teams: list(),
|
||||||
|
players: list()
|
||||||
|
}
|
||||||
|
|
||||||
defstruct [
|
defstruct [
|
||||||
server_status: :offline,
|
server_status: :offline,
|
||||||
server_name: "",
|
server_name: "",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue