I have some new ideas https://github.com/colyseus/colyseus/issues/224
0
Reputation
4
Posts
1386
Profile views
0
Followers
0
Following
Posts made by daimonkor
RE: Use PM2, typescript for Heroku
posted in General Discussion •
@endel Thanks for help, I found heroku dyno listen process on change and crush
Java Colyseus Client problem with reconnect
posted in Questions & Help •
Hi all, please help. I have turn based server. There is problem with implement reconnect feature (after network disconnected) with saving user sessionId and roomId
The client:
private val serverRoomListener = object : Room.Listener() {
override fun onLeave() {
Timber.e("leave")
task = object : Timer.Task() {
override fun run() {
ServerClient.getInstance(ServerClient.Builder(url = SERVER_WS)).also {
it.setListener(object: Client.Listener{
override fun onMessage(message: Any?) {
}
override fun onClose(code: Int, reason: String?, remote: Boolean) {
}
override fun onError(e: java.lang.Exception?) {
}
override fun onOpen(id: String?) {
val rejoin = it.rejoin(currentRoom.name, it.id)
if(rejoin.hasJoined()){
task.cancel()
}
}
})
it.connect()
}
}
}
Timer.schedule(task, 10f, 0f, 0)
}
Timer tick delay 10s
The server "colyseus": "^0.9.32":
onJoin(client, options?, auth?) {
console.log(this.getLogTag(), options, auth, client.id);
if (options.create) {
this.state.masterPlayer = client.id
} else {
this.state.slavePlayer = client.id
}
console.log(this.getLogTag(), 'Client joined: ' + client.id);
if (this.clients.length == 2) {
this.lock();
this.state.state = State.GAME;
let command = {};
this.clients.forEach(function (value) {
command[value.id] = {}
});
this.state.command = command
}
this.broadcastPatch()
}
async onLeave(client, consented?) {
try {
if (consented) {
throw new Error("consented leave");
}
console.log(this.getLogTag(), "Count users:", this.clients.length, consented);
await this.allowReconnection(client);
console.log(this.getLogTag(), 'Reconnect client: ' + client.id);
} catch (e) {
console.log(this.getLogTag(), 'Error: ' + e);
console.log(this.getLogTag(), 'Client left: ' + client.id);
if (client.id == this.state.masterPlayer) {
this.state.masterPlayer = null;
// this.unlock()
} else if (client.id == this.state.slavePlayer) {
this.state.slavePlayer = null;
// this.unlock()
}
}
}
reconnection server log http://prntscr.com/mvsyas
Thanks for help.
Use PM2, typescript for Heroku
posted in General Discussion •
Please help, how configure pm2 with watcher changes files and restart after crush?
Old config used nodemon.
package.json
{
"name": "test-server",
"version": "0.0.1",
"description": "test server",
"main": "index.js",
"scripts": {
"start": "nodemon -L --exec ts-node src/index.ts",
"build-ts": "tsc",
"postinstall": "npm run build-ts"
},
"engines": {
"node": "8.9.1"
},
"author": "test",
"license": "ISC",
"dependencies": {
"express-basic-auth": "^1.1.6",
"@colyseus/monitor": "^0.1.11",
"colyseus": "^0.9.28",
"cors": "^2.8.5",
"express": "^4.16.4",
"nodemon": "^1.18.9"
},
"devDependencies": {
"@types/express": "^4.16.0",
"@types/node": "^10.12.18",
"ts-node": "^8.0.1",
"typescript": "^3.2.4"
}
}
tsconfig.json
{
"compilerOptions": {
"outDir": "lib",
"module": "commonjs",
"lib": ["es6"],
"target": "es2016",
"declaration": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"sourceMap": true,
},
"include": [
"**/*.ts"
]
}
Thanks for help