Multiplayer
- Edited
After some debugging I found reason multiplayer is not working.
const playerIsAlreadyInGame = !!RpgWorld.getPlayers().find(p => !!p.mongoId)
if (playerIsAlreadyInGame) {
throw new Error('PLAYER_IN_GAME')
}
Can you please explain what did you mean with the first line? You set mongoId to player.id on first player login, so this line will always return true after first player login.
Hello,
Actually RpgWorld.getPlayers()
searches for players assigned to a room (in RPGJS, a room is a map). If the player is already on a map, the message indicates that the player is already in the game.
Make sure you don't send the player with the changeMap
method once the connection is established
- Edited
Hi @Samarium, thanks for your answer.
I deleted changeMap
in function onConnected
in main/server/player.ts
and still I can not login with two different accounts
To reproduce error create clean project with npx degit rpgjs/starter my-rpg-game
and add all things for MMORPG:
title-screen
plugin- configuration for server
- delete
changeMap
in functiononConnected
I just tested and there is indeed the problem. I'll make the correction in the next few days
The correction has been made, try to upgrade the plugin:
npm install @rpgjs/title-screen@3.0.0-rc.1
- Edited
Thanks so much for the update, I really appreciate it. Will try your fix now
It works now! Thanks again.
I got the same problem. After install @rpgjs/title-screen@3.0.0-rc.1
keep the error.
I try to set variable PLAYER_IN_GAME to false but don't work.
onDisconnected(player: RpgPlayer) {
player.setVariable('PLAYER_IN_GAME', false)
},
- Edited
Maybe using npm run dev
is the problem for that. If I reload the page works, but after some modifications in server I cant login again.
#update
After interact with some npcs and apply player.save()
, the error appears.
#update2
I save the state after update variable on disconnect and works. I will keep testing.
onDisconnected(player: RpgPlayer) {
player.setVariable('PLAYER_IN_GAME', false)
player.save()
},
#update3
Ok, after add some item to player the error appears. I don't know why.
I guess the error is something in the npm run dev
. Maybe after reload we need to disconnect all players before start again. This explain why, after reload, keep spawning players (freezed players).
#update4
Maybe we can fix this create another field to mongodb, like 'connected'.
const playerIsAlreadyInGame = user.connected
if (playerIsAlreadyInGame) {
throw new Error('PLAYER_IN_GAME')
}
And when connect, set to true and when disconnect or reload server, we set to false. Or, just let player login and connect, without this block.
Maybe just a notification mail like "another useragent/ip log to your account. You want to disconnect all and change password?".
What the need for this validation? To prevent players to join many times in same map? Or just for validation if player "is online"? If is just a online checker, maybe we need to remove this. If someone hack my account I cant log in again? Need to be a more complex way to block login, like notify in email to change password and block account login until password is changed, etc. But for now, maybe remove this is a good way to solve this. Each update in my code I need to delete player from database and create again to test... isn't productive. Or check if is in development mode and bypass this.
This is to avoid that a person plays with several characters with the same account
I'll look at the problem in more detail, and I'll send a feedback