mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-03-09 20:29:17 +07:00
Added server module with extremely basic socket support
This commit is contained in:
parent
2254bc925d
commit
015c878c3c
15
build.gradle
15
build.gradle
@ -176,6 +176,21 @@ project(":core") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project(":server") {
|
||||||
|
apply plugin: "java"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// TODO: $gdxVersion is pulling an older file for some reason
|
||||||
|
compile "com.badlogicgames.gdx:gdx-backend-headless:1.9.9"
|
||||||
|
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile project(":core")
|
||||||
|
compile group: 'commons-cli', name: 'commons-cli', version: cliVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tasks.eclipse.doLast {
|
tasks.eclipse.doLast {
|
||||||
delete ".project"
|
delete ".project"
|
||||||
}
|
}
|
46
server/build.gradle
Normal file
46
server/build.gradle
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
apply plugin: "java"
|
||||||
|
|
||||||
|
sourceCompatibility = 1.7
|
||||||
|
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||||
|
|
||||||
|
project.ext.mainClassName = "gdx.diablo.server.Server"
|
||||||
|
project.ext.assetsDir = new File("../android/assets");
|
||||||
|
|
||||||
|
task run(dependsOn: classes, type: JavaExec) {
|
||||||
|
main = project.mainClassName
|
||||||
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
|
standardInput = System.in
|
||||||
|
workingDir = project.assetsDir
|
||||||
|
ignoreExitValue = true
|
||||||
|
}
|
||||||
|
|
||||||
|
task dist(type: Jar) {
|
||||||
|
from files(sourceSets.main.output.classesDir)
|
||||||
|
from files(sourceSets.main.output.resourcesDir)
|
||||||
|
from {configurations.compile.collect {zipTree(it)}}
|
||||||
|
from files(project.assetsDir);
|
||||||
|
|
||||||
|
manifest {
|
||||||
|
attributes 'Server-Class': project.mainClassName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dist.dependsOn classes
|
||||||
|
|
||||||
|
eclipse {
|
||||||
|
project {
|
||||||
|
name = appName + "-server"
|
||||||
|
linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/android/assets'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
|
||||||
|
doLast {
|
||||||
|
def classpath = new XmlParser().parse(file(".classpath"))
|
||||||
|
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
|
||||||
|
def writer = new FileWriter(file(".classpath"))
|
||||||
|
def printer = new XmlNodePrinter(new PrintWriter(writer))
|
||||||
|
printer.setPreserveWhitespace(true)
|
||||||
|
printer.print(classpath)
|
||||||
|
}
|
||||||
|
}
|
60
server/src/gdx/diablo/server/Server.java
Normal file
60
server/src/gdx/diablo/server/Server.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package gdx.diablo.server;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Net;
|
||||||
|
import com.badlogic.gdx.backends.headless.HeadlessApplication;
|
||||||
|
import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration;
|
||||||
|
import com.badlogic.gdx.net.ServerSocket;
|
||||||
|
import com.badlogic.gdx.net.ServerSocketHints;
|
||||||
|
import com.badlogic.gdx.net.Socket;
|
||||||
|
import com.badlogic.gdx.net.SocketHints;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
public class Server extends ApplicationAdapter {
|
||||||
|
private static final String TAG = "Server";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
HeadlessApplicationConfiguration config = new HeadlessApplicationConfiguration();
|
||||||
|
new HeadlessApplication(new Server(), config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Server() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void create() {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
DateFormat format = DateFormat.getDateTimeInstance();
|
||||||
|
Gdx.app.log(TAG, format.format(calendar.getTime()));
|
||||||
|
|
||||||
|
try {
|
||||||
|
InetAddress address = InetAddress.getLocalHost();
|
||||||
|
Gdx.app.log(TAG, "IP Address: " + address.getHostAddress());
|
||||||
|
Gdx.app.log(TAG, "Host Name: " + address.getHostName());
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
Gdx.app.error(TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, "awaiting connection...");
|
||||||
|
|
||||||
|
ServerSocketHints hints = new ServerSocketHints();
|
||||||
|
hints.acceptTimeout = 0;
|
||||||
|
|
||||||
|
ServerSocket server = Gdx.net.newServerSocket(Net.Protocol.TCP, 6112, hints);
|
||||||
|
|
||||||
|
Socket socket = server.accept(new SocketHints());
|
||||||
|
Gdx.app.log(TAG, "connection from " + socket.getRemoteAddress());
|
||||||
|
socket.dispose();
|
||||||
|
|
||||||
|
Gdx.app.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
Gdx.app.log(TAG, "shutting down...");
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
include 'tester', 'ds1viewer', 'mapbuilder', 'mpqviewer', 'desktop', 'android', 'core'
|
include 'tester', 'ds1viewer', 'mapbuilder', 'mpqviewer', 'server', 'desktop', 'android', 'core'
|
Loading…
Reference in New Issue
Block a user