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
This commit is contained in:
parent
43cb19c934
commit
f9976ec817
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
package com.jme3.network;
|
package com.jme3.network;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the connection back to a client that is being
|
* This is the connection back to a client that is being
|
||||||
@ -52,4 +53,24 @@ public interface HostedConnection extends MessageConnection
|
|||||||
* sending the optional reason to the remote client.
|
* 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> T getAttribute( String name );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a read-only set of attribute names currently stored
|
||||||
|
* for this client session.
|
||||||
|
*/
|
||||||
|
public Set<String> attributeNames();
|
||||||
}
|
}
|
||||||
|
@ -330,6 +330,8 @@ public class DefaultServer implements Server
|
|||||||
private Endpoint reliable;
|
private Endpoint reliable;
|
||||||
private Endpoint fast;
|
private Endpoint fast;
|
||||||
|
|
||||||
|
private Map<String,Object> sessionData = new ConcurrentHashMap<String,Object>();
|
||||||
|
|
||||||
public Connection()
|
public Connection()
|
||||||
{
|
{
|
||||||
id = nextId.getAndIncrement();
|
id = nextId.getAndIncrement();
|
||||||
@ -369,6 +371,21 @@ public class DefaultServer implements Server
|
|||||||
reliable.close();
|
reliable.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object setAttribute( String name, Object value )
|
||||||
|
{
|
||||||
|
return sessionData.put(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getAttribute( String name )
|
||||||
|
{
|
||||||
|
return (T)sessionData.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> attributeNames()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableSet(sessionData.keySet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class Redispatch implements MessageListener<HostedConnection>
|
protected class Redispatch implements MessageListener<HostedConnection>
|
||||||
|
@ -6,6 +6,5 @@ SpiderMonkey networking module. The {@link com.jme3.network.Network}
|
|||||||
class is the entry point for creating default implementations
|
class is the entry point for creating default implementations
|
||||||
of {@link com.jme3.network.Client} and {@link com.jme3.network.Server}
|
of {@link com.jme3.network.Client} and {@link com.jme3.network.Server}
|
||||||
implementations.
|
implementations.
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user