Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Not Alone
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexandre GERBIER
Not Alone
Commits
fe97423e
Commit
fe97423e
authored
Nov 27, 2020
by
Natanael BOUTEILLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout de getJoueur dans thrift + ajout structure de stockage des joueurs dans hashmap
parent
e72e43a1
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
68 additions
and
16 deletions
+68
-16
not-alone-core/src/main/thrift/game-server.thrift
not-alone-core/src/main/thrift/game-server.thrift
+2
-0
not-alone-doc/src/doc/asciidoc/_sections/composants.adoc
not-alone-doc/src/doc/asciidoc/_sections/composants.adoc
+3
-12
not-alone-server/src/main/java/fr/univnantes/alma/NotAloneApplication.java
...src/main/java/fr/univnantes/alma/NotAloneApplication.java
+3
-0
not-alone-server/src/main/java/fr/univnantes/alma/common/GameJoinRequest.java
.../main/java/fr/univnantes/alma/common/GameJoinRequest.java
+8
-0
not-alone-server/src/main/java/fr/univnantes/alma/common/GameService.java
.../src/main/java/fr/univnantes/alma/common/GameService.java
+4
-0
not-alone-server/src/main/java/fr/univnantes/alma/game/Game.java
...ne-server/src/main/java/fr/univnantes/alma/game/Game.java
+16
-2
not-alone-server/src/main/java/fr/univnantes/alma/game/GameServiceController.java
...n/java/fr/univnantes/alma/game/GameServiceController.java
+7
-0
not-alone-server/src/main/java/fr/univnantes/alma/game/Player.java
...-server/src/main/java/fr/univnantes/alma/game/Player.java
+9
-0
not-alone-server/src/main/java/fr/univnantes/alma/handler/GameServiceHandler.java
...n/java/fr/univnantes/alma/handler/GameServiceHandler.java
+9
-1
not-alone-server/src/test/java/fr/univnantes/alma/NotAloneApplicationTest.java
...test/java/fr/univnantes/alma/NotAloneApplicationTest.java
+7
-1
No files found.
not-alone-core/src/main/thrift/game-server.thrift
View file @
fe97423e
...
@@ -11,4 +11,6 @@ service GameServerService {
...
@@ -11,4 +11,6 @@ service GameServerService {
i32 createGame(i32 numberOfPlayers)
i32 createGame(i32 numberOfPlayers)
i32 join(i32 gameId, JoinRequest request) throws (1:common.GameNotFound e)
i32 join(i32 gameId, JoinRequest request) throws (1:common.GameNotFound e)
list<string> getJoueurs(i32 gameId) throws (1:common.GameNotFound e)
}
}
not-alone-doc/src/doc/asciidoc/_sections/composants.adoc
View file @
fe97423e
...
@@ -45,18 +45,9 @@ component GameServer as gs
...
@@ -45,18 +45,9 @@ component GameServer as gs
component Player as player
component Player as player
component Traque as traque
component Traque as traque
component Creature as creature
component Creature as creature
traque -(0-"livrerCarteSurvie" gs
traque -(0- gs
gs -0)--"jouerCarte" player
gs -0)-- player
gs -0)--"jouerPion" player
gs -0)--"join" player
creature -left0)--"livrerCarteTraque" gs
creature -left0)-- gs
....
.Diagramme de composants
[plantuml]
....
component GameServer as gs
gs --> createGame
gs --> join
....
....
not-alone-server/src/main/java/fr/univnantes/alma/NotAloneApplication.java
View file @
fe97423e
package
fr.univnantes.alma
;
package
fr.univnantes.alma
;
import
fr.univnantes.alma.common.GameService
;
import
fr.univnantes.alma.thrift.GameServerService
;
import
fr.univnantes.alma.thrift.GameServerService
;
import
fr.univnantes.alma.handler.GameServiceHandler
;
import
fr.univnantes.alma.handler.GameServiceHandler
;
import
org.apache.thrift.protocol.TBinaryProtocol
;
import
org.apache.thrift.protocol.TBinaryProtocol
;
...
@@ -32,6 +33,8 @@ public class NotAloneApplication {
...
@@ -32,6 +33,8 @@ public class NotAloneApplication {
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
GameServerService
.
Processor
<
GameServiceHandler
>(
handler
),
protocolFactory
);
return
new
ServletRegistrationBean
(
tServlet
,
"/api"
);
return
new
ServletRegistrationBean
(
tServlet
,
"/api"
);
}
}
}
}
not-alone-server/src/main/java/fr/univnantes/alma/common/GameJoinRequest.java
View file @
fe97423e
package
fr.univnantes.alma.common
;
package
fr.univnantes.alma.common
;
public
class
GameJoinRequest
{
public
class
GameJoinRequest
{
private
String
name
;
public
GameJoinRequest
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getName
()
{
return
this
.
name
;
}
}
}
not-alone-server/src/main/java/fr/univnantes/alma/common/GameService.java
View file @
fe97423e
...
@@ -2,6 +2,8 @@ package fr.univnantes.alma.common;
...
@@ -2,6 +2,8 @@ package fr.univnantes.alma.common;
import
fr.univnantes.alma.common.GameJoinRequest
;
import
fr.univnantes.alma.common.GameJoinRequest
;
import
java.util.List
;
public
interface
GameService
{
public
interface
GameService
{
/**
/**
...
@@ -20,4 +22,6 @@ public interface GameService {
...
@@ -20,4 +22,6 @@ public interface GameService {
*/
*/
int
join
(
int
gameId
,
GameJoinRequest
request
);
int
join
(
int
gameId
,
GameJoinRequest
request
);
List
<
String
>
getJoueurs
(
int
gameId
);
}
}
not-alone-server/src/main/java/fr/univnantes/alma/game/Game.java
View file @
fe97423e
...
@@ -3,6 +3,10 @@ package fr.univnantes.alma.game;
...
@@ -3,6 +3,10 @@ package fr.univnantes.alma.game;
import
fr.univnantes.alma.common.GameJoinRequest
;
import
fr.univnantes.alma.common.GameJoinRequest
;
import
org.atlanmod.commons.log.Log
;
import
org.atlanmod.commons.log.Log
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
...
@@ -12,7 +16,7 @@ public class Game {
...
@@ -12,7 +16,7 @@ public class Game {
* Stores arriving registrations.
* Stores arriving registrations.
*/
*/
private
final
BlockingQueue
<
GameJoinRequest
>
requests
;
private
final
BlockingQueue
<
GameJoinRequest
>
requests
;
private
Map
<
String
,
Player
>
players
;
/**
/**
* Counter used to increment player identifications.
* Counter used to increment player identifications.
*/
*/
...
@@ -25,6 +29,7 @@ public class Game {
...
@@ -25,6 +29,7 @@ public class Game {
public
Game
(
int
expectedPlayers
)
{
public
Game
(
int
expectedPlayers
)
{
this
.
expectedPlayers
=
new
AtomicInteger
(
expectedPlayers
);
this
.
expectedPlayers
=
new
AtomicInteger
(
expectedPlayers
);
this
.
requests
=
new
ArrayBlockingQueue
<
GameJoinRequest
>(
expectedPlayers
);
this
.
requests
=
new
ArrayBlockingQueue
<
GameJoinRequest
>(
expectedPlayers
);
this
.
players
=
new
HashMap
<>(
expectedPlayers
);
play
=
new
Thread
(()
->
this
.
start
());
play
=
new
Thread
(()
->
this
.
start
());
play
.
start
();
play
.
start
();
...
@@ -47,9 +52,10 @@ public class Game {
...
@@ -47,9 +52,10 @@ public class Game {
GameJoinRequest
request
;
GameJoinRequest
request
;
while
(
request
s
.
size
()
<
expectedPlayers
.
intValue
())
{
while
(
player
s
.
size
()
<
expectedPlayers
.
intValue
())
{
try
{
try
{
request
=
requests
.
take
();
request
=
requests
.
take
();
System
.
out
.
println
(
request
.
getName
());
this
.
handleRequest
(
request
);
this
.
handleRequest
(
request
);
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
Log
.
error
(
e
);
Log
.
error
(
e
);
...
@@ -58,5 +64,13 @@ public class Game {
...
@@ -58,5 +64,13 @@ public class Game {
}
}
private
void
handleRequest
(
GameJoinRequest
request
)
{
private
void
handleRequest
(
GameJoinRequest
request
)
{
players
.
put
(
request
.
getName
(),
new
Player
(
request
.
getName
()));
}
public
List
<
String
>
getJoueurs
()
{
LinkedList
<
String
>
liste
=
new
LinkedList
<>();
liste
.
addAll
(
players
.
keySet
());
return
liste
;
}
}
}
}
not-alone-server/src/main/java/fr/univnantes/alma/game/GameServiceController.java
View file @
fe97423e
...
@@ -6,6 +6,7 @@ import fr.univnantes.alma.common.GameService;
...
@@ -6,6 +6,7 @@ import fr.univnantes.alma.common.GameService;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
...
@@ -34,4 +35,10 @@ public class GameServiceController implements GameService {
...
@@ -34,4 +35,10 @@ public class GameServiceController implements GameService {
return
game
.
join
(
request
);
return
game
.
join
(
request
);
}
}
@Override
public
List
<
String
>
getJoueurs
(
int
gameId
)
{
Game
game
=
games
.
get
(
gameId
);
return
game
.
getJoueurs
();
}
}
}
not-alone-server/src/main/java/fr/univnantes/alma/game/Player.java
0 → 100644
View file @
fe97423e
package
fr.univnantes.alma.game
;
public
class
Player
{
String
name
;
Player
(
String
name
)
{
this
.
name
=
name
;
}
}
not-alone-server/src/main/java/fr/univnantes/alma/handler/GameServiceHandler.java
View file @
fe97423e
...
@@ -9,6 +9,9 @@ import org.apache.thrift.TException;
...
@@ -9,6 +9,9 @@ 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
;
import
java.util.LinkedList
;
import
java.util.List
;
@Component
@Component
public
class
GameServiceHandler
implements
GameServerService
.
Iface
{
public
class
GameServiceHandler
implements
GameServerService
.
Iface
{
...
@@ -23,7 +26,12 @@ public class GameServiceHandler implements GameServerService.Iface {
...
@@ -23,7 +26,12 @@ public class GameServiceHandler implements GameServerService.Iface {
@Override
@Override
public
int
join
(
int
gameId
,
JoinRequest
request
)
throws
TException
{
public
int
join
(
int
gameId
,
JoinRequest
request
)
throws
TException
{
//TODO: translate JoinRequest into GameJoinRequest
//TODO: translate JoinRequest into GameJoinRequest
return
service
.
join
(
gameId
,
new
GameJoinRequest
());
String
name
=
request
.
getName
();
return
service
.
join
(
gameId
,
new
GameJoinRequest
(
name
));
}
}
@Override
public
List
<
String
>
getJoueurs
(
int
gameId
)
throws
TException
{
return
service
.
getJoueurs
(
gameId
);
}
}
}
not-alone-server/src/test/java/fr/univnantes/alma/NotAloneApplicationTest.java
View file @
fe97423e
...
@@ -52,6 +52,12 @@ class NotAloneApplicationTest {
...
@@ -52,6 +52,12 @@ class NotAloneApplicationTest {
client
.
join
(
id
,
new
JoinRequest
(
"four"
));
client
.
join
(
id
,
new
JoinRequest
(
"four"
));
Thread
.
sleep
(
1000
);
Thread
.
sleep
(
10000
);
System
.
out
.
println
(
client
.
getJoueurs
(
id
));
Thread
.
sleep
(
10000
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment