Commit 4a6d798a authored by Natanael BOUTEILLER's avatar Natanael BOUTEILLER
Browse files

codegen update command on not alone player. Fork upstream merging

parents 3cb1e103 c22f0c08
......@@ -51,6 +51,7 @@
<sourceHighlighter>coderay</sourceHighlighter>
-->
<attributes>
<sourceHighlighter>coderay</sourceHighlighter>
<icons>font</icons>
<pagenums/>
<toc/>
......
= Conception détaillée
//:source-highlighter: rouge
.Diagramme de classe des cases
[plantuml, dc-case-not-alone, png]
......@@ -128,6 +128,22 @@ class "Case Traqué" {
....
== Game Server
[source, java]
----
class Klass {
String field;
}
----
[source, ocl]
----
context Klass
inv:
field->select()
----
.GameSever
[plantuml]
....
......
{
"name": "not-alone-web",
"name": "not-alone-player",
"version": "0.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "not-alone-web",
"version": "0.0.0",
"dependencies": {
"@creditkarma/thrift-client": "^0.16.1",
......
{
"name": "not-alone-web",
"name": "not-alone-player",
"version": "0.0.0",
"main": "dist/main.js",
"scripts": {
"prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
"prebuild": "tslint -c tslint.json -p tsconfig.json --fix && npm run codegen",
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"start": "node ./dist/main.js",
"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/\""
},
......
export interface GameInterface {
createGame(numberOfPlayers: number): Promise<number>;
join(gameId: number): Promise<number>;
}
import { IJoinRequest } from 'src/codegen/common';
import { IHandler } from '../codegen/common/GameService';
import { IHandler } from '../codegen/common/GameServerService';
import { PlayerService } from '../player/player-service';
export class ClientServiceHandler<Context> implements IHandler<Context> {
......@@ -23,4 +23,9 @@ export class ClientServiceHandler<Context> implements IHandler<Context> {
}
public getJoueurs(gameId: number): string[] | Promise<string[]> {
throw new Error('Method not implemented');
}
}
import { ThriftServer } from './thrift/thrift-server';
/**
* Port used for local Thrift server.
*/
const LOCAL_PORT = 8090;
class Main {
private server: ThriftServer;
constructor() {
console.log('Main class');
this.server = new ThriftServer(LOCAL_PORT);
}
}
const main: Main = new Main();
import { Client } from 'src/codegen/common/GameServerService';
import { GameInterface } from '../core/game';
import { CoreOptions } from 'request';
import { createHttpClient, ICreateHttpClientOptions } from '@creditkarma/thrift-client';
import { IJoinRequest, JoinRequest } from '../codegen/common/JoinRequest';
export class GameProxy implements GameInterface {
private thriftClient: Client<CoreOptions>;
constructor(options: ICreateHttpClientOptions) {
this.thriftClient = createHttpClient(Client, options);
}
createGame(numberOfPlayers: number): Promise<number> {
return this.thriftClient.createGame(numberOfPlayers);
}
join(gameId: number): Promise<number> {
const request: IJoinRequest = new JoinRequest();
request.name = 'me';
return this.thriftClient.join(gameId, request);
}
}
......@@ -2,7 +2,7 @@ import { createHttpClient, HttpConnection } from '@creditkarma/thrift-client';
import * as request from 'request';
import { CoreOptions } from 'request';
import { Client } from '../codegen/common/GameService';
import { Client } from '../codegen/common/GameServerService';
const CONFIG = {
hostName: 'localhost',
......
import { GameService } from '../codegen/common/';
import { GameServerService } 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() {
constructor(port: number) {
this.app = createThriftServer({
path: '/thrift',
thriftOptions: {
serviceName: 'calculator-service',
handler: new GameService.Processor(handler),
handler: new GameServerService.Processor(handler),
},
});
this.app.listen(PORT, () => {
console.log(`Express server listening on port: ${PORT}`);
this.app.listen(port, () => {
console.log(`Thrift Express server listening on port: ${port}`);
});
}
}
......
......@@ -2,14 +2,15 @@
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"outDir": "./dist/",
"sourceMap": true,
"declaration": false,
"module": "ES6",
"module": "CommonJS",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES5",
"strict": true,
"target": "ES2017",
"typeRoots": [
"node_modules/@types"
],
......
......@@ -59,6 +59,11 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
</plugins>
</build>
......
package fr.univnantes.alma;
import fr.univnantes.alma.common.GameService;
import fr.univnantes.alma.thrift.GameServerService;
import fr.univnantes.alma.handler.GameServiceHandler;
import org.apache.thrift.protocol.TBinaryProtocol;
......@@ -33,8 +32,6 @@ public class NotAloneApplication {
public ServletRegistrationBean gameServer(TProtocolFactory protocolFactory, GameServiceHandler handler) {
TServlet tServlet = new TServlet(new GameServerService.Processor<GameServiceHandler>(handler), protocolFactory);
return new ServletRegistrationBean(tServlet, "/api");
}
}
package fr.univnantes.alma.player;
public interface PlayerInterface {
void startGame(int gameId);
}
package fr.univnantes.alma.player;
import fr.univnantes.alma.thrift.PlayerService.Client;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import java.net.SocketAddress;
public class PlayerProxy implements PlayerInterface {
private Client client;
public PlayerProxy(String addr, int port) throws TTransportException {
TTransport transport = new TSocket(addr, port);
TProtocol protocol = new TBinaryProtocol(transport);
client = new Client(protocol);
}
@Override
public void startGame(int gameId) {
try {
client.startGame(gameId);
} catch (TException e) {
e.printStackTrace();
}
}
}
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