Skip to content

Commit

Permalink
Added some document📄
Browse files Browse the repository at this point in the history
  • Loading branch information
wtbdev committed Jul 26, 2021
1 parent 6c99b51 commit 43f0313
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 101 deletions.
10 changes: 10 additions & 0 deletions GetStarted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## How to complie rukkit?
this is a eclipse project.So you can following these steps to complie.
- Step 1
Import this project into your eclipse IDE.
- Step 2
Add JRE Library into project to fix errors.
- Step 3
Export a jar as other eclipse project.
- Step 4
Well done.Have fun!
2 changes: 2 additions & 0 deletions Plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Plugin
not completed.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ This project based on netty framework so it as stable as Dedicated Servers.

## About
Some plugin system design referenced Nukkit.

## Unstable warning
this is still a unstable build.If you find bugs,please commit issues.
if you fixed some bugs, you can have a PR.
104 changes: 51 additions & 53 deletions src/cn/rukkit/Rukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,91 +8,89 @@
import cn.rukkit.plugin.*;
import cn.rukkit.game.mod.*;

public class Rukkit
{
public class Rukkit {
public static final String RUKKIT_VERSION = "0.7.0";
public static final int SUPPORT_GAME_VERSION = 151;
private static Logger log = LoggerFactory.getLogger(Rukkit.class);
private static RoundConfig round;
private static RukkitConfig config;

private static CommandManager commandManager;

private static ConnectionManager connectionManager;

private static PluginManager pluginManager;

private static ModManager modManager;

private static GameServer server;

public static void shutdown(String message)
{
public static void shutdown(String message) {
// TODO: Implement this method
}

/**
* load Plugin.
*/
public static final void loadPlugin(){
* load Plugin.
*/
public static final void loadPlugin() {

}

/**
* Returns current gameInstance.
*/
* Returns current gameInstance.
*/
public static final void getGameInstance() {

}

/**
* Get a rukkit config.
* {@link RukkitConfig}
*/
* Get a rukkit config.
* {@link RukkitConfig}
*/
public static final RukkitConfig getConfig() {
return config;
}

/**
* Get a ingame config.
* Including map, credits, etc. {@link RoundConfig}
*/
* Get a ingame config.
* Including map, credits, etc. {@link RoundConfig}
*/
public static final RoundConfig getRoundConfig() {
return round;
}

public static final CommandManager getCommandManager() {
return commandManager;
}

public static final ConnectionManager getConnectionManager() {
return connectionManager;
}

public static final GameServer getGameServer() {
return server;
}

public static final void loadRukkitConfig() throws IOException, IllegalAccessException, InstantiationException {
if (config != null) return;
config = (RukkitConfig) new RukkitConfig().loadConfig();
/*File confFile = new File(getEnvPath() + "/rukkit.yml");
if (confFile.exists() && confFile.isFile()) {
log.debug("Found Config file.Reading...");
config = new Yaml().loadAs(new FileReader(confFile), RukkitConfig.class);
} else {
log.debug("Config file.not found.Creating...");
confFile.delete();
confFile.createNewFile();
RukkitConfig cfg = new RukkitConfig();
FileWriter writer = new FileWriter(confFile);
writer.write(new Yaml().dumpAs(cfg, null, DumperOptions.FlowStyle.BLOCK));
writer.flush();
writer.close();
config = cfg;
}*/
if (confFile.exists() && confFile.isFile()) {
log.debug("Found Config file.Reading...");
config = new Yaml().loadAs(new FileReader(confFile), RukkitConfig.class);
} else {
log.debug("Config file.not found.Creating...");
confFile.delete();
confFile.createNewFile();
RukkitConfig cfg = new RukkitConfig();
FileWriter writer = new FileWriter(confFile);
writer.write(new Yaml().dumpAs(cfg, null, DumperOptions.FlowStyle.BLOCK));
writer.flush();
writer.close();
config = cfg;
}*/
}

public static final void loadRoundConfig() throws IOException {
if (round != null) return;
File confFile = new File(getEnvPath() + "/server.yml");
Expand All @@ -112,22 +110,22 @@ public static final void loadRoundConfig() throws IOException {
round = cfg;
}
}

public static final String getEnvPath() {
return System.getProperty("user.dir");
}

/**
* Start Server ignore config port.
* @param port server port.
*/
* Start Server ignore config port.
* @param port server port.
*/
public static final void startServer(int port) {

}

/**
* Start a Rukkit server.
*/
* Start a Rukkit server.
*/
public static final void startServer() throws IOException, InterruptedException, IllegalAccessException, InstantiationException {
long time = System.currentTimeMillis();
log.info("Loading server config...");
Expand Down
28 changes: 20 additions & 8 deletions src/cn/rukkit/network/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@
import io.netty.channel.*;
import cn.rukkit.command.*;

public class Connection
{
public class Connection {
public NetworkPlayer player;
public ConnectionHandler handler;
//public ChannelHandlerContext ctx;
// Ping runnable.
public class PingTasker {


/**
* Ping runnable.
*/
public class PingTasker implements Runnable {
@Override
public void run() {
// TODO: Implement this method
}
}
// TeamTask Scheduler.
public class TeamTasker {


/**
* TeamTask Scheduler.
*/
public class TeamTasker implements Runnable {
@Override
public void run() {
// TODO: Implement this method
}
}

public Connection(ConnectionHandler handler) {
this.handler = handler;
}
Expand Down
63 changes: 53 additions & 10 deletions src/cn/rukkit/network/ConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.netty.util.concurrent.*;
import java.util.*;
import cn.rukkit.game.*;
import cn.rukkit.network.packet.*;

public class ConnectionManager
{
Expand All @@ -14,55 +15,94 @@ public class ConnectionManager

private GameServer server;

/**
* Add a connection to list.
* When player registered,this function will add it into management.
*/
public void add(Connection connection)
{
connections.add(connection);
playerManager.add(connection.player);
CHANNEL_GROUP.add(connection.handler.ctx.channel());
}

public ChannelGroupFuture broadcast(Object msg)

/**
* Broadcast a message to all connections.
* @params mag Packet msg.
*/
public ChannelGroupFuture broadcast(Packet msg)
{
return CHANNEL_GROUP.writeAndFlush(msg);
}

public ChannelGroupFuture broadcast(Object msg, ChannelMatcher matcher)
/**
* Broadcast a message to all connections,but using a ChannelMatcher.
* @params mag Packet msg.
* @params matcher ChannelMatcher.
*/
public ChannelGroupFuture broadcast(Packet msg, ChannelMatcher matcher)
{
return CHANNEL_GROUP.writeAndFlush(msg, matcher);
}


/**
* Flush all connections.
*/
public ChannelGroup flush()
{
return CHANNEL_GROUP.flush();
}


/**
* Discard a connection.Auto disconnect when connection discorded.
* @params connection Connection to discard.
*/
public boolean discard(Connection connection)
{
connection.handler.ctx.disconnect();
connections.remove(connection);
playerManager.remove(connection.player);
return CHANNEL_GROUP.remove(connection.handler.ctx.channel());
}

/**
* Disconnect all Connections.
*/
public ChannelGroupFuture disconnect()
{
return CHANNEL_GROUP.disconnect();
}


/**
* Disconnect Connections with ChannelMatcher.
* @params matcher ChannelMatcher
*/
public ChannelGroupFuture disconnect(ChannelMatcher matcher)
{
return CHANNEL_GROUP.disconnect(matcher);
}

public boolean contains(Channel channel)

/**
* check a connection whether in Group.
* @params connection Connection need to be checked.
*/
public boolean contains(Connection connection)
{
return CHANNEL_GROUP.contains(channel);
return CHANNEL_GROUP.contains(connection.handler.ctx.channel());
}


/**
* Return Group size.
*/
public int size()
{
return CHANNEL_GROUP.size();
}

/**
* Init a ConnectionManager.
* @params server GameServer
*/
public ConnectionManager(GameServer server) {
this.server = server;
}
Expand All @@ -71,6 +111,9 @@ public void getPlayerAsList() {

}

/**
* Get playerManager.
*/
public PlayerManager getPlayerManager() {
return playerManager;
}
Expand Down
Loading

0 comments on commit 43f0313

Please sign in to comment.