Compare commits

..

4 Commits

Author SHA1 Message Date
49cebb9f0a Add todo file
All checks were successful
continuous-integration/drone/push Build is passing
2023-01-18 00:18:49 +01:00
c10eca266a Add static file serving and basic docker config 2023-01-18 00:18:35 +01:00
3fcb1fb8f5 Fix chat breaking when players leave 2023-01-18 00:17:23 +01:00
fce7419c55 Add todo 2023-01-17 19:29:10 +01:00
7 changed files with 39 additions and 2 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
node_modules
dist
.env.development

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM node:19.4-alpine AS frontend
ARG server_url
RUN test -n "${server_url}"
COPY glebby-client /glebby-client
WORKDIR /glebby-client
RUN npm install
ENV VITE_GLEBBY_SERVER_URL=${server_url}
RUN npx vite build --outDir static
FROM python:3.11-alpine
COPY glebby-server /glebby-server
WORKDIR /glebby-server
RUN pip install -r requirements.txt
RUN pip install gunicorn
COPY --from=frontend /glebby-client/static /glebby-server/static
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--threads", "100", "glebby:app"]

5
TODO.md Normal file
View File

@ -0,0 +1,5 @@
- [ ] composition api
- [ ] quart
- [ ] lobby
- [ ] actual game logic
- [ ] websocket url config

View File

@ -11,6 +11,7 @@ export default {
Game
},
data(): { ws: WebSocket, model: any } {
console.log(import.meta.env.VITE_GLEBBY_SERVER_URL)
return {
ws: new WebSocket(import.meta.env.VITE_GLEBBY_SERVER_URL),
model: null

View File

@ -128,7 +128,7 @@ export default defineComponent({
<div class="chatbox-scroller">
<div class="chatbox-scroller-content">
<div v-for="message in chatMessages" class="chatbox-message">
<code>{{ model.players.get(message.from)!.name }}#{{ message.from }}:</code> {{ message.message }}
<code v-if="model.players.get(message.from)">{{ model.players.get(message.from)!.name }}#{{ message.from }}:</code> {{ message.message }}
</div>
</div>
</div>

View File

@ -1,2 +1,3 @@
venv
__pycache__
static

View File

@ -117,6 +117,8 @@ class GlebbyState:
self.next_client_id += 1
return client_id
# TODO: Instead of using clients_lock, synchronize clients throught incoming_messages
# Make add_client and remove_client simply push events into the queue
def add_client(self, sock):
client_id = self._get_next_client_id()
self.broadcast(client_id, {'type': 'join'})
@ -150,9 +152,14 @@ class GlebbyState:
state = GlebbyState()
state.start_event_thread()
app = Flask(__name__)
# TODO: Examine Quart (basically an asyncio version of flask)
app = Flask(__name__, static_url_path='')
sock = Sock(app)
@app.route('/')
def index():
return app.send_static_file('index.html')
@sock.route('/glebby')
def echo(sock):
client_id = state.add_client(sock)