Everybody has root powers (take two)

Removed concept of root completely
Reformatted code.
This commit is contained in:
Steven Lawson 2011-09-25 19:03:14 -04:00
parent fb77c50bcd
commit 879ecfd279
7 changed files with 762 additions and 633 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/nbproject/private/
/build/
/dist/

View file

@ -55,7 +55,14 @@ is divided into following sections:
</target> </target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init"> <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
<available file="${manifest.file}" property="manifest.available"/> <available file="${manifest.file}" property="manifest.available"/>
<available file="${application.splash}" property="splashscreen.available"/> <condition property="splashscreen.available">
<and>
<not>
<equals arg1="${application.splash}" arg2="" trim="true"/>
</not>
<available file="${application.splash}"/>
</and>
</condition>
<condition property="main.class.available"> <condition property="main.class.available">
<and> <and>
<isset property="main.class"/> <isset property="main.class"/>
@ -70,8 +77,14 @@ is divided into following sections:
<isset property="main.class.available"/> <isset property="main.class.available"/>
</and> </and>
</condition> </condition>
<condition property="do.archive">
<not>
<istrue value="${jar.archive.disabled}"/>
</not>
</condition>
<condition property="do.mkdist"> <condition property="do.mkdist">
<and> <and>
<isset property="do.archive"/>
<isset property="libs.CopyLibs.classpath"/> <isset property="libs.CopyLibs.classpath"/>
<not> <not>
<istrue value="${mkdist.disabled}"/> <istrue value="${mkdist.disabled}"/>
@ -84,40 +97,41 @@ is divided into following sections:
<isset property="do.mkdist"/> <isset property="do.mkdist"/>
</and> </and>
</condition> </condition>
<condition property="manifest.available+main.class+mkdist.available+splashscreen.available">
<and>
<istrue value="${manifest.available+main.class+mkdist.available}"/>
<istrue value="${splashscreen.available}"/>
</and>
</condition>
<condition property="do.archive">
<not>
<istrue value="${jar.archive.disabled}"/>
</not>
</condition>
<condition property="do.archive+manifest.available"> <condition property="do.archive+manifest.available">
<and> <and>
<isset property="manifest.available"/> <isset property="manifest.available"/>
<istrue value="${do.archive}"/> <istrue value="${do.archive}"/>
</and> </and>
</condition> </condition>
<condition property="do.archive+main.class.available">
<and>
<isset property="main.class.available"/>
<istrue value="${do.archive}"/>
</and>
</condition>
<condition property="do.archive+splashscreen.available">
<and>
<isset property="splashscreen.available"/>
<istrue value="${do.archive}"/>
</and>
</condition>
<condition property="do.archive+manifest.available+main.class"> <condition property="do.archive+manifest.available+main.class">
<and> <and>
<istrue value="${manifest.available+main.class}"/> <istrue value="${manifest.available+main.class}"/>
<istrue value="${do.archive}"/> <istrue value="${do.archive}"/>
</and> </and>
</condition> </condition>
<condition property="do.archive+manifest.available+main.class+mkdist.available"> <condition property="manifest.available-mkdist.available">
<and> <or>
<istrue value="${manifest.available+main.class+mkdist.available}"/> <istrue value="${manifest.available}"/>
<istrue value="${do.archive}"/> <isset property="do.mkdist"/>
</and> </or>
</condition> </condition>
<condition property="do.archive+manifest.available+main.class+mkdist.available+splashscreen.available"> <condition property="manifest.available+main.class-mkdist.available">
<and> <or>
<istrue value="${manifest.available+main.class+mkdist.available+splashscreen.available}"/> <istrue value="${manifest.available+main.class}"/>
<istrue value="${do.archive}"/> <isset property="do.mkdist"/>
</and> </or>
</condition> </condition>
<condition property="have.tests"> <condition property="have.tests">
<or> <or>
@ -173,8 +187,17 @@ is divided into following sections:
<condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'"> <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
<length length="0" string="${endorsed.classpath}" when="greater"/> <length length="0" string="${endorsed.classpath}" when="greater"/>
</condition> </condition>
<property name="javac.fork" value="false"/> <condition else="false" property="jdkBug6558476">
<and>
<matches pattern="1\.[56]" string="${java.specification.version}"/>
<not>
<os family="unix"/>
</not>
</and>
</condition>
<property name="javac.fork" value="${jdkBug6558476}"/>
<property name="jar.index" value="false"/> <property name="jar.index" value="false"/>
<property name="jar.index.metainf" value="${jar.index}"/>
<available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/> <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/>
</target> </target>
<target name="-post-init"> <target name="-post-init">
@ -302,7 +325,9 @@ is divided into following sections:
<delete> <delete>
<files includesfile="${javac.includesfile.binary}"/> <files includesfile="${javac.includesfile.binary}"/>
</delete> </delete>
<delete file="${javac.includesfile.binary}"/> <delete>
<fileset file="${javac.includesfile.binary}"/>
</delete>
</sequential> </sequential>
</macrodef> </macrodef>
</target> </target>
@ -312,7 +337,8 @@ is divided into following sections:
<attribute default="${excludes}" name="excludes"/> <attribute default="${excludes}" name="excludes"/>
<attribute default="**" name="testincludes"/> <attribute default="**" name="testincludes"/>
<sequential> <sequential>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true" tempdir="${build.dir}"> <property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<batchtest todir="${build.test.results.dir}"> <batchtest todir="${build.test.results.dir}">
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}"> <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
<filename name="@{testincludes}"/> <filename name="@{testincludes}"/>
@ -328,11 +354,56 @@ is divided into following sections:
<formatter type="brief" usefile="false"/> <formatter type="brief" usefile="false"/>
<formatter type="xml"/> <formatter type="xml"/>
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/> <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg value="-ea"/>
<jvmarg line="${run.jvmargs}"/> <jvmarg line="${run.jvmargs}"/>
</junit> </junit>
</sequential> </sequential>
</macrodef> </macrodef>
</target> </target>
<target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" name="profile-init"/>
<target name="-profile-pre-init">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target name="-profile-post-init">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target name="-profile-init-macrodef-profile">
<macrodef name="resolve">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${env.@{value}}"/>
</sequential>
</macrodef>
<macrodef name="profile">
<attribute default="${main.class}" name="classname"/>
<element name="customize" optional="true"/>
<sequential>
<property environment="env"/>
<resolve name="profiler.current.path" value="${profiler.info.pathvar}"/>
<java classname="@{classname}" dir="${profiler.info.dir}" fork="true" jvm="${profiler.info.jvm}">
<jvmarg value="${profiler.info.jvmargs.agent}"/>
<jvmarg line="${profiler.info.jvmargs}"/>
<env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
<arg line="${application.args}"/>
<classpath>
<path path="${run.classpath}"/>
</classpath>
<syspropertyset>
<propertyref prefix="run-sys-prop."/>
<mapper from="run-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<customize/>
</java>
</sequential>
</macrodef>
</target>
<target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile" name="-profile-init-check">
<fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
<fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
</target>
<target depends="-init-debug-args" name="-init-macrodef-nbjpda"> <target depends="-init-debug-args" name="-init-macrodef-nbjpda">
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1"> <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
<attribute default="${main.class}" name="name"/> <attribute default="${main.class}" name="name"/>
@ -427,6 +498,7 @@ is divided into following sections:
</target> </target>
<target name="-init-macrodef-copylibs"> <target name="-init-macrodef-copylibs">
<macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/3"> <macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${manifest.file}" name="manifest"/>
<element name="customize" optional="true"/> <element name="customize" optional="true"/>
<sequential> <sequential>
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/> <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
@ -442,7 +514,7 @@ is divided into following sections:
</chainedmapper> </chainedmapper>
</pathconvert> </pathconvert>
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/> <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
<copylibs compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}"> <copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
<fileset dir="${build.classes.dir}"/> <fileset dir="${build.classes.dir}"/>
<manifest> <manifest>
<attribute name="Class-Path" value="${jar.classpath}"/> <attribute name="Class-Path" value="${jar.classpath}"/>
@ -571,10 +643,10 @@ is divided into following sections:
<!-- Empty placeholder for easier customization. --> <!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. --> <!-- You can override this target in the ../build.xml file. -->
</target> </target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-without-manifest" unless="manifest.available"> <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-without-manifest" unless="manifest.available-mkdist.available">
<j2seproject1:jar/> <j2seproject1:jar/>
</target> </target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class"> <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class-mkdist.available">
<j2seproject1:jar manifest="${manifest.file}"/> <j2seproject1:jar manifest="${manifest.file}"/>
</target> </target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available"> <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
@ -583,44 +655,53 @@ is divided into following sections:
<j2seproject1:attribute name="Main-Class" value="${main.class}"/> <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
</j2seproject1:manifest> </j2seproject1:manifest>
</j2seproject1:jar> </j2seproject1:jar>
<echo>To run this application from the command line without Ant, try:</echo> <echo level="info">To run this application from the command line without Ant, try:</echo>
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/> <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
<property location="${dist.jar}" name="dist.jar.resolved"/> <property location="${dist.jar}" name="dist.jar.resolved"/>
<pathconvert property="run.classpath.with.dist.jar"> <pathconvert property="run.classpath.with.dist.jar">
<path path="${run.classpath}"/> <path path="${run.classpath}"/>
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/> <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
</pathconvert> </pathconvert>
<echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo> <echo level="info">java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
</target> </target>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-init-macrodef-copylibs" if="do.archive+manifest.available+main.class+mkdist.available+splashscreen.available" name="-do-jar-with-libraries-and-splashscreen"> <target depends="init" if="do.archive" name="-do-jar-with-libraries-create-manifest" unless="manifest.available">
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
<touch file="${tmp.manifest.file}" verbose="false"/>
</target>
<target depends="init" if="do.archive+manifest.available" name="-do-jar-with-libraries-copy-manifest">
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
<copy file="${manifest.file}" tofile="${tmp.manifest.file}"/>
</target>
<target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+main.class.available" name="-do-jar-with-libraries-set-main">
<manifest file="${tmp.manifest.file}" mode="update">
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</target>
<target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-with-libraries-set-splashscreen">
<basename file="${application.splash}" property="splashscreen.basename"/> <basename file="${application.splash}" property="splashscreen.basename"/>
<mkdir dir="${build.classes.dir}/META-INF"/> <mkdir dir="${build.classes.dir}/META-INF"/>
<copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/> <copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/>
<j2seproject3:copylibs> <manifest file="${tmp.manifest.file}" mode="update">
<customize> <attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
<attribute name="Main-Class" value="${main.class}"/> </manifest>
<attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
</customize>
</j2seproject3:copylibs>
<echo>To run this application from the command line without Ant, try:</echo>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<echo>java -jar "${dist.jar.resolved}"</echo>
</target> </target>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-init-macrodef-copylibs" if="do.archive+manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries" unless="splashscreen.available"> <target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen" if="do.mkdist" name="-do-jar-with-libraries-pack">
<j2seproject3:copylibs> <j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
<customize> <echo level="info">To run this application from the command line without Ant, try:</echo>
<attribute name="Main-Class" value="${main.class}"/>
</customize>
</j2seproject3:copylibs>
<echo>To run this application from the command line without Ant, try:</echo>
<property location="${dist.jar}" name="dist.jar.resolved"/> <property location="${dist.jar}" name="dist.jar.resolved"/>
<echo>java -jar "${dist.jar.resolved}"</echo> <echo level="info">java -jar "${dist.jar.resolved}"</echo>
</target> </target>
<target depends="-do-jar-with-libraries-pack" if="do.archive" name="-do-jar-with-libraries-delete-manifest">
<delete>
<fileset file="${tmp.manifest.file}"/>
</delete>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen,-do-jar-with-libraries-pack,-do-jar-with-libraries-delete-manifest" name="-do-jar-with-libraries"/>
<target name="-post-jar"> <target name="-post-jar">
<!-- Empty placeholder for easier customization. --> <!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. --> <!-- You can override this target in the ../build.xml file. -->
</target> </target>
<target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries-and-splashscreen,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/> <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
<!-- <!--
================= =================
EXECUTION SECTION EXECUTION SECTION
@ -685,6 +766,72 @@ is divided into following sections:
<j2seproject1:nbjpdareload/> <j2seproject1:nbjpdareload/>
</target> </target>
<target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/> <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
<!--
=================
PROFILING SECTION
=================
-->
<target depends="profile-init,compile" description="Profile a project in the IDE." if="netbeans.home" name="profile">
<nbprofiledirect>
<classpath>
<path path="${run.classpath}"/>
</classpath>
</nbprofiledirect>
<profile/>
</target>
<target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="netbeans.home" name="profile-single">
<fail unless="profile.class">Must select one file in the IDE or set profile.class</fail>
<nbprofiledirect>
<classpath>
<path path="${run.classpath}"/>
</classpath>
</nbprofiledirect>
<profile classname="${profile.class}"/>
</target>
<!--
=========================
APPLET PROFILING SECTION
=========================
-->
<target depends="profile-init,compile-single" if="netbeans.home" name="profile-applet">
<nbprofiledirect>
<classpath>
<path path="${run.classpath}"/>
</classpath>
</nbprofiledirect>
<profile classname="sun.applet.AppletViewer">
<customize>
<arg value="${applet.url}"/>
</customize>
</profile>
</target>
<!--
=========================
TESTS PROFILING SECTION
=========================
-->
<target depends="profile-init,compile-test-single" if="netbeans.home" name="profile-test-single">
<nbprofiledirect>
<classpath>
<path path="${run.test.classpath}"/>
</classpath>
</nbprofiledirect>
<junit dir="${profiler.info.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" jvm="${profiler.info.jvm}" showoutput="true">
<env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
<jvmarg value="${profiler.info.jvmargs.agent}"/>
<jvmarg line="${profiler.info.jvmargs}"/>
<test name="${profile.class}"/>
<classpath>
<path path="${run.test.classpath}"/>
</classpath>
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
<mapper from="test-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
</junit>
</target>
<!-- <!--
=============== ===============
JAVADOC SECTION JAVADOC SECTION
@ -696,11 +843,12 @@ is divided into following sections:
<classpath> <classpath>
<path path="${javac.classpath}"/> <path path="${javac.classpath}"/>
</classpath> </classpath>
<fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}"> <fileset dir="${src.dir}" excludes="*.java,${excludes}" includes="${includes}">
<filename name="**/*.java"/> <filename name="**/*.java"/>
</fileset> </fileset>
<fileset dir="${build.generated.sources.dir}" erroronmissingdir="false"> <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
<include name="**/*.java"/> <include name="**/*.java"/>
<exclude name="*.java"/>
</fileset> </fileset>
</javadoc> </javadoc>
<copy todir="${dist.javadoc.dir}"> <copy todir="${dist.javadoc.dir}">
@ -731,7 +879,7 @@ is divided into following sections:
<target if="do.depend.true" name="-compile-test-depend"> <target if="do.depend.true" name="-compile-test-depend">
<j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/> <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
</target> </target>
<target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test"> <target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
<j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir="${test.src.dir}"/> <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir="${test.src.dir}"/>
<copy todir="${build.test.classes.dir}"> <copy todir="${build.test.classes.dir}">
<fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
@ -746,7 +894,7 @@ is divided into following sections:
<!-- Empty placeholder for easier customization. --> <!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. --> <!-- You can override this target in the ../build.xml file. -->
</target> </target>
<target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single"> <target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail> <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
<j2seproject3:force-recompile destdir="${build.test.classes.dir}"/> <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
<j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/> <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/>

