Kano001 commited on
Commit
c14e7e9
·
verified ·
1 Parent(s): 059d5e8

Upload 4 files

Browse files
src/app.config.ts ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import config from "@colyseus/tools";
2
+ import { monitor } from "@colyseus/monitor";
3
+ import { playground } from "@colyseus/playground";
4
+
5
+ /**
6
+ * Import your Room files
7
+ */
8
+ import { MyRoom } from "./rooms/MyRoom";
9
+
10
+ export default config({
11
+
12
+ initializeGameServer: (gameServer) => {
13
+ /**
14
+ * Define your room handlers:
15
+ */
16
+ gameServer.define('my_room', MyRoom);
17
+
18
+ },
19
+
20
+ initializeExpress: (app) => {
21
+ /**
22
+ * Bind your custom express routes here:
23
+ * Read more: https://expressjs.com/en/starter/basic-routing.html
24
+ */
25
+ app.get("/hello_world", (req, res) => {
26
+ res.send("It's time to kick ass and chew bubblegum!");
27
+ });
28
+
29
+ /**
30
+ * Use @colyseus/playground
31
+ * (It is not recommended to expose this route in a production environment)
32
+ */
33
+ if (process.env.NODE_ENV !== "production") {
34
+ app.use("/", playground);
35
+ }
36
+
37
+ /**
38
+ * Use @colyseus/monitor
39
+ * It is recommended to protect this route with a password
40
+ * Read more: https://docs.colyseus.io/tools/monitor/#restrict-access-to-the-panel-using-a-password
41
+ */
42
+ app.use("/colyseus", monitor());
43
+ },
44
+
45
+
46
+ beforeListen: () => {
47
+ /**
48
+ * Before before gameServer.listen() is called.
49
+ */
50
+ }
51
+ });
src/index.ts ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * IMPORTANT:
3
+ * ---------
4
+ * Do not manually edit this file if you'd like to host your server on Colyseus Cloud
5
+ *
6
+ * If you're self-hosting (without Colyseus Cloud), you can manually
7
+ * instantiate a Colyseus Server as documented here:
8
+ *
9
+ * See: https://docs.colyseus.io/server/api/#constructor-options
10
+ */
11
+ import { listen } from "@colyseus/tools";
12
+
13
+ // Import Colyseus config
14
+ import app from "./app.config";
15
+
16
+ // Create and listen on 2567 (or PORT environment variable.)
17
+ listen(app);
src/rooms/MyRoom.ts ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Room, Client } from "@colyseus/core";
2
+ import { MyRoomState } from "./schema/MyRoomState";
3
+
4
+ export class MyRoom extends Room<MyRoomState> {
5
+ maxClients = 4;
6
+
7
+ onCreate (options: any) {
8
+ this.setState(new MyRoomState());
9
+
10
+ this.onMessage("type", (client, message) => {
11
+ //
12
+ // handle "type" message
13
+ //
14
+ });
15
+ }
16
+
17
+ onJoin (client: Client, options: any) {
18
+ console.log(client.sessionId, "joined!");
19
+ }
20
+
21
+ onLeave (client: Client, consented: boolean) {
22
+ console.log(client.sessionId, "left!");
23
+ }
24
+
25
+ onDispose() {
26
+ console.log("room", this.roomId, "disposing...");
27
+ }
28
+
29
+ }
src/rooms/schema/MyRoomState.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import { Schema, Context, type } from "@colyseus/schema";
2
+
3
+ export class MyRoomState extends Schema {
4
+
5
+ @type("string") mySynchronizedProperty: string = "Hello world";
6
+
7
+ }