Commit f45c7750 authored by Dennis Willers's avatar Dennis Willers
Browse files

Implement Service 4 Checking, if a user allowed to play the game in a spezific role

parent bd74510d
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import { GuesserComponent } from './guesser/guesser.component';
import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import {MatIconModule} from '@angular/material/icon';
import {MatIconModule} from '@angular/material/icon';
import {MatTooltipModule} from '@angular/material/tooltip';
import {MatTooltipModule} from '@angular/material/tooltip';
import {IsAllowedToPlay} from './dao/isAllowedToPlay';


@NgModule({
@NgModule({
  declarations: [
  declarations: [
@@ -52,7 +53,9 @@ import {MatTooltipModule} from '@angular/material/tooltip';
    MatIconModule,
    MatIconModule,
    MatTooltipModule
    MatTooltipModule
  ],
  ],
  providers: [],
  providers: [
    IsAllowedToPlay
  ],
  bootstrap: [AppComponent]
  bootstrap: [AppComponent]
})
})
export class AppModule { }
export class AppModule { }
+7 −0
Original line number Original line Diff line number Diff line
import {Injectable} from '@angular/core';

@Injectable()
export class IsAllowedToPlay {
  isAllowed = false;
  role = '';
}
+18 −12
Original line number Original line Diff line number Diff line
import {Component, OnInit} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {ProgressSpinnerMode} from '@angular/material/progress-spinner';
import {CardInfo} from '../interface/cardInfo';
import {CardInfo} from '../interface/cardInfo';
import {TabuMiddlewareService} from '../dao/TabuMiddlewareService';
import {TabuMiddlewareService} from '../dao/TabuMiddlewareService';
import {ActivatedRoute, Router} from '@angular/router';
import {ActivatedRoute, Router} from '@angular/router';
import {GameStatus} from '../interface/gameStatus';
import {GameStatus} from '../interface/gameStatus';
import {io} from 'socket.io-client';
import {io} from 'socket.io-client';
import {environment} from '../../environments/environment';
import {environment} from '../../environments/environment';
import {IsAllowedToPlay} from '../dao/isAllowedToPlay';


@Component({
@Component({
  selector: 'app-game',
  selector: 'app-game',
@@ -38,35 +38,41 @@ export class GameComponent implements OnInit {
    red: 0,
    red: 0,
    blue: 0,
    blue: 0,
    redTurn: true,
    redTurn: true,
    activeExplainer: false,
    activeExplainer: 1,
    activeWatchdog: false
    activeWatchdog: 1
  };
  };
  team = '';
  team = '';


  color = 'primary';
  color = 'primary';
  mode: ProgressSpinnerMode = 'determinate';
  value = 50;
  value = 50;

  constructor(private service: TabuMiddlewareService,
  constructor(private service: TabuMiddlewareService,
              private router: Router,
              private router: Router,
              private activatedRoute: ActivatedRoute) {}
              private activatedRoute: ActivatedRoute,
              private isAllowedToPlay: IsAllowedToPlay) {}


  ngOnInit(): void {
  ngOnInit(): void {
    this.activatedRoute.paramMap.subscribe(params => {
    this.activatedRoute.paramMap.subscribe(params => {
      this.sessionName = String(params.get('sessionName'));
      this.sessionName = String(params.get('sessionName'));
      this.team = String(params.get('team'));
      const url = this.router.url.split('/');
      const url = this.router.url.split('/');
      const checkUser = url[url.length - 1];
      const checkUser = url[url.length - 1];
      if (checkUser === 'watchdog') {
      if (checkUser === 'watchdog') {
        if (!this.isAllowedToPlay.isAllowed || this.isAllowedToPlay.role !== 'watchdog') {
          this.router.navigate([this.sessionName + '/' + this.team]);
        } else {
          this.isWatchdog = true;
          this.isWatchdog = true;
        }
      } else if (checkUser === 'explainer') {
      } else if (checkUser === 'explainer') {
        if (!this.isAllowedToPlay.isAllowed || this.isAllowedToPlay.role !== 'explainer') {
          this.router.navigate([this.sessionName + '/' + this.team]);
        } else {
          this.isExplainer = true;
          this.isExplainer = true;
          this.service.getS2C({spielname: this.sessionName});
          this.service.getS2C({spielname: this.sessionName});
        }
        }
      }
      this.fillGamestatus();
      this.fillGamestatus();
      this.team = String(params.get('team'));
      this.socket = io(environment.tabuServerURL);
      this.socket = io(environment.tabuServerURL, {
        // WARNING: in that case, there is no fallback to long-polling
        transports: [ 'websocket' ] // or [ 'websocket', 'polling' ], which is the same thing
      });
      this.listen();
      this.listen();
    });
    });
    this.startTimer();
    this.startTimer();
@@ -90,7 +96,7 @@ export class GameComponent implements OnInit {
  }
  }


  onTimesUp(): void{
  onTimesUp(): void{
    this.socket.disconnect()
    this.socket.disconnect();
    this.router.navigate([this.sessionName + '/' + this.team]);
    this.router.navigate([this.sessionName + '/' + this.team]);
  }
  }


@@ -101,7 +107,7 @@ export class GameComponent implements OnInit {
      this.timeLeft = (this.TIME_LIMIT - this.timePassed);
      this.timeLeft = (this.TIME_LIMIT - this.timePassed);
      if (this.timeLeft === 0) {
      if (this.timeLeft === 0) {
        console.log('Times up!');
        console.log('Times up!');
        //this.onTimesUp();
        this.onTimesUp();
      }
      }
    }, 593);
    }, 593);
  }
  }
