Alan01252/battlecity-js-remake
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
This is a port/remake of an old online game I used to play based on the code here: https://github.com/Deceth/Battle-City Very much a work in progress / hobby project Basic playable version of the client here: https://alanhollis.com/battlecity-js-remake/ Arrow Keys move, Shift to shoot Multiplayer will not run without a server running and js changed # Development ## Client - cd ./client - npm install - npm run dev # starts Vite dev server on http://localhost:8020 - npm run build # optional production build to ./client/dist ## Server - cd ./server - npm start # Express + Socket.IO on http://localhost:8021 - npm run dev # optional: auto-restart with nodemon ### Discord activity feed (optional) The server can announce joins, leaves, and orb detonations to a Discord channel when a bot is configured: 1. Visit the [Discord Developer Portal](https://discord.com/developers/applications), create an application, and add a **Bot** user. Copy the generated **token**. 2. Invite the bot to your server with permissions to read messages and send messages in the target channel. The simplest option is to select the **Send Messages** and **Embed Links** scopes when generating the OAuth invite link. 3. In Discord, enable **Developer Mode** (User Settings → Advanced) so you can right click the channel and copy its **Channel ID**. If you want the bot to post into an existing thread, copy the **Thread ID** as well. 4. Before starting the BattleCity server, export the following environment variables so the notifier can authenticate: ```bash export DISCORD_BOT_TOKEN="<bot token>" export DISCORD_CHANNEL_ID="<channel id>" # optional extras export DISCORD_THREAD_ID="<thread id>" export DISCORD_BOT_ACTIVITY="Monitoring the battlefield" ``` When the variables are set and `discord.js` is installed, the server will connect the bot on startup and stream notifications to the configured channel. ## Google login / registration setup 1. Create a Google Cloud project (or reuse an existing one) and add an **OAuth 2.0 Client ID** for a web application via the [Google Identity Services](https://console.cloud.google.com/apis/credentials). Authorize the JavaScript origins you will use for the client (e.g. `http://localhost:8020`). 2. Copy the generated client ID and expose it to the server by setting `GOOGLE_CLIENT_ID` (or `GOOGLE_CLIENT_IDS` if you have multiple IDs, separated with commas or semicolons) before starting the server. The server reads those values to validate Google tokens and to advertise which IDs clients should use via `/api/identity/config`. 3. Expose the same client ID to the Vite client by adding `=<your-client-id>` (or `VITE_GOOGLE_CLIENT_IDS=...`) to a `.env.local` file inside `client/` or by exporting it in your shell before running `npm run dev`. The identity manager reads those build-time variables to decide whether to render the Google sign-in button. 4. Restart the dev server(s) after changing the environment variables. When both sides are configured, the lobby will show the “Register with Google” button and `/api/auth/google` will accept tokens issued for the configured client IDs. ## Bot Client - cd ./bot - npm install - node index.js --server http://localhost:8021 --city 0 # joins the server as a roaming recruit bot - The game server now auto-launches a bot process for each fake city (via the same script), so make sure `npm install` has been run in `bot/` before starting the server.