]> git.cworth.org Git - empires-server/log
empires-server
3 years agoAdd "express-session" as a dependency
Carl Worth [Wed, 20 May 2020 23:55:11 +0000 (16:55 -0700)]
Add "express-session" as a dependency

This commit was entirely created by "npm install express-session"

This module will give us some middleware for doing server-based
sessions, (stored in a cookie in the client).

3 years agolmno: Be forgiving in game ID values received from the user
Carl Worth [Wed, 20 May 2020 02:10:27 +0000 (19:10 -0700)]
lmno: Be forgiving in game ID values received from the user

Most significantly, we now accept a lowercase version of the ID.

But also, game ID values are intentionally chosen not to have
ambiguous character in them, (such as "M"/"N" or "S"/"F"), which might
sound similar when someone says a game ID aloud. So on the input side
we accept either form and canonicalize to the only letter which can
possibly exist in a game ID.

3 years agoempires: Serve the actual game file from the root of the app
Carl Worth [Sun, 17 May 2020 21:45:34 +0000 (14:45 -0700)]
empires: Serve the actual game file from the root of the app

This game.html file is actually totally static, but it lives at a
dynamic path (which includes the game ID in the path), so within the
dynamic app we need to serve the static file. To arrange for this we
symlink to the static file. Note that we're not committing the symlink
to git since the destination location can differ on each system.

3 years agoIncorporate empires.js as a sub-app within lmno.js
Carl Worth [Sun, 17 May 2020 19:40:44 +0000 (12:40 -0700)]
Incorporate empires.js as a sub-app within lmno.js

Now, instead of calling listen() the empires.js simply exports its app
object so that the higher level lmno server can mount all of its
available paths with app.use('/empires/<GAMEID>/', empires.app).

At the same time, empires.js no longer constructs a Game object, but
instead the higher-level /new API within lmno.js calls into
empires.Game to create a game for a specific ID. Then, there's also a
new middleware in lmno.js to lookup this game object by the ID from
the path and add it as a property of the request object. So all of the
empires.js entry points now fetch that game object from the request as
their first statement.

3 years agoRemove old placeholder code for sending "Hello World"
Carl Worth [Sun, 17 May 2020 19:32:43 +0000 (12:32 -0700)]
Remove old placeholder code for sending "Hello World"

Obviously, this was a leftover from some tutorial content, and we
don't really need or want this.

3 years agoempires: Return immediately from reveal_next if we aren't in the REVEAL state
Carl Worth [Sun, 17 May 2020 19:28:35 +0000 (12:28 -0700)]
empires: Return immediately from reveal_next if we aren't in the REVEAL state

I think this fix came about after Kevin did some testing by mashing on
all of the host buttons as fast as possible.

It's definitely a correct fix as far as it's true we shouldn't be
revealing anything if we're not in the REVEAL state. But I think we're
due for a better audit of what's happening to various pieces of state
on state transitions, (such as, shouldn't the interval timer get
cleared before we _leave_ the REVEAL state).

3 years agoRename server.js to empires.js
Carl Worth [Sun, 17 May 2020 19:26:42 +0000 (12:26 -0700)]
Rename server.js to empires.js

We have multiple express-based server apps implemented here now, so
the name "server.js" is now ambiguous. We rename it "empires.js" to
make clear that its an implementation only of the empires game.

3 years agoAdd a new server: lmno.js
Carl Worth [Sun, 17 May 2020 19:19:53 +0000 (12:19 -0700)]
Add a new server: lmno.js

This is the new top-level server for all dynamic content and games
that we plan to host at https://lmno.games. The previous server
implementation (in server.js) will likely be subsumed as a
sub-application within this new server soon.

3 years agoImplement a more correct response to /reset
Carl Worth [Mon, 11 May 2020 23:03:54 +0000 (16:03 -0700)]
Implement a more correct response to /reset

Specifically, we fix things here to clear some internal state that was
previously being missed (the "characters_to_reveal" field) and we also
fix things to report to the clients the new game state and the emptty
list of players.

3 years agoSend multiple game-state events (if needed) when a client connects
Carl Worth [Mon, 11 May 2020 21:52:09 +0000 (14:52 -0700)]
Send multiple game-state events (if needed) when a client connects

