Skip to content

Commit c4037d4

Browse files
author
Lee Yunjin
committed
update ceversi..
1 parent e4fa450 commit c4037d4

28 files changed

Lines changed: 2334 additions & 281 deletions

ceversi/.dockerignore

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Build Betting WASM
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
8+
jobs:
9+
build-wasm:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Install clang
16+
run: |
17+
sudo apt-get update
18+
sudo apt-get install -y clang
19+
20+
- name: Build wasm
21+
run: make wasm
22+
23+
- name: Verify JS syntax
24+
run: node --check public/script.js
25+
26+
- name: Upload wasm artifact
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: betting-logic-wasm
30+
path: public/betting_logic.wasm

ceversi/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ othello.db
44
libs/
55
*.o
66
server
7+
public/betting_logic.wasm

ceversi/Dockerfile

Lines changed: 31 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,65 @@
11
# --- C Build Stage ---
22
FROM alpine:latest AS c_builder
33

4-
# Install build dependencies.
5-
# Using edge community repository to ensure latest versions of libraries.
6-
RUN apk add --no-cache \
7-
gcc musl-dev make sqlite-dev openssl-dev cjson-dev uriparser-dev libc-utils linux-headers git \
4+
# Install build dependencies from edge community for latest library support
5+
RUN apk update && apk add --no-cache \
6+
tcc clang lld musl-dev make sqlite-dev openssl-dev cjson-dev uriparser-dev git libc-utils linux-headers cmake \
87
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
98

109
WORKDIR /app
1110

12-
# Copy the entire project context.
13-
COPY . .
11+
# Build libttak (external dependency)
12+
ARG LIBTTAK_REPO="https://github.com/religiya-serdtsa/libttak.git"
13+
ARG LIBTTAK_REF="main"
14+
RUN git clone --depth 1 --branch "${LIBTTAK_REF}" "${LIBTTAK_REPO}" /app/libttak
15+
WORKDIR /app/libttak
16+
RUN make clean && LDFLAGS="${LDFLAGS} -Wl,--no-eh-frame-hdr -fuse-ld=lld" make -j$(nproc) && \
17+
make install
1418

15-
# Clone cwist at build time (version-pinned via CWIST_REF).
16-
# This avoids shipping cwist source in the build context and keeps dependencies reproducible.
17-
ARG CWIST_REPO="https://github.com/gg582/cwist.git"
19+
# Build cwist (core framework)
20+
ARG CWIST_REPO="https://github.com/religiya-serdtsa/cwist.git"
1821
ARG CWIST_REF="main"
1922
RUN git clone --depth 1 --branch "${CWIST_REF}" "${CWIST_REPO}" /app/cwist
23+
RUN git -C /app/cwist submodule update --init --recursive
2024

