use of games.strategy.net.IServerMessenger 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.IServerMessenger in project triplea by triplea-game.
the class VaultTest method testLocal.
@Test
public void testLocal() throws Exception {
final IServerMessenger messenger = mock(IServerMessenger.class);
when(messenger.getLocalNode()).thenReturn(new Node("dummy", InetAddress.getLocalHost(), 0));
final UnifiedMessenger unifiedMessenger = new UnifiedMessenger(messenger);
final ChannelMessenger channelMessenger = new ChannelMessenger(unifiedMessenger);
// RemoteMessenger remoteMessenger = new RemoteMessenger(unifiedMessenger);
final Vault vault = new Vault(channelMessenger);
final byte[] data = new byte[] { 0, 1, 2, 3, 4, 5 };
final VaultID id = vault.lock(data);
vault.unlock(id);
assertArrayEquals(data, vault.get(id));
vault.release(id);
}
use of games.strategy.net.IServerMessenger in project triplea by triplea-game.
the class InGameLobbyWatcher method newInGameLobbyWatcher.
/**
* Reads SystemProperties to see if we should connect to a lobby server
*
* <p>
* After creation, those properties are cleared, since we should watch the first start game.
* </p>
*
* @return null if no watcher should be created
*/
public static InGameLobbyWatcher newInGameLobbyWatcher(final IServerMessenger gameMessenger, final JComponent parent, final InGameLobbyWatcher oldWatcher) {
final String host = System.getProperty(LOBBY_HOST);
final String port = System.getProperty(LOBBY_PORT);
final String hostedBy = System.getProperty(LOBBY_GAME_HOSTED_BY);
if (host == null || port == null) {
return null;
}
// clear the properties
System.clearProperty(LOBBY_HOST);
System.clearProperty(LOBBY_PORT);
System.clearProperty(LOBBY_GAME_HOSTED_BY);
// add them as temporary properties (in case we load an old savegame and need them again)
System.setProperty(LOBBY_HOST + GameRunner.OLD_EXTENSION, host);
System.setProperty(LOBBY_PORT + GameRunner.OLD_EXTENSION, port);
System.setProperty(LOBBY_GAME_HOSTED_BY + GameRunner.OLD_EXTENSION, hostedBy);
final IConnectionLogin login = challengeProperties -> {
final Map<String, String> properties = new HashMap<>();
properties.put(LobbyLoginValidator.ANONYMOUS_LOGIN, Boolean.TRUE.toString());
properties.put(LobbyLoginValidator.LOBBY_VERSION, LobbyServer.LOBBY_VERSION.toString());
properties.put(LobbyLoginValidator.LOBBY_WATCHER_LOGIN, Boolean.TRUE.toString());
return properties;
};
try {
System.out.println("host:" + host + " port:" + port);
final String mac = MacFinder.getHashedMacAddress();
final ClientMessenger messenger = new ClientMessenger(host, Integer.parseInt(port), getRealName(hostedBy) + "_" + LOBBY_WATCHER_NAME, mac, login);
final UnifiedMessenger um = new UnifiedMessenger(messenger);
final RemoteMessenger rm = new RemoteMessenger(um);
final RemoteHostUtils rhu = new RemoteHostUtils(messenger.getServerNode(), gameMessenger);
rm.registerRemote(rhu, RemoteHostUtils.getRemoteHostUtilsName(um.getLocalNode()));
return new InGameLobbyWatcher(messenger, rm, gameMessenger, parent, oldWatcher);
} catch (final Exception e) {
ClientLogger.logQuietly("Failed to create in-game lobby watcher", e);
return null;
}
}
use of games.strategy.net.IServerMessenger in project triplea by triplea-game.
the class ClientLoginIntegrationTest method newServerMessenger.
private static IServerMessenger newServerMessenger() throws Exception {
final ServerMessenger serverMessenger = new ServerMessenger("server", 0);
serverMessenger.setAcceptNewConnections(true);
serverMessenger.setLoginValidator(newLoginValidator(serverMessenger));
return serverMessenger;
}
use of games.strategy.net.IServerMessenger in project triplea by triplea-game.
the class StatusTest method testStatus.
@Test
public void testStatus() throws Exception {
final IServerMessenger messenger = mock(IServerMessenger.class);
final INode dummyNode = new Node("dummy", InetAddress.getLocalHost(), 0);
when(messenger.getLocalNode()).thenReturn(dummyNode);
when(messenger.getServerNode()).thenReturn(dummyNode);
when(messenger.isConnected()).thenReturn(true);
when(messenger.isServer()).thenReturn(true);
final Messengers messengers = new Messengers(messenger);
final StatusManager manager = new StatusManager(messengers);
assertNull(manager.getStatus(messenger.getLocalNode()));
manager.setStatus("test");
Interruptibles.sleep(200);
assertEquals("test", manager.getStatus(messenger.getLocalNode()));
assertEquals("test", new StatusManager(messengers).getStatus(messenger.getLocalNode()));
}
Aggregations