//
// $Id$

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
    {
        /** Reject all authentication requests. */
        public void authenticateConnection (AuthingConnection conn)
        {
            Log.info("Rejecting request: " + conn.getAuthRequest());
            AuthResponseData rdata = new AuthResponseData();
            rdata.code = _errmsg;
            connectionWasAuthenticated(conn, new AuthResponse(rdata));
        }
    }

    protected static String _errmsg;
}

@@ -46,16 +46,55 @@
 erver;%0A%0A
+import com.samskivert.util.StringUtil;%0A
 import c
@@ -665,24 +665,129 @@
 ());%0A    %7D%0A%0A
+    // documentation inherited%0A    protected int%5B%5D getListenPorts ()%0A    %7B%0A        return _ports;%0A    %7D%0A%0A
     public s
@@ -850,17 +850,17 @@
 ength %3C 
-1
+2
 ) %7B%0A    
@@ -903,16 +903,22 @@
 ejector 
+ports 
 error_ms
@@ -961,32 +961,84 @@
 -1);%0A        %7D%0A%0A
+        _ports = StringUtil.parseIntArray(args%5B0%5D);%0A
         _errmsg 
@@ -1044,17 +1044,17 @@
  = args%5B
-0
+1
 %5D;%0A     
@@ -2113,10 +2113,45 @@
 errmsg;%0A
+    protected static int%5B%5D _ports;%0A
 %7D%0A

Allow the set of ports to be specified for the rejector.