This implements the latest change as of version 0.6 of the API protocol.

This change fixes a bug in the current empires-html client where
reloading the browser when in the middle of the game would break the
client, (by displaying some content that's inappropriate for the
current state). By sending each step-wise transition through the game
states, the client does not get confused.

3 years agoImplement the /reveal,/start endpoints as well as the "game-state" event
Carl Worth [Sun, 10 May 2020 22:45:46 +0000 (15:45 -0700)]
Implement the /reveal,/start endpoints as well as the "game-state" event

This brings us up to protocol version 0.5 and should be a pretty
playable server at this point. Upon receiving the "/reveal" API
request the server will transition to the "reveal" game-state and from
there will broadcast the names of each character to all clients, one
name every three seconds, (and sending an empty name at the end to
clear off the last name). The "/reveal" API request can be sent
additional times if the players want to see the names again.

3 years agoRename a variable from "player_string" to "player_data"
Carl Worth [Sun, 10 May 2020 21:21:19 +0000 (14:21 -0700)]
Rename a variable from "player_string" to "player_data"

The name of "player_string" made me think this is just a string
representation of a player's name. But instead, this variable is
holding the JSON representation of the data block of a
"player-register" event. So a name of "player_data" is much more
clear.

3 years agoRename player-register/player-deregister to player-join/player-leave
Carl Worth [Sun, 10 May 2020 16:54:39 +0000 (09:54 -0700)]
Rename player-register/player-deregister to player-join/player-leave

This brings the server into compliance with protocol version 0.3.

3 years agoReplace "Example app" with "Empires server" in the welcome message
Carl Worth [Sun, 10 May 2020 15:50:08 +0000 (08:50 -0700)]
Replace "Example app" with "Empires server" in the welcome message

Since this is far from being an example app at this point.

3 years agoSend a comment to every connected client every 15 seconds
Carl Worth [Sun, 10 May 2020 15:40:14 +0000 (08:40 -0700)]
Send a comment to every connected client every 15 seconds

This prevents timeouts when the client receives nothing from the
server. For example, firefox appeares to give up on the server when it
receives nothing for two minutes.

3 years agoRename broadcast() to broadcast_event() supported by broadcast_string()
Carl Worth [Sun, 10 May 2020 15:35:21 +0000 (08:35 -0700)]
Rename broadcast() to broadcast_event() supported by broadcast_string()

The lower-level broadcast_string() simply sends a string to all clients.

The higher-level broadcast_event() sends a structured event (with both an
event type and a separate data block, as well as ending with two newlines),
exactly as clients will be expecting.

3 years agoFix typo in comment
Carl Worth [Sun, 10 May 2020 15:34:23 +0000 (08:34 -0700)]
Fix typo in comment

No functional change here.

3 years agoPerform broadcasts of deregister and capture events
Carl Worth [Mon, 4 May 2020 00:34:23 +0000 (17:34 -0700)]
Perform broadcasts of deregister and capture events

Allowing clients to track this state

3 years agoAdd an API for server-sent events at `/events`
Carl Worth [Sun, 3 May 2020 22:05:23 +0000 (15:05 -0700)]
Add an API for server-sent events at `/events`

So far there are two event types being sent here:

  players: An event reporting the complete list of registered players

  player-register: An event reporting a new player has registered

I'm not 100% sure these are all formatted correctly yet. I'll need to
implement a client to listen to these events and then check that.

3 years agoAdd some linting fixes
Carl Worth [Sun, 3 May 2020 22:03:56 +0000 (15:03 -0700)]
Add some linting fixes

Specifically some missing semicolons and a missing const.

It's funny that I didn't realize that emacs was doing live linting of
JavaScript all along here, (and highlighting all problems with various
colors and underlining).

3 years agoUse the cors package to set a permissive CORS header
Carl Worth [Sun, 3 May 2020 02:28:12 +0000 (19:28 -0700)]
Use the cors package to set a permissive CORS header

Specifically, with this change the server will emit a header of:

Access-Control-Allow-Origin: *

allowing requests to come from anywhere (for now).

This was necessary in the testing that Kevin is currently doing (where
he his hosting his test front-end spearately from the server).

