@Override public void connectionAdded(Server server, HostedConnection hc) { // Just in case super.connectionAdded(server, hc); // Send the client the registration information hc.send(SerializerRegistrationsMessage.INSTANCE); } }
/** * Removes any RMI hosting services associated with the specified * connection. Calls to getRmiRegistry() will return null for * this connection. * This method is called automatically for all leaving connections if * autohost is set to true. */ public void stopHostingOnConnection( HostedConnection hc ) { RmiRegistry rmi = hc.getAttribute(ATTRIBUTE_NAME); if( rmi == null ) { return; } if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "stopHostingOnConnection:{0}", hc); } hc.setAttribute(ATTRIBUTE_NAME, null); //rpc.close(); }
public synchronized void close() { if( !isRunning ) { return; } // Gracefully let any connections know that the server is // going down. Without this, their connections will simply // error out. for( HostedConnection conn : server.getConnections() ) { conn.close("Server is shutting down."); } try { Thread.sleep(1000); // wait a couple beats to let the messages go out } catch( InterruptedException e ) { e.printStackTrace(); } server.close(); isRunning = false; notifyAll(); }
@Override public void messageReceived(HostedConnection source, Message m) { if (m instanceof ChatMessage) { // Keep track of the name just in case we // want to know it for some other reason later and it's // a good example of session data ChatMessage cm = (ChatMessage)m; source.setAttribute("name", cm.getName()); // Check for a / command if( cm.message.startsWith("/") ) { runCommand(source, cm.name, cm.message); return; } System.out.println("Broadcasting:" + m + " reliable:" + m.isReliable()); // Just rebroadcast... the reliable flag will stay the // same so if it came in on UDP it will go out on that too source.getServer().broadcast(cm); } else { System.err.println("Received odd message:" + m); } } }
/** * Sets up RPC hosting services for the hosted connection allowing * getRpcConnection() to return a valid RPC connection object. * This method is called automatically for all new connections if * autohost is set to true. */ @Override public void startHostingOnConnection( HostedConnection hc ) { if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "startHostingOnConnection:{0}", hc); } hc.setAttribute(ATTRIBUTE_NAME, new RpcConnection(hc)); }
/** * Retrieves the RpcConnection for the specified HostedConnection * if that HostedConnection has had RPC services started using * startHostingOnConnection() (or via autohosting). Returns null * if the connection currently doesn't have RPC hosting services * attached. */ public RpcConnection getRpcConnection( HostedConnection hc ) { return hc.getAttribute(ATTRIBUTE_NAME); }
if (players.size() < maxPlayers) { Keeper keeper = LobbyUtils.getNextKeeper(false, players.keySet()); ClientInfo clientInfo = new ClientInfo(conn.getAttribute(ATTRIBUTE_SYSTEM_MEMORY), conn.getAddress(), conn.getId()); clientInfo.setName(playerName); clientInfo.setKeeper(keeper); conn.setAttribute(ATTRIBUTE_SESSION, session); conn.setAttribute(ATTRIBUTE_KEEPER_ID, keeper.getId()); conn.close("Game full!");
@Override public void stopHostingOnConnection(HostedConnection conn) { logger.log(Level.FINER, "stopHostingOnConnection({0})", conn); ChatSessionImpl player = getChatSession(conn); if (player != null) { // Then we are still hosting on the connection... it's // possible that stopHostingOnConnection() is called more than // once for a particular connection since some other game code // may call it and it will also be called during connection shutdown. conn.setAttribute(ATTRIBUTE_SESSION, null); // Remove player session from the active sessions list players.remove(player); // Send the leave event to other players for (ChatSessionImpl chatter : players) { if (chatter == player) { // Don't send our enter event to ourselves continue; } chatter.playerLeft(conn.getId(), player.name); } } }
protected void postMessage(ChatSessionImpl from, String message) { logger.log(Level.INFO, "chat> {0} said:{1}", new Object[]{from.name, message}); for (ChatSessionImpl chatter : players) { chatter.newMessage(from.conn.getId(), from.conn.getAttribute(ATTRIBUTE_KEEPER_ID), from.name, message); } }
public void connectionAdded(Server server, HostedConnection conn) { System.out.println("Client Connected: "+conn.getId()); //conn.close("goodbye"); }
/** * Sets up RMI hosting services for the hosted connection allowing * getRmiRegistry() to return a valid RmiRegistry object. * This method is called automatically for all new connections if * autohost is set to true. */ public void startHostingOnConnection( HostedConnection hc ) { if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "startHostingOnConnection:{0}", hc); } RmiRegistry rmi = new RmiRegistry(hc, rpcService.getRpcConnection(hc), rmiId, defaultChannel); hc.setAttribute(ATTRIBUTE_NAME, rmi); // Register any global shares for( Map.Entry<String, GlobalShare> e : globalShares.entrySet() ) { GlobalShare share = e.getValue(); rmi.share(share.channel, e.getKey(), share.object, share.type); } }
/** * Returns the RMI registry for the specific HostedConnection. Each connection * has its own registry with its own connection-specific shared objects. */ public RmiRegistry getRmiRegistry( HostedConnection hc ) { return hc.getAttribute(ATTRIBUTE_NAME); }
/** * Starts hosting the chat services on the specified connection using a * specified player name. This causes the player to 'enter' the chat room * and will then be able to send/receive messages. */ public void startHostingOnConnection(HostedConnection conn, String playerName) { logger.log(Level.FINER, "startHostingOnConnection({0})", conn); ChatSessionImpl session = new ChatSessionImpl(conn, playerName); conn.setAttribute(ATTRIBUTE_SESSION, session); // Expose the session as an RMI resource to the client RmiRegistry rmi = rmiService.getRmiRegistry(conn); rmi.share(NetworkConstants.CHAT_CHANNEL, session, ChatSession.class); players.add(session); // Send the enter event to other players for (ChatSessionImpl chatter : players) { if (chatter == session) { // Don't send our enter event to ourselves continue; } chatter.playerJoined(conn.getId(), playerName); } }
/** * Starts hosting the chat services on the specified connection using a * generated player name. */ @Override public void startHostingOnConnection(HostedConnection conn) { startHostingOnConnection(conn, "Client:" + conn.getId()); }
public void messageReceived(HostedConnection source, com.jme3.network.Message message) { if (message instanceof PingMessage){ System.out.println("Server: Received ping message!"); source.send(new PongMessage()); } } }
/** * Removes any RPC hosting services associated with the specified * connection. Calls to getRpcConnection() will return null for * this connection. The connection's RpcConnection is also closed, * releasing any waiting synchronous calls with a "Connection closing" * error. * This method is called automatically for all leaving connections if * autohost is set to true. */ @Override public void stopHostingOnConnection( HostedConnection hc ) { RpcConnection rpc = hc.getAttribute(ATTRIBUTE_NAME); if( rpc == null ) { return; } if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "stopHostingOnConnection:{0}", hc); } hc.setAttribute(ATTRIBUTE_NAME, null); rpc.close(); }
/** * Sets up the specified connection for hosting remote * entity data commands. By default this is performed automatically * in addConnection() and is controlled by the setAutoHost() property. */ public void startHostingOnConnection( HostedConnection hc ) { log.debug("startHostingOnConnection:" + hc); hc.setAttribute(HostedEntityData.ATTRIBUTE_NAME, new HostedEntityData(this, hc, ed)); }
/** * Returns the attributeName attribute of the supplied source * HostConnection. If there is no value at that attribute then * the miss() method is called. */ protected Object getSourceDelegate( HostedConnection source ) { Object result = source.getAttribute(attributeName); if( result == null ) { miss(source); } return result; } }
/** * Starts hosting the chat services on the specified connection using a * generated player name. */ @Override public void startHostingOnConnection(HostedConnection conn) { startHostingOnConnection(conn, "Client:" + conn.getId()); }
@Override public void removePlayer(ClientInfo keeper) { AbstractLobbySessionImpl lobbySessionImpl; synchronized (playerLock) { lobbySessionImpl = players.remove(keeper); } // Disconnect player if (lobbySessionImpl.getHostedConnection() != null) { lobbySessionImpl.getHostedConnection().close("You have been kicked from the game!"); } // Notify players notifyPlayersChange(); }