+13 −9
Original line number Original line Diff line number Diff line
import { Component, OnInit } from '@angular/core';
import {Component, Input, OnInit} from '@angular/core';
import {TabuMiddlewareService} from '../dao/TabuMiddlewareService';
import {TabuMiddlewareService} from '../dao/TabuMiddlewareService';
import {GameStatus} from '../interface/gameStatus';
import {GameStatus} from '../interface/gameStatus';
import {ActivatedRoute, Router} from '@angular/router';
import {ActivatedRoute, Router} from '@angular/router';
import {io} from 'socket.io-client';
import {io} from 'socket.io-client';
import {environment} from '../../environments/environment';
import {environment} from '../../environments/environment';
import {IsAllowedToPlay} from '../dao/isAllowedToPlay';
@Component({
@Component({
  selector: 'app-guesser',
  selector: 'app-guesser',
  templateUrl: './guesser.component.html',
  templateUrl: './guesser.component.html',
@@ -22,22 +23,25 @@ export class GuesserComponent implements OnInit {
    red: 0,
    red: 0,
    blue: 0,
    blue: 0,
    redTurn: true,
    redTurn: true,
    activeExplainer: false,
    activeExplainer: 1,
    activeWatchdog: false
    activeWatchdog: 1
  };
  };
  team = '';
  team = '';


  constructor(private router: Router, private activatedRoute: ActivatedRoute, private service: TabuMiddlewareService) { }
  constructor(private router: Router,
              private activatedRoute: ActivatedRoute,
              private service: TabuMiddlewareService,
              private isAllowedToPlay: IsAllowedToPlay) { }


  ngOnInit(): void {
  ngOnInit(): void {
    this.activatedRoute.paramMap.subscribe(params => {
    this.activatedRoute.paramMap.subscribe(params => {
      this.sessionName = String(params.get('sessionName'));
      this.sessionName = String(params.get('sessionName'));
      this.team = String(params.get('team'));
      this.team = String(params.get('team'));
      if (!this.isAllowedToPlay.isAllowed || this.isAllowedToPlay.role !== 'guesser') {
        this.router.navigate([this.sessionName + '/' + this.team]);
      }
      this.fillGamestatus();
      this.fillGamestatus();
      this.socket = io(environment.tabuServerURL, {
      this.socket = io(environment.tabuServerURL);
        // WARNING: in that case, there is no fallback to long-polling
        transports: [ 'websocket' ] // or [ 'websocket', 'polling' ], which is the same thing
      });
      this.listen();
      this.listen();
    });
    });
    this.startTimer();
    this.startTimer();
@@ -71,7 +75,7 @@ export class GuesserComponent implements OnInit {
      this.timeLeft = (this.TIME_LIMIT - this.timePassed);
      this.timeLeft = (this.TIME_LIMIT - this.timePassed);
      if (this.timeLeft === 0) {
      if (this.timeLeft === 0) {
        console.log('Times up!');
        console.log('Times up!');
        //this.onTimesUp();
        this.onTimesUp();
      }
      }
    }, 593);
    }, 593);
  }
  }
+2 −2
Original line number Original line Diff line number Diff line
@@ -3,6 +3,6 @@ export interface GameStatus {
  red: number;
  red: number;
  blue: number;
  blue: number;
  redTurn: boolean;
  redTurn: boolean;
  activeExplainer: boolean;
  activeExplainer: number;
  activeWatchdog: boolean;
  activeWatchdog: number;
}
}
Loading