Navigation

    Colyseus
    • Login
    • Search
    • Recent
    • Tags
    • Users
    1. Home
    2. daimonkor
    daimonkor

    daimonkor

    @daimonkor

    Chat Follow Unfollow
    0
    Reputation
    4
    Posts
    1109
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Continue chat with daimonkor
      • Flag Profile
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    daimonkor Follow

    Posts made by daimonkor

    RE: Java Colyseus Client problem with reconnect

    I have some new ideas https://github.com/colyseus/colyseus/issues/224

    posted in Questions & Help •
    RE: Use PM2, typescript for Heroku

    @endel Thanks for help, I found heroku dyno listen process on change and crush

    posted in General Discussion •
    Java Colyseus Client problem with reconnect

    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.

    posted in Questions & Help •
    Use PM2, typescript for Heroku

    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

    posted in General Discussion •