Commit b5d55e28 authored by Mamadou Saliou DIALLO's avatar Mamadou Saliou DIALLO

get new modification from upstream

parent 9dbc3179
......@@ -16,7 +16,7 @@ struct PlayerID{
1: string id
}
service GameServerService {
service GameService {
i32 createGame(i32 numberOfPlayers)
......
......@@ -44,7 +44,7 @@ struct BoardGameState {
service PlayerService {
bool ping() throws (1:common.InvalidOperationException e)
string startGame(BoardGameState boardGameState)
string startGame(i32 gameId)
PlayerStateResponse blockActions()
PlayerStateResponse unblockActions()
void showPlayedCard()
......
......@@ -51,6 +51,7 @@
<sourceHighlighter>coderay</sourceHighlighter>
-->
<attributes>
<sourceHighlighter>coderay</sourceHighlighter>
<icons>font</icons>
<pagenums/>
<toc/>
......
= Conception détaillée
//:source-highlighter: rouge
== Game Server
[source, java]
----
class Klass {
String field;
}
----
[source, ocl]
----
context Klass
inv:
field->select()
----
.GameSever
[plantuml]
....
......@@ -78,4 +94,4 @@ partition Game::run() {
:Game Start>
stop
}
----
----
\ No newline at end of file
{
"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",
"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 { 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/GameService';
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);
}
}
......@@ -5,12 +5,11 @@ 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: {
......@@ -18,8 +17,8 @@ export class ThriftServer {
handler: new GameService.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"
],
......
......@@ -61,6 +61,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</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.thrift.GameServerService;
import fr.univnantes.alma.thrift.GameService;
import fr.univnantes.alma.handler.GameServiceHandler;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
......@@ -30,7 +30,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");
}
......
......@@ -3,12 +3,13 @@ package fr.univnantes.alma.handler;
import fr.univnantes.alma.common.GameInterface;
import fr.univnantes.alma.common.GameJoinRequest;
import fr.univnantes.alma.thrift.*;
import fr.univnantes.alma.thrift.GameService;
import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class GameServiceHandler implements GameServerService.Iface {
public class GameServiceHandler implements GameService.Iface {
@Autowired
GameInterface service;
......
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();
}
}
}
package fr.univnantes.alma;
import fr.univnantes.alma.thrift.GameServerService;
import fr.univnantes.alma.thrift.GameService;
import fr.univnantes.alma.thrift.JoinRequest;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocol;
......@@ -24,7 +24,7 @@ class NotAloneApplicationTest {
@LocalServerPort
protected int port;
protected GameServerService.Iface client;
protected GameService.Iface client;
@BeforeEach
public void setUp() throws Exception {
......@@ -32,7 +32,7 @@ class NotAloneApplicationTest {
TProtocol protocol = protocolFactory.getProtocol(transport);
client = new GameServerService.Client(protocol);
client = new GameService.Client(protocol);
}
@Test
......
This diff is collapsed.
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