Skip to content

Commit

Permalink
Initial commit, limbo working for 47 protocol (1.8.9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigner committed Aug 30, 2016
0 parents commit a6e90c7
Show file tree
Hide file tree
Showing 50 changed files with 2,602 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.idea
*.iml
world.schematic
server.properties
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Limbo

This project is a simple Minecraft Limbo server, supporting multiple protocols, without any external library.
Handle basic packets, keep alive, gamemode, map.

## Features

Loads a map from a schematic file.
Handles Bungeecord ip forwarding.
Config file to modify server properties.

## Supported protocols

- 1.8.9 (47)

More protocols will be implemented soon.

## Todo-List

Compression

Encryption

Basic Chat system

Mojang auth if online mode

## Timers

Project start : 28th August 2016
Last update : 30th August 2016
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.rigner</groupId>
<artifactId>Limbo</artifactId>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

</project>
131 changes: 131 additions & 0 deletions src/main/java/net/rigner/limbo/Limbo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package net.rigner.limbo;

import net.rigner.limbo.world.Schematic;
import net.rigner.limbo.world.World;
import net.rigner.limbo.world.nbt.NBTTag;

import java.io.FileInputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
import java.util.logging.*;
import java.util.zip.GZIPInputStream;

/**
* Created by Rigner on 28/08/16 for project for project Limbo.
* All rights reserved.
*/
public class Limbo
{
public static final Logger LOGGER = Logger.getLogger("Limbo");

private NetworkManager networkManager;
private LimboConfiguration limboConfiguration;
private World world;
private boolean run;

private Limbo(LimboConfiguration limboConfiguration)
{
this.limboConfiguration = limboConfiguration;
}

private void loadWorld(String fileName)
{
Limbo.LOGGER.info("Loading schematic from " + fileName);
try (FileInputStream fileInputStream = new FileInputStream(fileName))
{
this.world = Schematic.toWorld(NBTTag.readTag(new GZIPInputStream(fileInputStream)).toCompoundTag());
fileInputStream.close();
}
catch (Exception ex)
{
Limbo.LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
Limbo.LOGGER.info("World loading failed");
this.world = null;
return ;
}
Limbo.LOGGER.info("World loaded");
}

private void run()
{
this.networkManager = new NetworkManager(this.world, this.limboConfiguration);
this.run = true;

try
{
this.networkManager.bind(this.limboConfiguration.getIp(), this.limboConfiguration.getPort());
Limbo.LOGGER.info("Listening on port 25565");
while (this.run)
this.networkManager.select();
}
catch (Exception ex)
{
Limbo.LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
}
}

private void stop()
{
this.run = false;
this.networkManager.stop();
}

public static void main(String[] args)
{
Limbo.LOGGER.setUseParentHandlers(false);
Limbo.LOGGER.addHandler(new ConsoleHandler());
Limbo.LOGGER.getHandlers()[0].setFormatter(new LogFormatter());

LimboConfiguration limboConfiguration = LimboConfiguration.load();
if (limboConfiguration == null)
return ;
Limbo limbo = new Limbo(limboConfiguration);
limbo.loadWorld(limboConfiguration.getSchematicFile());
if (limbo.world == null)
return ;
Runtime.getRuntime().addShutdownHook(new Thread(limbo::stop));
limbo.run();
System.exit(0);
}

private static class LogFormatter extends Formatter
{
private static final String FORMAT = "[%1$tT][%3$s] %4$s : %5$s%6$s%n";
private Date date = new Date();

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
public String format(LogRecord record)
{
this.date.setTime(record.getMillis());
String source;
if (record.getSourceClassName() != null)
{
source = record.getSourceClassName();
if (record.getSourceMethodName() != null)
source += " " + record.getSourceMethodName();
}
else
source = record.getLoggerName();
String message = formatMessage(record);
String throwable = "";
if (record.getThrown() != null)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println();
record.getThrown().printStackTrace(pw);
pw.close();
throwable = sw.toString();
}
return String.format(LogFormatter.FORMAT,
this.date,
source,
record.getLoggerName(),
record.getLevel().getLocalizedName(),
message,
throwable);
}
}
}
154 changes: 154 additions & 0 deletions src/main/java/net/rigner/limbo/LimboConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package net.rigner.limbo;

