mirror of
https://github.com/correl/mage.git
synced 2025-04-10 17:00:08 -09:00
* Join Table - Changed handling of messages while creating or joining a table.
This commit is contained in:
parent
50056df24e
commit
fe82b49930
4 changed files with 39 additions and 8 deletions
Mage.Client/src/main/java/mage/client
Mage.Server/src/main/java/mage/server
|
@ -356,7 +356,7 @@ public class NewTableDialog extends MageDialog {
|
|||
} catch (ClassNotFoundException ex) {
|
||||
handleError(ex);
|
||||
}
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining table.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
// JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining table.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
session.removeTable(roomId, table.getTableId());
|
||||
table = null;
|
||||
}//GEN-LAST:event_btnOKActionPerformed
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
package mage.client.remote;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
@ -252,6 +254,12 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
else if (callback.getMethod().equals("endGameInfo")) {
|
||||
MageFrame.getInstance().showGameEndDialog((GameEndView) callback.getData());
|
||||
}
|
||||
else if (callback.getMethod().equals("showUserMessage")) {
|
||||
List<String> messageData = (List<String>) callback.getData();
|
||||
if (messageData.size() == 2) {
|
||||
JOptionPane.showMessageDialog(null, messageData.get(1), messageData.get(0), JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
}
|
||||
else if (callback.getMethod().equals("gameInform")) {
|
||||
|
||||
if (callback.getMessageId() > messageId) {
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
package mage.server;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -174,28 +176,40 @@ public class TableController {
|
|||
}
|
||||
|
||||
public synchronized boolean joinTable(UUID userId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
user.showUserMessage("Join Table", "No available seats.");
|
||||
return false;
|
||||
}
|
||||
Seat seat = table.getNextAvailableSeat(playerType);
|
||||
if (seat == null) {
|
||||
throw new GameException("No available seats.");
|
||||
user.showUserMessage("Join Table", "No available seats.");
|
||||
return false;
|
||||
}
|
||||
Deck deck = Deck.load(deckList, false, false);
|
||||
|
||||
if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
|
||||
table.getValidator().getName();
|
||||
throw new InvalidDeckException(
|
||||
new StringBuilder(name).append(" has an invalid deck for the ").append(table.getValidator().getName()).append(" Format").toString(),
|
||||
table.getValidator().getInvalid());
|
||||
StringBuilder sb = new StringBuilder("You (").append(name).append(") have an invalid deck for the selected ").append(table.getValidator().getName()).append(" Format. \n\n");
|
||||
for (Map.Entry<String, String> entry : table.getValidator().getInvalid().entrySet()) {
|
||||
sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
|
||||
}
|
||||
sb.append("\n\nSelect a deck that is appropriate for the selected format and try again!");
|
||||
user.showUserMessage("Join Table", sb.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = createPlayer(name, seat.getPlayerType(), skill);
|
||||
if (player == null) {
|
||||
throw new GameException(new StringBuilder("Could not create player ").append(name).append(" of type ").append(seat.getPlayerType().toString()).toString());
|
||||
String message = new StringBuilder("Could not create player ").append(name).append(" of type ").append(seat.getPlayerType().toString()).toString();
|
||||
logger.warn(new StringBuilder("User: ").append(user.getName()).append(" => ").append(message).toString());
|
||||
user.showUserMessage("Join Table",message);
|
||||
return false;
|
||||
}
|
||||
match.addPlayer(player, deck);
|
||||
table.joinTable(player, seat);
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
user.addTable(player.getId(), table);
|
||||
logger.info("player joined " + player.getId());
|
||||
//only inform human players and add them to sessionPlayerMap
|
||||
|
|
|
@ -29,6 +29,8 @@ package mage.server;
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
@ -164,6 +166,13 @@ public class User {
|
|||
fireCallback(new ClientCallback("showGameEndDialog", gameId));
|
||||
}
|
||||
|
||||
public void showUserMessage(final String titel, String message) {
|
||||
List<String> messageData = new LinkedList<String>();
|
||||
messageData.add(titel);
|
||||
messageData.add(message);
|
||||
fireCallback(new ClientCallback("showUserMessage", null, messageData ));
|
||||
}
|
||||
|
||||
public void watchGame(final UUID gameId) {
|
||||
fireCallback(new ClientCallback("watchGame", gameId));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue