mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
...
This commit is contained in:
parent
e4c8c5db4c
commit
ac69e684ad
3 changed files with 44 additions and 20 deletions
|
@ -48,6 +48,7 @@ public class Session {
|
|||
private UUID sessionId;
|
||||
private UUID clientId;
|
||||
private String username;
|
||||
private int messageId = 0;
|
||||
private final CallbackServerSession callback = new CallbackServerSession();
|
||||
|
||||
public Session(String userName, UUID clientId) {
|
||||
|
@ -78,6 +79,8 @@ public class Session {
|
|||
|
||||
public void fireCallback(ClientCallback call) {
|
||||
try {
|
||||
call.setMessageId(messageId++);
|
||||
logger.info(sessionId + " - " + call.getMessageId() + " - " + call.getMethod());
|
||||
callback.setCallback(call);
|
||||
} catch (InterruptedException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
|
|
|
@ -104,6 +104,7 @@ public class GameController implements GameCallback {
|
|||
new Listener<PlayerQueryEvent> () {
|
||||
@Override
|
||||
public void event(PlayerQueryEvent event) {
|
||||
// logger.info(event.getPlayerId() + "--" + event.getQueryType() + "--" + event.getMessage());
|
||||
switch (event.getQueryType()) {
|
||||
case ASK:
|
||||
ask(event.getPlayerId(), event.getMessage());
|
||||
|
@ -132,6 +133,9 @@ public class GameController implements GameCallback {
|
|||
case AMOUNT:
|
||||
amount(event.getPlayerId(), event.getMessage(), event.getMin(), event.getMax());
|
||||
break;
|
||||
case LOOK:
|
||||
lookAtCards(event.getPlayerId(), event.getMessage(), event.getCards());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,7 +261,7 @@ public class GameController implements GameCallback {
|
|||
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerInteger(data);
|
||||
}
|
||||
|
||||
private void updateGame() {
|
||||
private synchronized void updateGame() {
|
||||
|
||||
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||
entry.getValue().update(getGameView(entry.getKey()));
|
||||
|
@ -267,57 +271,71 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
|
||||
private void ask(UUID playerId, String question) {
|
||||
private synchronized void ask(UUID playerId, String question) {
|
||||
informOthers(playerId);
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).ask(question, getGameView(playerId));
|
||||
}
|
||||
|
||||
private void chooseAbility(UUID playerId, Collection<? extends Ability> choices) {
|
||||
private synchronized void chooseAbility(UUID playerId, Collection<? extends Ability> choices) {
|
||||
informOthers(playerId);
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).chooseAbility(new AbilityPickerView(choices));
|
||||
}
|
||||
|
||||
private void choose(UUID playerId, String message, String[] choices) {
|
||||
private synchronized void choose(UUID playerId, String message, String[] choices) {
|
||||
informOthers(playerId);
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).choose(message, choices);
|
||||
}
|
||||
|
||||
private void target(UUID playerId, String question, Cards cards, boolean required) {
|
||||
private synchronized void target(UUID playerId, String question, Cards cards, boolean required) {
|
||||
informOthers(playerId);
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).target(question, new CardsView(cards), required, getGameView(playerId));
|
||||
}
|
||||
|
||||
private void target(UUID playerId, String question, Collection<? extends Ability> abilities, boolean required) {
|
||||
private synchronized void target(UUID playerId, String question, Collection<? extends Ability> abilities, boolean required) {
|
||||
informOthers(playerId);
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).target(question, new CardsView(abilities, game), required, getGameView(playerId));
|
||||
}
|
||||
|
||||
private void select(UUID playerId, String message) {
|
||||
private synchronized void select(UUID playerId, String message) {
|
||||
informOthers(playerId);
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).select(message, getGameView(playerId));
|
||||
}
|
||||
|
||||
private void playMana(UUID playerId, String message) {
|
||||
private synchronized void playMana(UUID playerId, String message) {
|
||||
informOthers(playerId);
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).playMana(message, getGameView(playerId));
|
||||
}
|
||||
|
||||
private void playXMana(UUID playerId, String message) {
|
||||
private synchronized void playXMana(UUID playerId, String message) {
|
||||
informOthers(playerId);
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).playXMana(message, getGameView(playerId));
|
||||
}
|
||||
|
||||
private void amount(UUID playerId, String message, int min, int max) {
|
||||
private synchronized void amount(UUID playerId, String message, int min, int max) {
|
||||
informOthers(playerId);
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).getAmount(message, min, max);
|
||||
}
|
||||
|
||||
private void revealCards(String name, Cards cards) {
|
||||
private synchronized void revealCards(String name, Cards cards) {
|
||||
for (GameSession session: gameSessions.values()) {
|
||||
session.revealCards(name, new CardsView(cards));
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void lookAtCards(UUID playerId, String name, Cards cards) {
|
||||
if (gameSessions.containsKey(playerId))
|
||||
gameSessions.get(playerId).revealCards(name, new CardsView(cards));
|
||||
}
|
||||
|
||||
private void informOthers(UUID playerId) {
|
||||
final String message = "Waiting for " + game.getPlayer(playerId).getName();
|
||||
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||
|
|
|
@ -34,6 +34,9 @@ import java.net.URLClassLoader;
|
|||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*
|
||||
* some code courtesy of http://tech.puredanger.com/2006/11/09/classloader/
|
||||
*
|
||||
*/
|
||||
public class PluginClassLoader extends URLClassLoader {
|
||||
|
||||
|
|
Loading…
Reference in a new issue