use of games.strategy.engine.message.unifiedmessenger.UnifiedMessenger 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.engine.message.unifiedmessenger.UnifiedMessenger in project triplea by triplea-game.
the class ClientModel method createClientMessenger.
boolean createClientMessenger(Component ui) {
gameDataOnStartup = gameSelectorModel.getGameData();
gameSelectorModel.setCanSelect(false);
ui = JOptionPane.getFrameForComponent(ui);
this.ui = ui;
// load in the saved name!
final ClientProps props = getProps(ui);
if (props == null) {
gameSelectorModel.setCanSelect(true);
cancel();
return false;
}
final String name = props.getName();
logger.log(Level.FINE, "Client playing as:" + name);
ClientSetting.PLAYER_NAME.save(name);
ClientSetting.flush();
final int port = props.getPort();
if (port >= 65536 || port <= 0) {
EventThreadJOptionPane.showMessageDialog(ui, "Invalid Port: " + port, "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
final String address = props.getHost();
try {
final String mac = MacFinder.getHashedMacAddress();
messenger = new ClientMessenger(address, port, name, mac, objectStreamFactory, new ClientLogin(this.ui));
} catch (final CouldNotLogInException e) {
EventThreadJOptionPane.showMessageDialog(ui, e.getMessage());
return false;
} catch (final Exception ioe) {
ioe.printStackTrace(System.out);
EventThreadJOptionPane.showMessageDialog(ui, "Unable to connect:" + ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
messenger.addErrorListener(this);
final UnifiedMessenger unifiedMessenger = new UnifiedMessenger(messenger);
channelMessenger = new ChannelMessenger(unifiedMessenger);
remoteMessenger = new RemoteMessenger(unifiedMessenger);
channelMessenger.registerChannelSubscriber(channelListener, IClientChannel.CHANNEL_NAME);
chatPanel = new ChatPanel(messenger, channelMessenger, remoteMessenger, ServerModel.CHAT_NAME, Chat.ChatSoundProfile.GAME_CHATROOM);
if (getIsServerHeadlessTest()) {
gameSelectorModel.setClientModelForHostBots(this);
((ChatPanel) chatPanel).getChatMessagePanel().addServerMessage("Welcome to an automated dedicated host service (a host bot). " + "\nIf anyone disconnects, the autosave will be reloaded (a save might be loaded right now). " + "\nYou can get the current save, or you can load a save (only saves that it has the map for).");
}
remoteMessenger.registerRemote(observerWaitingToJoin, ServerModel.getObserverWaitingToStartName(messenger.getLocalNode()));
// save this, it will be cleared later
gameDataOnStartup = gameSelectorModel.getGameData();
final IServerStartupRemote serverStartup = getServerStartup();
final PlayerListing players = serverStartup.getPlayerListing();
internalPlayerListingChanged(players);
if (!serverStartup.isGameStarted(messenger.getLocalNode())) {
remoteMessenger.unregisterRemote(ServerModel.getObserverWaitingToStartName(messenger.getLocalNode()));
}
gameSelectorModel.setIsHostHeadlessBot(hostIsHeadlessBot);
return true;
}
use of games.strategy.engine.message.unifiedmessenger.UnifiedMessenger 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.engine.message.unifiedmessenger.UnifiedMessenger in project triplea by triplea-game.
the class ChatIntegrationTest method setUp.
@BeforeEach
public void setUp() throws Exception {
serverMessenger = new ServerMessenger("Server", 0);
serverMessenger.setAcceptNewConnections(true);
final int serverPort = serverMessenger.getLocalNode().getSocketAddress().getPort();
final String mac = MacFinder.getHashedMacAddress();
client1Messenger = new ClientMessenger("localhost", serverPort, "client1", mac);
client2Messenger = new ClientMessenger("localhost", serverPort, "client2", mac);
final UnifiedMessenger serverUnifiedMessenger = new UnifiedMessenger(serverMessenger);
serverRemoteMessenger = new RemoteMessenger(serverUnifiedMessenger);
serverChannelMessenger = new ChannelMessenger(serverUnifiedMessenger);
final UnifiedMessenger client1UnifiedMessenger = new UnifiedMessenger(client1Messenger);
client1RemoteMessenger = new RemoteMessenger(client1UnifiedMessenger);
client1ChannelMessenger = new ChannelMessenger(client1UnifiedMessenger);
final UnifiedMessenger client2UnifiedMessenger = new UnifiedMessenger(client2Messenger);
client2RemoteMessenger = new RemoteMessenger(client2UnifiedMessenger);
client2ChannelMessenger = new ChannelMessenger(client2UnifiedMessenger);
serverModeratorController = new NullModeratorController(serverMessenger, null);
serverModeratorController.register(serverRemoteMessenger);
}
use of games.strategy.engine.message.unifiedmessenger.UnifiedMessenger in project triplea by triplea-game.
the class VaultTest method setUp.
@BeforeEach
public void setUp() throws IOException {
serverMessenger = new ServerMessenger("Server", 0);
serverMessenger.setAcceptNewConnections(true);
final int serverPort = serverMessenger.getLocalNode().getSocketAddress().getPort();
final String mac = MacFinder.getHashedMacAddress();
clientMessenger = new ClientMessenger("localhost", serverPort, "client1", mac);
final UnifiedMessenger serverUnifiedMessenger = new UnifiedMessenger(serverMessenger);
final UnifiedMessenger clientUnifiedMessenger = new UnifiedMessenger(clientMessenger);
serverVault = new Vault(new ChannelMessenger(serverUnifiedMessenger));
clientVault = new Vault(new ChannelMessenger(clientUnifiedMessenger));
Thread.yield();
}
Aggregations