Skip to content

Commit

Permalink
Add command parsing errors & docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklanng committed Mar 23, 2024
1 parent 19ffc31 commit a6db37b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 18 deletions.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" }
8 changes: 8 additions & 0 deletions src/telnet/render.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
3 changes: 3 additions & 0 deletions src/telnet/server.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
32 changes: 23 additions & 9 deletions src/telnet/states.gleam
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
}

0 comments on commit a6db37b

Please sign in to comment.