use of games.strategy.net.INode in project triplea by triplea-game.
the class HeadlessGameServer method remoteMutePlayer.
public String remoteMutePlayer(final String playerName, final int minutes, 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, "");
// (48 hours max)
final Instant expire = Instant.now().plus(Duration.ofMinutes(Math.min(60 * 24 * 2, minutes)));
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 Mute of Player: " + playerName);
messenger.notifyUsernameMutingOfPlayer(realName, expire);
messenger.notifyIpMutingOfPlayer(ip, expire);
messenger.notifyMacMutingOfPlayer(mac, expire);
return;
}
}
} catch (final Exception e) {
logger.log(Level.SEVERE, "Failed to notify mute of player", e);
}
}).start();
return null;
}
System.out.println("Attempted remote mute player with invalid password.");
return "Invalid password!";
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class ServerModel method getLauncher.
public Optional<ServerLauncher> getLauncher() {
synchronized (this) {
disallowRemoveConnections();
// -1 since we dont count outselves
final int clientCount = serverMessenger.getNodes().size() - 1;
final Map<String, INode> remotePlayers = new HashMap<>();
for (final Entry<String, String> entry : playersToNodeListing.entrySet()) {
final String playedBy = entry.getValue();
if (playedBy == null) {
return Optional.empty();
}
if (!playedBy.equals(serverMessenger.getLocalNode().getName())) {
serverMessenger.getNodes().stream().filter(node -> node.getName().equals(playedBy)).findAny().ifPresent(node -> remotePlayers.put(entry.getKey(), node));
}
}
return Optional.of(new ServerLauncher(clientCount, remoteMessenger, channelMessenger, serverMessenger, gameSelectorModel, getPlayerListingInternal(), remotePlayers, this, headless));
}
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class BanPlayerAction 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 ban", 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)) {
final String realName = node.getName().split(" ")[0];
final String ip = node.getAddress().getHostAddress();
final String mac = messenger.getPlayerMac(node.getName());
messenger.notifyUsernameMiniBanningOfPlayer(realName, null);
messenger.notifyIpMiniBanningOfPlayer(ip, null);
messenger.notifyMacMiniBanningOfPlayer(mac, null);
messenger.removeConnection(node);
return;
}
}
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class MutePlayerAction 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 mute", 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)) {
final String realName = node.getName().split(" ")[0];
final String ip = node.getAddress().getHostAddress();
final String mac = messenger.getPlayerMac(node.getName());
messenger.notifyUsernameMutingOfPlayer(realName, null);
messenger.notifyIpMutingOfPlayer(ip, null);
messenger.notifyMacMutingOfPlayer(mac, null);
return;
}
}
}
use of games.strategy.net.INode in project triplea by triplea-game.
the class SetMapClientAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
final INode serverNode = clientMessenger.getServerNode();
final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
final JComboBox<String> combo = new JComboBox<>(model);
model.addElement("");
for (final String game : availableGames) {
model.addElement(game);
}
if (serverNode == null || model.getSize() <= 1) {
JOptionPane.showMessageDialog(parent, "No available games", "No available games", JOptionPane.ERROR_MESSAGE);
return;
}
final int selectedOption = JOptionPane.showConfirmDialog(parent, combo, "Change Game To: ", JOptionPane.OK_CANCEL_OPTION);
if (selectedOption != JOptionPane.OK_OPTION) {
return;
}
final String name = (String) combo.getSelectedItem();
if (name == null || name.length() <= 1) {
return;
}
clientMessenger.changeServerGameTo(name);
}
Aggregations