View file

@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.38.3.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=fc2d0ea5 nbproject/build-impl.xml.data.CRC32=fc2d0ea5
nbproject/build-impl.xml.script.CRC32=66049b1e nbproject/build-impl.xml.script.CRC32=c47fa280
nbproject/build-impl.xml.stylesheet.CRC32=229523de@1.38.3.45 nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45

View file

@ -3,4 +3,4 @@ do.depend=false
do.jar=true do.jar=true
javac.debug=true javac.debug=true
javadoc.preview=true javadoc.preview=true
user.properties.file=C:\\Users\\Administrator\\.netbeans\\6.9\\build.properties user.properties.file=C:\\Users\\Michael\\.netbeans\\7.0\\build.properties

View file

@ -26,11 +26,11 @@ dist.jar=${dist.dir}/MCTelnet.jar
dist.javadoc.dir=${dist.dir}/javadoc dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath= endorsed.classpath=
excludes= excludes=
file.reference.craftbukkit.jar=C:\\Users\\Administrator\\Documents\\NetBeansProjects\\CBJars\\craftbukkit.jar file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=C:\\github\\craftbukkit-0.0.1-SNAPSHOT.jar
includes=** includes=**
jar.compress=false jar.compress=false
javac.classpath=\ javac.classpath=\
${file.reference.craftbukkit.jar} ${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=
javac.deprecation=false javac.deprecation=false
@ -57,6 +57,7 @@ javadoc.use=true
javadoc.version=false javadoc.version=false
javadoc.windowtitle= javadoc.windowtitle=
meta.inf.dir=${src.dir}/META-INF meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform platform.active=default_platform
run.classpath=\ run.classpath=\
${javac.classpath}:\ ${javac.classpath}:\

View file

@ -8,7 +8,6 @@ import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.server.MinecraftServer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
@ -22,229 +21,231 @@ import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.util.config.ConfigurationNode; import org.bukkit.util.config.ConfigurationNode;
/* public class MCTelnet extends JavaPlugin
* To change this template, choose Tools | Templates {
* and open the template in the editor. private ServerSocket listenerSocket;
*/ private ArrayList<TelnetListener> clientHolder;
private Thread listenerThread;
private boolean run = false;
int port = 8765;
InetAddress listenAddress;
/** public MCTelnet()
* {
* @author Administrator }
*/
public class MCTelnet extends JavaPlugin {
private ServerSocket listenerSocket;
private ArrayList<TelnetListener> clientHolder;
private Thread listenerThread;
private boolean run = false;
int port = 8765;
InetAddress listenAddress;
public MCTelnet()
{
} public void onDisable()
{
//public MCTelnet(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) { run = false;
// super(pluginLoader, instance, desc, folder, plugin, cLoader); if (listenerSocket != null)
//} {
try
{
synchronized (listenerSocket)
{
if (listenerSocket != null)
{
listenerSocket.close();
}
}
}
catch (IOException ex)
{
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
}
}
try
{
Thread.sleep(1000);
}
catch (InterruptedException ex)
{
Logger.getLogger(MCTelnet.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void onDisable() public void onEnable()
{ {
run = false; try
if(listenerSocket != null) {
{ Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Starting Up! Version: " + this.getDescription().getVersion() + " by bekvon");
try { run = true;
synchronized (listenerSocket) this.getConfiguration().load();
{ testConfig();
if(listenerSocket!=null) if (this.getConfiguration().getBoolean("encryptPasswords", false))
listenerSocket.close(); {
} encryptPasswords();
} catch (IOException ex) { }
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); port = this.getConfiguration().getInt("telnetPort", port);
} try
} {
try { String address = this.getConfiguration().getString("listenAddress", null);
Thread.sleep(1000); if (address != null)
} catch (InterruptedException ex) { {
Logger.getLogger(MCTelnet.class.getName()).log(Level.SEVERE, null, ex); listenAddress = InetAddress.getByName(address);
} }
} }
catch (Exception ex)
{
System.out.println("[MCTelnet] Exception when trying to binding to custom address:" + ex.getMessage());
}
if (listenAddress != null)
{
listenerSocket = new java.net.ServerSocket(port, 10, listenAddress);
}
else
{
listenerSocket = new java.net.ServerSocket(port, 10);
}
clientHolder = new ArrayList<TelnetListener>();
listenerThread = new Thread(new Runnable()
{
public void run()
{
acceptConnections();
}
});
listenerThread.start();
Field cfield = CraftServer.class.getDeclaredField("console");
cfield.setAccessible(true);
Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Listening on: " + listenerSocket.getInetAddress().getHostAddress() + ":" + port);
}
catch (Exception ex)
{
Logger.getLogger("Minecraft").log(Level.SEVERE, "[MCTelnet] - Unable to Enable! Error: " + ex.getMessage());
this.setEnabled(false);
}
}
public void onEnable() { private void encryptPasswords()
try { {
Logger.getLogger("Minecraft").log(Level.INFO,"[MCTelnet] - Starting Up! Version: " + this.getDescription().getVersion() + " by bekvon"); Map<String, ConfigurationNode> users = this.getConfiguration().getNodes("users");
run = true; if (users != null)
this.getConfiguration().load(); {
testConfig(); Iterator<Entry<String, ConfigurationNode>> thisIt = users.entrySet().iterator();
if(this.getConfiguration().getBoolean("encryptPasswords", false)) if (thisIt != null)
encryptPasswords(); {
port = this.getConfiguration().getInt("telnetPort", port); while (thisIt.hasNext())
try {
{ Entry<String, ConfigurationNode> thisEntry = thisIt.next();
String address = this.getConfiguration().getString("listenAddress",null); if (thisEntry != null)
if(address!=null) {
listenAddress = InetAddress.getByName(address); ConfigurationNode thisNode = thisEntry.getValue();
} if (thisNode != null && !thisNode.getBoolean("passEncrypted", false))
catch (Exception ex) {
{ this.getConfiguration().setProperty("users." + thisEntry.getKey() + ".password", hashPassword(thisNode.getString("password")));
System.out.println("[MCTelnet] Exception when trying to binding to custom address:" + ex.getMessage()); this.getConfiguration().setProperty("users." + thisEntry.getKey() + ".passEncrypted", true);
} this.getConfiguration().save();
if(listenAddress != null) }
{ }
listenerSocket = new java.net.ServerSocket(port, 10, listenAddress); }
} }
else }
{ }
listenerSocket = new java.net.ServerSocket(port,10);
}
clientHolder = new ArrayList<TelnetListener>();
listenerThread = new Thread(new Runnable() {
public void run() {
acceptConnections();
}
});
listenerThread.start();
Field cfield = CraftServer.class.getDeclaredField("console");
cfield.setAccessible(true);
Logger.getLogger("Minecraft").log(Level.INFO,"[MCTelnet] - Listening on: " + listenerSocket.getInetAddress().getHostAddress() + ":" + port);
} catch (Exception ex) {
Logger.getLogger("Minecraft").log(Level.SEVERE, "[MCTelnet] - Unable to Enable! Error: " + ex.getMessage());
this.setEnabled(false);
}
}
private void encryptPasswords() public static String hashPassword(String password)
{ {
boolean isEncrypt = this.getConfiguration().getBoolean("rootEncrypted",false); String hashword = null;
if(!isEncrypt) try
{ {
this.getConfiguration().setProperty("rootPass", hashPassword(this.getConfiguration().getString("rootPass"))); MessageDigest md5 = MessageDigest.getInstance("MD5");
this.getConfiguration().setProperty("rootEncrypted", true); md5.update(password.getBytes());
this.getConfiguration().save(); BigInteger hash = new BigInteger(1, md5.digest());
} hashword = hash.toString(16);
Map<String, ConfigurationNode> users = this.getConfiguration().getNodes("users"); }
if(users != null) catch (NoSuchAlgorithmException nsae)
{ {
Iterator<Entry<String, ConfigurationNode>> thisIt = users.entrySet().iterator(); }
if(thisIt != null) return hashword;
{ }
while(thisIt.hasNext())
{
Entry<String, ConfigurationNode> thisEntry = thisIt.next();
if(thisEntry != null)
{
ConfigurationNode thisNode = thisEntry.getValue();
if(thisNode != null && !thisNode.getBoolean("passEncrypted", false))
{
this.getConfiguration().setProperty("users."+thisEntry.getKey() +".password", hashPassword(thisNode.getString("password")));
this.getConfiguration().setProperty("users."+thisEntry.getKey() +".passEncrypted", true);
this.getConfiguration().save();
}
}
}
}
}
}
public static String hashPassword(String password) { private void acceptConnections()
String hashword = null; {
try { while (run)
MessageDigest md5 = MessageDigest.getInstance("MD5"); {
md5.update(password.getBytes()); try
BigInteger hash = new BigInteger(1, md5.digest()); {
hashword = hash.toString(16); Socket client = listenerSocket.accept();
} catch (NoSuchAlgorithmException nsae) { if (client != null)
} {
return hashword; clientHolder.add(new TelnetListener(client, this));
} System.out.print("[MCTelnet] - Client connected: " + client.getInetAddress().toString());
}
for (int i = 0; i < clientHolder.size(); i++)
{
TelnetListener thisListener = clientHolder.get(i);
if (thisListener.isAlive() == false)
{
clientHolder.remove(i);
}
}
}
catch (IOException ex)
{
run = false;
}
}
Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Shutting Down!");
for (int i = 0; i < clientHolder.size(); i++)
{
TelnetListener temp = clientHolder.get(i);
temp.killClient();
}
listenerSocket = null;
clientHolder.clear();
clientHolder = null;
this.setEnabled(false);
}
private void acceptConnections() private void testConfig()
{ {
while (run) String testConfig = this.getConfiguration().getString("telnetPort", null);
{ if (testConfig == null || testConfig.equals(""))
try { {
Socket client = listenerSocket.accept(); this.getConfiguration().setProperty("telnetPort", 8765);
if(client != null) this.getConfiguration().save();
{ }
clientHolder.add(new TelnetListener(client,this)); testConfig = this.getConfiguration().getString("listenAddress", null);
System.out.print("[MCTelnet] - Client connected: " + client.getInetAddress().toString()); if (testConfig == null || testConfig.equals(""))
} {
for(int i = 0; i < clientHolder.size(); i++) this.getConfiguration().setProperty("listenAddress", "0.0.0.0");
{ this.getConfiguration().save();
TelnetListener thisListener = clientHolder.get(i); }
if(thisListener.isAlive() == false) testConfig = this.getConfiguration().getString("encryptPasswords", null);
clientHolder.remove(i); if (testConfig == null || testConfig.equals(""))
} {
} catch (IOException ex) { this.getConfiguration().setProperty("encryptPasswords", true);
run = false; this.getConfiguration().save();
} }
}
Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Shutting Down!");
for(int i = 0; i < clientHolder.size(); i ++)
{
TelnetListener temp = clientHolder.get(i);
temp.killClient();
}
listenerSocket = null;
clientHolder.clear();
clientHolder = null;
this.setEnabled(false);
}
private void testConfig() }
{
String testConfig = this.getConfiguration().getString("telnetPort");
if (testConfig == null || testConfig.equals("")) {
this.getConfiguration().setProperty("telnetPort", 8765);
this.getConfiguration().save();
}
testConfig = this.getConfiguration().getString("listenAddress");
if (testConfig == null || testConfig.equals("")) {
this.getConfiguration().setProperty("listenAddress", "0.0.0.0");
this.getConfiguration().save();
}
testConfig = this.getConfiguration().getString("rootPass");
if (testConfig == null || testConfig.equals("")) {
this.getConfiguration().setProperty("rootPass", "abcd");
this.getConfiguration().setProperty("rootEncrypted", false);
this.getConfiguration().save();
}
testConfig = this.getConfiguration().getString("rootUser");
if (testConfig == null || testConfig.equals("")) {
this.getConfiguration().setProperty("rootUser", "console");
this.getConfiguration().save();
}
testConfig = this.getConfiguration().getString("encryptPasswords");
if (testConfig == null || testConfig.equals("")) {
this.getConfiguration().setProperty("encryptPasswords", true);
this.getConfiguration().save();
}
} @Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
@Override {
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (this.isEnabled())
if(this.isEnabled()) {
{ if (cmd.getName().equals("telnetreload"))
if(cmd.getName().equals("telnetreload")) {
{ if (sender instanceof ConsoleCommandSender)
if(sender instanceof ConsoleCommandSender) {
{ this.getConfiguration().load();
this.getConfiguration().load(); testConfig();
testConfig(); if (this.getConfiguration().getBoolean("encryptPasswords", false))
if(this.getConfiguration().getBoolean("encryptPasswords", false)) {
encryptPasswords(); encryptPasswords();
sender.sendMessage("[MCTelnet] - Reloaded Config..."); }
for(int i = 0; i < clientHolder.size(); i ++) sender.sendMessage("[MCTelnet] - Reloaded Config...");
{ for (int i = 0; i < clientHolder.size(); i++)
TelnetListener thisListener = clientHolder.get(i); {
thisListener.sendMessage("[MCTelnet] - Telnet Restarting..."); TelnetListener thisListener = clientHolder.get(i);
thisListener.killClient(); thisListener.sendMessage("[MCTelnet] - Telnet Restarting...");
} thisListener.killClient();
} }
return true; }
} return true;
} }
return super.onCommand(sender, cmd, commandLabel, args); }
} return super.onCommand(sender, cmd, commandLabel, args);
}
} }

