//Set-up Server here
server = new Server() {
protected Connection newConnection () {
// By providing our own connection implementation, we can store per
// connection state without a connection ID to state look up.
return new WarTugConnection();
}
};
// For consistency, the classes to be sent over the network are
// registered by the same method for both the client and server.
Network.register(server);
server.addListener(new Listener() {
public void received (Connection c, Object object) {
// We know all connections for this server are actually ChatConnections.
WarTugConnection connection = (WarTugConnection)c;
if (object instanceof RegisterName) {
if (numPlayers==2) return; //Only let two players on server
if (connection.name != null) return; // Ignore the object if the name is invalid.
String name = ((RegisterName)object).name;