Commit 90268335 authored by Thibault Chiche's avatar Thibault Chiche
Browse files

[COM] add conditions before sending

parent 1797cac1
......@@ -61,8 +61,10 @@ public class ComFacade {
public void sendShipsToEnnemy(List<Ship> listShips, List<LightPublicUser> recipients) {
M_PlaceShip mPlaceship = new M_PlaceShip(iDataCom.getMyPublicUserProfile(), listShips);
for (LightPublicUser recipient : recipients) {
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceship);
new Thread(os).start();
if (kIpCtrl.getHashMap().get(recipient.getId()) != null){
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceship);
new Thread(os).start();
}
}
}
......@@ -79,8 +81,10 @@ public class ComFacade {
public void notifyUserSignedOut() {
M_Deconnection mDeconnection = new M_Deconnection(iDataCom.getMyPublicUserProfile());
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mDeconnection);
new Thread(os).start();
if (ip != null){
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mDeconnection);
new Thread(os).start();
}
}
}
......@@ -92,8 +96,10 @@ public class ComFacade {
public void notifyNewMessage(com.utclo23.data.structure.Message message) {
M_Chat mChat = new M_Chat(iDataCom.getMyPublicUserProfile(), message);
for (LightPublicUser recipient : message.getRecipients()) {
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mChat);
new Thread(os).start();
if (kIpCtrl.getHashMap().get(recipient.getId()) != null){
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mChat);
new Thread(os).start();
}
}
}
......@@ -106,8 +112,10 @@ public class ComFacade {
public void notifyNewCoordinates(Mine mine, List<LightPublicUser> recipients) {
M_PlaceMine mPlaceMine = new M_PlaceMine(iDataCom.getMyPublicUserProfile(), mine);
for (LightPublicUser recipient : recipients) {
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceMine);
new Thread(os).start();
if (kIpCtrl.getHashMap().get(recipient.getId()) != null){
Sender os = new Sender(kIpCtrl.getHashMap().get(recipient.getId()).getHostAddress(), kIpCtrl.getPort(), mPlaceMine);
new Thread(os).start();
}
}
}
......@@ -120,9 +128,11 @@ public class ComFacade {
public void notifyNewGame(StatGame game) {
M_CreationGame mCreationGame = new M_CreationGame(iDataCom.getMyPublicUserProfile(), game);
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mCreationGame);
Thread thread = new Thread(os);
thread.start();
if(ip != null){
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mCreationGame);
Thread thread = new Thread(os);
thread.start();
}
}
}
......@@ -146,8 +156,10 @@ public class ComFacade {
public void leaveGame() {
M_LeaveGame mLeaveGame = new M_LeaveGame(iDataCom.getMyPublicUserProfile());
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mLeaveGame);
new Thread(os).start();
if(ip != null){
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mLeaveGame);
new Thread(os).start();
}
}
}
......@@ -210,9 +222,11 @@ public class ComFacade {
if (success) {
for (Inet4Address ip : kIpCtrl.getHashMap().values()) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mJoinGameResponse);
new Thread(os).start();
Logger.getLogger(ComFacade.class.getName()).log(Level.INFO, null, "Send success joinGame");
if(ip != null) {
Sender os = new Sender(ip.getHostAddress(), kIpCtrl.getPort(), mJoinGameResponse);
new Thread(os).start();
Logger.getLogger(ComFacade.class.getName()).log(Level.INFO, null, "Send success joinGame");
}
}
} else {
Sender os = new Sender(kIpCtrl.getHashMap().get(id).getHostAddress(), kIpCtrl.getPort(), mJoinGameResponse);
......
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