3 years agoAdd a dependency on the cors package
Carl Worth [Sun, 3 May 2020 02:26:43 +0000 (19:26 -0700)]
Add a dependency on the cors package

This commit was constructed with "npm install cors"

3 years agoAdd simple testing for the entire API
Carl Worth [Sun, 3 May 2020 02:24:34 +0000 (19:24 -0700)]
Add simple testing for the entire API

This is more "exercising" than testing, (it doesn't currently verify
the results), but I've verified the server isn't hitting any syntax
errors (with fairly decent code coverage I think) and I've manually
inspected the results to ensure they look correct.

3 years agoImplement the rest of the API
Carl Worth [Sun, 3 May 2020 02:23:37 +0000 (19:23 -0700)]
Implement the rest of the API

This is up to date with commit
0411bdc5c4dbad187f7e25fa1fb40a23c3e0e940 of the empires-api as found
at: https://git.cworth.org/git/empires-api

3 years agoAdd an ID value to each player
Carl Worth [Sat, 2 May 2020 23:53:13 +0000 (16:53 -0700)]
Add an ID value to each player

This is a first baby step toward implementing the more complete API
for the game which we defined today, and which can be found here:

https://git.cworth.org/git/empires-api

In this commit we also introduce a 'Game' class to encapsulate all
data necessary for the game, (so the 'players' array we had before,
but also the 'next_player_id' which we need now).

4 years agofixup errant newline
Carl Worth [Sun, 26 Apr 2020 22:29:52 +0000 (15:29 -0700)]
fixup errant newline

4 years agoBe a bit more berbose in variable names.
Carl Worth [Sun, 26 Apr 2020 22:29:07 +0000 (15:29 -0700)]
Be a bit more berbose in variable names.

Preferring actual words "request" and "response" instead of
abbreviations "req" and "res".

4 years agoMake the server store a list of players
Carl Worth [Sun, 26 Apr 2020 22:25:14 +0000 (15:25 -0700)]
Make the server store a list of players

Expecting both "name" and "character" on each post to the /register
API. Also add a /players API to list the players registered so far.

4 years agoExtend our simple web API with a new /register endpoint
Carl Worth [Sun, 26 Apr 2020 22:15:53 +0000 (15:15 -0700)]
Extend our simple web API with a new /register endpoint

Which uses body-parser and simply prints out the body of the request.

This can now be tested with curl by something as simple as:

curl -i -X POST -H "Content-Type: application/json" -d '{"foo": "bar"}' localhost:3000/register

4 years agoAdd dependency on body-parser package
Carl Worth [Sun, 26 Apr 2020 22:07:24 +0000 (15:07 -0700)]
Add dependency on body-parser package

This was done with:

npm install --save body-parser

4 years agostash: add gitignore (for 'Add dependency for express')
Carl Worth [Sun, 26 Apr 2020 22:06:56 +0000 (15:06 -0700)]
stash: add gitignore (for 'Add dependency for express')

4 years agoAdd Hello World node app
Carl Worth [Sun, 26 Apr 2020 21:55:34 +0000 (14:55 -0700)]
Add Hello World node app

This is similar to what is documented here:

https://medium.com/@adnanrahic/hello-world-app-with-node-js-and-express-c1eb7cfa8a30

but with some more modern content as recommended by Richard.

This can be run with:

node server

in the current directory, (and then pointing a user agent at localhost:3000).

4 years agoAdd resolved dependencies in package-lock.json file
Carl Worth [Sun, 26 Apr 2020 21:51:05 +0000 (14:51 -0700)]
Add resolved dependencies in package-lock.json file

The entire contents of this file were generated by the:

npm install --save express

command from the previous commit.

4 years agoAdd dependency for express package
Carl Worth [Sun, 26 Apr 2020 21:49:31 +0000 (14:49 -0700)]
Add dependency for express package

This was generated with:

npm install --save express

(This command also generated resolved dependencies in the
package-lock.json file but I'm not commiting that in this commit.)

4 years agoAdd new package.json for the families app
Carl Worth [Sun, 26 Apr 2020 21:46:22 +0000 (14:46 -0700)]
Add new package.json for the families app

This was generated with "npm init" (and accepting all defaults).