Skip to content

Commit c3f395b

Browse files
committed
add @colyseus/social as dependency on Server
1 parent 1ad7834 commit c3f395b

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Assets/Plugins/Colyseus/Auth.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Web;
3+
using System.Text;
34
using System.Collections.Specialized;
45
using System.Runtime.Serialization;
56
using System.Threading.Tasks;

Server/DemoRoom.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Room, Client, generateId } from "colyseus";
22
import { Schema, type, MapSchema, ArraySchema } from "@colyseus/schema";
3+
import { verifyToken, User, IUser } from "@colyseus/social";
34

45
class Entity extends Schema {
56
@type("number")
@@ -39,6 +40,10 @@ export class DemoRoom extends Room {
3940
this.setSimulationInterval((dt) => this.update(dt));
4041
}
4142

43+
async onAuth (options) {
44+
return await User.findById(verifyToken(options.token)._id);
45+
}
46+
4247
populateEnemies () {
4348
for (let i=0; i<=3; i++) {
4449
const enemy = new Enemy();
@@ -54,7 +59,7 @@ export class DemoRoom extends Room {
5459
return true;
5560
}
5661

57-
onJoin (client: Client, options: any) {
62+
onJoin (client: Client, options: any, user: IUser) {
5863
console.log("client joined!", client.sessionId);
5964
this.state.entities[client.sessionId] = new Player();
6065
}
@@ -96,4 +101,4 @@ export class DemoRoom extends Room {
96101
console.log("disposing DemoRoom...");
97102
}
98103

99-
}
104+
}

Server/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
"node": ">= 8.x"
1414
},
1515
"dependencies": {
16+
"@colyseus/social": "^0.10.0",
1617
"colyseus": "^0.10.1",
1718
"express": "^4.13.3",
19+
"express-jwt": "^5.3.1",
1820
"typescript": "^3.3.4000"
1921
},
2022
"devDependencies": {

0 commit comments

Comments
 (0)