mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +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 sessionId;
|
||||||
private UUID clientId;
|
private UUID clientId;
|
||||||
private String username;
|
private String username;
|
||||||
|
private int messageId = 0;
|
||||||
private final CallbackServerSession callback = new CallbackServerSession();
|
private final CallbackServerSession callback = new CallbackServerSession();
|
||||||
|
|
||||||
public Session(String userName, UUID clientId) {
|
public Session(String userName, UUID clientId) {
|
||||||
|
@ -78,6 +79,8 @@ public class Session {
|
||||||
|
|
||||||
public void fireCallback(ClientCallback call) {
|
public void fireCallback(ClientCallback call) {
|
||||||
try {
|
try {
|
||||||
|
call.setMessageId(messageId++);
|
||||||
|
logger.info(sessionId + " - " + call.getMessageId() + " - " + call.getMethod());
|
||||||
callback.setCallback(call);
|
callback.setCallback(call);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
logger.log(Level.SEVERE, null, ex);
|
logger.log(Level.SEVERE, null, ex);
|
||||||
|
|
|
@ -104,6 +104,7 @@ public class GameController implements GameCallback {
|
||||||
new Listener<PlayerQueryEvent> () {
|
new Listener<PlayerQueryEvent> () {
|
||||||
@Override
|
@Override
|
||||||
public void event(PlayerQueryEvent event) {
|
public void event(PlayerQueryEvent event) {
|
||||||
|
// logger.info(event.getPlayerId() + "--" + event.getQueryType() + "--" + event.getMessage());
|
||||||
switch (event.getQueryType()) {
|
switch (event.getQueryType()) {
|
||||||
case ASK:
|
case ASK:
|
||||||
ask(event.getPlayerId(), event.getMessage());
|
ask(event.getPlayerId(), event.getMessage());
|
||||||
|
@ -132,6 +133,9 @@ public class GameController implements GameCallback {
|
||||||
case AMOUNT:
|
case AMOUNT:
|
||||||
amount(event.getPlayerId(), event.getMessage(), event.getMin(), event.getMax());
|
amount(event.getPlayerId(), event.getMessage(), event.getMin(), event.getMax());
|
||||||
break;
|
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);
|
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerInteger(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGame() {
|
private synchronized void updateGame() {
|
||||||
|
|
||||||
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||||
entry.getValue().update(getGameView(entry.getKey()));
|
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);
|
informOthers(playerId);
|
||||||
|
if (gameSessions.containsKey(playerId))
|
||||||
gameSessions.get(playerId).ask(question, getGameView(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);
|
informOthers(playerId);
|
||||||
|
if (gameSessions.containsKey(playerId))
|
||||||
gameSessions.get(playerId).chooseAbility(new AbilityPickerView(choices));
|
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);
|
informOthers(playerId);
|
||||||
|
if (gameSessions.containsKey(playerId))
|
||||||
gameSessions.get(playerId).choose(message, choices);
|
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);
|
informOthers(playerId);
|
||||||
|
if (gameSessions.containsKey(playerId))
|
||||||
gameSessions.get(playerId).target(question, new CardsView(cards), required, getGameView(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);
|
informOthers(playerId);
|
||||||
|
if (gameSessions.containsKey(playerId))
|
||||||
gameSessions.get(playerId).target(question, new CardsView(abilities, game), required, getGameView(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);
|
informOthers(playerId);
|
||||||
|
if (gameSessions.containsKey(playerId))
|
||||||
gameSessions.get(playerId).select(message, getGameView(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);
|
informOthers(playerId);
|
||||||
|
if (gameSessions.containsKey(playerId))
|
||||||
gameSessions.get(playerId).playMana(message, getGameView(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);
|
informOthers(playerId);
|
||||||
|
if (gameSessions.containsKey(playerId))
|
||||||
gameSessions.get(playerId).playXMana(message, getGameView(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);
|
informOthers(playerId);
|
||||||
|
if (gameSessions.containsKey(playerId))
|
||||||
gameSessions.get(playerId).getAmount(message, min, max);
|
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()) {
|
for (GameSession session: gameSessions.values()) {
|
||||||
session.revealCards(name, new CardsView(cards));
|
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) {
|
private void informOthers(UUID playerId) {
|
||||||
final String message = "Waiting for " + game.getPlayer(playerId).getName();
|
final String message = "Waiting for " + game.getPlayer(playerId).getName();
|
||||||
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||||
|
|
|
@ -34,6 +34,9 @@ import java.net.URLClassLoader;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
*
|
||||||
|
* some code courtesy of http://tech.puredanger.com/2006/11/09/classloader/
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class PluginClassLoader extends URLClassLoader {
|
public class PluginClassLoader extends URLClassLoader {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue