use of games.strategy.net.INode in project triplea by triplea-game.
the class ServerGame method waitForPlayerToFinishStep.
private void waitForPlayerToFinishStep() {
final PlayerID playerId = getCurrentStep().getPlayerId();
// no player specified for the given step
if (playerId == null) {
return;
}
if (!getCurrentStep().getDelegate().delegateCurrentlyRequiresUserInput()) {
return;
}
final IGamePlayer player = gamePlayers.get(playerId);
if (player != null) {
// a local player
player.start(getCurrentStep().getName());
} else {
// a remote player
final INode destination = playerManager.getNode(playerId.getName());
final IGameStepAdvancer advancer = (IGameStepAdvancer) remoteMessenger.getRemote(ClientGame.getRemoteStepAdvancerName(destination));
advancer.startPlayerStep(getCurrentStep().getName(), playerId);
}
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class HeadlessGameServer method remoteBanPlayer.
public String remoteBanPlayer(final String playerName, final int hours, final String hashedPassword, final String salt) {
final String password = System.getProperty(LOBBY_GAME_SUPPORT_PASSWORD, "");
if (password.equals(GameRunner.NO_REMOTE_REQUESTS_ALLOWED)) {
return "Host not accepting remote requests!";
}
final String localPassword = System.getProperty(LOBBY_GAME_SUPPORT_PASSWORD, "");
// milliseconds (30 days max)
final Instant expire = Instant.now().plus(Duration.ofHours(Math.min(24 * 30, hours)));
if (hashPassword(localPassword, salt).equals(hashedPassword)) {
new Thread(() -> {
if (getServerModel() == null) {
return;
}
final IServerMessenger messenger = getServerModel().getMessenger();
if (messenger == null) {
return;
}
final Set<INode> nodes = messenger.getNodes();
if (nodes == null) {
return;
}
try {
for (final INode node : nodes) {
final String realName = node.getName().split(" ")[0];
final String ip = node.getAddress().getHostAddress();
final String mac = messenger.getPlayerMac(node.getName());
if (realName.equals(playerName)) {
System.out.println("Remote Ban of Player: " + playerName);
try {
messenger.notifyUsernameMiniBanningOfPlayer(realName, expire);
} catch (final Exception e) {
logger.log(Level.SEVERE, "Failed to notify username ban of player", e);
}
try {
messenger.notifyIpMiniBanningOfPlayer(ip, expire);
} catch (final Exception e) {
logger.log(Level.SEVERE, "Failed to notify IP ban of player", e);
}
try {
messenger.notifyMacMiniBanningOfPlayer(mac, expire);
} catch (final Exception e) {
logger.log(Level.SEVERE, "Failed to notify MAC ban of player", e);
}
messenger.removeConnection(node);
}
}
} catch (final Exception e) {
logger.log(Level.SEVERE, "Failed to notify ban of player", e);
}
}).start();
return null;
}
System.out.println("Attempted remote ban player with invalid password.");
return "Invalid password!";
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class BootPlayerAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
final JComboBox<String> combo = new JComboBox<>(model);
model.addElement("");
for (final INode node : new TreeSet<>(messenger.getNodes())) {
if (!node.equals(messenger.getLocalNode())) {
model.addElement(node.getName());
}
}
if (model.getSize() == 1) {
JOptionPane.showMessageDialog(parent, "No remote players", "No Remote Players", JOptionPane.ERROR_MESSAGE);
return;
}
final int selectedOption = JOptionPane.showConfirmDialog(parent, combo, "Select player to remove", JOptionPane.OK_CANCEL_OPTION);
if (selectedOption != JOptionPane.OK_OPTION) {
return;
}
final String name = (String) combo.getSelectedItem();
for (final INode node : messenger.getNodes()) {
if (node.getName().equals(name)) {
messenger.removeConnection(node);
}
}
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class ChatPlayerPanel method setDynamicPreferredSize.
/**
* set minimum size based on players (number and max name length) and distribution to playerIDs.
*/
private void setDynamicPreferredSize() {
final List<INode> onlinePlayers = chat.getOnlinePlayers();
int maxNameLength = 0;
final FontMetrics fontMetrics = this.getFontMetrics(UIManager.getFont("TextField.font"));
for (final INode onlinePlayer : onlinePlayers) {
maxNameLength = Math.max(maxNameLength, fontMetrics.stringWidth(onlinePlayer.getName()));
}
int iconCounter = 0;
if (setCellRenderer instanceof PlayerChatRenderer) {
iconCounter = ((PlayerChatRenderer) setCellRenderer).getMaxIconCounter();
}
setPreferredSize(new Dimension(maxNameLength + 40 + iconCounter * 14, 80));
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class PlayerChatRenderer method setIconMap.
private void setIconMap() {
final PlayerManager playerManager = game.getPlayerManager();
PlayerList playerList;
game.getData().acquireReadLock();
try {
playerList = game.getData().getPlayerList();
} finally {
game.getData().releaseReadLock();
}
// new HashSet removes duplicates
for (final INode playerNode : new HashSet<>(playerManager.getPlayerMapping().values())) {
final Set<String> players = playerManager.getPlayedBy(playerNode);
if (players.size() > 0) {
final List<Icon> icons = players.stream().filter(player -> uiContext != null && uiContext.getFlagImageFactory() != null).map(player -> new ImageIcon(uiContext.getFlagImageFactory().getSmallFlag(playerList.getPlayerId(player)))).collect(Collectors.toList());
maxIconCounter = Math.max(maxIconCounter, icons.size());
playerMap.put(playerNode.toString(), players);
if (uiContext == null) {
iconMap.put(playerNode.toString(), null);
} else {
iconMap.put(playerNode.toString(), icons);
}
}
}
}
Aggregations