View file

@ -1,8 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.bekvon.bukkit.mctelnet; package com.bekvon.bukkit.mctelnet;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -26,388 +21,369 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.util.config.ConfigurationNode; import org.bukkit.util.config.ConfigurationNode;
/** public class TelnetListener extends Handler implements CommandSender
* {
* @author Administrator private boolean run;
*/ private boolean isAuth;
public class TelnetListener extends Handler implements CommandSender { private String authUser;
private Thread listenThread;
Socket clientSocket;
MinecraftServer mcserv;
BufferedReader instream;
BufferedWriter outstream;
MCTelnet parent;
String ip;
String passRegex = "[^a-zA-Z0-9\\-\\.\\_]";
String commandRegex = "[^a-zA-Z0-9 \\-\\.\\_\\\"]";
private boolean run; public TelnetListener(Socket inSock, MCTelnet iparent)
private boolean isAuth; {
private String authUser; run = true;
private boolean isRoot; clientSocket = inSock;
parent = iparent;
passRegex = parent.getConfiguration().getString("passwordRegex", passRegex);
commandRegex = parent.getConfiguration().getString("commandRegex", commandRegex);
ip = clientSocket.getInetAddress().toString();
listenThread = new Thread(new Runnable()
{
public void run()
{
mainLoop();
}
});
listenThread.start();
}
private Thread listenThread; private void mainLoop()
Socket clientSocket; {
MinecraftServer mcserv; try
BufferedReader instream; {
BufferedWriter outstream; instream = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
MCTelnet parent; outstream = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
String ip; //sendTelnetCommand(251,3);
String passRegex = "[^a-zA-Z0-9\\-\\.\\_]"; //sendTelnetCommand(253,3);
String commandRegex = "[^a-zA-Z0-9 \\-\\.\\_\\\"]"; sendTelnetCommand(251, 34);
sendTelnetCommand(253, 34);
sendTelnetCommand(252, 1);
sendTelnetCommand(253, 1);
outstream.write("[MCTelnet] - Session Started!\r\n");
outstream.flush();
}
catch (IOException ex)
{
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
run = false;
}
if (!clientSocket.getInetAddress().isLoopbackAddress() || !parent.getConfiguration().getBoolean("allowAuthlessLocalhost", false))
{
authenticateLoop();
}
else
{
isAuth = true;
authUser = parent.getConfiguration().getString("rootUser");
}
commandLoop();
shutdown();
}
public TelnetListener(Socket inSock, MCTelnet iparent) private void authenticateLoop()
{ {
run = true; int retrys = 0;
clientSocket = inSock; while (run && clientSocket.isConnected() && isAuth == false)
parent = iparent; {
passRegex = parent.getConfiguration().getString("passwordRegex",passRegex); try
commandRegex = parent.getConfiguration().getString("commandRegex",commandRegex); {
ip = clientSocket.getInetAddress().toString(); outstream.write("Username:");
listenThread = new Thread(new Runnable() { outstream.flush();
public void run() { String username = instream.readLine().replaceAll(passRegex, "");
mainLoop(); sendTelnetCommand(251, 1);
} sendTelnetCommand(254, 1);
}); outstream.write("Password:");
listenThread.start(); outstream.flush();
} String pw = instream.readLine().replaceAll(passRegex, "");
outstream.write("\r\n");
sendTelnetCommand(252, 1);
sendTelnetCommand(253, 1);
ConfigurationNode parentnode = parent.getConfiguration().getNode("users");
if (parentnode != null)
{
ConfigurationNode usernode = parentnode.getNode(username);
if (usernode != null)
{
String userpw = usernode.getString("password");
if (usernode.getBoolean("passEncrypted", false))
{
pw = MCTelnet.hashPassword(pw);
}
if (pw.equals(userpw))
{
authUser = username;
isAuth = true;
}
}
}
if (isAuth)
{
outstream.write("Logged In as " + authUser + "!\r\n:");
outstream.flush();
}
else
{
Thread.sleep(2000);
outstream.write("Invalid Username or Password!\r\n\r\n");
outstream.flush();
}
retrys++;
if (retrys == 3 && isAuth == false)
{
try
{
outstream.write("Too many failed login attempts!");
outstream.flush();
}
catch (Exception ex)
{
}
return;
}
}
catch (Exception ex)
{
run = false;
authUser = null;
isAuth = false;
}
}
}
private void mainLoop() private void commandLoop()
{ {
try { try
instream = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); {
outstream = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream())); if (isAuth)
//sendTelnetCommand(251,3); {
//sendTelnetCommand(253,3); String[] validCommands = new String[0];
sendTelnetCommand(251,34);
sendTelnetCommand(253,34);
sendTelnetCommand(252,1);
sendTelnetCommand(253,1);
outstream.write("[MCTelnet] - Session Started!\r\n");
outstream.flush();
} catch (IOException ex) {
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
run = false;
}
if(!clientSocket.getInetAddress().isLoopbackAddress() || !parent.getConfiguration().getBoolean("allowAuthlessLocalhost", false))
{
authenticateLoop();
}
else
{
isAuth = true;
isRoot = true;
authUser = parent.getConfiguration().getString("rootUser");
}
commandLoop();
shutdown();
}
private void authenticateLoop() Logger.getLogger("Minecraft").addHandler(this);
{
int retrys=0;
while(run && clientSocket.isConnected() && isAuth == false)
{
try {
outstream.write("Username:");
outstream.flush();
String username = instream.readLine().replaceAll(passRegex, "");
sendTelnetCommand(251,1);
sendTelnetCommand(254,1);
outstream.write("Password:");
outstream.flush();
String pw = instream.readLine().replaceAll(passRegex, "");
outstream.write("\r\n");
sendTelnetCommand(252,1);
sendTelnetCommand(253,1);
String rootuser = parent.getConfiguration().getString("rootUser");
String rootpass = parent.getConfiguration().getString("rootPass");
if (rootuser != null && !rootuser.equals("") && username.equals(rootuser)) {
if(parent.getConfiguration().getBoolean("rootEncrypted",false))
{
pw = MCTelnet.hashPassword(pw);
}
if (rootpass != null && !rootpass.equals("") && pw.equals(rootpass)) {
authUser = rootuser;
isAuth = true;
isRoot = true;
}
} else {
ConfigurationNode parentnode = parent.getConfiguration().getNode("users");
if (parentnode != null) {
ConfigurationNode usernode = parentnode.getNode(username);
if (usernode != null) {
String userpw = usernode.getString("password");
if(usernode.getBoolean("passEncrypted", false))
{
pw = MCTelnet.hashPassword(pw);
}
if (pw.equals(userpw)) {
authUser = username;
isAuth = true;
}
}
}
}
if (isAuth) {
outstream.write("Logged In as " + authUser + "!\r\n:");
outstream.flush();
} else {
Thread.sleep(2000);
outstream.write("Invalid Username or Password!\r\n\r\n");
outstream.flush();
}
retrys++;
if (retrys == 3 && isAuth == false) {
try
{
outstream.write("Too many failed login attempts!");
outstream.flush();
} catch (Exception ex)
{ }
return;
}
} catch (Exception ex) {
run = false;
authUser = null;
isAuth = false;
isRoot = false;
}
}
}
private void commandLoop() { while (run && clientSocket.isConnected() && isAuth)
try { {
if (isAuth) { String command = "";
ConfigurationNode usernode; command = instream.readLine().replaceAll(commandRegex, "");
String commands = ""; if (command.equals("exit"))
String[] validCommands = new String[0]; {
if (isRoot) { run = false;
Logger.getLogger("Minecraft").addHandler(this); clientSocket.close();
} else { return;
usernode = parent.getConfiguration().getNode("users").getNode(authUser); }
if (usernode != null) { if (!clientSocket.isClosed())
if (usernode.getString("log", "false").equals("true")) { {
Logger.getLogger("Minecraft").addHandler(this); parent.getServer().dispatchCommand(this, command);
} System.out.println("[MCTelnet] " + authUser + " issued command: " + command);
commands = usernode.getString("commands"); }
if (commands != null) { }
validCommands = commands.split("\\,"); }
} }
for (int i = 0; i < validCommands.length; i++) { catch (Exception ex)
String thisCommand = validCommands[i]; {
validCommands[i] = thisCommand.trim(); }
} }
}
}
while (run && clientSocket.isConnected() && isAuth) {
String command = "";
command = instream.readLine().replaceAll(commandRegex, "");
if (command.equals("exit")) {
run = false;
clientSocket.close();
return;
}
boolean elevate = false;
boolean allowCommand = false;
if(command.startsWith("sudo "))
{
if(!isRoot)
{
elevate = true;
}
command = command.substring(5);
}
if (!isRoot) {
for (int i = 0; i < validCommands.length; i++) {
if (command.equals(validCommands[i]) || (command.startsWith(validCommands[i] + " "))) {
allowCommand = true;
i = validCommands.length;
}
}
}
if(elevate && !allowCommand)
{
sendTelnetCommand(251,1);
sendTelnetCommand(254,1);
outstream.write("Root Password:");
outstream.flush();
String pw = instream.readLine().replaceAll(passRegex, "");
outstream.write("\r\n");
sendTelnetCommand(252,1);
sendTelnetCommand(253,1);
String rootpass = parent.getConfiguration().getString("rootPass");
if(parent.getConfiguration().getBoolean("rootEncrypted", false))
{
pw=MCTelnet.hashPassword(pw);
}
if (pw.equals(rootpass)) {
allowCommand = true;
}
}
if (!clientSocket.isClosed()) {
if (isRoot || allowCommand) {
//((CraftServer)getServer()).dispatchCommand(new ConsoleCommandSender(getServer()), command);
//mcserv.issueCommand(command, this);
parent.getServer().dispatchCommand(this, command);
System.out.println("[MCTelnet] "+authUser+" issued command: " + command);
} else {
if(!command.equals(""))
{
outstream.write("You do not have permission to use this command...\r\n:");
outstream.flush();
}
}
}
}
}
} catch (Exception ex) {
}
}
public boolean isAlive() public boolean isAlive()
{ {
return run; return run;
} }
public void killClient() public void killClient()
{ {
try { try
run = false; {
outstream.write("[MCTelnet] - Closing Connection!"); run = false;
clientSocket.close(); outstream.write("[MCTelnet] - Closing Connection!");
} catch (IOException ex) { clientSocket.close();
} }
} catch (IOException ex)
{
}
}
private void shutdown() { private void shutdown()
try { {
run = false; try
Logger.getLogger("Minecraft").removeHandler(this); {
Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] Closing connection: " + ip); run = false;
if(!clientSocket.isClosed()) Logger.getLogger("Minecraft").removeHandler(this);
{ Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] Closing connection: " + ip);
outstream.write("[MCTelnet] - Closing Connection!"); if (!clientSocket.isClosed())
clientSocket.close(); {
} outstream.write("[MCTelnet] - Closing Connection!");
mcserv = null; clientSocket.close();
parent = null; }
} catch (Exception ex) { mcserv = null;
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); parent = null;
run = false; }
} catch (Exception ex)
} {
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
run = false;
}
}
@Override @Override
public void publish(LogRecord record) { public void publish(LogRecord record)
try { {
if(!clientSocket.isClosed()) try
{ {
outstream.write(ChatColor.stripColor(record.getMessage())+"\r\n:"); if (!clientSocket.isClosed())
outstream.flush(); {
} outstream.write(ChatColor.stripColor(record.getMessage()) + "\r\n:");
} catch (IOException ex) { outstream.flush();
} }
} }
catch (IOException ex)
{
}
}
@Override @Override
public void flush() { public void flush()
if(clientSocket.isConnected()) {
{ if (clientSocket.isConnected())
try { {
outstream.flush(); try
} catch (IOException ex) { {
} outstream.flush();
} }
} catch (IOException ex)
{
}
}
}
public void sendMessage(String string)
{
if (clientSocket.isConnected())
{
try
{
string = ChatColor.stripColor(string);
outstream.write(string + "\r\n:");
outstream.flush();
}
catch (IOException ex)
{
}
}
}
public void sendMessage(String string) { public boolean isOp()
if(clientSocket.isConnected()) {
{ if (authUser.equalsIgnoreCase("console"))
try { {
string = ChatColor.stripColor(string); return true;
outstream.write(string + "\r\n:"); }
outstream.flush(); if (parent.getConfiguration().getBoolean("allowOPsAll", false))
} catch (IOException ex) { {
} return parent.getServer().getPlayer(authUser).isOp();
} }
} return false;
}
public boolean isOp() { public boolean isPlayer()
if(authUser.equalsIgnoreCase("console")) {
return true; return false;
if(parent.getConfiguration().getBoolean("allowOPsAll",false)) }
return parent.getServer().getPlayer(authUser).isOp();
return false;
}
public boolean isPlayer() { public Server getServer()
return false; {
} return parent.getServer();
}
public Server getServer() { @Override
return parent.getServer(); public void close() throws SecurityException
} {
shutdown();
}
@Override private void sendTelnetCommand(int command, int option)
public void close() throws SecurityException { {
shutdown(); if (clientSocket.isConnected())
} {
try
{
String tcmd = ("" + ((char) 255) + ((char) command) + ((char) option));
outstream.write(tcmd);
outstream.flush();
}
catch (IOException ex)
{
}
}
}
private void sendTelnetCommand(int command, int option) public String getName()
{ {
if(clientSocket.isConnected()) return authUser;
{ }
try {
String tcmd = ("" + ((char) 255) + ((char) command) + ((char) option));
outstream.write(tcmd);
outstream.flush();
} catch (IOException ex) {
}
}
}
public String getName() { public boolean isPermissionSet(String string)
return authUser; {
} return true;
}
public boolean isPermissionSet(String string) { public boolean isPermissionSet(Permission prmsn)
return true; {
} return true;
}
public boolean isPermissionSet(Permission prmsn) { public boolean hasPermission(String string)
return true; {
} return true;
}
public boolean hasPermission(String string) { public boolean hasPermission(Permission prmsn)
return true; {
} return true;
}
public boolean hasPermission(Permission prmsn) { public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln)
return true; {
} return null;
}
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln) { public PermissionAttachment addAttachment(Plugin plugin)
return null; {
} return null;
}
public PermissionAttachment addAttachment(Plugin plugin) { public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i)
return null; {
} return null;
}
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i) { public PermissionAttachment addAttachment(Plugin plugin, int i)
return null; {
} return null;
}
public PermissionAttachment addAttachment(Plugin plugin, int i) { public void removeAttachment(PermissionAttachment pa)
return null; {
} return;
}
public void removeAttachment(PermissionAttachment pa) { public void recalculatePermissions()
return; {
} return;
}
public void recalculatePermissions() { public Set<PermissionAttachmentInfo> getEffectivePermissions()
return; {
} return null;
}
public Set<PermissionAttachmentInfo> getEffectivePermissions() { public void setOp(boolean bln)
return null; {
} return;
}
public void setOp(boolean bln) {
return;
}
} }