Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alexandre Ducarne
ai12-othello
Commits
10b31ec9
Commit
10b31ec9
authored
Nov 26, 2019
by
Thomas Lecluse
Browse files
Merge branch 'feature/data/v2' into 'int/v2'
Feature/data/v2 See merge request
!27
parents
3d41a2e2
82952314
Changes
14
Hide whitespace changes
Inline
Side-by-side
src/main/java/client/data/ComToDataClientImpl.java
View file @
10b31ec9
...
...
@@ -27,11 +27,13 @@ public class ComToDataClientImpl implements IComToData {
@Override
public
void
addNewUser
(
UserLight
user
)
{
dataCoreClient
.
getListConnectedUsers
().
add
(
user
);
dataCoreClient
.
getDataToMain
().
updateUserList
(
user
);
}
@Override
public
void
notifyNewGame
(
GameLight
newGameCreated
)
{
dataCoreClient
.
getListGameLight
().
add
(
newGameCreated
);
dataCoreClient
.
getDataToMain
().
showNewGame
(
newGameCreated
);
}
@Override
...
...
@@ -41,7 +43,7 @@ public class ComToDataClientImpl implements IComToData {
@Override
public
void
receiveChatMessage
(
Message
message
)
{
dataCoreClient
.
getDataToGame
().
displayMessage
(
message
);
}
@Override
...
...
@@ -86,6 +88,16 @@ public class ComToDataClientImpl implements IComToData {
dataCoreClient
.
getDataToMain
().
sendLists
(
players
,
gamesAvailable
);
}
@Override
public
void
forwardPlayers
(
List
<
UserLight
>
players
)
{
dataCoreClient
.
setListConnectedUsers
(
players
);
}
@Override
public
void
forwardGames
(
List
<
GameLight
>
games
)
{
dataCoreClient
.
setListGameLight
(
games
);
}
@Override
public
void
receiveServerStateOnConnection
(
ArrayList
<
UserLight
>
usersOnline
,
ArrayList
<
GameLight
>
gamesOnline
)
{
...
...
src/main/java/client/data/DataCoreClient.java
View file @
10b31ec9
package
main.java.client.data
;
import
main.java.common.dataModel.*
;
import
main.java.common.interfaces.client.IComToData
;
import
main.java.common.interfaces.client.IDataToCom
;
import
main.java.common.interfaces.client.IDataToMain
;
import
main.java.common.interfaces.client.IMainToData
;
import
main.java.common.interfaces.client.*
;
import
java.util.List
;
...
...
@@ -17,13 +14,16 @@ public class DataCoreClient {
private
MainToDataImpl
mainToDataImpl
;
private
ComToDataClientImpl
comToDataClientImpl
;
private
GameToDataImpl
gameToDataImpl
;
private
IDataToCom
dataToCom
;
private
IDataToMain
dataToMain
;
private
IDataToGame
dataToGame
;
public
DataCoreClient
()
{
mainToDataImpl
=
new
MainToDataImpl
(
this
);
comToDataClientImpl
=
new
ComToDataClientImpl
(
this
);
gameToDataImpl
=
new
GameToDataImpl
(
this
);
}
public
List
<
UserLight
>
getListConnectedUsers
()
{
...
...
@@ -66,6 +66,10 @@ public class DataCoreClient {
this
.
listGameLight
=
listGameLight
;
}
public
List
<
GameLight
>
getListGameLight
(){
return
listGameLight
;
}
private
boolean
isMoveValid
(
Move
playerMove
,
Board
boardGame
)
{
return
false
;
}
...
...
@@ -77,4 +81,12 @@ public class DataCoreClient {
public
void
setDataToMain
(
IDataToMain
dataToMain
)
{
this
.
dataToMain
=
dataToMain
;
}
public
IDataToGame
getDataToGame
()
{
return
dataToGame
;
}
public
GameToDataImpl
getGameToDataImpl
()
{
return
gameToDataImpl
;
}
}
src/main/java/client/data/GameToDataImpl.java
0 → 100644
View file @
10b31ec9
package
main.java.client.data
;
import
main.java.common.dataModel.GameLight
;
import
main.java.common.dataModel.Message
;
import
main.java.common.dataModel.UserLight
;
import
main.java.common.dataModel.UserZero
;
import
main.java.common.interfaces.client.IGameToData
;
import
java.sql.Timestamp
;
import
java.util.Date
;
import
java.util.ListIterator
;
import
java.util.UUID
;
public
class
GameToDataImpl
implements
IGameToData
{
DataCoreClient
dataCoreClient
;
public
GameToDataImpl
(
DataCoreClient
dataCoreClient
)
{
this
.
dataCoreClient
=
dataCoreClient
;
}
@Override
public
void
playMove
(
int
x
,
int
y
,
UserZero
u
)
{
}
@Override
public
void
getPlayer
(
UUID
id
)
{
}
@Override
public
void
newGameAvailable
(
GameLight
gl
)
{
dataCoreClient
.
getDataToCom
().
addNewGameAvailable
(
gl
);
}
@Override
public
void
askGame
(
UUID
gameId
,
UUID
userId
)
{
}
@Override
public
void
newMessage
(
String
m
,
UUID
pid
,
UUID
gameId
)
throws
Exception
{
dataCoreClient
.
getDataToCom
().
sendChatMessage
(
m
,
new
Timestamp
(
new
Date
().
getTime
()),
pid
,
gameId
);
}
}
src/main/java/client/data/MainToDataImpl.java
View file @
10b31ec9
package
main.java.client.data
;
import
main.java.common.dataModel.GameHeavy
;
import
main.java.common.dataModel.GameLight
;
import
main.java.common.dataModel.UserHeavy
;
import
main.java.common.dataModel.UserLight
;
import
main.java.common.dataModel.*
;
import
main.java.common.interfaces.client.IMainToData
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
...
...
@@ -69,7 +66,9 @@ public class MainToDataImpl implements IMainToData {
@Override
public
Scene
newGame
(
UserLight
ul
,
Boolean
spectatorsOk
,
Boolean
chatOk
,
Boolean
creatorPlayWhite
,
int
limitMove
,
Scene
sceneFx
)
{
return
null
;
GameLight
gameCreated
=
new
GameLight
(
UUID
.
randomUUID
(),
ul
,
null
,
GameStatus
.
PENDING
,
spectatorsOk
,
chatOk
,
creatorPlayWhite
,
limitMove
);
dataCoreClient
.
getDataToGame
().
getGameScreen
(
gameCreated
,
sceneFx
);
return
sceneFx
;
}
@Override
...
...
@@ -123,6 +122,7 @@ public class MainToDataImpl implements IMainToData {
userFile
.
renameTo
(
oldFile
);
try
{
createUser
(
profileLight
,
profileHeavy
);
//dataCoreClient.getDataToCom().notifyUpdateProfile(profileLight); TO DISCUSS WITH COM
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
oldFile
.
renameTo
(
userFile
);
...
...
src/main/java/client/game/model/IHMGameCore.java
View file @
10b31ec9
package
main.java.client.game.model
;
import
main.java.common.dataModel.GameLight
;
import
main.java.common.dataModel.UserZero
;
import
main.java.common.interfaces.client.IGameToData
;
...
...
@@ -33,6 +34,11 @@ public class IHMGameCore implements IGameToData {
}
@Override
public
void
newGameAvailable
(
GameLight
gl
)
{
}
/**
* @param gameId
* @param userId
...
...
@@ -44,10 +50,11 @@ public class IHMGameCore implements IGameToData {
/**
* @param m
* @param pid
* @param pId
* @param gameId
*/
@Override
public
void
newMessage
(
String
m
,
UUID
p
id
)
{
public
void
newMessage
(
String
m
,
UUID
p
Id
,
UUID
gameId
)
throws
Exception
{
}
}
src/main/java/client/network/DataToComClientImpl.java
View file @
10b31ec9
...
...
@@ -48,7 +48,7 @@ public class DataToComClientImpl implements IDataToCom {
}
@Override
public
void
sendChatMessage
(
String
message
,
Timestamp
time
)
{
public
void
sendChatMessage
(
String
message
,
Timestamp
time
,
UUID
playerID
,
UUID
gameID
)
{
// TODO Auto-generated method stub
}
...
...
src/main/java/common/dataModel/GameHeavy.java
View file @
10b31ec9
...
...
@@ -60,6 +60,11 @@ public class GameHeavy extends GameMeta {
this
.
spectators
=
spectators
;
}
public
GameLight
convertToGameLight
()
{
return
new
GameLight
(
this
.
getId
(),
this
.
getGameCreator
(),
this
.
getPlayer2
(),
this
.
getStatus
(),
this
.
isOkSpectators
(),
this
.
isOkChat
(),
this
.
isWhiteCreator
(),
this
.
getLimitMove
());
}
@Override
public
String
toString
()
{
return
"GameHeavy{"
+
...
...
src/main/java/common/dataModel/UserLight.java
View file @
10b31ec9
...
...
@@ -68,6 +68,10 @@ public class UserLight extends UserMeta {
this
.
wonGames
=
wonGames
;
}
public
UserZero
convertToUserZero
()
{
return
new
UserZero
(
this
.
getId
(),
this
.
getPseudo
());
}
@Override
public
String
toString
()
{
return
"UserLight{"
+
...
...
src/main/java/common/interfaces/client/IComToData.java
View file @
10b31ec9
...
...
@@ -113,6 +113,10 @@ public interface IComToData {
public
void
receivePlayersnGames
(
List
<
UserLight
>
players
,
List
<
GameLight
>
gamesAvailable
);
public
void
forwardPlayers
(
List
<
UserLight
>
players
);
public
void
forwardGames
(
List
<
GameLight
>
games
);
/**
* Receive lists of all users and games available on server.
*
...
...
src/main/java/common/interfaces/client/IDataToCom.java
View file @
10b31ec9
...
...
@@ -48,7 +48,7 @@ public interface IDataToCom {
* @param message : the message
* @param time : the timestamp when the message was written
*/
void
sendChatMessage
(
String
message
,
Timestamp
time
);
void
sendChatMessage
(
String
message
,
Timestamp
time
,
UUID
playerID
,
UUID
gameID
);
/**
* Send a disconnecting request to the server.
...
...
src/main/java/common/interfaces/client/IGameToData.java
View file @
10b31ec9
...
...
@@ -2,6 +2,7 @@ package main.java.common.interfaces.client;
import
java.util.UUID
;
import
main.java.common.dataModel.GameLight
;
import
main.java.common.dataModel.UserZero
;
public
interface
IGameToData
{
...
...
@@ -9,7 +10,9 @@ public interface IGameToData {
public
void
getPlayer
(
UUID
id
);
public
void
newGameAvailable
(
GameLight
gl
);
public
void
askGame
(
UUID
gameId
,
UUID
userId
);
public
void
newMessage
(
String
m
,
UUID
pid
)
;
public
void
newMessage
(
String
m
,
UUID
pid
,
UUID
gameId
)
throws
Exception
;
}
src/main/java/common/interfaces/server/IComToData.java
View file @
10b31ec9
package
main.java.common.interfaces.server
;
import
java.s
ecurity
.Timestamp
;
import
java.s
ql
.Timestamp
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
import
main.java.common.dataModel.GameLight
;
...
...
@@ -52,7 +53,7 @@ public interface IComToData {
* @param gameID : the UUID of the game in which the message was sent
* @return the message to transfer
*/
Message
receiveNewChatMessage
(
String
message
,
Timestamp
timestamp
,
UUID
userID
,
UUID
gameID
);
Message
receiveNewChatMessage
(
String
message
,
Timestamp
timestamp
,
UUID
userID
,
UUID
gameID
)
throws
Exception
;
/**
* Get all the participants (players & spectators) of a game.
...
...
@@ -60,7 +61,7 @@ public interface IComToData {
* @param gameID : the UUID of the game
* @return the list of users
*/
ArrayList
<
UUID
>
getAllGameParticipants
(
UUID
gameID
);
ArrayList
<
UUID
>
getAllGameParticipants
(
UUID
gameID
)
throws
Exception
;
/**
* Notify that a user has been disconnected.
...
...
@@ -83,4 +84,10 @@ public interface IComToData {
* @param move : the move to send
*/
void
sendMove
(
Move
move
);
public
List
<
UserLight
>
getListUsers
();
public
List
<
GameLight
>
getListGames
();
public
void
updateListOnModifyProfile
(
UserLight
userModified
);
}
src/main/java/server/data/ComToDataServerImpl.java
View file @
10b31ec9
package
main.java.server.data
;
import
main.java.common.dataModel.GameLight
;
import
main.java.common.dataModel.Message
;
import
main.java.common.dataModel.Move
;
import
main.java.common.dataModel.UserLight
;
import
main.java.common.dataModel.*
;
import
main.java.common.interfaces.server.IComToData
;
import
java.s
ecurity.Timestamp
;
import
java.
util.ArrayList
;
import
java.util.
UUID
;
import
java.s
ql.Array
;
import
java.
sql.Timestamp
;
import
java.util.
*
;
public
class
ComToDataServerImpl
implements
IComToData
{
...
...
@@ -25,12 +22,17 @@ public class ComToDataServerImpl implements IComToData {
@Override
public
void
addAuthenticatedPlayer
(
UserLight
userLight
)
{
dataCoreServer
.
l
istConnectedUsers
.
add
(
userLight
);
dataCoreServer
.
getL
istConnectedUsers
()
.
add
(
userLight
);
}
@Override
public
void
createGame
(
GameLight
gameLight
)
{
GameHeavy
newGame
=
new
GameHeavy
(
gameLight
.
getId
(),
gameLight
.
getGameCreator
(),
gameLight
.
getPlayer2
(),
gameLight
.
getStatus
(),
gameLight
.
isOkSpectators
(),
gameLight
.
isOkChat
(),
gameLight
.
isWhiteCreator
(),
gameLight
.
getLimitMove
(),
new
ArrayList
<
Move
>(),
null
,
gameLight
.
isOkChat
()
?
new
Chat
(
new
ArrayList
<
Message
>(),
gameLight
)
:
null
,
null
,
gameLight
.
isOkSpectators
()
?
new
ArrayList
<
UserZero
>()
:
null
);
dataCoreServer
.
getListGameHeavy
().
add
(
newGame
);
dataCoreServer
.
getDataToCom
().
notifyNewGame
(
gameLight
);
}
@Override
...
...
@@ -39,13 +41,52 @@ public class ComToDataServerImpl implements IComToData {
}
@Override
public
Message
receiveNewChatMessage
(
String
message
,
Timestamp
timestamp
,
UUID
userID
,
UUID
gameID
)
{
return
null
;
public
Message
receiveNewChatMessage
(
String
message
,
Timestamp
timestamp
,
UUID
userID
,
UUID
gameID
)
throws
Exception
{
ListIterator
<
UserLight
>
itUser
=
dataCoreServer
.
getListConnectedUsers
().
listIterator
();
Message
newMessage
=
new
Message
(
timestamp
,
message
,
null
);
boolean
userFound
=
false
;
while
(
itUser
.
hasNext
()&&!
userFound
){
UserLight
currentUser
=
itUser
.
next
();
if
(
currentUser
.
getId
()==
userID
)
{
userFound
=
true
;
newMessage
.
setAuthor
(
currentUser
.
convertToUserZero
());
}
}
if
(!
userFound
)
throw
new
Exception
(
"Author not found"
);
ListIterator
<
GameHeavy
>
itGame
=
dataCoreServer
.
getListGameHeavy
().
listIterator
();
boolean
gameFound
=
false
;
while
(
itGame
.
hasNext
()&&!
gameFound
){
GameHeavy
currentGame
=
itGame
.
next
();
if
(
currentGame
.
getId
()==
gameID
)
{
gameFound
=
true
;
currentGame
.
getChat
().
getChat
().
add
(
newMessage
);
}
}
if
(!
gameFound
)
throw
new
Exception
(
"Game not found"
);
return
newMessage
;
}
@Override
public
ArrayList
<
UUID
>
getAllGameParticipants
(
UUID
gameID
)
{
return
null
;
public
ArrayList
<
UUID
>
getAllGameParticipants
(
UUID
gameID
)
throws
Exception
{
ArrayList
<
UUID
>
gameParticipants
=
new
ArrayList
<
UUID
>();
ListIterator
<
GameHeavy
>
itGame
=
dataCoreServer
.
getListGameHeavy
().
listIterator
();
boolean
gameFound
=
false
;
while
(
itGame
.
hasNext
()&&!
gameFound
){
GameHeavy
currentGame
=
itGame
.
next
();
if
(
currentGame
.
getId
()==
gameID
)
{
gameFound
=
true
;
gameParticipants
.
add
(
currentGame
.
getGameCreator
().
getId
());
gameParticipants
.
add
(
currentGame
.
getPlayer2
().
getId
());
for
(
UserZero
spectator
:
currentGame
.
getSpectators
())
{
gameParticipants
.
add
(
spectator
.
getId
());
}
}
}
if
(!
gameFound
)
throw
new
Exception
(
"Game not found"
);
return
gameParticipants
;
}
@Override
...
...
@@ -62,4 +103,32 @@ public class ComToDataServerImpl implements IComToData {
public
void
sendMove
(
Move
move
)
{
}
@Override
public
List
<
UserLight
>
getListUsers
()
{
return
dataCoreServer
.
getListConnectedUsers
();
}
public
List
<
GameLight
>
getListGames
()
{
List
<
GameLight
>
listGameLight
=
new
ArrayList
<
GameLight
>();
for
(
GameHeavy
gameHeavy
:
dataCoreServer
.
getListGameHeavy
())
{
listGameLight
.
add
(
gameHeavy
.
convertToGameLight
());
}
return
listGameLight
;
}
@Override
public
void
updateListOnModifyProfile
(
UserLight
userModified
)
{
ListIterator
<
UserLight
>
it
=
dataCoreServer
.
getListConnectedUsers
().
listIterator
();
boolean
found
=
false
;
int
index
=
0
;
while
(
it
.
hasNext
()&&!
found
){
if
(
it
.
next
().
getId
()==
userModified
.
getId
())
found
=
true
;
else
index
++;
}
dataCoreServer
.
getListConnectedUsers
().
set
(
index
,
userModified
);
//dataCoreServer.getDataToCom().notifyListUserChange(); TO DISCUSS WITH COM
}
}
src/main/java/server/data/DataCoreServer.java
View file @
10b31ec9
...
...
@@ -10,10 +10,10 @@ import main.java.common.dataModel.UserLight;
import
main.java.common.interfaces.server.IDataToCom
;
public
class
DataCoreServer
{
List
<
UserLight
>
listConnectedUsers
;
List
<
GameHeavy
>
listGameHeavy
;
ComToDataServerImpl
comToDataServerImpl
;
IDataToCom
dataToCom
;
private
List
<
UserLight
>
listConnectedUsers
;
private
List
<
GameHeavy
>
listGameHeavy
;
private
ComToDataServerImpl
comToDataServerImpl
;
private
IDataToCom
dataToCom
;
public
DataCoreServer
()
{
comToDataServerImpl
=
new
ComToDataServerImpl
(
this
);
...
...
@@ -32,4 +32,16 @@ public class DataCoreServer {
private
boolean
isMoveValid
(
Move
playerMove
,
Board
boardGame
)
{
return
false
;
}
public
List
<
UserLight
>
getListConnectedUsers
()
{
return
listConnectedUsers
;
}
public
List
<
GameHeavy
>
getListGameHeavy
()
{
return
listGameHeavy
;
}
public
IDataToCom
getDataToCom
()
{
return
dataToCom
;
}
}
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