Implement being aware of the handshake
All checks were successful
Build & Test / nix-build (push) Successful in 1m6s
All checks were successful
Build & Test / nix-build (push) Successful in 1m6s
This commit is contained in:
parent
c742fa7c97
commit
5c708a22d2
@ -23,7 +23,10 @@ defmodule Amethyst.Server.Generic do
|
||||
alias Amethyst.Minecraft.Read
|
||||
|
||||
def get_packet(client) do
|
||||
|
||||
{[length], ""} = get_varint(client, "")
|
||||
{:ok, full_packet} = :gen_tcp.recv(client, length)
|
||||
{[id], data} = Read.start(full_packet) |> Read.varint() |> Read.stop()
|
||||
{id, data}
|
||||
end
|
||||
|
||||
defp get_varint(client, acc) do
|
||||
|
@ -18,10 +18,16 @@ defmodule Amethyst.Server.Stage1 do
|
||||
@moduledoc """
|
||||
This module contains the stage 1 (Handshaking) server logic.
|
||||
"""
|
||||
require Logger
|
||||
alias Amethyst.Minecraft.Read
|
||||
|
||||
@spec serve(:gen_tcp.socket()) :: no_return()
|
||||
def serve(client) do
|
||||
|
||||
{id, data} = Amethyst.Server.Generic.get_packet(client)
|
||||
case deserialize(id, data) do
|
||||
{:handshake, ver, addr, port, next} -> Logger.info("Got handshake on ver #{ver}, #{addr}:#{port} moving to #{next}")
|
||||
end
|
||||
serve(client)
|
||||
end
|
||||
|
||||
## DESERIALIZATION
|
||||
@ -34,9 +40,9 @@ defmodule Amethyst.Server.Stage1 do
|
||||
3 -> :transfer
|
||||
_ -> raise RuntimeError, "Client requested moving to an unknown state!"
|
||||
end
|
||||
%{type: :handshake, version: ver, address: addr, port: port, next: next}
|
||||
{:handshake, ver, addr, port, next}
|
||||
end
|
||||
def deserialize(<<type, _::binary>>) do
|
||||
def deserialize(type, _) do
|
||||
raise RuntimeError, "Got unknown packet type #{type}!"
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user