fix: encode strings to bytes for binary SSH + use port 22

This commit is contained in:
Greg Hendrickson
2026-01-27 18:17:47 +00:00
parent 730f2eb37a
commit 692c6c92dc
3 changed files with 9 additions and 6 deletions

View File

@@ -24,7 +24,7 @@ RUN useradd -m shellmate && \
USER shellmate USER shellmate
RUN ssh-keygen -t ed25519 -f /etc/shellmate/ssh_host_key -N "" RUN ssh-keygen -t ed25519 -f /etc/shellmate/ssh_host_key -N ""
EXPOSE 2222 EXPOSE 22
ENV STOCKFISH_PATH=/usr/games/stockfish ENV STOCKFISH_PATH=/usr/games/stockfish

View File

@@ -2,9 +2,9 @@ services:
shellmate: shellmate:
build: . build: .
ports: ports:
- "2222:2222" - "22:22"
environment: environment:
- SHELLMATE_SSH_PORT=2222 - SHELLMATE_SSH_PORT=22
- SHELLMATE_REDIS_URL=redis://redis:6379 - SHELLMATE_REDIS_URL=redis://redis:6379
- SHELLMATE_DATABASE_URL=postgresql://shellmate:shellmate@postgres:5432/shellmate - SHELLMATE_DATABASE_URL=postgresql://shellmate:shellmate@postgres:5432/shellmate
- STOCKFISH_PATH=/usr/games/stockfish - STOCKFISH_PATH=/usr/games/stockfish
@@ -13,7 +13,7 @@ services:
- postgres - postgres
restart: unless-stopped restart: unless-stopped
healthcheck: healthcheck:
test: ["CMD", "nc", "-z", "localhost", "2222"] test: ["CMD", "nc", "-z", "localhost", "22"]
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 3 retries: 3

View File

@@ -90,6 +90,9 @@ async def run_simple_menu(process, username: str, mode: str, width: int, height:
def __init__(self, proc): def __init__(self, proc):
self._proc = proc self._proc = proc
def write(self, data): def write(self, data):
# Encode string to bytes for binary mode SSH
if isinstance(data, str):
data = data.encode('utf-8')
self._proc.stdout.write(data) self._proc.stdout.write(data)
def flush(self): def flush(self):
pass pass
@@ -250,10 +253,10 @@ async def run_chess_game(process, console, username: str, opponent: str) -> None
elif char == '\x7f' or char == '\b': # Backspace elif char == '\x7f' or char == '\b': # Backspace
if move_buffer: if move_buffer:
move_buffer = move_buffer[:-1] move_buffer = move_buffer[:-1]
process.stdout.write('\b \b') process.stdout.write(b'\b \b')
elif char.isprintable(): elif char.isprintable():
move_buffer += char move_buffer += char
process.stdout.write(char) process.stdout.write(char.encode('utf-8'))
except Exception as e: except Exception as e:
logger.error(f"Game input error: {e}") logger.error(f"Game input error: {e}")