mirror of
https://github.com/correl/mage.git
synced 2025-01-12 03:00:13 +00:00
Merge
This commit is contained in:
commit
3d94de5956
2 changed files with 22 additions and 16 deletions
|
@ -77,8 +77,6 @@ public class Session {
|
|||
private CallbackClientDaemon callbackDaemon;
|
||||
private ScheduledFuture<?> future;
|
||||
private Connection connection;
|
||||
private boolean reconnecting = false;
|
||||
private boolean connecting = false;
|
||||
|
||||
/**
|
||||
* For locking session object.
|
||||
|
@ -94,7 +92,6 @@ public class Session {
|
|||
}
|
||||
|
||||
public synchronized boolean connect(Connection connection) {
|
||||
this.connecting = true;
|
||||
if (isConnected()) {
|
||||
disconnect(true);
|
||||
}
|
||||
|
@ -103,6 +100,7 @@ public class Session {
|
|||
}
|
||||
|
||||
public boolean connect() {
|
||||
sessionState = SessionState.CONNECTING;
|
||||
try {
|
||||
System.setSecurityManager(null);
|
||||
System.setProperty("http.nonProxyHosts", "code.google.com");
|
||||
|
@ -130,25 +128,20 @@ public class Session {
|
|||
this.userName = connection.getUsername();
|
||||
sessionId = server.registerClient(userName, client.getId(), client.getVersion());
|
||||
callbackDaemon = new CallbackClientDaemon(sessionId, client, server);
|
||||
sessionState = SessionState.CONNECTED;
|
||||
serverState = server.getServerState();
|
||||
future = sessionExecutor.scheduleWithFixedDelay(new ServerPinger(), 5, 5, TimeUnit.SECONDS);
|
||||
logger.info("Connected to RMI server at " + connection.getHost() + ":" + connection.getPort());
|
||||
client.connected("Connected to " + connection.getHost() + ":" + connection.getPort() + " ");
|
||||
reconnecting = false;
|
||||
connecting = false;
|
||||
return true;
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("", ex);
|
||||
if (!reconnecting) {
|
||||
disconnect(false);
|
||||
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
||||
}
|
||||
disconnect(false);
|
||||
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
||||
} catch (RemoteException ex) {
|
||||
logger.fatal("Unable to connect to server - ", ex);
|
||||
if (!reconnecting) {
|
||||
disconnect(false);
|
||||
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
||||
}
|
||||
disconnect(false);
|
||||
client.showMessage("Unable to connect to server. " + ex.getMessage());
|
||||
} catch (NotBoundException ex) {
|
||||
logger.fatal("Unable to connect to server - ", ex);
|
||||
}
|
||||
|
@ -158,9 +151,11 @@ public class Session {
|
|||
public synchronized void disconnect(boolean showMessage) {
|
||||
if (sessionState == SessionState.CONNECTED)
|
||||
sessionState = SessionState.DISCONNECTING;
|
||||
if (connection == null)
|
||||
if (future != null && !future.isDone())
|
||||
future.cancel(true);
|
||||
if (connection == null || server == null)
|
||||
return;
|
||||
if (sessionState == SessionState.CONNECTED) {
|
||||
if (sessionState == SessionState.DISCONNECTING) {
|
||||
try {
|
||||
server.deregisterClient(sessionId);
|
||||
} catch (Exception ex) {
|
||||
|
@ -728,6 +723,7 @@ public class Session {
|
|||
|
||||
private void handleRemoteException(RemoteException ex) {
|
||||
logger.fatal("Communication error", ex);
|
||||
sessionState = SessionState.SERVER_UNAVAILABLE;
|
||||
disconnect(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -200,7 +200,9 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
|
|||
Permanent attacker = game.getPermanent(attackers.get(0));
|
||||
Player player = game.getPlayer(attacker.getControllerId());
|
||||
int damage = attacker.getPower().getValue();
|
||||
if (attacker != null && canDamage(attacker, first)) {
|
||||
if (attacker == null)
|
||||
return;
|
||||
if (canDamage(attacker, first)) {
|
||||
Map<UUID, Integer> assigned = new HashMap<UUID, Integer>();
|
||||
for (UUID blockerId: blockerOrder) {
|
||||
Permanent blocker = game.getPermanent(blockerId);
|
||||
|
@ -237,6 +239,14 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
|
|||
blocker.damage(entry.getValue(), attacker.getId(), game, true, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (UUID blockerId: blockerOrder) {
|
||||
Permanent blocker = game.getPermanent(blockerId);
|
||||
if (canDamage(blocker, first)) {
|
||||
attacker.damage(blocker.getPower().getValue(), blocker.getId(), game, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void defenderDamage(Permanent attacker, int amount, Game game) {
|
||||
|
|
Loading…
Reference in a new issue