Commit 2731f183 authored by Quentin DRUAULT-AUBIN's avatar Quentin DRUAULT-AUBIN

Final commit

parents 46436322 d3ced366
...@@ -20,8 +20,37 @@ ...@@ -20,8 +20,37 @@
<name>lo23</name> <name>lo23</name>
</organization> </organization>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</reporting>
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.0.201403182114</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
...@@ -155,6 +184,7 @@ ...@@ -155,6 +184,7 @@
<activeByDefault>false</activeByDefault> <activeByDefault>false</activeByDefault>
</activation> </activation>
<properties> <properties>
<sonar.host.url>https://sonarcloud.io</sonar.host.url> <sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>lo23</sonar.organization> <sonar.organization>lo23</sonar.organization>
<sonar.login>a7f86fb85267f6c368ef07d969a16ccf4be0db4b</sonar.login> <sonar.login>a7f86fb85267f6c368ef07d969a16ccf4be0db4b</sonar.login>
......
...@@ -12,9 +12,7 @@ package com.utclo23.battleship; ...@@ -12,9 +12,7 @@ package com.utclo23.battleship;
*/ */
public class GameException extends Exception { public class GameException extends Exception {
public GameException() {
}
public GameException(String message) { public GameException(String message) {
super(message); super(message);
} }
......
...@@ -10,7 +10,6 @@ import com.utclo23.data.structure.Mine; ...@@ -10,7 +10,6 @@ import com.utclo23.data.structure.Mine;
import com.utclo23.data.structure.StatGame; import com.utclo23.data.structure.StatGame;
import com.utclo23.com.messages.*; import com.utclo23.com.messages.*;
import com.utclo23.data.facade.IDataCom; import com.utclo23.data.facade.IDataCom;
import com.utclo23.data.structure.Game;
import com.utclo23.data.structure.LightPublicUser; import com.utclo23.data.structure.LightPublicUser;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.InterfaceAddress; import java.net.InterfaceAddress;
...@@ -118,9 +117,9 @@ public class ComFacade { ...@@ -118,9 +117,9 @@ public class ComFacade {
*/ */
public void notifyNewCoordinates(Mine mine, List<LightPublicUser> recipients) { public void notifyNewCoordinates(Mine mine, List<LightPublicUser> recipients) {
M_PlaceMine mPlaceMine = new M_PlaceMine(iDataCom.getMyPublicUserProfile(), mine); M_PlaceMine mPlaceMine = new M_PlaceMine(iDataCom.getMyPublicUserProfile(), mine);
System.out.println("recipients notify: " + recipients.size()); System.out.println("recipients new coordinates notify: " + recipients.size());
for (LightPublicUser recipient : recipients) { for (LightPublicUser recipient : recipients) {
System.out.println("notifyNewCoordinates +" + recipient.getPlayerName()); System.out.println("notifyNewCoordinates +" + recipient.getPlayerName()+" mine "+mine.getCoord().getX()+" "+mine.getCoord().getY());
if (kIpCtrl.getHashMap().get(recipient.getId()) != null) { if (kIpCtrl.getHashMap().get(recipient.getId()) != null) {
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceMine); Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceMine);
new Thread(os).start(); new Thread(os).start();
...@@ -159,16 +158,17 @@ public class ComFacade { ...@@ -159,16 +158,17 @@ public class ComFacade {
} }
/** /**
* Called to send "leave game" notification to everybody. * Called to send "leave game" notification to all users in the game.
* @param recipients: receivers of the notification
*/ */
public void leaveGame() { public void leaveGame(List<LightPublicUser> recipients) {
M_LeaveGame mLeaveGame = new M_LeaveGame(iDataCom.getMyPublicUserProfile()); M_LeaveGame mLeaveGame = new M_LeaveGame(iDataCom.getMyPublicUserProfile());
for (Inet4Address ip : kIpCtrl.getHashMap().values()) { for (LightPublicUser recipient : recipients) {
if (ip != null) { if (kIpCtrl.getHashMap().get(recipient.getId()) != null) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mLeaveGame); Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mLeaveGame);
new Thread(os).start(); new Thread(os).start();
} }
} }
} }
/** /**
...@@ -243,4 +243,20 @@ public class ComFacade { ...@@ -243,4 +243,20 @@ public class ComFacade {
Logger.getLogger(ComFacade.class.getName()).log(Level.INFO, null, "Fail joinGame"); Logger.getLogger(ComFacade.class.getName()).log(Level.INFO, null, "Fail joinGame");
} }
} }
/**
* Called to remove a game given in parameter in the game's list of all
* connected users
* @param idGame is the game to remove
*/
public void removeGame(String idGame){
M_RemoveGame m_RemoveGame = new M_RemoveGame(iDataCom.getMyPublicUserProfile(), idGame);
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
if (ip != null) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), m_RemoveGame);
Thread thread = new Thread(os);
thread.start();
}
}
}
} }
...@@ -9,7 +9,6 @@ import java.util.HashMap; ...@@ -9,7 +9,6 @@ import java.util.HashMap;
import java.net.Inet4Address; import java.net.Inet4Address;
import com.utclo23.data.facade.IDataCom; import com.utclo23.data.facade.IDataCom;
import java.net.InterfaceAddress; import java.net.InterfaceAddress;
import java.util.Iterator;
/** /**
* Class containing a hashmap with UID and corresponding IP address of the known * Class containing a hashmap with UID and corresponding IP address of the known
......
...@@ -41,66 +41,68 @@ public class M_Bleu extends Message { ...@@ -41,66 +41,68 @@ public class M_Bleu extends Message {
@Override @Override
public void callback(IDataCom iDataCom) { public void callback(IDataCom iDataCom) {
Logger.getLogger(M_Bleu.class.getName()).log(Level.INFO, null, "Blue message received");
List<String> myUsersId = new ArrayList(KnownIPController.getInstance().getHashMap().keySet()); if(iDataCom.getMyPublicUserProfile() != null){
List<LightPublicUser> myUsersProfile = new ArrayList(iDataCom.getConnectedUsers()); List<String> myUsersId = new ArrayList(KnownIPController.getInstance().getHashMap().keySet());
List<LightPublicUser> myUsersProfile = new ArrayList(iDataCom.getConnectedUsers());
HashMap<String, Inet4Address> newPairs = new HashMap(); HashMap<String, Inet4Address> newPairs = new HashMap();
List<LightPublicUser> newUsersProfile = new ArrayList(); List<LightPublicUser> newUsersProfile = new ArrayList();
// Envoi message bleu aux autres targets afin que tout le monde ait // Envoi message bleu aux autres targets afin que tout le monde ait
// les mêmes joueurs connectés. Les premiers qui recevront ces messages // les mêmes joueurs connectés. Les premiers qui recevront ces messages
// seront prioritaires // seront prioritaires
HashMap<String, Inet4Address> tmpHash = new HashMap(KnownIPController.getInstance().getHashMap()); HashMap<String, Inet4Address> tmpHash = new HashMap(KnownIPController.getInstance().getHashMap());
tmpHash.put(iDataCom.getMyPublicUserProfile().getId(), KnownIPController.getInstance().getMyInetAddress()); tmpHash.put(iDataCom.getMyPublicUserProfile().getId(), KnownIPController.getInstance().getMyInetAddress());
List<LightPublicUser> tmp = new ArrayList(iDataCom.getConnectedUsers()); List<LightPublicUser> tmp = new ArrayList(iDataCom.getConnectedUsers());
tmp.add(iDataCom.getMyPublicUserProfile().getLightPublicUser()); tmp.add(iDataCom.getMyPublicUserProfile().getLightPublicUser());
if (this.otherTargets != null) { if (this.otherTargets != null) {
for (Inet4Address ipDest : this.otherTargets) { for (Inet4Address ipDest : this.otherTargets) {
// On envoie pas si on avait déjà l'IP dans le hashMap // On envoie pas si on avait déjà l'IP dans le hashMap
if (!KnownIPController.getInstance().getHashMap().containsValue(ipDest)) { if (!KnownIPController.getInstance().getHashMap().containsValue(ipDest)) {
M_Bleu m_Bleu = new M_Bleu(iDataCom.getMyPublicUserProfile(), M_Bleu m_Bleu = new M_Bleu(iDataCom.getMyPublicUserProfile(),
tmpHash, tmp, iDataCom.getGameList(), null); tmpHash, tmp, iDataCom.getGameList(), null);
Sender os = new Sender(ipDest.getHostAddress(), KnownIPController.getInstance().getPort(), m_Bleu); Sender os = new Sender(ipDest.getHostAddress(), KnownIPController.getInstance().getPort(), m_Bleu);
new Thread(os).start(); new Thread(os).start();
}
} }
} }
}
// Envoi message rouge à ceux non déjà présents dans nos joueurs connectés
for (Map.Entry<String, Inet4Address> entry : this.hashMapReceived.entrySet()) {
if (!entry.getKey().equals(iDataCom.getMyPublicUserProfile().getId())
&& !myUsersId.contains(entry.getKey())) {
M_Rouge mRouge = new M_Rouge(iDataCom.getMyPublicUserProfile(), tmpHash, tmp, iDataCom.getGameList());
Sender os = new Sender(entry.getValue().getHostAddress(), KnownIPController.getInstance().getPort(), mRouge);
Thread thread = new Thread(os);
thread.start();
newPairs.put(entry.getKey(), entry.getValue()); // Envoi message rouge à tout le monde sauf nous.
for (Map.Entry<String, Inet4Address> entry : this.hashMapReceived.entrySet()) {
if (!entry.getKey().equals(iDataCom.getMyPublicUserProfile().getId())) {
if(!myUsersId.contains(entry.getKey())) {
newPairs.put(entry.getKey(), entry.getValue());
}
M_Rouge mRouge = new M_Rouge(iDataCom.getMyPublicUserProfile(), tmpHash, tmp, iDataCom.getGameList());
Sender os = new Sender(entry.getValue().getHostAddress(), KnownIPController.getInstance().getPort(), mRouge);
Thread thread = new Thread(os);
thread.start();
}
} }
}
for (LightPublicUser key : this.usersReceived) { for (LightPublicUser key : this.usersReceived) {
if (!key.getId().equals(iDataCom.getMyPublicUserProfile().getLightPublicUser().getId()) if (!key.getId().equals(iDataCom.getMyPublicUserProfile().getLightPublicUser().getId())
&& !myUsersProfile.contains(key)) { && !myUsersProfile.contains(key)) {
newUsersProfile.add(key); newUsersProfile.add(key);
}
} }
}
// Maj de nos listes avec les nouvelles données reçues // Maj de nos listes avec les nouvelles données reçues
// maj de la liste des games // maj de la liste des games
for (StatGame game : this.listGamesReceived) { for (StatGame game : this.listGamesReceived) {
if (!iDataCom.getGameList().contains(game)) { if (!iDataCom.getGameList().contains(game)) {
iDataCom.addNewGame(game); iDataCom.addNewGame(game);
}
}
for (Map.Entry<String, Inet4Address> entry : newPairs.entrySet()) {
KnownIPController.getInstance().getHashMap().put(entry.getKey(), entry.getValue());
}
for (LightPublicUser key : newUsersProfile) {
iDataCom.addConnectedUser(key);
} }
}
for (Map.Entry<String, Inet4Address> entry : newPairs.entrySet()) {
KnownIPController.getInstance().getHashMap().put(entry.getKey(), entry.getValue());
}
for (LightPublicUser key : newUsersProfile) {
iDataCom.addConnectedUser(key);
} }
} }
} }
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.utclo23.com.messages;
import com.utclo23.data.facade.IDataCom;
import com.utclo23.data.structure.PublicUser;
/**
* M_LeaveGame is a Message generated when a user wants to leave a game.
* @author Thibault CHICHE
*/
public class M_RemoveGame extends Message {
private final String idGame;
/**
* Constructor.
* @param user is the message's sender
* @param idGame is the id of the game to remove
*/
public M_RemoveGame(PublicUser user, String idGame){
super(user);
this.idGame = idGame;
}
@Override
public void callback(IDataCom iDataCom){
iDataCom.removeGame(idGame);
}
}
...@@ -14,15 +14,16 @@ import java.io.File; ...@@ -14,15 +14,16 @@ import java.io.File;
*/ */
public class Configuration { public class Configuration {
public Configuration() {
}
/** /**
* directory of saved profiles * directory of saved profiles
*/ */
public final static String SAVE_DIR = System.getProperty("user.home")+File.separator+"MyData"; public static final String SAVE_DIR = System.getProperty("user.home")+File.separator+"MyData";
public final static int WIDTH = 10; public static final int WIDTH = 10;
public final static int HEIGHT = 10; public static final int HEIGHT = 10;
public static final String PLAYER = "player";
public static final String SPECTATOR = "spectator";
} }
...@@ -7,8 +7,6 @@ package com.utclo23.data.facade; ...@@ -7,8 +7,6 @@ package com.utclo23.data.facade;
import com.utclo23.data.module.DataException; import com.utclo23.data.module.DataException;
import com.utclo23.data.structure.*; import com.utclo23.data.structure.*;
import java.net.NetworkInterface;
import java.rmi.server.UID;
import java.util.List; import java.util.List;
/** /**
...@@ -17,21 +15,96 @@ import java.util.List; ...@@ -17,21 +15,96 @@ import java.util.List;
*/ */
public interface IDataCom { public interface IDataCom {
/**
*
* @param game
*/
public void addNewGame(StatGame game); public void addNewGame(StatGame game);
public void removeGame(String id);
/**
*
* @param ships
*/
public void setEnnemyShips(List<Ship> ships); public void setEnnemyShips(List<Ship> ships);
/**
*
* @param mine
*/
public void forwardCoordinates(Mine mine); public void forwardCoordinates(Mine mine);
/**
*
*/
public void opponentHasLeftGame(); public void opponentHasLeftGame();
/**
*
*/
public void connectionLostWithOpponent(); public void connectionLostWithOpponent();
/**
*
* @param user
*/
public void addConnectedUser(LightPublicUser user); public void addConnectedUser(LightPublicUser user);
/**
*
* @param user
*/
public void removeConnectedUser(LightPublicUser user); public void removeConnectedUser(LightPublicUser user);
/**
*
* @param msg
*/
public void forwardMessage(Message msg); public void forwardMessage(Message msg);
/**
*
* @return
*/
public PublicUser getMyPublicUserProfile(); public PublicUser getMyPublicUserProfile();
/**
*
* @param user
* @param id
* @param role
* @throws DataException
*/
public void updateGameList(LightPublicUser user, String id, String role) throws DataException; public void updateGameList(LightPublicUser user, String id, String role) throws DataException;
/**
*
* @return
*/
public List<StatGame> getGameList(); public List<StatGame> getGameList();
/**
*
* @return
*/
public List<LightPublicUser> getConnectedUsers(); public List<LightPublicUser> getConnectedUsers();
/**
*
* @throws DataException
*/
public void connectionImpossible() throws DataException; public void connectionImpossible() throws DataException;
/**
*
* @param game
* @throws DataException
*/
public void receptionGame(Game game) throws DataException; public void receptionGame(Game game) throws DataException;
/**
*
* @param profile
*/
public void receivePublicUserProfile(PublicUser profile); public void receivePublicUserProfile(PublicUser profile);
} }
...@@ -8,7 +8,6 @@ package com.utclo23.data.facade; ...@@ -8,7 +8,6 @@ package com.utclo23.data.facade;
import com.utclo23.data.module.DataException; import com.utclo23.data.module.DataException;
import com.utclo23.data.structure.*; import com.utclo23.data.structure.*;
import java.net.InterfaceAddress; import java.net.InterfaceAddress;
import java.rmi.server.UID;
import java.util.List; import java.util.List;
import java.util.Date; import java.util.Date;
...@@ -18,37 +17,192 @@ import java.util.Date; ...@@ -18,37 +17,192 @@ import java.util.Date;
*/ */
public interface IDataIHMMain { public interface IDataIHMMain {
/**
*
* @param playerName
* @param password
* @param firstName
* @param lastName
* @param birthDate
* @param imageFile
* @throws DataException
*/
public void createUser(String playerName, String password, String firstName, String lastName, Date birthDate, String imageFile) throws DataException; public void createUser(String playerName, String password, String firstName, String lastName, Date birthDate, String imageFile) throws DataException;
/**
*
* @param password
* @param firstName
* @param lastName
* @param birthDate
* @param imageFile
* @throws DataException
*/
public void updateUser(String password, String firstName, String lastName, Date birthDate, String imageFile) throws DataException; public void updateUser(String password, String firstName, String lastName, Date birthDate, String imageFile) throws DataException;
/**
*
* @param id
*/
public void askPublicUserProfile(String id); public void askPublicUserProfile(String id);
/**
*
* @return
*/
public List<StatGame> getGameList(); public List<StatGame> getGameList();
/**
*
* @param name
* @param computerMode
* @param spectator
* @param spectatorChat
* @param type
* @return
* @throws DataException
*/
public Game createGame(String name, boolean computerMode, boolean spectator, boolean spectatorChat, GameType type) throws DataException; public Game createGame(String name, boolean computerMode, boolean spectator, boolean spectatorChat, GameType type) throws DataException;
/**
*
* @param username
* @param password
* @throws DataException
*/
public void signin(String username, String password) throws DataException; public void signin(String username, String password) throws DataException;
public void signOut() throws Exception;
/**
*
* @throws DataException
*/
public void signOut() throws DataException;
/**
*
* @return
*/
public List<LightPublicUser> getConnectedUsers(); public List<LightPublicUser> getConnectedUsers();
/**
*
* @return
*/
public PublicUser getMyPublicUserProfile(); public PublicUser getMyPublicUserProfile();
/**
*
* @return
*/
public Owner getMyOwnerProfile(); public Owner getMyOwnerProfile();
/**
*
* @return
*/
public List<String> getIPDiscovery(); public List<String> getIPDiscovery();
/**
*
* @param discoveryNodes
* @throws DataException
*/
public void setIPDiscovery(List<String> discoveryNodes) throws DataException; public void setIPDiscovery(List<String> discoveryNodes) throws DataException;
/**
*
* @param id
* @param role
*/
public void gameConnectionRequestGame(String id, String role); public void gameConnectionRequestGame(String id, String role);
/**
public void setNetworkInterface(InterfaceAddress net_interface) ; *
* @param netinterface
*/
public void setNetworkInterface(InterfaceAddress netinterface);
/**
*
* @param playername
* @throws DataException
*/
public void updatePlayername(String playername) throws DataException; public void updatePlayername(String playername) throws DataException;
/**
*
* @param firstname
* @throws DataException
*/
public void updateFirstname(String firstname) throws DataException; public void updateFirstname(String firstname) throws DataException;
/**
*
* @param lastname
* @throws DataException
*/
public void updateLastname(String lastname) throws DataException; public void updateLastname(String lastname) throws DataException;
/**
*
* @param birthdate
* @throws DataException
*/
public void updateBirthdate(Date birthdate) throws DataException; public void updateBirthdate(Date birthdate) throws DataException;
/**
*
* @param fileImage
* @throws DataException
*/
public void updateFileImage(String fileImage) throws DataException; public void updateFileImage(String fileImage) throws DataException;