Changes to server format
All checks were successful
Build & Test / nix-build (push) Successful in 1m12s
All checks were successful
Build & Test / nix-build (push) Successful in 1m12s
This commit is contained in:
parent
38da310fd8
commit
ec9f9c87ac
@ -227,17 +227,19 @@ defmodule Amethyst.Server.Configuration do
|
||||
end
|
||||
|
||||
## HANDLING
|
||||
def handle({:serverbound_plugin_message, channel, data}, client) do
|
||||
handle_plugin_message(channel, data, client)
|
||||
def handle({:serverbound_plugin_message, channel, data}, client, state) do
|
||||
handle_plugin_message(channel, data, client, state)
|
||||
end
|
||||
def handle(tuple, _) do
|
||||
Logger.error("Unhandled but known packet #{elem(tuple, 0)}")
|
||||
end
|
||||
defp handle_plugin_message("minecraft:brand", data, _client) do
|
||||
defp handle_plugin_message("minecraft:brand", data, _client, state) do
|
||||
{[brand], ""} = Read.start(data) |> Read.string |> Read.stop
|
||||
Logger.info("Client using brand: #{brand}")
|
||||
{:ok, [{:brand, brand} | state]}
|
||||
end
|
||||
defp handle_plugin_message("amethyst:hello", _data, _client) do
|
||||
defp handle_plugin_message("amethyst:hello", _data, _client, state) do
|
||||
Logger.info("Client is Amethyst aware! Hello!")
|
||||
{:ok, [{:amethyst, true} | state]}
|
||||
end
|
||||
end
|
||||
|
@ -51,12 +51,15 @@ require Logger
|
||||
defmacro __using__(_opts) do
|
||||
quote do
|
||||
@spec serve(:gen_tcp.socket()) :: no_return()
|
||||
def serve(client) do
|
||||
def serve(client, state \\ []) do
|
||||
{id, data} = Amethyst.Server.Generic.get_packet(client)
|
||||
packet = deserialize(id, data)
|
||||
Logger.debug("Got packet #{inspect(packet)}")
|
||||
handle(packet, client)
|
||||
serve(client)
|
||||
{result, state} = handle(packet, client, state)
|
||||
if result != :ok do
|
||||
Logger.warning("Handler returned result #{result}")
|
||||
end
|
||||
serve(client, state)
|
||||
end
|
||||
|
||||
|
||||
|
@ -48,8 +48,8 @@ defmodule Amethyst.Server.Handshake do
|
||||
|
||||
## HANDLING
|
||||
# Handshake https://wiki.vg/Protocol#Handshake
|
||||
@spec handle(any(), any()) :: no_return()
|
||||
def handle({:handshake, 767, addr, port, next}, client) do
|
||||
@spec handle(any(), any(), any()) :: no_return()
|
||||
def handle({:handshake, 767, addr, port, next}, client, _state) do
|
||||
Logger.info("Got handshake, version 767 on #{addr}:#{port}. Wants to move to #{next}")
|
||||
case next do
|
||||
:status -> Amethyst.Server.Status.serve(client)
|
||||
@ -57,7 +57,8 @@ defmodule Amethyst.Server.Handshake do
|
||||
_ -> raise RuntimeError, "Unhandled move to next mode #{next}"
|
||||
end
|
||||
end
|
||||
def handle(tuple, _) do
|
||||
def handle(tuple, _, state) do
|
||||
Logger.error("Unhandled but known packet #{elem(tuple, 0)}")
|
||||
{:unhandled, state}
|
||||
end
|
||||
end
|
||||
|
@ -104,7 +104,7 @@ defmodule Amethyst.Server.Login do
|
||||
|
||||
## HANDLING
|
||||
# Login Start https://wiki.vg/Protocol#Login_Start
|
||||
def handle({:login_start, name, uuid}, client) do
|
||||
def handle({:login_start, name, uuid}, client, state) do
|
||||
Logger.info("Logging in #{name} (#{uuid})")
|
||||
if Application.fetch_env!(:amethyst, :encryption) do
|
||||
raise RuntimeError, "Encryption is currently unsupported." # TODO: Implement encryption
|
||||
@ -115,11 +115,14 @@ defmodule Amethyst.Server.Login do
|
||||
else
|
||||
transmit({:login_success, uuid, name, [], false}, client)
|
||||
end
|
||||
{:ok, state}
|
||||
end
|
||||
def handle({:login_acknowledged}, client) do
|
||||
def handle({:login_acknowledged}, client, state) do
|
||||
Amethyst.Server.Configuration.serve(client)
|
||||
{:ok, state}
|
||||
end
|
||||
def handle(tuple, _) do
|
||||
def handle(tuple, _, state) do
|
||||
Logger.error("Unhandled but known packet #{elem(tuple, 0)}")
|
||||
{:unhandled, state}
|
||||
end
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ defmodule Amethyst.Server.Status do
|
||||
|
||||
## HANDLING
|
||||
# Status Request https://wiki.vg/Protocol#Status_Request
|
||||
def handle({:status_request}, client) do
|
||||
def handle({:status_request}, client, state) do
|
||||
# We want to make this more dynamic in the future, but this works for now
|
||||
packet = {:status_response, ~s({
|
||||
"version": {"name": "1.21", "protocol": 767},
|
||||
@ -63,12 +63,15 @@ defmodule Amethyst.Server.Status do
|
||||
"preventsChatReports": true
|
||||
})}
|
||||
transmit(packet, client)
|
||||
{:ok, state}
|
||||
end
|
||||
def handle({:ping_request, payload}, client) do
|
||||
def handle({:ping_request, payload}, client, state) do
|
||||
packet = {:ping_response, payload}
|
||||
transmit(packet, client)
|
||||
{:ok, state}
|
||||
end
|
||||
def handle(tuple, _) do
|
||||
def handle(tuple, _, state) do
|
||||
Logger.error("Unhandled but known packet #{elem(tuple, 0)}")
|
||||
{:unhandled, state}
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user