Add server support for pausing and unpausing
This commit is contained in:
1 file changed
+43
-1
+43
-1
@@ -186,7 +186,49 @@ app.ws('/ws', {
|
||||
console.log('received:', message, 'from', ws.id)
|
||||
if (message == 'ping') ws.send('ping')
|
||||
if (message.type) {
|
||||
if (
|
||||
if (message.type == 'multiplayer_player_unpause') {
|
||||
const multiplayerInfo = multiplayerClients.find(
|
||||
client => client.Id == ws.id
|
||||
)
|
||||
if (!multiplayerInfo) return
|
||||
multiplayerInfo.Paused = false
|
||||
const index = multiplayerClients.findIndex(client => client.Id == ws.id)
|
||||
if (index === -1) return
|
||||
multiplayerClients[index] = multiplayerInfo
|
||||
for (const multiplayerClientInfo of multiplayerClients) {
|
||||
if (ws.id == multiplayerClientInfo.Id) continue
|
||||
const client = Array.from(clients).find(
|
||||
client => client.id === multiplayerClientInfo.Id
|
||||
)
|
||||
if (!client) continue
|
||||
client.send({
|
||||
type: 'multiplayer_player_unpause',
|
||||
id: multiplayerInfo.UserID,
|
||||
paused: false
|
||||
})
|
||||
}
|
||||
} else if (message.type == 'multiplayer_player_pause') {
|
||||
const multiplayerInfo = multiplayerClients.find(
|
||||
client => client.Id == ws.id
|
||||
)
|
||||
if (!multiplayerInfo) return
|
||||
multiplayerInfo.Paused = true
|
||||
const index = multiplayerClients.findIndex(client => client.Id == ws.id)
|
||||
if (index === -1) return
|
||||
multiplayerClients[index] = multiplayerInfo
|
||||
for (const multiplayerClientInfo of multiplayerClients) {
|
||||
if (ws.id == multiplayerClientInfo.Id) continue
|
||||
const client = Array.from(clients).find(
|
||||
client => client.id === multiplayerClientInfo.Id
|
||||
)
|
||||
if (!client) continue
|
||||
client.send({
|
||||
type: 'multiplayer_player_pause',
|
||||
id: multiplayerInfo.UserID,
|
||||
paused: true
|
||||
})
|
||||
}
|
||||
} else if (
|
||||
message.type == 'multiplayer_player_move' &&
|
||||
message.x !== undefined &&
|
||||
message.y !== undefined &&
|
||||
|
||||
Reference in new issue
Block a user