🤓
Custom Servers
Are you ready to take your island to the next level?
To support match making, new mechanics and data persistence it is recommended to explore running your own server. This will allow players to connect and experience custom gameplay.
You can use basic API interactions but we recommend using a framework such as Colyseus to handle multiplayer gameplay.
If you want to use the Sunflower Land Scene, but point to your own server you can use the following setup:
class ExternalScene extends window.BaseScene {
constructor() {
super({
name: "test_island",
mmo: {
enabled: true,
url: "ws://localhost:2567", // Your Websocket server
roomId: "community_island",
},
player: {
spawn: {
x: 210,
y: 280,
},
},
});
}
}
- 1.Sign up for an account at fly.io
- 2.
- 3.Sign in to the Command Line Interface
fly auth login
- 4.Create a
Dockerfile
in the root of theExample Server
project
FROM node:14
ENV PORT 8080
WORKDIR /usr/src/app
COPY package.json ./
COPY yarn.lock ./
RUN yarn install
# run this for production
# npm ci --only=production
COPY . .
EXPOSE 8080
CMD [ "yarn", "start" ]
- 5.Build and test the Docker container
docker build -t community-island-server .
docker run community-island-server
- 6.Create a fly.io application
fly launch
- 7.Deploy the application
fly deploy
- 8.Check the application is running!
fly open
This section follows on from the previous section
Developing in the Cloud
- 1.Add a 1GB
volume
to the project
fly volumes create myvolume --size 1
- 2.Add the volume to the fly config
fly.toml
[mounts]
source="myvolume"
destination="/data"
- 3.Deploy the application
fly deploy
- 4.Add a SQLLite3 Database to the application. For this step I will be creating a new express route under
/timestamps
. In reality you likely want to access this data from colysues code.- 1.Install sqllite to the applicationyarn add sqlite3
- 2.Import
sqllite3
in index.tsimport sqlite3 from "sqlite3"; - 3.Create the timestamp route in
index.ts
. This code will insert a new timestamp each time a page is visited.app.get("/timestamps", (req, res) => {const database = new sqlite3.Database("./db");database.serialize(() => {database.run("CREATE TABLE IF NOT EXISTS example (timestamp INTEGER)");database.run("INSERT INTO example VALUES (?)", Date.now());database.all("SELECT * from example", (err, rows) => {res.send(JSON.stringify(rows));});});database.close();});
- 5.Deploy the application
fly deploy
- 6.Access the new route
fly open /timestamps
For a small cloud deployment we recommend the following specifications:
CPU: 1vCPU
Memory: 2GB
For more advanced configurations you may need additional resources or load balancing. Please visit the colyseus documentation for instructions on how to set up this type of deployment:
https://docs.colyseus.io/deployment/
Last modified 2mo ago