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