Clone04 commited on
Commit
9d105ec
·
verified ·
1 Parent(s): 3e048c4

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +4 -50
server.js CHANGED
@@ -1,50 +1,4 @@
1
- const colyseus = require("colyseus");
2
- const http = require("http");
3
- const express = require("express"); // optional
4
- const monitor = require("@colyseus/monitor").monitor;
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!’))