21-
# 1. Install Headers (Include) manually to system paths.
22-
# This resolves compilation issues where Makefiles use relative paths (e.g., -I../include)
23-
# by making headers available globally in /usr/local/include.
24-
RUN cp -r /app/cwist/include/* /usr/local/include/ && \
25-
cp -r /app/libs/include/* /usr/local/include/ 2>/dev/null || true
26-
27-
# 2. Build Library & Install (Link).
28-
# Build libcwist.a and copy it to /usr/lib so the linker finds it automatically
29-
# without needing specific -L flags.
3025
WORKDIR /app/cwist
31-
RUN make clean 2>/dev/null || true; \
32-
make && \
33-
cp libcwist.a /usr/lib/
3426

35-
# 3. Build Main Server.
36-
# Navigate back to root to build the backend server binary.
37-
WORKDIR /app
38-
RUN make clean 2>/dev/null || true; \
39-
make
27+
# Define a compiler wrapper to enforce gnu17 standard during library build
28+
RUN printf '#!/bin/sh\n/usr/bin/gcc -std=gnu17 "$@"' > /usr/local/bin/gcc-std && \
29+
chmod +x /usr/local/bin/gcc-std
4030

31+
# Build cwist with linked libttak
32+
RUN rm -rf lib/libttak && mkdir -p lib && \
33+
cp -r /app/libttak lib/libttak && \
34+
env LDFLAGS="${LDFLAGS} -fuse-ld=lld -Wl,--no-eh-frame-hdr" CC=/usr/local/bin/gcc-std make -j$(nproc) && \
35+
env CC=/usr/local/bin/gcc-std make install
4136

42-
# --- Go Build Stage ---
43-
FROM golang:1.25-alpine AS go_builder
37+
# Build Main Server
4438
WORKDIR /app
45-
46-
COPY go.mod go.sum ./
47-
RUN go mod download
48-
49-
COPY main.go ./
50-
# Build the Go relay with CGO disabled for static linking.
51-
RUN CGO_ENABLED=0 go build -o ceversi_relay .
39+
COPY . .
40+
RUN make clean && make -j$(nproc)
5241

5342

5443
# --- Final Run Stage ---
5544
FROM alpine:latest
5645

57-
# Install runtime dependencies required for the C server.
46+
# Install runtime shared libraries
5847
RUN apk add --no-cache \
5948
sqlite-libs openssl cjson uriparser libgcc \
6049
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
6150

6251
WORKDIR /app
6352

64-
# Copy the compiled C backend binary.
65-
COPY --from=c_builder /app/server ./ceversi-backend
66-
67-
# Copy the compiled Go relay binary.
68-
COPY --from=go_builder /app/ceversi_relay ./ceversi-relay
69-
53+
# Copy binary and assets from builder
54+
COPY --from=c_builder /app/server ./ceversi
7055
COPY public/ ./public/
71-
72-
# Copy root-level templates and fallback assets.
7356
COPY index.html.tmpl .
7457
COPY style.css .
7558
COPY script.js .
76-
COPY othello.db .
7759

78-
EXPOSE 31744
79-
80-
# Default environment variable for the relay URL.
81-
ENV RELAY_URL="wss://portal.gosuda.org/relay"
60+
# Ensure database file existence for initialization
61+
RUN touch othello.db
8262

83-
# Start the relay server.
84-
# We hardcode the server-url in CMD to ensure it connects correctly without shell expansion issues.
85-
ENTRYPOINT ["./ceversi-relay"]
86-
CMD ["--name", "ceversi", \
87-
"--port", "31744", \
88-
"--backend-port", "31745", \
89-
"--c-server", "./ceversi-backend", \
90-
"--server-url", "wss://portal.gosuda.org/relay"]
63+
EXPOSE 31744
9164

65+
ENTRYPOINT ["./ceversi", "--no-certs"]

ceversi/Makefile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
CC = gcc
2-
CFLAGS = -Wall -Wextra -I../include -O2
3-
LDFLAGS = -L.. -lcwist -lcjson -lssl -lcrypto -lsqlite3 -luriparser -lpthread
2+
CFLAGS = -Wall -Wextra -O3
3+
LDFLAGS = -lcwist -lttak -lcjson -lssl -lcrypto -luriparser -lpthread -ldl -lm
44

5-
SRCS = src/main.c src/db.c src/handlers.c src/utils.c
5+
SRCS = src/main.c src/db.c src/handlers.c src/utils.c src/memory.c src/betting_logic.c
66
OBJS = $(SRCS:.c=.o)
77
TARGET = server
8+
WASM_SRC = src/betting_logic_wasm.c
9+
WASM_OUT = public/betting_logic.wasm
810

9-
all: $(TARGET)
11+
all: $(TARGET) wasm
1012

1113
$(TARGET): $(OBJS)
1214
$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS)
@@ -15,6 +17,15 @@ $(TARGET): $(OBJS)
1517
$(CC) $(CFLAGS) -c $< -o $@
1618

1719
clean:
18-
rm -f $(OBJS) $(TARGET)
20+
rm -f $(OBJS) $(TARGET) $(WASM_OUT)
1921

20-
.PHONY: all clean
22+
wasm: $(WASM_OUT)
23+
24+
$(WASM_OUT): $(WASM_SRC) src/betting_logic.c src/betting_logic.h
25+
clang --target=wasm32 -O3 -nostdlib \
26+
-Wl,--no-entry -Wl,--export=wasm_betting_single_delta \
27+
-Wl,--export=wasm_betting_can_wager -Wl,--export=wasm_betting_project_points \
28+
-Wl,--export=wasm_betting_multiplayer_reward \
29+
$(WASM_SRC) src/betting_logic.c -o $(WASM_OUT)
30+
31+
.PHONY: all clean wasm

ceversi/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ make # builds ./server
2626
```
2727
Feel free to customize `docker-compose.yml` or `Makefile` if you’re targeting something exotic.
2828

29+
### Systemd install (apt-based distros)
30+
```bash
31+
sudo ./install.sh
32+
```
33+
This script mirrors the Docker build steps on the host, installs the binary + assets into `/opt/ceversi`, and drops a `ceversi.service` unit so `systemd` keeps it alive. Manage it with `systemctl status|restart ceversi.service` and tail logs via `journalctl -u ceversi.service -f`.
34+
2935
## Project Map
3036
- `src/` – the C engine (handlers, utils, DB glue).
3137
- `public/` + `index.html` – the chill front-end.

ceversi/docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
version: '3.8'
22
services:
33
ceversi:
4+
init: true
5+
stop_signal: SIGTERM
6+
stop_grace_period: 30s
7+
network_mode: "host"
48
build: .
59
ports:
610
- "31744:31744"
@@ -11,4 +15,4 @@ services:
1115
- ./style.css:/app/style.css
1216
- ./script.js:/app/script.js
1317
- ./othello.db:/app/othello.db
14-
restart: always
18+
restart: always

ceversi/index.html.tmpl

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
</div>
1717

1818
<div class="nav-links">
19-
<a href="#" class="active" onclick="showView('lobby')">Play</a>
20-
<a href="#" onclick="showRankings()">Rank</a>
19+
<a id="nav-play" href="#" class="active" onclick="showView('lobby'); return false;">Play</a>
20+
<a id="nav-rank" href="#" onclick="showRankings(); return false;">Rank</a>
21+
<a id="nav-betting" href="#" onclick="showBettingZone(); return false;">Betting</a>
2122

2223
<div id="auth-controls">
2324
<button class="btn btn-primary btn-sm" onclick="showAuthModal()">Login</button>
@@ -62,6 +63,10 @@
6263
<button class="btn btn-primary" onclick="startLocalGame('othello')">Othello</button>
6364
<button class="btn btn-outline" onclick="startLocalGame('reversi')">Reversi</button>
6465
</div>
66+
<div class="form-group">
67+
<label>SinglePlayer Sessions</label>
68+
<div id="single-session-list" style="font-size:0.85rem; color:var(--text-secondary);">Loading singleplayer sessions...</div>
69+
</div>
6570
</div>
6671

6772
<div class="card">
@@ -77,6 +82,10 @@
7782
<button class="btn btn-primary" onclick="startMultiplayerGame('othello')">Join Othello</button>
7883
<button class="btn btn-outline" onclick="startMultiplayerGame('reversi')">Join Reversi</button>
7984
</div>
85+
<div class="form-group">
86+
<label>Multiplayer Rooms</label>
87+
<div id="multi-session-list" style="font-size:0.85rem; color:var(--text-secondary);">Loading rooms...</div>
88+
</div>
8089
</div>
8190
</div>
8291
<div id="connection-status" style="text-align:center; margin-top:1rem; color:var(--text-secondary);"></div>
@@ -103,6 +112,63 @@
103112
</div>
104113
</div>
105114

115+
116+
<div id="betting-zone" class="view-container hidden">
117+
<div class="hero-section">
118+
<h2>Betting Zone</h2>
119+
<p>Virtual money starts at 1000 points. Auto reset only when points reach -1000.</p>
120+
</div>
121+
<div class="card">
122+
<div style="display:flex;justify-content:space-between;align-items:center;gap:1rem;flex-wrap:wrap;">
123+
<div>
124+
<strong>My Points:</strong> <span id="betting-points">-</span>
125+
</div>
126+
</div>
127+
<div style="margin-top:1rem;font-size:0.85rem;color:var(--text-secondary);">10 slots total (4 Easy / 3 Medium / 3 Hard). Slots stay fixed until server reset.</div>
128+
<div id="betting-slots" style="margin-top:1rem; display:grid; gap:0.8rem;"></div>
129+
<div style="margin-top:1rem;">
130+
<h3 style="margin-bottom:0.6rem;">Betting Point Rank</h3>
131+
<table style="width:100%; text-align:left; border-collapse:collapse;">
132+
<thead>
133+
<tr style="border-bottom:1px solid var(--border-color);">
134+
<th style="padding:8px;">Rank</th>
135+
<th style="padding:8px;">Identity</th>
136+
<th style="padding:8px;">Points</th>
137+
</tr>
138+
</thead>
139+
<tbody id="betting-rankings-body"></tbody>
140+
</table>
141+
</div>
142+
<div style="margin-top:1rem;">
143+
<h3 style="margin-bottom:0.6rem;">Multiplayer Prediction Bet</h3>
144+
<div style="display:flex;gap:0.5rem;flex-wrap:wrap;align-items:center;">
145+
<input type="number" id="mp-bet-room" min="1" placeholder="Room" style="max-width:90px;">
146+
<input type="number" id="mp-bet-amount" min="1" value="100" style="max-width:100px;">
147+
<button class="btn btn-primary btn-sm" onclick="placeMultiplayerBet(1)">Bet P1</button>
148+
<button class="btn btn-outline btn-sm" onclick="placeMultiplayerBet(2)">Bet P2</button>
149+
<button class="btn btn-outline btn-sm" onclick="loadMultiplayerBetHistory()">Refresh History</button>
150+
</div>
151+
<div id="mp-bet-preview" style="margin-top:0.5rem;font-size:0.85rem;color:var(--text-secondary);">
152+
예상 포인트 변동을 표시합니다.
153+
</div>
154+
<table style="width:100%; margin-top:0.7rem; text-align:left; border-collapse:collapse;">
155+
<thead>
156+
<tr style="border-bottom:1px solid var(--border-color);">
157+
<th style="padding:6px;">Room</th>
158+
<th style="padding:6px;">Target</th>
159+
<th style="padding:6px;">Amount</th>
160+
<th style="padding:6px;">Settled</th>
161+
</tr>
162+
</thead>
163+
<tbody id="mp-bet-history-body"></tbody>
164+
</table>
165+
</div>
166+
</div>
167+
<div style="margin-top:1rem; text-align:center;">
168+
<button class="btn btn-outline" onclick="showView('lobby')">Back</button>
169+
</div>
170+
</div>
171+
106172
<div id="game-area" class="view-container {% if not room_id %}hidden{% endif %}">
107173
<div class="game-layout">
108174
<div class="game-sidebar">

0 commit comments

Comments
 (0)