Skip to content

Commit 874166d

Browse files
committed
First commit, nonworking
0 parents  commit 874166d

27 files changed

+1363
-0
lines changed

build.xml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- You may freely edit this file. See commented blocks below for -->
3+
<!-- some examples of how to customize the build. -->
4+
<!-- (If you delete it and reopen the project it will be recreated.) -->
5+
<!-- By default, only the Clean and Build commands use this build script. -->
6+
<!-- Commands such as Run, Debug, and Test only use this build script if -->
7+
<!-- the Compile on Save feature is turned off for the project. -->
8+
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
9+
<!-- in the project's Project Properties dialog box.-->
10+
<project name="MCPlexer" default="default" basedir=".">
11+
<description>Builds, tests, and runs the project MCPlexer.</description>
12+
<import file="nbproject/build-impl.xml"/>
13+
<!--
14+
15+
There exist several targets which are by default empty and which can be
16+
used for execution of your tasks. These targets are usually executed
17+
before and after some main targets. They are:
18+
19+
-pre-init: called before initialization of project properties
20+
-post-init: called after initialization of project properties
21+
-pre-compile: called before javac compilation
22+
-post-compile: called after javac compilation
23+
-pre-compile-single: called before javac compilation of single file
24+
-post-compile-single: called after javac compilation of single file
25+
-pre-compile-test: called before javac compilation of JUnit tests
26+
-post-compile-test: called after javac compilation of JUnit tests
27+
-pre-compile-test-single: called before javac compilation of single JUnit test
28+
-post-compile-test-single: called after javac compilation of single JUunit test
29+
-pre-jar: called before JAR building
30+
-post-jar: called after JAR building
31+
-post-clean: called after cleaning build products
32+
33+
(Targets beginning with '-' are not intended to be called on their own.)
34+
35+
Example of inserting an obfuscator after compilation could look like this:
36+
37+
<target name="-post-compile">
38+
<obfuscate>
39+
<fileset dir="${build.classes.dir}"/>
40+
</obfuscate>
41+
</target>
42+
43+
For list of available properties check the imported
44+
nbproject/build-impl.xml file.
45+
46+
47+
Another way to customize the build is by overriding existing main targets.
48+
The targets of interest are:
49+
50+
-init-macrodef-javac: defines macro for javac compilation
51+
-init-macrodef-junit: defines macro for junit execution
52+
-init-macrodef-debug: defines macro for class debugging
53+
-init-macrodef-java: defines macro for class execution
54+
-do-jar-with-manifest: JAR building (if you are using a manifest)
55+
-do-jar-without-manifest: JAR building (if you are not using a manifest)
56+
run: execution of project
57+
-javadoc-build: Javadoc generation
58+
test-report: JUnit report generation
59+
60+
An example of overriding the target for project execution could look like this:
61+
62+
<target name="run" depends="MCPlexer-impl.jar">
63+
<exec dir="bin" executable="launcher.exe">
64+
<arg file="${dist.jar}"/>
65+
</exec>
66+
</target>
67+
68+
Notice that the overridden target depends on the jar target and not only on
69+
the compile target as the regular run target does. Again, for a list of available
70+
properties which you can use, check the target you are overriding in the
71+
nbproject/build-impl.xml file.
72+
73+
-->
74+
</project>

build/classes/.netbeans_automatic_build

Whitespace-only changes.

build/classes/mcplexer/Handler.class

209 Bytes
Binary file not shown.

build/classes/mcplexer/Main.class

464 Bytes
Binary file not shown.
Binary file not shown.
1.77 KB
Binary file not shown.
1.31 KB
Binary file not shown.

build/classes/mcplexer/Server$1.class

187 Bytes
Binary file not shown.
Binary file not shown.

build/classes/mcplexer/Server.class

2.22 KB
Binary file not shown.
1.4 KB
Binary file not shown.
1.65 KB
Binary file not shown.

manifest.mf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
X-COMMENT: Main-Class will be added automatically by build
3+

nbproject/build-impl.xml

+894
Large diffs are not rendered by default.

nbproject/genfiles.properties

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build.xml.data.CRC32=6cc72dee
2+
build.xml.script.CRC32=2ab59fed
3+
build.xml.stylesheet.CRC32=[email protected]
4+
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5+
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6+
nbproject/build-impl.xml.data.CRC32=6cc72dee
7+
nbproject/build-impl.xml.script.CRC32=6e8084f4
8+
nbproject/build-impl.xml.stylesheet.CRC32=[email protected]

