Search in sources :

Example 41 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class ModeratorController method boot.

@Override
public void boot(final INode node) {
    assertUserIsAdmin();
    // You can't boot the server node
    if (serverMessenger.getServerNode().equals(node)) {
        throw new IllegalStateException("Cannot boot server node");
    }
    final INode modNode = MessageContext.getSender();
    final String mac = getNodeMacAddress(node);
    serverMessenger.removeConnection(node);
    logger.info(String.format("User was booted from the lobby. Username: %s IP: %s Mac: %s Mod Username: %s Mod IP: %s Mod Mac: %s", node.getName(), node.getAddress().getHostAddress(), mac, modNode.getName(), modNode.getAddress().getHostAddress(), getNodeMacAddress(modNode)));
}
Also used : INode(games.strategy.net.INode)

Example 42 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class RemoteHostUtils method getConnections.

@Override
public String getConnections() {
    if (!MessageContext.getSender().equals(serverNode)) {
        return "Not accepted!";
    }
    if (serverMessenger != null) {
        final StringBuilder sb = new StringBuilder("Connected: " + serverMessenger.isConnected() + "\n" + "Nodes: \n");
        final Set<INode> nodes = serverMessenger.getNodes();
        if (nodes == null) {
            sb.append("  null\n");
        } else {
            for (final INode node : nodes) {
                sb.append("  ").append(node).append("\n");
            }
        }
        return sb.toString();
    }
    return "Not a server.";
}
Also used : INode(games.strategy.net.INode)

Example 43 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class UnifiedMessengerHub method sendResultsToCaller.

private void sendResultsToCaller(final GUID methodId, final InvocationInProgress invocationInProgress) {
    final RemoteMethodCallResults result = invocationInProgress.getResults();
    final INode caller = invocationInProgress.getCaller();
    final SpokeInvocationResults spokeResults = new SpokeInvocationResults(result, methodId);
    send(spokeResults, caller);
}
Also used : INode(games.strategy.net.INode)

Example 44 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class UnifiedMessengerHub method messageReceived.

@Override
public void messageReceived(final Serializable msg, final INode from) {
    if (msg instanceof HasEndPointImplementor) {
        synchronized (endPointMutex) {
            final HasEndPointImplementor hasEndPoint = (HasEndPointImplementor) msg;
            final Collection<INode> nodes = endPoints.computeIfAbsent(hasEndPoint.endPointName, k -> new ArrayList<>());
            if (nodes.contains(from)) {
                throw new IllegalStateException("Already contained, new" + from + " existing, " + nodes + " name " + hasEndPoint.endPointName);
            }
            nodes.add(from);
        }
    } else if (msg instanceof NoLongerHasEndPointImplementor) {
        synchronized (endPointMutex) {
            final NoLongerHasEndPointImplementor hasEndPoint = (NoLongerHasEndPointImplementor) msg;
            final Collection<INode> nodes = endPoints.get(hasEndPoint.endPointName);
            if (nodes != null) {
                if (!nodes.remove(from)) {
                    throw new IllegalStateException("Not removed!");
                }
                if (nodes.isEmpty()) {
                    endPoints.remove(hasEndPoint.endPointName);
                }
            }
        }
    } else if (msg instanceof HubInvoke) {
        final HubInvoke invoke = (HubInvoke) msg;
        final Collection<INode> endPointCols = new ArrayList<>();
        synchronized (endPointMutex) {
            if (endPoints.containsKey(invoke.call.getRemoteName())) {
                endPointCols.addAll(endPoints.get(invoke.call.getRemoteName()));
            }
        }
        // the node will already have routed messages to local invokers
        endPointCols.remove(from);
        if (endPointCols.isEmpty()) {
            if (invoke.needReturnValues) {
                final RemoteMethodCallResults results = new RemoteMethodCallResults(new RemoteNotFoundException("Not found:" + invoke.call.getRemoteName()));
                send(new SpokeInvocationResults(results, invoke.methodCallId), from);
            }
        // no end points, this is ok, we
        // we are a channel with no implementors
        } else {
            invoke(invoke, endPointCols, from);
        }
    } else if (msg instanceof HubInvocationResults) {
        final HubInvocationResults results = (HubInvocationResults) msg;
        results(results, from);
    }
}
Also used : INode(games.strategy.net.INode) ArrayList(java.util.ArrayList) HasEndPointImplementor(games.strategy.engine.message.unifiedmessenger.HasEndPointImplementor) NoLongerHasEndPointImplementor(games.strategy.engine.message.unifiedmessenger.NoLongerHasEndPointImplementor) NoLongerHasEndPointImplementor(games.strategy.engine.message.unifiedmessenger.NoLongerHasEndPointImplementor) Collection(java.util.Collection)

Example 45 with INode

use of games.strategy.net.INode in project triplea by triplea-game.

the class UnifiedMessengerHub method invoke.

private void invoke(final HubInvoke hubInvoke, final Collection<INode> remote, final INode from) {
    if (hubInvoke.needReturnValues) {
        if (remote.size() != 1) {
            throw new IllegalStateException("Too many nodes:" + remote + " for remote name " + hubInvoke.call);
        }
        final InvocationInProgress invocationInProgress = new InvocationInProgress(remote.iterator().next(), hubInvoke, from);
        invocations.put(hubInvoke.methodCallId, invocationInProgress);
    }
    // invoke remotely
    final SpokeInvoke invoke = new SpokeInvoke(hubInvoke.methodCallId, hubInvoke.needReturnValues, hubInvoke.call, from);
    for (final INode node : remote) {
        send(invoke, node);
    }
}
Also used : INode(games.strategy.net.INode)

Aggregations

INode (games.strategy.net.INode)46 IModeratorController (games.strategy.engine.lobby.server.IModeratorController)10 RemoteName (games.strategy.engine.message.RemoteName)8 BorderLayout (java.awt.BorderLayout)8 JLabel (javax.swing.JLabel)7 JPanel (javax.swing.JPanel)7 JPasswordField (javax.swing.JPasswordField)5 IServerMessenger (games.strategy.net.IServerMessenger)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Node (games.strategy.net.Node)3 Dimension (java.awt.Dimension)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)3 JComboBox (javax.swing.JComboBox)3 Chat (games.strategy.engine.chat.Chat)2 GameRunner (games.strategy.engine.framework.GameRunner)2 IGamePlayer (games.strategy.engine.gamePlayer.IGamePlayer)2