diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-20 04:03:32 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-20 04:03:32 +0200 |
commit | f37219cfbf4db6a5ee5d62909155c5b1e47e1085 (patch) | |
tree | 47e8afe6dc36d984bce4d62f8e67e559a43bef48 /src | |
parent | 338f2c1c421db1c9712d0c522703437ecdf625df (diff) | |
download | JRummikub-f37219cfbf4db6a5ee5d62909155c5b1e47e1085.tar JRummikub-f37219cfbf4db6a5ee5d62909155c5b1e47e1085.zip |
Include libs and dedicated server
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@505 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/resource/bogus_mina_tls.cert | bin | 0 -> 937 bytes | |||
-rw-r--r-- | src/jrummikub/server/DedicatedServer.java | 84 |
2 files changed, 84 insertions, 0 deletions
diff --git a/src/jrummikub/resource/bogus_mina_tls.cert b/src/jrummikub/resource/bogus_mina_tls.cert Binary files differnew file mode 100644 index 0000000..d34502d --- /dev/null +++ b/src/jrummikub/resource/bogus_mina_tls.cert diff --git a/src/jrummikub/server/DedicatedServer.java b/src/jrummikub/server/DedicatedServer.java new file mode 100644 index 0000000..a31c6f5 --- /dev/null +++ b/src/jrummikub/server/DedicatedServer.java @@ -0,0 +1,84 @@ +package jrummikub.server; + +import java.io.IOException; +import java.net.InetAddress; + +import org.apache.vysper.mina.TCPEndpoint; +import org.apache.vysper.storage.OpenStorageProviderRegistry; +import org.apache.vysper.xmpp.addressing.Entity; +import org.apache.vysper.xmpp.authorization.UserAuthorization; +import org.apache.vysper.xmpp.modules.extension.xep0045_muc.MUCModule; +import org.apache.vysper.xmpp.modules.extension.xep0045_muc.storage.InMemoryOccupantStorageProvider; +import org.apache.vysper.xmpp.modules.extension.xep0045_muc.storage.InMemoryRoomStorageProvider; +import org.apache.vysper.xmpp.modules.roster.persistence.MemoryRosterManager; +import org.apache.vysper.xmpp.server.XMPPServer; + +@SuppressWarnings("deprecation") +public class DedicatedServer { + String serverPassword; + String hostName; + + public DedicatedServer(String serverPassword) { + this.serverPassword = serverPassword; + try { + InetAddress addr = InetAddress.getLocalHost(); + hostName = addr.getCanonicalHostName(); + } catch (Exception e) { + hostName = "localhost"; + } + + } + + public String getHostName() { + return hostName; + } + + public void start() throws Exception { + XMPPServer server = new XMPPServer(hostName); + + OpenStorageProviderRegistry providerRegistry = new OpenStorageProviderRegistry(); + providerRegistry.add(new ServerPasswordAuthorization()); + providerRegistry.add(new MemoryRosterManager()); + providerRegistry.add(new InMemoryRoomStorageProvider()); + providerRegistry.add(new InMemoryOccupantStorageProvider()); + + server.setStorageProviderRegistry(providerRegistry); + server.addEndpoint(new TCPEndpoint()); + + server.setTLSCertificateInfo( + getClass().getResource( + "/jrummikub/resource/bogus_mina_tls.cert").openStream(), + "boguspw"); + + server.start(); + MUCModule muc = new MUCModule("play"); + server.addModule(muc); + + } + + public class ServerPasswordAuthorization implements UserAuthorization { + @Override + public boolean verifyCredentials(Entity entity, String password, + Object credentials) { + return password.equals(serverPassword); + } + + @Override + public boolean verifyCredentials(String entity, String password, + Object credentials) { + return password.equals(serverPassword); + } + } + + public static void main(String[] args) { + + DedicatedServer server = new DedicatedServer("password"); + System.out.println("Server hostname is " + server.getHostName()); + try { + server.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} |