Commit 350118ed authored by Corentin Guillevic's avatar Corentin Guillevic
Browse files

Add the modifications of master branch

parent a60e88b2
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
// Types
......@@ -27,7 +28,7 @@ struct TColor {
//Service
service GameServerService {
service GameService {
TRoomId createRoom(TPlayerId playerId) throws (1:common.InvalidOperationException e)
......
include "common.thrift"
namespace java fr.univnantes.alma.thrift
namespace js common
//Type
......@@ -52,7 +53,7 @@ struct TCreature{
//Service
service GameClientService {
service PlayerService {
bool ping() throws (1:common.InvalidOperationException e)
void sendGameDescription(TPlayerTeam team, THand hand, TScore score, TPlanet planet, list<TCardReserve> reserve, list<TTraque> traquesInformation, TCreature creatureInformation)
......
......@@ -68,7 +68,7 @@ class Room{
- currentActivatePowers : PowerContainer[*]
- nextRoundPowers : PowerContainer[*]
- gameRoundVariables : GameRoundVariables
- gameClientHandler : GameClientHandler
- playerServiceHandler : GameClientHandler
- initializePlayer(creatureId : Integer, playerNumber : Integer)
- initializeReserve(playerNumber : Integer)
......
node_modules/
node/
dist/
src/codegen/
\ No newline at end of file
This diff is collapsed.
{
"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
}
}
......@@ -5,7 +5,7 @@ import fr.univnantes.alma.server.game.item.planet.Planet;
import fr.univnantes.alma.thrift.InvalidOperationException;
import fr.univnantes.alma.thrift.Response;
public interface GameService {
public interface RoomService {
/**
* Create a room if the player is not already in a room
......
package fr.univnantes.alma.server;
import fr.univnantes.alma.server.handler.GameServiceHandler;
import fr.univnantes.alma.thrift.GameServerService;
import fr.univnantes.alma.thrift.GameService;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServlet;
......@@ -28,7 +28,7 @@ public class NotAloneApplication {
@Bean
public ServletRegistrationBean gameServer(TProtocolFactory protocolFactory, GameServiceHandler handler) {
TServlet tServlet = new TServlet(new GameServerService.Processor<GameServiceHandler>(handler), protocolFactory);
TServlet tServlet = new TServlet(new GameService.Processor<GameServiceHandler>(handler), protocolFactory);
return new ServletRegistrationBean(tServlet, "/api");
}
......
......@@ -22,7 +22,7 @@ import fr.univnantes.alma.server.game.item.power.modifier.PowerModifierType;
import fr.univnantes.alma.server.game.item.power.recurrent.PowerRecurrent;
import fr.univnantes.alma.server.game.utilitary.Conversion;
import fr.univnantes.alma.server.game.utilitary.Pair;
import fr.univnantes.alma.server.handler.GameClientHandler;
import fr.univnantes.alma.server.handler.PlayerServiceHandler;
import fr.univnantes.alma.thrift.Response;
import fr.univnantes.alma.thrift.TAskAction;
import fr.univnantes.alma.thrift.TPair;
......@@ -113,10 +113,10 @@ public class Game implements GameInterface {
/**
* The game client handler
*/
private GameClientHandler gameClientHandler;
private PlayerServiceHandler playerServiceHandler;
public Game(int playerNumber, int creatureId, Planet planet, Board board, Room room) {
this.gameClientHandler = new GameClientHandler();
this.playerServiceHandler = new PlayerServiceHandler();
this.planet = planet;
this.board = board;
this.board.initializeScore(playerNumber);
......@@ -133,8 +133,8 @@ public class Game implements GameInterface {
sendFirstRoundStart();
}
public Game(int playerNumber, int creatureId, Planet planet, Board board, Room room, GameClientHandler gameClientHandler) {
this.gameClientHandler = gameClientHandler;
public Game(int playerNumber, int creatureId, Planet planet, Board board, Room room, PlayerServiceHandler playerServiceHandler) {
this.playerServiceHandler = playerServiceHandler;
this.planet = planet;
this.board = board;
this.board.initializeScore(playerNumber);
......@@ -608,7 +608,7 @@ public class Game implements GameInterface {
public Action askAction(int inGameIdPlayer, TAskAction askedAction) {
//TODO
try{
return Conversion.toAction(gameClientHandler.askAction(askedAction));
return Conversion.toAction(playerServiceHandler.askAction(askedAction));
}
catch (Exception e){
throw new IllegalArgumentException("Unknown error");
......
package fr.univnantes.alma.server.game;
import fr.univnantes.alma.common.GameService;
import fr.univnantes.alma.common.RoomService;
import fr.univnantes.alma.server.game.item.board.Board;
import fr.univnantes.alma.server.game.item.planet.Planet;
import fr.univnantes.alma.thrift.InvalidOperationException;
......@@ -12,7 +12,7 @@ import java.util.HashMap;
import java.util.Map;
@Component
public class GameServiceController implements GameService {
public class RoomServiceController implements RoomService {
private final Map<String, Room> rooms = new HashMap<>();
private final Map<String, String> players = new HashMap<>();
......
package fr.univnantes.alma.server.handler;
import fr.univnantes.alma.common.GameService;
import fr.univnantes.alma.common.RoomService;
import fr.univnantes.alma.server.game.item.Phase;
import fr.univnantes.alma.server.game.item.board.Board;
import fr.univnantes.alma.server.game.item.board.BoardColor;
......@@ -18,9 +18,9 @@ import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class GameServiceHandler implements GameServerService.Iface {
public class GameServiceHandler implements GameService.Iface {
@Autowired
GameService service;
RoomService service;
@Override
public TRoomId createRoom(TPlayerId playerId) throws TException {
......
......@@ -5,7 +5,7 @@ import org.apache.thrift.TException;
import java.util.List;
public class GameClientHandler implements GameClientService.Iface {
public class PlayerServiceHandler implements PlayerService.Iface {
@Override
public boolean ping() throws InvalidOperationException, TException {
return false;
......
Supports Markdown
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