From f9976ec8178373a6f63adb958260e4d334f616fc Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Fri, 18 Mar 2011 02:10:45 +0000 Subject: [PATCH] Added server-side client-specific session attributes for tucking player data, etc.. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7018 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/network/HostedConnection.java | 23 ++++++++++++++++++- .../com/jme3/network/base/DefaultServer.java | 21 +++++++++++++++-- .../networking/com/jme3/network/package.html | 1 - 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/engine/src/networking/com/jme3/network/HostedConnection.java b/engine/src/networking/com/jme3/network/HostedConnection.java index e0daec48a..d8d3b40be 100644 --- a/engine/src/networking/com/jme3/network/HostedConnection.java +++ b/engine/src/networking/com/jme3/network/HostedConnection.java @@ -32,6 +32,7 @@ package com.jme3.network; +import java.util.Set; /** * This is the connection back to a client that is being @@ -51,5 +52,25 @@ public interface HostedConnection extends MessageConnection * Closes and removes this connection from the server * sending the optional reason to the remote client. */ - public void close( String reason ); + public void close( String reason ); + + /** + * Sets a session attribute specific to this connection. + * + * @return The previous session value for this key or null + * if there was no previous value. + */ + public Object setAttribute( String name, Object value ); + + /** + * Retrieves a previosly stored session attribute or + * null if no such attribute exists. + */ + public T getAttribute( String name ); + + /** + * Returns a read-only set of attribute names currently stored + * for this client session. + */ + public Set attributeNames(); } diff --git a/engine/src/networking/com/jme3/network/base/DefaultServer.java b/engine/src/networking/com/jme3/network/base/DefaultServer.java index e5cc01665..0d05fb93c 100644 --- a/engine/src/networking/com/jme3/network/base/DefaultServer.java +++ b/engine/src/networking/com/jme3/network/base/DefaultServer.java @@ -328,7 +328,9 @@ public class DefaultServer implements Server { private long id; private Endpoint reliable; - private Endpoint fast; + private Endpoint fast; + + private Map sessionData = new ConcurrentHashMap(); public Connection() { @@ -368,7 +370,22 @@ public class DefaultServer implements Server if( reliable != null ) { reliable.close(); } - } + } + + public Object setAttribute( String name, Object value ) + { + return sessionData.put(name, value); + } + + public T getAttribute( String name ) + { + return (T)sessionData.get(name); + } + + public Set attributeNames() + { + return Collections.unmodifiableSet(sessionData.keySet()); + } } protected class Redispatch implements MessageListener diff --git a/engine/src/networking/com/jme3/network/package.html b/engine/src/networking/com/jme3/network/package.html index 4c01ab769..ffb0138cf 100644 --- a/engine/src/networking/com/jme3/network/package.html +++ b/engine/src/networking/com/jme3/network/package.html @@ -6,6 +6,5 @@ SpiderMonkey networking module. The {@link com.jme3.network.Network} class is the entry point for creating default implementations of {@link com.jme3.network.Client} and {@link com.jme3.network.Server} implementations. -