Skip to content

Commit

Permalink
fixes #190
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot committed May 17, 2024
1 parent 4a721f3 commit 88e8b12
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
45 changes: 33 additions & 12 deletions server/Jigs/GameRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
import { Room, Client, ServerError } from "colyseus";
const db = require("../services/db");
import { InputData, MyRoomState, Player, ZombieState } from "./GameState";
import { InputData, MyRoomState, Player, PlayerMap, ZombieState } from "./GameState";

var roomModel = require('../models/room.ts');

Expand Down Expand Up @@ -74,7 +74,7 @@ export class GameRoom extends Room<MyRoomState> {

async onAuth(client, options, request) {

const userData = await this.checkAccess(client, options);
const userData = await this.checkAccess(client, options, this.state.playerMap);
if (userData) {
return userData;

Expand All @@ -97,13 +97,12 @@ export class GameRoom extends Room<MyRoomState> {
//await this.Layers.load(options.nodeName, this.share);
await this.Collisions.add(this);


await roomModel.getRoom(options.nodeNumber).then((result: any) => {
this.state.mapWidth = result[0].field_map_width_value * 16;
this.state.mapHeight = result[0].field_map_height_value * 16;
this.state.missionAccepted = result[0].field_mission_accepted_target_id;

console.log('-----MA---------' + this.state.missionAccepted);

}).catch(function (err) {
console.log('room error' + err)
});
Expand Down Expand Up @@ -145,15 +144,27 @@ export class GameRoom extends Room<MyRoomState> {
});
}

checkAccess(client, options) {
console.log('client.id:' + client.id);
console.log(options);
// this.p2player.getUnlockedRooms();
console.log('Access Checked');
return true;
}
checkAccess(client, options, playerMap) {
if (playerMap.size == 0) {
console.log('no people');
return true
} else {
playerMap.forEach((value, key) => {
console.log("value" + value.profileId);

if (value == options.profile_id) {
console.log('Access failed');
return false;
}
// console.log('client.id:' + client.id);
// console.log(options);
// this.p2player.getUnlockedRooms();
console.log('Access Checked');
return true;

})
}
}

fixedTick(timeStep: number) {
const velocity = 2;
Expand All @@ -180,7 +191,11 @@ export class GameRoom extends Room<MyRoomState> {
}, val);
});
}
////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////
async onJoin(client: Client, options: any) {
console.log(client.sessionId, "joined!");
console.log(options.playerId, "joined!");
Expand All @@ -191,14 +206,20 @@ export class GameRoom extends Room<MyRoomState> {
player.profileId = options.profileId;
player.p2Player = new P2player();

const playerMap = new PlayerMap();
playerMap.profileId = options.profileId;

await player.p2Player.load(player.playerId, this.share, player, client, this);
this.world.addBody(player.p2Player.Body);
this.state.players.set(client.sessionId, player);
this.state.playerMap.set(client.sessionId, playerMap)
}

////////////////////////////////////////////////////////////////////////////////
onLeave(client: Client, consented: boolean) {
console.log(client.sessionId, "left!");
this.state.players.delete(client.sessionId);
this.state.playerMap.delete(client.sessionId);

}

onStateChange(state) {
Expand Down
7 changes: 6 additions & 1 deletion server/Jigs/GameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class ZombieState extends Schema {
@type("number") dead: number;
}

export class PlayerMap extends Schema{
profileId: number;
}

export class MyRoomState extends Schema {
npcResult: any;
NpcResult: any;
Expand All @@ -50,7 +54,8 @@ export class MyRoomState extends Schema {
@type("number") mapWidth: number;
@type("number") mapHeight: number;
@type({map: ZombieState}) mobResult = new MapSchema<ZombieState>();
@type({ map: Player }) players = new MapSchema<Player>();
@type({map: Player }) players = new MapSchema<Player>();
@type({map: PlayerMap }) playerMap = new MapSchema<PlayerMap>();

destroySomething() {
console.log('destroy all the things');
Expand Down

0 comments on commit 88e8b12

Please sign in to comment.