Update server.js
Browse files
server.js
CHANGED
@@ -1,50 +1,4 @@
|
|
1 |
-
const
|
2 |
-
const
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
// Initialize the Express app (optional)
|
7 |
-
const app = express();
|
8 |
-
|
9 |
-
// Create HTTP & WebSocket servers
|
10 |
-
const server = http.createServer(app);
|
11 |
-
const gameServer = new colyseus.Server({
|
12 |
-
server: server,
|
13 |
-
});
|
14 |
-
|
15 |
-
// Define a room handler
|
16 |
-
class MyRoom extends colyseus.Room {
|
17 |
-
onCreate(options) {
|
18 |
-
console.log("Room created!", options);
|
19 |
-
}
|
20 |
-
|
21 |
-
onJoin(client, options) {
|
22 |
-
console.log(client.sessionId, "joined!");
|
23 |
-
}
|
24 |
-
|
25 |
-
onLeave(client, consented) {
|
26 |
-
console.log(client.sessionId, "left!");
|
27 |
-
}
|
28 |
-
|
29 |
-
onMessage(client, message) {
|
30 |
-
console.log(client.sessionId, "sent message", message);
|
31 |
-
this.broadcast("messages", message);
|
32 |
-
}
|
33 |
-
|
34 |
-
onDispose() {
|
35 |
-
console.log("Room disposed!");
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
-
// Register the room handler
|
40 |
-
gameServer.define("my_room", MyRoom);
|
41 |
-
|
42 |
-
// Serve static files (optional)
|
43 |
-
app.use(express.static("public"));
|
44 |
-
app.use("/colyseus", monitor());
|
45 |
-
|
46 |
-
// Start the server
|
47 |
-
const port = process.env.PORT || 7860;
|
48 |
-
server.listen(port, () => {
|
49 |
-
console.log(`Listening on ws://localhost:${port}`);
|
50 |
-
});
|
|
|
1 |
+
const express = require(‘express’)
|
2 |
+
const app = express()
|
3 |
+
app.get(‘/’, (req, res) => res.send(‘Hello World!’))
|
4 |
+
app.listen(3000, () => console.log(‘Example app listening on port 3000!’))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|