Skip to content

Commit

Permalink
Initial Import
Browse files Browse the repository at this point in the history
  • Loading branch information
cniemira committed Jan 3, 2015
1 parent 017b3e6 commit d8f7a74
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Eclipse Stuff
*.classpath
*.project
3 changes: 3 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: net.rptools.maptool.server.StandaloneServer
Class-Path: maptool-1.3.jar
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
This package contains a utility to bootstrap a standalone MapTool server.

To use, you need MapTool from rptools.net:
http://www.rptools.net/index.php?page=downloads#MapTool

Download a .zip file, extract, and then drop the provided standalone.jar file into this folder alongside
the maptool-1.3bXX.jar (as of this writing, b91 is current and is the only version this server has been
tested with). You can then start the standalone server like so:

java -cp standalone.jar:maptool-1.3.bXX.jar -Dserver.port="51234" net.rptools.maptool.server.StandaloneServer

You can also rename (or better, `ln -s`) maptool-1.3.bXX.jar -> maptool-1.3.jar and run it this way:

java -jar standalone.jar

You can declare any of the following properties to configure the server:

server.name (registers at rptools.net if set)
server.port (defaults to 51234)
server.gmPassword
server.playerPassword

You can also declare the following. The actual value doesn't matter, if you set them at all, they're on.

log.debug
server.useStrictTokenManagement
server.playersCanRevealVision
server.useIndividualViews
server.playersReceiveCampaignMacros
server.useToolTipsForDefaultRollFormat
server.restrictedImpersonation


Something like this should do you fine:

java -cp standalone.jar:maptool-1.3.b91.jar \
-Dserver.gmPassword="secret" \
-Dserver.playerPassword="******" \
-Dserver.useStrictTokenManagement="on" \
-Dserver.useIndividualViews="on" \
-Dserver.playersReceiveCampaignMacros="on" \
-Dserver.restrictedImpersonation="on" \
net.rptools.maptool.server.StandaloneServer
96 changes: 96 additions & 0 deletions src/net/rptools/maptool/server/StandaloneServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package net.rptools.maptool.server;

import java.io.IOException;

import net.rptools.maptool.client.AssetTransferHandler;
import net.rptools.maptool.client.MapToolRegistry;
import net.rptools.maptool.model.Campaign;
import net.rptools.maptool.model.CampaignFactory;
import net.rptools.maptool.server.MapToolServer;
import net.rptools.maptool.server.ServerConfig;
import net.rptools.maptool.server.ServerPolicy;
import net.rptools.maptool.transfer.AssetTransferManager;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class StandaloneServer {
private static final Logger log = Logger.getLogger(StandaloneServer.class);

private static boolean haveProp(String name) {
if(System.getProperty(name) != null) {
return true;
}
return false;

}

private static void startServer(String id, ServerConfig config, ServerPolicy policy, Campaign campaign) throws IOException {
AssetTransferManager assetTransferManager = new AssetTransferManager();
assetTransferManager.addConsumerListener(new AssetTransferHandler());
assetTransferManager.flush();

MapToolServer server = new MapToolServer(config, policy);
server.setCampaign(campaign);

if (config.isServerRegistered()) {
log.debug("Attempting To Register Server");
try {
int result = MapToolRegistry.registerInstance(config.getServerName(), config.getPort());
if (result == 3) {
log.error("Already Registered", null);
System.exit(1);
}
} catch (Exception e) {
log.error("Could Not Register Server", e);
System.exit(1);
}
} else {
log.debug("Will Not Register Server");
}
}


public static void main(String [] args) {
org.apache.log4j.BasicConfigurator.configure();

if(haveProp("log.debug")) {
Logger.getRootLogger().setLevel(Level.DEBUG);
} else {
Logger.getRootLogger().setLevel(Level.INFO);
}

Campaign campaign = CampaignFactory.createBasicCampaign();

String port_number = System.getProperty("server.port");
int port;
if (port_number == null) {
port = 51234;
} else {
port = Integer.parseInt(port_number);
}

ServerConfig config = new ServerConfig("StandaloneServer",
System.getProperty("server.gmPassword"),
System.getProperty("server.playerPassword"),
port,
System.getProperty("server.name"));

ServerPolicy policy = new ServerPolicy();
policy.setUseStrictTokenManagement(haveProp("server.useStrictTokenManagement"));
policy.setPlayersCanRevealVision(haveProp("server.playersCanRevealVision"));
policy.setUseIndividualViews(haveProp("server.useIndividualViews"));
policy.setPlayersReceiveCampaignMacros(haveProp("server.playersReceiveCampaignMacros"));
policy.setUseToolTipsForDefaultRollFormat(haveProp("server.useToolTipsForDefaultRollFormat"));
policy.setRestrictedImpersonation(haveProp("server.restrictedImpersonation"));

try {
startServer(null, config, policy, campaign);
} catch (Exception e) {
log.error("Could not start server", e);
System.exit(1);
}

log.info("Started on port " + port);
}
}

0 comments on commit d8f7a74

Please sign in to comment.