Blog Details

Linux 作業系統 cutexyz > Blog > 武功秘籍 > 武功秘籍 – GameServer

武功秘籍 – GameServer

# Game Server setup
# What we choosed? https://colyseus.io/

# First, setup the execution envuirnoment
# go to https://docs.colyseus.io/, check the document.  

# before we star to install nodejs
# Node.js 是能夠在伺服器端運行 JavaScript 的開放原始碼、跨平台 JavaScript 執行環境
# NVM 是 Node.js 的版本管理器 (node version manager)
# NPM 是Node Package Manager的縮寫 用來管理專案使用到的套件

# install node.js by nvm
# go to the offical nodejs website and check the download url,   
# https://nodejs.org/en/download
# follow the steps about the NVM version installation
# login ubuntu and change to the root account
sudo su -

# go to the /tmp folder
cd /tmp

# installs nvm (Node Version Manager)
# where to check the latest version info, https://github.com/nvm-sh/nvm/releases
# 舊的安裝指令, curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash

# after the the previous step, we need to reopen the terminal or execute the following command
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# then we can proceed to the next step

# download and install Node.js
nvm install 20

# verifies the right Node.js version is in the environment
node -v # should print `v20.14.0`

# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`

# check the node version can be displayed correctly
node -v
## output: v18.16.0

# update and upgrade system lib
apt update
apt upgrade

# go to the colyseus examples url
# https://github.com/colyseus/colyseus-examples
# check out the git, install run it
# go back to the home directory
cd
git clone https://github.com/colyseus/colyseus-examples.git
cd colyseus-examples
npm install
npm start

# after run the server, we can try to use client examples
# browse the url here, 網站輸入網址  http://localhost:2567  

# after try thec chat examples, we can go to setup the game example now
# we find the github url first
# we got it, https://github.com/colyseus/cocos-demo-tictactoe
# check out the git, install run it
git clone https://github.com/colyseus/cocos-demo-tictactoe.git
cd cocos-demo-tictactoe/Server
npm install
npm start

# Now the server is on, where is the client
# Let's go to the cocos creator official site
# https://www.cocos.com/creator-download
# download and install CocosDashboard
# register the cocos account from dashboard
# after registered account, login to the CocosDashboard
# change to the Editor tab and download the latest IDE 3.7.3(選擇下載版本)
# after download Editor, go to the Project tab abd choose "Add"
# Add the "cocos-demo-tictactoe" directory to the project
# find the C:\cocos-demo-tictactoe-master\assets\scripts\SceneManager.ts
# open this file and replace this line with new one ( new ip )

# //let endpoint : string = `ws://${this.serverURL}:${this.port}`;
# let endpoint : string = `ws://10.40.22.70:${this.port}`; 

# press play with main scene and browser platform
# done

參考資料
1. Colyseus framework, https://colyseus.io/
2. Server & Client, https://github.com/colyseus/cocos-demo-tictactoe

Leave A Comment

All fields marked with an asterisk (*) are required