nbproject/private/private.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
compile.on.save=true
2+
user.properties.file=/home/joe/.netbeans/6.9/build.properties

nbproject/private/private.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
3+
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
4+
</project-private>

nbproject/project.properties

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
annotation.processing.enabled=true
2+
annotation.processing.enabled.in.editor=false
3+
annotation.processing.processor.options=
4+
annotation.processing.processors.list=
5+
annotation.processing.run.all.processors=true
6+
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
7+
build.classes.dir=${build.dir}/classes
8+
build.classes.excludes=**/*.java,**/*.form
9+
# This directory is removed when the project is cleaned:
10+
build.dir=build
11+
build.generated.dir=${build.dir}/generated
12+
build.generated.sources.dir=${build.dir}/generated-sources
13+
# Only compile against the classpath explicitly listed here:
14+
build.sysclasspath=ignore
15+
build.test.classes.dir=${build.dir}/test/classes
16+
build.test.results.dir=${build.dir}/test/results
17+
# Uncomment to specify the preferred debugger connection transport:
18+
#debug.transport=dt_socket
19+
debug.classpath=\
20+
${run.classpath}
21+
debug.test.classpath=\
22+
${run.test.classpath}
23+
# This directory is removed when the project is cleaned:
24+
dist.dir=dist
25+
dist.jar=${dist.dir}/MCPlexer.jar
26+
dist.javadoc.dir=${dist.dir}/javadoc
27+
excludes=
28+
includes=**
29+
jar.compress=false
30+
javac.classpath=
31+
# Space-separated list of extra javac options
32+
javac.compilerargs=
33+
javac.deprecation=false
34+
javac.processorpath=\
35+
${javac.classpath}
36+
javac.source=1.5
37+
javac.target=1.5
38+
javac.test.classpath=\
39+
${javac.classpath}:\
40+
${build.classes.dir}:\
41+
${libs.junit.classpath}:\
42+
${libs.junit_4.classpath}
43+
javac.test.processorpath=\
44+
${javac.test.classpath}
45+
javadoc.additionalparam=
46+
javadoc.author=false
47+
javadoc.encoding=${source.encoding}
48+
javadoc.noindex=false
49+
javadoc.nonavbar=false
50+
javadoc.notree=false
51+
javadoc.private=false
52+
javadoc.splitindex=true
53+
javadoc.use=true
54+
javadoc.version=false
55+
javadoc.windowtitle=
56+
main.class=mcplexer.Main
57+
manifest.file=manifest.mf
58+
meta.inf.dir=${src.dir}/META-INF
59+
platform.active=default_platform
60+
run.classpath=\
61+
${javac.classpath}:\
62+
${build.classes.dir}
63+
# Space-separated list of JVM arguments used when running the project
64+
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
65+
# or test-sys-prop.name=value to set system properties for unit tests):
66+
run.jvmargs=
67+
run.test.classpath=\
68+
${javac.test.classpath}:\
69+
${build.test.classes.dir}
70+
source.encoding=UTF-8
71+
src.dir=src
72+
test.src.dir=test

nbproject/project.xml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://www.netbeans.org/ns/project/1">
3+
<type>org.netbeans.modules.java.j2seproject</type>
4+
<configuration>
5+
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
6+
<name>MCPlexer</name>
7+
<source-roots>
8+
<root id="src.dir"/>
9+
</source-roots>
10+
<test-roots>
11+
<root id="test.src.dir"/>
12+
</test-roots>
13+
</data>
14+
</configuration>
15+
</project>

resources/minecraft_server.jar

374 KB
Binary file not shown.

src/mcplexer/Handler.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package mcplexer;
2+
3+
/**
4+
*
5+
* @author Joe Stein
6+
*/
7+
public interface Handler
8+
{
9+
public void write(String s);
10+
public void read(String s);
11+
}

src/mcplexer/Main.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2010 Joe Stein.
3+
*
4+
*/
5+
6+
package mcplexer;
7+
8+
/**
9+
*
10+
* @author joe
11+
*/
12+
public class Main {
13+
14+
/**
15+
* @param args the command line arguments
16+
*/
17+
public static void main(String[] args) {
18+
Server s = new Server(512,512);
19+
}
20+
21+
}

