Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Split program entrypoint and server logic #10

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
*.so
/server
/cobolcraft
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get update && apt-get install -y tini gcc g++ make gnucobol && rm -rf /v

# Copy source files
COPY Makefile .
COPY server.cob .
COPY main.cob .
COPY src ./src
COPY CBL_GC_SOCKET ./CBL_GC_SOCKET
COPY blobs ./blobs
Expand All @@ -19,4 +19,4 @@ ENV COB_PRE_LOAD=CBL_GC_SOCKET:CBL_GC_SOCKET/CBL_GC_SOCKET.so

# Run the server within Tini (to handle signals properly)
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["./server"]
CMD ["./cobolcraft"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
COBC = cobc

LIB = CBL_GC_SOCKET/CBL_GC_SOCKET.so
SRC = server.cob src/*.cob
BIN = server
SRC = main.cob src/*.cob
BIN = cobolcraft

all: $(BIN)

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ docker build -t cobolcraft .
docker run --rm -p 25565:25565 cobolcraft
```

To configure the server, edit the variables in `main.cob` (limited options available).

## Why?

Well, there are quite a lot of rumors and stigma surrounding COBOL.
Expand Down
14 changes: 14 additions & 0 deletions main.cob
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Main.

DATA DIVISION.
WORKING-STORAGE SECTION.
*> Configuration
01 PORT PIC X(5) VALUE "25565".
01 WHITELIST-ENABLE PIC 9(1) VALUE 0.
01 WHITELIST-PLAYER PIC X(16) VALUE "Notch".

PROCEDURE DIVISION.
CALL "Server" USING PORT WHITELIST-ENABLE WHITELIST-PLAYER.

END PROGRAM Main.
16 changes: 9 additions & 7 deletions server.cob → src/server.cob
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. server.
PROGRAM-ID. Server.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
Expand All @@ -13,9 +13,6 @@ FD FD-REGISTRY-BLOB.
01 REGISTRY-BLOB-REC PIC X(64).

WORKING-STORAGE SECTION.
01 PORT PIC X(5) VALUE "25565".
01 WHITELIST-ENABLE PIC 9(1) VALUE 0.
01 WHITELIST-PLAYER PIC X(16) VALUE "Notch".
*> Socket variables (server socket handle, client socket handle, error number)
01 LISTEN PIC X(4).
01 HNDL PIC X(4).
Expand All @@ -38,9 +35,14 @@ WORKING-STORAGE SECTION.
01 TEMP-INT32 PIC 9(10).
01 TEMP-INT64 PIC 9(20).

PROCEDURE DIVISION.
LINKAGE SECTION.
*> Configuration provided by main program
01 PORT PIC X(5).
01 WHITELIST-ENABLE PIC 9(1).
01 WHITELIST-PLAYER PIC X(16).

Main.
PROCEDURE DIVISION USING PORT WHITELIST-ENABLE WHITELIST-PLAYER.
StartServer.
DISPLAY "Starting server...".
CALL "Socket-Listen" USING PORT LISTEN ERRNO.
PERFORM HandleError.
Expand Down Expand Up @@ -548,4 +550,4 @@ HandleError SECTION.

EXIT SECTION.

END PROGRAM server.
END PROGRAM Server.