mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 08:11:54 +00:00
added deployment
This commit is contained in:
+2
-2
@@ -13,11 +13,11 @@ RUN npm install
|
|||||||
# Copy the rest of the application code
|
# Copy the rest of the application code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the application
|
# Build the client-side application
|
||||||
RUN npm run build-prod
|
RUN npm run build-prod
|
||||||
|
|
||||||
# Expose the port the app runs on
|
# Expose the port the app runs on
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Define the command to run the app
|
# Define the command to run the app
|
||||||
CMD [ "node", "dist/server/server.js" ]
|
CMD ["npm", "run", "start:server"]
|
||||||
@@ -15,10 +15,10 @@
|
|||||||
* improve front page DONE 8/12/2024
|
* improve front page DONE 8/12/2024
|
||||||
* attacks cancel out DONE 8/13/2024
|
* attacks cancel out DONE 8/13/2024
|
||||||
* upload and start server
|
* upload and start server
|
||||||
* fix enemy islands when attacking
|
|
||||||
* better algorithm for name render placement
|
* better algorithm for name render placement
|
||||||
* make boats larger
|
* make boats larger
|
||||||
* have boats not get close to shore
|
* have boats not get close to shore
|
||||||
* make coasts look better
|
* make coasts look better
|
||||||
* add shader to dim border
|
* add shader to dim border
|
||||||
* remove player.info()
|
* remove player.info()
|
||||||
|
* fix enemy islands when attacking
|
||||||
|
|||||||
Generated
+8
@@ -9,6 +9,7 @@
|
|||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/jimp": "^0.2.28",
|
"@types/jimp": "^0.2.28",
|
||||||
"colord": "^2.9.3",
|
"colord": "^2.9.3",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"jimp": "^0.22.12",
|
"jimp": "^0.22.12",
|
||||||
"node-addon-api": "^8.1.0",
|
"node-addon-api": "^8.1.0",
|
||||||
@@ -5170,6 +5171,13 @@
|
|||||||
"node": ">= 8"
|
"node": ">= 8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/crypto": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==",
|
||||||
|
"deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in.",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
"node_modules/css-select": {
|
"node_modules/css-select": {
|
||||||
"version": "4.3.0",
|
"version": "4.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/css-select/-/css-select-4.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/css-select/-/css-select-4.3.0.tgz",
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/jimp": "^0.2.28",
|
"@types/jimp": "^0.2.28",
|
||||||
"colord": "^2.9.3",
|
"colord": "^2.9.3",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"jimp": "^0.22.12",
|
"jimp": "^0.22.12",
|
||||||
"node-addon-api": "^8.1.0",
|
"node-addon-api": "^8.1.0",
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {defaultConfig} from "../core/configuration/DefaultConfig";
|
import {defaultConfig} from "../core/configuration/DefaultConfig";
|
||||||
import {TerrainMap} from "../core/Game";
|
import {TerrainMap} from "../core/Game";
|
||||||
|
import {PseudoRandom} from "../core/PseudoRandom";
|
||||||
import {ServerMessage, ServerMessageSchema} from "../core/Schemas";
|
import {ServerMessage, ServerMessageSchema} from "../core/Schemas";
|
||||||
import {loadTerrainMap} from "../core/TerrainMapLoader";
|
import {loadTerrainMap} from "../core/TerrainMapLoader";
|
||||||
import {generateUniqueID} from "../core/Util";
|
|
||||||
import {ClientGame, createClientGame} from "./ClientGame";
|
import {ClientGame, createClientGame} from "./ClientGame";
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
|
|
||||||
@@ -18,6 +18,8 @@ class Client {
|
|||||||
private lobbiesContainer: HTMLElement | null;
|
private lobbiesContainer: HTMLElement | null;
|
||||||
private lobbiesInterval: NodeJS.Timeout | null = null;
|
private lobbiesInterval: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
|
private random = new PseudoRandom(1234)
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.lobbiesContainer = document.getElementById('lobbies-container');
|
this.lobbiesContainer = document.getElementById('lobbies-container');
|
||||||
|
|
||||||
@@ -84,7 +86,7 @@ class Client {
|
|||||||
if (this.game != null) {
|
if (this.game != null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.game = createClientGame(getUsername(), generateUniqueID(), lobbyID, defaultConfig, map)
|
this.game = createClientGame(getUsername(), this.random.nextID(), lobbyID, defaultConfig, map)
|
||||||
this.game.joinLobby()
|
this.game.joinLobby()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ export class ClientGame {
|
|||||||
) { }
|
) { }
|
||||||
|
|
||||||
public joinLobby() {
|
public joinLobby() {
|
||||||
this.socket = new WebSocket(`ws://localhost:3000`)
|
const wsHost = process.env.WEBSOCKET_URL || window.location.host;
|
||||||
|
this.socket = new WebSocket(`ws://${wsHost}`)
|
||||||
this.socket.onopen = () => {
|
this.socket.onopen = () => {
|
||||||
console.log('Connected to game server!');
|
console.log('Connected to game server!');
|
||||||
this.socket.send(
|
this.socket.send(
|
||||||
|
|||||||
@@ -30,4 +30,8 @@ export class PseudoRandom {
|
|||||||
nextFloat(min: number, max: number): number {
|
nextFloat(min: number, max: number): number {
|
||||||
return this.next() * (max - min) + min;
|
return this.next() * (max - min) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nextID(): string {
|
||||||
|
return this.nextInt(0, 1000000).toString(36).padStart(5, '0');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
import {Cell} from "./Game";
|
import {Cell} from "./Game";
|
||||||
|
|
||||||
export function generateUniqueID(): string {
|
|
||||||
const array = new Uint8Array(16);
|
|
||||||
crypto.getRandomValues(array);
|
|
||||||
return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function manhattanDist(c1: Cell, c2: Cell): number {
|
export function manhattanDist(c1: Cell, c2: Cell): number {
|
||||||
return Math.abs(c1.x - c2.x) + Math.abs(c1.y - c2.y);
|
return Math.abs(c1.x - c2.x) + Math.abs(c1.y - c2.y);
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,8 @@ import {Client} from "./Client";
|
|||||||
import {Lobby} from "./Lobby";
|
import {Lobby} from "./Lobby";
|
||||||
import {GameServer} from "./GameServer";
|
import {GameServer} from "./GameServer";
|
||||||
import {Config} from "../core/configuration/Config";
|
import {Config} from "../core/configuration/Config";
|
||||||
import {generateUniqueID} from "../core/Util";
|
|
||||||
import {defaultConfig} from "../core/configuration/DefaultConfig";
|
import {defaultConfig} from "../core/configuration/DefaultConfig";
|
||||||
|
import {PseudoRandom} from "../core/PseudoRandom";
|
||||||
|
|
||||||
export class GameManager {
|
export class GameManager {
|
||||||
|
|
||||||
@@ -14,6 +14,8 @@ export class GameManager {
|
|||||||
|
|
||||||
private games: Map<GameID, GameServer> = new Map()
|
private games: Map<GameID, GameServer> = new Map()
|
||||||
|
|
||||||
|
private random = new PseudoRandom(123)
|
||||||
|
|
||||||
constructor(private settings: Config) { }
|
constructor(private settings: Config) { }
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ export class GameManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startGame(lobby: Lobby) {
|
startGame(lobby: Lobby) {
|
||||||
const gs = new GameServer(generateUniqueID(), lobby.clients, defaultConfig)
|
const gs = new GameServer(this.random.nextID(), lobby.clients, defaultConfig)
|
||||||
this.games.set(gs.id, gs)
|
this.games.set(gs.id, gs)
|
||||||
gs.start()
|
gs.start()
|
||||||
}
|
}
|
||||||
@@ -61,7 +63,7 @@ export class GameManager {
|
|||||||
|
|
||||||
if (now > this.lastNewLobby + this.settings.lobbyCreationRate()) {
|
if (now > this.lastNewLobby + this.settings.lobbyCreationRate()) {
|
||||||
this.lastNewLobby = now
|
this.lastNewLobby = now
|
||||||
this.addLobby(new Lobby(generateUniqueID(), this.settings.lobbyLifetime()))
|
this.addLobby(new Lobby(this.random.nextID(), this.settings.lobbyLifetime()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Regular → Executable
+4
-4
@@ -1,20 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Ensure you're authenticated with Google Cloud
|
# Ensure you're authenticated with Google Cloud
|
||||||
gcloud auth configure-docker
|
gcloud auth configure-docker us-central1-docker.pkg.dev
|
||||||
|
|
||||||
# Build the new Docker image
|
# Build the new Docker image
|
||||||
docker build -t openfrontio .
|
docker build -t openfrontio .
|
||||||
|
|
||||||
# Tag the new image (use a version number or 'latest')
|
# Tag the new image (use a version number or 'latest')
|
||||||
docker tag openfrontio gcr.io/[YOUR-PROJECT-ID]/openfrontio:latest
|
docker tag openfrontio us-central1-docker.pkg.dev/openfrontio/openfrontio/game-server:latest
|
||||||
|
|
||||||
# Push the new image to Google Container Registry
|
# Push the new image to Google Container Registry
|
||||||
docker push gcr.io/[YOUR-PROJECT-ID]/openfrontio:latest
|
docker push us-central1-docker.pkg.dev/openfrontio/openfrontio/game-server:latest
|
||||||
|
|
||||||
# Update the GCE instance with the new container image
|
# Update the GCE instance with the new container image
|
||||||
gcloud compute instances update-container openfrontio-instance \
|
gcloud compute instances update-container openfrontio-instance \
|
||||||
--container-image us-central1-docker.pkg.dev/openfrontio/openfrontio:latest \
|
--container-image us-central1-docker.pkg.dev/openfrontio/openfrontio/game-server:latest \
|
||||||
--zone=us-central1-a
|
--zone=us-central1-a
|
||||||
|
|
||||||
echo "Deployment complete. New version should be live soon."
|
echo "Deployment complete. New version should be live soon."
|
||||||
+57
-49
@@ -1,59 +1,67 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {fileURLToPath} from 'url';
|
import {fileURLToPath} from 'url';
|
||||||
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
||||||
|
import webpack from 'webpack';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
export default {
|
export default (env, argv) => {
|
||||||
entry: './src/client/Client.ts',
|
const isProduction = argv.mode === 'production';
|
||||||
output: {
|
|
||||||
filename: 'bundle.js',
|
return {
|
||||||
path: path.resolve(__dirname, 'out'),
|
entry: './src/client/Client.ts',
|
||||||
},
|
output: {
|
||||||
module: {
|
filename: 'bundle.js',
|
||||||
rules: [
|
path: path.resolve(__dirname, 'out'),
|
||||||
{
|
|
||||||
test: /\.ts$/,
|
|
||||||
use: 'ts-loader',
|
|
||||||
exclude: /node_modules/,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.(png|jpe?g|gif)$/i,
|
|
||||||
type: 'asset/resource',
|
|
||||||
generator: {
|
|
||||||
filename: 'images/[hash][ext][query]'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.ts', '.js'],
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: './src/client/index.html',
|
|
||||||
filename: 'index.html'
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
devServer: {
|
|
||||||
static: {
|
|
||||||
directory: path.join(__dirname, 'out'),
|
|
||||||
},
|
},
|
||||||
compress: true,
|
module: {
|
||||||
port: 9000,
|
rules: [
|
||||||
proxy: [
|
{
|
||||||
{
|
test: /\.ts$/,
|
||||||
context: ['/socket'],
|
use: 'ts-loader',
|
||||||
target: 'ws://localhost:3000',
|
exclude: /node_modules/,
|
||||||
ws: true,
|
},
|
||||||
},
|
{
|
||||||
{
|
test: /\.(png|jpe?g|gif)$/i,
|
||||||
context: ['/lobbies', '/join_game', '/join_lobby'], // Add any other API endpoints here
|
type: 'asset/resource',
|
||||||
target: 'http://localhost:3000',
|
generator: {
|
||||||
secure: false,
|
filename: 'images/[hash][ext][query]'
|
||||||
changeOrigin: true,
|
}
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.ts', '.js'],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: './src/client/index.html',
|
||||||
|
filename: 'index.html'
|
||||||
|
}),
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
'process.env.WEBSOCKET_URL': JSON.stringify(isProduction ? '' : 'localhost:3000')
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
},
|
devServer: isProduction ? {} : {
|
||||||
|
static: {
|
||||||
|
directory: path.join(__dirname, 'out'),
|
||||||
|
},
|
||||||
|
compress: true,
|
||||||
|
port: 9000,
|
||||||
|
proxy: [
|
||||||
|
{
|
||||||
|
context: ['/socket'],
|
||||||
|
target: 'ws://localhost:3000',
|
||||||
|
ws: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
context: ['/lobbies', '/join_game', '/join_lobby'],
|
||||||
|
target: 'http://localhost:3000',
|
||||||
|
secure: false,
|
||||||
|
changeOrigin: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user