src/mcplexer/NetworkHandler.java

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package mcplexer;
2+
3+
import java.io.IOException;
4+
import java.net.ServerSocket;
5+
import java.net.Socket;
6+
import java.util.logging.Level;
7+
import java.util.logging.Logger;
8+
9+
/**
10+
*
11+
* @author Joe Stein
12+
*/
13+
public class NetworkHandler implements Handler
14+
{
15+
private final int MAX_CONNECTIONS = 1;
16+
private int connectionCount = 0;
17+
private StreamReader[] clients = new StreamReader[MAX_CONNECTIONS];
18+
private ServerSocket servSock;
19+
20+
public void write(String s)
21+
{
22+
throw new UnsupportedOperationException("Not supported yet.");
23+
}
24+
25+
public void read(String s)
26+
{
27+
System.out.println("Received " + s);
28+
}
29+
30+
public void remove(int id)
31+
{
32+
connectionCount--;
33+
clients[id] = null;
34+
}
35+
36+
private class Connector implements Runnable
37+
{
38+
private boolean keepRunning = true;
39+
40+
public void run()
41+
{
42+
while (keepRunning)
43+
{
44+
try {
45+
Socket client = servSock.accept();
46+
if (connectionCount >= MAX_CONNECTIONS)
47+
{
48+
// send reject
49+
client.getOutputStream().write("Maximum clients connected".getBytes());
50+
} else
51+
{
52+
// find empty spot
53+
int spot = 0;
54+
while (clients[spot] != null && spot < clients.length)
55+
{
56+
spot++;
57+
}
58+
clients[spot] = new NetworkReader(client.getInputStream(),NetworkHandler.this,spot);
59+
connectionCount++;
60+
61+
}
62+
} catch (IOException ex) {
63+
Logger.getLogger(NetworkHandler.class.getName()).log(Level.SEVERE, null, ex);
64+
kill();
65+
}
66+
}
67+
}
68+
69+
protected void kill()
70+
{
71+
keepRunning = false;
72+
}
73+
}
74+
}

src/mcplexer/NetworkReader.java

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2010 Joe Stein.
3+
*
4+
*/
5+
6+
package mcplexer;
7+
8+
import java.io.IOException;
9+
import java.io.InputStream;
10+
import java.util.logging.Level;
11+
import java.util.logging.Logger;
12+
13+
/**
14+
*
15+
* @author Joe Stein
16+
*/
17+
public class NetworkReader extends StreamReader
18+
{
19+
private int id;
20+
21+
public NetworkReader(InputStream is, NetworkHandler h, int id)
22+
{
23+
super(is,h);
24+
this.id = id;
25+
}
26+
27+
@Override
28+
public void kill()
29+
{
30+
try {
31+
keepRunning = false;
32+
((NetworkHandler) handler).remove(id);
33+
reader.close();
34+
} catch (IOException ex) {
35+
Logger.getLogger(StreamReader.class.getName()).log(Level.SEVERE, null, ex);
36+
}
37+
}
38+
}

src/mcplexer/Server.java

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package mcplexer;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.Scanner;
6+
import java.util.logging.Level;
7+
import java.util.logging.Logger;
8+
9+
/**
10+
*
11+
* @author Joe Stein
12+
*/
13+
public class Server
14+
{
15+
private Process serverProcess;
16+
private ServerHandler serverHandler;
17+
18+
public Server(int maxMem, int minMem)
19+
{
20+
Thread t = new Thread(new CommandHandler());
21+
t.start();
22+
try {
23+
File f = new File("resources/minecraft_server.jar");
24+
System.out.println(f.exists());
25+
System.out.println(f.getAbsolutePath());
26+
serverProcess = Runtime.getRuntime().exec("java -jar -Xmx" + maxMem + "M -Xms" + minMem + "M resources/minecraft_server.jar nogui");
27+
System.out.println(serverProcess == null);
28+
serverHandler = new ServerHandler(serverProcess);
29+
/*try {
30+
Thread.sleep(3000);
31+
} catch (InterruptedException ex) {
32+
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
33+
}
34+
serverProcess.destroy(); */
35+
} catch (IOException ex) {
36+
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
37+
}
38+
}
39+
40+
private class CommandHandler implements Runnable
41+
{
42+
private boolean keepRunning = true;
43+
44+
public void run()
45+
{
46+
Scanner scan = new Scanner(System.in);
47+
while (keepRunning)
48+
{
49+
String input = scan.nextLine();
50+
if (input.equals("kill"))
51+
{
52+
serverProcess.destroy();
53+
keepRunning = false;
54+
}
55+
serverHandler.write(input);
56+
}
57+
}
58+
59+
}
60+
}

0 commit comments

Comments
 (0)