A simple server useful for rejecting client logins when we don't want to
run a real server. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3131 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// $Id: Rejector.java,v 1.1 2004/10/13 01:02:19 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.threerings.util.MessageBundle;
|
||||
|
||||
import com.threerings.presents.Log;
|
||||
import com.threerings.presents.net.AuthResponse;
|
||||
import com.threerings.presents.net.AuthResponseData;
|
||||
import com.threerings.presents.server.net.AuthingConnection;
|
||||
|
||||
/**
|
||||
* A simple server that does nothing more than spit out a canned error
|
||||
* response to everyone who logs in.
|
||||
*/
|
||||
public class Rejector extends PresentsServer
|
||||
{
|
||||
// documentation inherited
|
||||
public void init ()
|
||||
throws Exception
|
||||
{
|
||||
super.init();
|
||||
conmgr.setAuthenticator(new RejectingAuthenticator());
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
if (args.length < 1) {
|
||||
System.err.println("Usage: Rejector error_msg [args]");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
_errmsg = args[0];
|
||||
if (args.length > 1) {
|
||||
String[] eargs = new String[args.length-1];
|
||||
System.arraycopy(args, 1, eargs, 0, eargs.length);
|
||||
_errmsg = MessageBundle.tcompose(_errmsg, eargs);
|
||||
}
|
||||
|
||||
Rejector server = new Rejector();
|
||||
try {
|
||||
server.init();
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
Log.warning("Unable to initialize server.");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An authenticator implementation that refuses all authentication
|
||||
* requests.
|
||||
*/
|
||||
protected class RejectingAuthenticator extends Authenticator
|
||||
{
|
||||
/**
|
||||
* Accept all authentication requests.
|
||||
*/
|
||||
public void authenticateConnection (AuthingConnection conn)
|
||||
{
|
||||
Log.info("Accepting request: " + conn.getAuthRequest());
|
||||
AuthResponseData rdata = new AuthResponseData();
|
||||
rdata.code = _errmsg;
|
||||
connectionWasAuthenticated(conn, new AuthResponse(rdata));
|
||||
}
|
||||
}
|
||||
|
||||
protected static String _errmsg;
|
||||
}
|
||||
Reference in New Issue
Block a user