generated from cartesiancs-dev/devent-frame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
63 lines (51 loc) · 1.44 KB
/
server.js
File metadata and controls
63 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
let player = {
}
export async function socket (io) {
io.on("connection", (socket) => {
socket.emit("connected", player)
console.log(player)
socket.on("disconnect", () => {
try {
console.log(socket.id);
io.emit('remove', player[socket.id].uuid)
delete player[socket.id]
} catch (error) {
console.log('error')
}
})
socket.on('init', (data) => {
player[socket.id] = {
uuid: data.uuid,
position: {
x:0,
y:0,
z:0
},
rotation:0
}
io.emit("init", data)
});
socket.on('move', (data) => {
//console.log(data)
io.emit("move", data)
});
socket.on('stop', (data) => {
try {
console.log(data)
player[socket.id].position = data.position
console.log(player)
io.emit("stop", data)
} catch (error) {
console.log('error')
}
});
socket.on('rotation', (data) => {
try {
player[socket.id].rotation = data.rotation
io.emit("rotation", data)
} catch (error) {
console.log('error')
}
});
});
}