Commit b169bc35 authored by Gerson Sunyé's avatar Gerson Sunyé
Browse files

Add new module 'not-alone-player' for players' related classes and communication-related stuff

- Module 'not-alone-web' is now reserved to Angular-related code
- This separation should help dealing with npm dependencies

Merge branch 'master' of gitlab.univ-nantes.fr:naomod/ooad/projet-2020
parents e40e0c3d 83bee15a
namespace java fr.univnantes.alma.thrift
namespace js core
namespace js common
exception InvalidOperationException {
1: i32 code,
......
include "common.thrift"
namespace java fr.univnantes.alma.thrift
namespace js common
struct JoinRequest {
1: string name
}
service GameServerService {
service GameService {
i32 createGame(i32 numberOfPlayers)
......
include "common.thrift"
namespace java fr.univnantes.alma.thrift
namespace js common
service GameClientService {
bool ping() throws (1:common.InvalidOperationException e)
service PlayerService {
void startGame(i32 gameId)
}
node_modules/
node/
dist/
\ No newline at end of file
{
"name": "not-alone-web",
"version": "0.0.0",
"scripts": {
"prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"test": "echo \"Error: no test specified\" && exit 1",
"codegen": "\"./node_modules/.bin/thrift-typescript\" --target thrift-server --sourceDir \"../not-alone-core/src/main/thrift/\" --outDir \"./src/codegen/\""
},
"private": true,
"devDependencies": {
"@creditkarma/thrift-parser": "^1.2.0",
"@creditkarma/thrift-typescript": "^3.7.6",
"@types/thrift": "^0.10.10",
"codelyzer": "^6.0.1",
"tslint": "^6.1.3"
},
"dependencies": {
"@creditkarma/thrift-client": "^0.16.1",
"@creditkarma/thrift-server-core": "^0.16.1",
"@creditkarma/thrift-server-express": "^0.16.1"
},
"browser": {
"crypto": false,
"stream": false
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>not-alone</artifactId>
<groupId>fr.univnantes.alma</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>not-alone-player</artifactId>
<name>Not Alone Player Services</name>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.10.0</version>
<configuration>
<workingDirectory>./</workingDirectory>
<nodeVersion>v14.11.0</nodeVersion>
<npmVersion>7.0.10</npmVersion>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
<execution>
<id>code generation</id>
<phase>compile</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run codegen</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>./dist/not-alone-web</directory>
<targetPath>static</targetPath>
</resource>
</resources>
</build>
</project>
import { IJoinRequest } from 'src/codegen/common';
import { IHandler } from '../codegen/common/GameService';
import { PlayerService } from '../player/player-service';
export class ClientServiceHandler<Context> implements IHandler<Context> {
private service: PlayerService;
constructor() {
this.service = new PlayerService();
}
public createGame(numberOfPlayers: number, context?: Context): number | Promise<number> {
throw new Error('Method not implemented.');
}
public join(gameId: number, request: IJoinRequest, context?: Context): number | Promise<number> {
throw new Error('Method not implemented.');
}
public startGame(gameId: number): void | Promise<void> {
return this.service.startGame(gameId);
}
}
export class PlayerService {
startGame(gameId: number): void {
console.log('Start game', gameId);
}
}
import { createHttpClient, HttpConnection } from '@creditkarma/thrift-client';
import * as request from 'request';
import { CoreOptions } from 'request';
import { Client } from '../codegen/common/GameService';
const CONFIG = {
hostName: 'localhost',
port: 8045,
};
const thriftClient: Client<CoreOptions> = createHttpClient(Client, CONFIG);
const id: Promise<Number> = thriftClient.createGame(8);
export class ThriftClient {}
import { GameService } from '../codegen/common/';
import { ClientServiceHandler } from '../handler/client-service-handler';
import * as express from 'express';
import { createThriftServer } from '@creditkarma/thrift-server-express';
const handler: ClientServiceHandler<express.Request> = new ClientServiceHandler<express.Request>();
const PORT = 8090;
export class ThriftServer {
private app: express.Application;
constructor() {
this.app = createThriftServer({
path: '/thrift',
thriftOptions: {
serviceName: 'calculator-service',
handler: new GameService.Processor(handler),
},
});
this.app.listen(PORT, () => {
console.log(`Express server listening on port: ${PORT}`);
});
}
}
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "ES6",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"paths": {
"core-js/es7/reflect": [
"node_modules/core-js/proposals/reflect-metadata"
]
}
},
"include": ["target/generated-sources/thrift//**/*", "src/**/*"]
}
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"arrow-return-shorthand": true,
"callable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"deprecation": {
"severity": "warn"
},
"eofline": true,
"forin": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": [
true,
"spaces"
],
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-arg": true,
"no-bitwise": true,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-super": true,
"no-empty": false,
"no-empty-interface": true,
"no-eval": true,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-misused-new": true,
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-shadowed-variable": true,
"no-string-literal": false,
"no-string-throw": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unnecessary-initializer": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"prefer-const": true,
"quotemark": [
true,
"single"
],
"radix": true,
"semicolon": [
true,
"always"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"unified-signatures": true,
"variable-name": false,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"no-output-on-prefix": true,
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-input-rename": true,
"no-output-rename": true,
"use-life-cycle-interface": true,
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true
}
}
......@@ -2,7 +2,7 @@ package fr.univnantes.alma.game;
import fr.univnantes.alma.common.GameJoinRequest;
import fr.univnantes.alma.common.GameService;
import fr.univnantes.alma.common.GameInterface;
import org.springframework.stereotype.Component;
import java.util.HashMap;
......@@ -12,7 +12,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.atlanmod.commons.Preconditions.checkArgument;
@Component
public class GameServiceController implements GameService {
public class GameServiceController implements GameInterface {
private final AtomicInteger idCounter = new AtomicInteger(0);
private final Map<Integer, Game> games = new HashMap<>();
......
......@@ -8,7 +8,7 @@
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"codegen": "./node_modules/.bin/thrift-typescript --sourceDir ../not-alone-core/src/main/thrift/ --outDir ./target/generated-sources/thrift/"
"codegen": "\"./node_modules/.bin/thrift-typescript\" --sourceDir \"../not-alone-core/src/main/thrift/\" --outDir \"./src/codegen/\""
},
"private": true,
"devDependencies": {
......
......@@ -21,7 +21,7 @@
<configuration>
<workingDirectory>./</workingDirectory>
<nodeVersion>v14.11.0</nodeVersion>
<npmVersion>6.14.8</npmVersion>
<npmVersion>7.0.10</npmVersion>
</configuration>
<executions>
<execution>
......@@ -29,12 +29,17 @@
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm run build</id>
......@@ -46,8 +51,8 @@
</configuration>
</execution>
<execution>
<id>code geneation</id>
<phase>generate-sources</phase>
<id>code generation</id>
<phase>compile</phase>
<goals>
<goal>npm</goal>
</goals>
......@@ -66,5 +71,4 @@
</resources>
</build>
</project>
......@@ -23,6 +23,7 @@
<module>not-alone-server</module>
<module>not-alone-web</module>
<module>not-alone-core</module>
<module>not-alone-player</module>
</modules>
<build>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment