diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b83e702 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/gleam-lang/gleam:v1.0.0-erlang-alpine + +# Add project code +COPY . /build/ + +# Add data +COPY ./data /data + +# Compile the project +RUN cd /build \ + && gleam export erlang-shipment \ + && mv build/erlang-shipment /app \ + && rm -r /build + +# Run the server +WORKDIR /app +ENTRYPOINT ["/app/entrypoint.sh"] +CMD ["run"] \ No newline at end of file diff --git a/README.md b/README.md index df2aca1..1aace5e 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,6 @@ [![Package Version](https://img.shields.io/hexpm/v/gleamud)](https://hex.pm/packages/gleamud) [![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gleamud/) -## TEMPORARY STEP - -We're using an unreleased feature from the HEAD of main of Glisten. -You will need to git clone Glisten to a sibling folder to Gleamud until this change gets merged. - ## Development ```sh diff --git a/gleam.toml b/gleam.toml index d26ff0a..fdef222 100644 --- a/gleam.toml +++ b/gleam.toml @@ -14,13 +14,13 @@ version = "1.0.0" [dependencies] gleam_stdlib = "~> 0.34 or ~> 1.0" -glisten = { path = "../glisten" } gleam_otp = "~> 0.10" gleam_erlang = "~> 0.24" repeatedly = "~> 2.1" chromatic = "~> 1.0" tom = "~> 0.3" simplifile = "~> 1.5" +glisten = "~> 2.0" [dev-dependencies] gleeunit = "~> 1.0" diff --git a/manifest.toml b/manifest.toml index 193e580..74d990a 100644 --- a/manifest.toml +++ b/manifest.toml @@ -7,7 +7,7 @@ packages = [ { name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" }, { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, { name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" }, - { name = "glisten", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], source = "local", path = "../glisten" }, + { name = "glisten", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "CF3A9383E9BA4A8CBAF2F7B799716290D02F2AC34E7A77556B49376B662B9314" }, { name = "repeatedly", version = "2.1.1", build_tools = ["gleam"], requirements = [], otp_app = "repeatedly", source = "hex", outer_checksum = "38808C3EC382B0CD981336D5879C24ECB37FCB9C1D1BD128F7A80B0F74404D79" }, { name = "simplifile", version = "1.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "EB9AA8E65E5C1E3E0FDCFC81BC363FD433CB122D7D062750FFDF24DE4AC40116" }, { name = "tom", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "0831C73E45405A2153091226BF98FB485ED16376988602CC01A5FD086B82D577" }, @@ -19,7 +19,7 @@ gleam_erlang = { version = "~> 0.24" } gleam_otp = { version = "~> 0.10" } gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } gleeunit = { version = "~> 1.0" } -glisten = { path = "../glisten" } +glisten = { version = "~> 2.0"} repeatedly = { version = "~> 2.1" } -simplifile = { version = "~> 1.5"} +simplifile = { version = "~> 1.5" } tom = { version = "~> 0.3" } diff --git a/src/telnet/render.gleam b/src/telnet/render.gleam index 68d11e3..5faf622 100644 --- a/src/telnet/render.gleam +++ b/src/telnet/render.gleam @@ -112,6 +112,14 @@ fn center(str: String, width: Int) -> String { } } +// fn wrap(str: String, width: Int) -> String { +// str +// |> string.split("\n") +// |> list.fold([], fn(lines, line) { todo }) +// |> string.join("\n") +// } + +// be sure to call this after wrap fn insert_carriage_returns(str: String) -> String { string.replace(str, "\n", "\n\r") } diff --git a/src/telnet/server.gleam b/src/telnet/server.gleam index 74cbb0f..ed54f6f 100644 --- a/src/telnet/server.gleam +++ b/src/telnet/server.gleam @@ -86,6 +86,9 @@ fn handle_iac(msg: BitArray, tcp_subject: Subject(game_connection.Message)) { } } +import gleam/io + fn handle_input(msg: BitArray, tcp_subject: Subject(game_connection.Message)) { + io.debug(msg) process.send(tcp_subject, game_connection.Data(msg)) } diff --git a/src/telnet/states.gleam b/src/telnet/states.gleam index 5e35e44..4ce4e6c 100644 --- a/src/telnet/states.gleam +++ b/src/telnet/states.gleam @@ -1,5 +1,6 @@ import gleam/bit_array import gleam/erlang/process.{type Subject} +import gleam/list import gleam/option.{type Option, None, Some} import gleam/string import simulation @@ -102,17 +103,20 @@ pub fn handle_input( <<13:8, 0:8>> -> { let assert Ok(_) = render.println("", conn) let assert Some(command_subject) = state.directory.command_subject - let command = parse_command(state.buffer) - case command { - Some(com) -> { + case parse_command(state.buffer) { + Ok(com) -> { process.send(command_subject, com) - Nil } - None -> { + Error(UnknownCommand) -> { let assert Ok(_) = render.error("Huh?", state.conn) let assert Ok(_) = render.prompt("", conn) Nil } + Error(SayWhat) -> { + let assert Ok(_) = render.error("Say what?", state.conn) + let assert Ok(_) = render.prompt("", conn) + Nil + } } #(InWorld(conn, dim, dir, ""), None) } @@ -149,10 +153,20 @@ pub fn handle_update(state: State, update: simulation.Update) -> State { } } -fn parse_command(str: String) -> Option(simulation.Command) { +type ParseCommandError { + UnknownCommand + SayWhat +} + +fn parse_command(str: String) -> Result(simulation.Command, ParseCommandError) { case string.split(string.reverse(string.trim(str)), " ") { - ["look", ..] -> Some(simulation.CommandLook) - ["say", ..rest] -> Some(simulation.CommandSayRoom(string.join(rest, " "))) - _ -> None + ["look", ..] -> Ok(simulation.CommandLook) + ["say", ..rest] -> { + case list.length(rest) { + 0 -> Error(SayWhat) + _ -> Ok(simulation.CommandSayRoom(string.join(rest, " "))) + } + } + _ -> Error(UnknownCommand) } }