import java.io.File;
import java.io.FileInputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
import java.util.logging.Level;

/**
* Created by Rigner on 30/08/16 for project Limbo.
* All rights reserved.
*/
public class LimboConfiguration
{
private int maxSlots;
private short port;
private String ip;
private String schematicFile;
private byte dimension;
private byte gameMode;
private double spawnX;
private double spawnY;
private double spawnZ;
private float spawnYaw;
private float spawnPitch;
private boolean reducedDebugInfo;

private LimboConfiguration()
{
}

static LimboConfiguration load()
{
try
{
File file = new File("server.properties");
if (!file.exists())
Files.copy(Limbo.class.getResourceAsStream("/server.properties"), Paths.get(file.toURI()));
Properties properties = new Properties();
properties.load(new FileInputStream(file));
LimboConfiguration limboConfiguration = new LimboConfiguration();
limboConfiguration.maxSlots = LimboConfiguration.getInt(properties, "maxSlots", -1);
limboConfiguration.port = (short)LimboConfiguration.getInt(properties, "server-port", 25565);
limboConfiguration.ip = LimboConfiguration.getString(properties, "server-ip", "localhost");
limboConfiguration.schematicFile = LimboConfiguration.getString(properties, "schematic-file", "world.schematic");
limboConfiguration.dimension = (byte)LimboConfiguration.getInt(properties, "dimension", 1);
limboConfiguration.gameMode = (byte)LimboConfiguration.getInt(properties, "gamemode", 2);
limboConfiguration.reducedDebugInfo = Boolean.parseBoolean(LimboConfiguration.getString(properties, "reduceddebuginfo", "true"));

String[] split = LimboConfiguration.getString(properties, "spawn", "0.5;64;0.5;0;0").split(";");
try
{
limboConfiguration.spawnX = Double.parseDouble(split[0]);
limboConfiguration.spawnY = Double.parseDouble(split[1]);
limboConfiguration.spawnZ = Double.parseDouble(split[2]);
limboConfiguration.spawnYaw = Float.parseFloat(split[3]);
limboConfiguration.spawnPitch = Float.parseFloat(split[4]);
}
catch (NumberFormatException | IndexOutOfBoundsException ex)
{
throw new InvalidPropertiesFormatException("Invalid coordinate format");
}
return limboConfiguration;
}
catch (Exception ex)
{
Limbo.LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
}
return null;
}

private static int getInt(Properties properties, String key, int def) throws InvalidPropertiesFormatException
{
String result = properties.getProperty(key);
if (result == null)
return def;
try
{
return Integer.parseInt(result);
}
catch (NumberFormatException ex)
{
throw new InvalidPropertiesFormatException(key + " is not a number property");
}
}

private static String getString(Properties properties, String key, String def) throws InvalidPropertiesFormatException
{
String result = properties.getProperty(key);
return result == null ? def : result;
}

public byte getDimension()
{
return this.dimension;
}

public byte getGameMode()
{
return this.gameMode;
}

public double getSpawnX()
{
return this.spawnX;
}

public double getSpawnY()
{
return this.spawnY;
}

public int getMaxSlots()
{
return this.maxSlots;
}

public double getSpawnZ()
{
return this.spawnZ;
}

short getPort()
{
return this.port;
}

String getIp()
{
return this.ip;
}

String getSchematicFile()
{
return this.schematicFile;
}

public float getSpawnYaw()
{
return this.spawnYaw;
}

public float getSpawnPitch()
{
return this.spawnPitch;
}

public boolean isReducedDebugInfo()
{
return this.reducedDebugInfo;
}
}
Loading

0 comments on commit a6e90c7

Please sign in to comment.