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

get new modification from upstream

parent 9dbc3179
...@@ -16,7 +16,7 @@ struct PlayerID{ ...@@ -16,7 +16,7 @@ struct PlayerID{
1: string id 1: string id
} }
service GameServerService { service GameService {
i32 createGame(i32 numberOfPlayers) i32 createGame(i32 numberOfPlayers)
......
...@@ -44,7 +44,7 @@ struct BoardGameState { ...@@ -44,7 +44,7 @@ struct BoardGameState {
service PlayerService { service PlayerService {
bool ping() throws (1:common.InvalidOperationException e) bool ping() throws (1:common.InvalidOperationException e)
string startGame(BoardGameState boardGameState) string startGame(i32 gameId)
PlayerStateResponse blockActions() PlayerStateResponse blockActions()
PlayerStateResponse unblockActions() PlayerStateResponse unblockActions()
void showPlayedCard() void showPlayedCard()
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
<sourceHighlighter>coderay</sourceHighlighter> <sourceHighlighter>coderay</sourceHighlighter>
--> -->
<attributes> <attributes>
<sourceHighlighter>coderay</sourceHighlighter>
<icons>font</icons> <icons>font</icons>
<pagenums/> <pagenums/>
<toc/> <toc/>
......
= Conception détaillée = Conception détaillée
//:source-highlighter: rouge
== Game Server == Game Server
[source, java]
----
class Klass {
String field;
}
----
[source, ocl]
----
context Klass
inv:
field->select()
----
.GameSever .GameSever
[plantuml] [plantuml]
.... ....
...@@ -78,4 +94,4 @@ partition Game::run() { ...@@ -78,4 +94,4 @@ partition Game::run() {
:Game Start> :Game Start>
stop stop
} }
---- ----
\ No newline at end of file
{ {
"name": "not-alone-web", "name": "not-alone-player",
"version": "0.0.0", "version": "0.0.0",
"main": "dist/main.js",
"scripts": { "scripts": {
"prebuild": "tslint -c tslint.json -p tsconfig.json --fix", "prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
"build": "tsc", "build": "tsc",
"prestart": "npm run build", "prestart": "npm run build",
"start": "node .", "start": "node ./dist/main.js",
"test": "echo \"Error: no test specified\" && exit 1", "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/\"" "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'; ...@@ -5,12 +5,11 @@ import * as express from 'express';
import { createThriftServer } from '@creditkarma/thrift-server-express'; import { createThriftServer } from '@creditkarma/thrift-server-express';
const handler: ClientServiceHandler<express.Request> = new ClientServiceHandler<express.Request>(); const handler: ClientServiceHandler<express.Request> = new ClientServiceHandler<express.Request>();
const PORT = 8090;
export class ThriftServer { export class ThriftServer {
private app: express.Application; private app: express.Application;
constructor() { constructor(port: number) {
this.app = createThriftServer({ this.app = createThriftServer({
path: '/thrift', path: '/thrift',
thriftOptions: { thriftOptions: {
...@@ -18,8 +17,8 @@ export class ThriftServer { ...@@ -18,8 +17,8 @@ export class ThriftServer {
handler: new GameService.Processor(handler), handler: new GameService.Processor(handler),
}, },
}); });
this.app.listen(PORT, () => { this.app.listen(port, () => {
console.log(`Express server listening on port: ${PORT}`); console.log(`Thrift Express server listening on port: ${port}`);
}); });
} }
} }
......
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
"compileOnSave": false, "compileOnSave": false,
"compilerOptions": { "compilerOptions": {
"baseUrl": "./", "baseUrl": "./",
"outDir": "./dist/out-tsc", "outDir": "./dist/",
"sourceMap": true, "sourceMap": true,
"declaration": false, "declaration": false,
"module": "ES6", "module": "CommonJS",
"moduleResolution": "node", "moduleResolution": "node",
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"target": "ES5", "strict": true,
"target": "ES2017",
"typeRoots": [ "typeRoots": [
"node_modules/@types" "node_modules/@types"
], ],
......
...@@ -61,6 +61,11 @@ ...@@ -61,6 +61,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
</plugins> </plugins>
</build> </build>
......
package fr.univnantes.alma; package fr.univnantes.alma;
import fr.univnantes.alma.thrift.GameServerService; import fr.univnantes.alma.thrift.GameService;
import fr.univnantes.alma.handler.GameServiceHandler; import fr.univnantes.alma.handler.GameServiceHandler;
import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocolFactory; import org.apache.thrift.protocol.TProtocolFactory;
...@@ -30,7 +30,7 @@ public class NotAloneApplication { ...@@ -30,7 +30,7 @@ public class NotAloneApplication {
@Bean @Bean
public ServletRegistrationBean gameServer(TProtocolFactory protocolFactory, GameServiceHandler handler) { 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"); return new ServletRegistrationBean(tServlet, "/api");
} }
......
...@@ -3,12 +3,13 @@ package fr.univnantes.alma.handler; ...@@ -3,12 +3,13 @@ package fr.univnantes.alma.handler;
import fr.univnantes.alma.common.GameInterface; import fr.univnantes.alma.common.GameInterface;
import fr.univnantes.alma.common.GameJoinRequest; import fr.univnantes.alma.common.GameJoinRequest;
import fr.univnantes.alma.thrift.*; import fr.univnantes.alma.thrift.*;
import fr.univnantes.alma.thrift.GameService;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class GameServiceHandler implements GameServerService.Iface { public class GameServiceHandler implements GameService.Iface {
@Autowired @Autowired
GameInterface service; 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; package fr.univnantes.alma;
import fr.univnantes.alma.thrift.GameServerService; import fr.univnantes.alma.thrift.GameService;
import fr.univnantes.alma.thrift.JoinRequest; import fr.univnantes.alma.thrift.JoinRequest;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.protocol.TProtocol;
...@@ -24,7 +24,7 @@ class NotAloneApplicationTest { ...@@ -24,7 +24,7 @@ class NotAloneApplicationTest {
@LocalServerPort @LocalServerPort
protected int port; protected int port;
protected GameServerService.Iface client; protected GameService.Iface client;
@BeforeEach @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
...@@ -32,7 +32,7 @@ class NotAloneApplicationTest { ...@@ -32,7 +32,7 @@ class NotAloneApplicationTest {
TProtocol protocol = protocolFactory.getProtocol(transport); TProtocol protocol = protocolFactory.getProtocol(transport);
client = new GameServerService.Client(protocol); client = new GameService.Client(protocol);
} }
@Test @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