├── core
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── bin
│ ├── .gitignore
│ └── log4j.xml
└── src
│ ├── com
│ └── game
│ │ ├── message
│ │ ├── MessagePool.java
│ │ └── struct
│ │ │ ├── Bean.java
│ │ │ ├── Handler.java
│ │ │ └── Message.java
│ │ ├── netty
│ │ ├── Client.java
│ │ ├── Netty.java
│ │ ├── Server.java
│ │ ├── coder
│ │ │ ├── Decoder.java
│ │ │ └── Encoder.java
│ │ └── handler
│ │ │ └── Handler.java
│ │ ├── script
│ │ ├── ScriptLoader.java
│ │ └── struct
│ │ │ └── IScript.java
│ │ ├── thread
│ │ ├── pool
│ │ │ ├── FixedPoolExecutor.java
│ │ │ └── NormalThread.java
│ │ └── queue
│ │ │ ├── FixTaskThread.java
│ │ │ └── ITask.java
│ │ └── util
│ │ ├── IdGenerator.java
│ │ └── TimeUtil.java
│ └── log4j.xml
├── res
├── .project
├── jar
│ ├── c3p0-0.9.1.1.jar
│ ├── commons-io-2.4.jar
│ ├── dom4j-1.6.1.jar
│ ├── ehcache-2.8.3.jar
│ ├── freemarker-2.3.20.jar
│ ├── guava-17.0.jar
│ ├── log4j-1.2.17.jar
│ ├── mybatis-3.2.6.jar
│ ├── mysql-connector-java-5.1.30.jar
│ ├── netty-all-5.0.0.Alpha1.jar
│ ├── protobuf-java-2.5.0.jar
│ ├── slf4j-api-1.6.6.jar
│ └── slf4j-log4j12-1.7.7.jar
└── message
│ ├── account.xml
│ ├── login.xml
│ ├── map.xml
│ ├── message.txt
│ └── role.xml
├── robot-mmo
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── bin
│ ├── Start.class
│ ├── com
│ │ └── game
│ │ │ ├── client
│ │ │ ├── GameClient$1.class
│ │ │ ├── GameClient.class
│ │ │ ├── GameHandler.class
│ │ │ └── thread
│ │ │ │ └── ClientThread.class
│ │ │ ├── config
│ │ │ └── ConfigManager.class
│ │ │ ├── login
│ │ │ ├── handler
│ │ │ │ ├── ResLoginCreateRoleHandler.class
│ │ │ │ └── ResLoginHandler.class
│ │ │ └── message
│ │ │ │ ├── ReqLoginCreateRoleMessage.class
│ │ │ │ ├── ReqLoginMessage.class
│ │ │ │ ├── ReqLoginSelectRoleMessage.class
│ │ │ │ ├── ResLoginCreateRoleMessage.class
│ │ │ │ ├── ResLoginMessage.class
│ │ │ │ └── RoleBrief.class
│ │ │ ├── manager
│ │ │ ├── Manager.class
│ │ │ └── ManagerPool.class
│ │ │ └── message
│ │ │ └── manager
│ │ │ └── MessageManager.class
│ ├── log4j.xml
│ └── message.xml
├── build.xml
├── config
│ └── config.xml
└── src
│ ├── Start.java
│ ├── com
│ └── game
│ │ ├── client
│ │ ├── GameClient.java
│ │ ├── GameHandler.java
│ │ └── thread
│ │ │ └── ClientThread.java
│ │ ├── config
│ │ └── ConfigManager.java
│ │ ├── login
│ │ ├── handler
│ │ │ ├── ResLoginCreateRoleHandler.java
│ │ │ └── ResLoginHandler.java
│ │ └── message
│ │ │ ├── ReqLoginCreateRoleMessage.java
│ │ │ ├── ReqLoginMessage.java
│ │ │ ├── ReqLoginSelectRoleMessage.java
│ │ │ ├── ResLoginCreateRoleMessage.java
│ │ │ ├── ResLoginMessage.java
│ │ │ └── RoleBrief.java
│ │ ├── manager
│ │ ├── Manager.java
│ │ └── ManagerPool.java
│ │ └── message
│ │ └── manager
│ │ └── MessageManager.java
│ ├── log4j.xml
│ └── message.xml
├── server-mmo
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── bin
│ ├── .gitignore
│ ├── Start.class
│ ├── log4j.xml
│ └── message.xml
├── build.xml
├── config
│ ├── db-config.xml
│ ├── db-data.xml
│ ├── game.xml
│ └── server.xml
├── proto.bat
├── proto
│ └── role.proto
└── src
│ ├── Start.java
│ ├── com
│ ├── config
│ │ ├── manager
│ │ │ └── ConfigManager.java
│ │ └── struct
│ │ │ ├── GameConfig.java
│ │ │ └── ServerConfig.java
│ ├── db
│ │ ├── DbFactory.java
│ │ ├── config
│ │ │ ├── DbConfigManager.java
│ │ │ ├── bean
│ │ │ │ └── MapBean.java
│ │ │ ├── container
│ │ │ │ └── MapContainer.java
│ │ │ ├── dao
│ │ │ │ └── MapDao.java
│ │ │ └── mapper
│ │ │ │ └── Map.xml
│ │ └── data
│ │ │ ├── bean
│ │ │ ├── AccountBean.java
│ │ │ └── RoleBean.java
│ │ │ ├── dao
│ │ │ ├── AccountDao.java
│ │ │ └── RoleDao.java
│ │ │ └── mapper
│ │ │ ├── Account.xml
│ │ │ └── Role.xml
│ ├── game
│ │ ├── account
│ │ │ ├── cache
│ │ │ │ ├── AccountCache.java
│ │ │ │ └── Key.java
│ │ │ ├── manager
│ │ │ │ └── AccountManager.java
│ │ │ └── struct
│ │ │ │ └── Account.java
│ │ ├── login
│ │ │ ├── handler
│ │ │ │ ├── ReqLoginCreateRoleHandler.java
│ │ │ │ ├── ReqLoginHandler.java
│ │ │ │ └── ReqLoginSelectRoleHandler.java
│ │ │ ├── manager
│ │ │ │ ├── LoginManager.java
│ │ │ │ └── LoginStateManager.java
│ │ │ ├── message
│ │ │ │ ├── ReqLoginCreateRoleMessage.java
│ │ │ │ ├── ReqLoginMessage.java
│ │ │ │ ├── ReqLoginSelectRoleMessage.java
│ │ │ │ ├── ResLoginCreateRoleMessage.java
│ │ │ │ ├── ResLoginMessage.java
│ │ │ │ └── RoleBrief.java
│ │ │ └── struct
│ │ │ │ └── LoginState.java
│ │ ├── map
│ │ │ ├── handler
│ │ │ │ └── ReqMapMoveHandler.java
│ │ │ ├── manager
│ │ │ │ └── MapManager.java
│ │ │ ├── message
│ │ │ │ ├── MapInfo.java
│ │ │ │ ├── Position.java
│ │ │ │ ├── ReqMapMoveMessage.java
│ │ │ │ ├── ResMapChangeMessage.java
│ │ │ │ ├── ResMapPositionChangeMessage.java
│ │ │ │ ├── ResMapRoleMessage.java
│ │ │ │ ├── ResMapRoundAllMessage.java
│ │ │ │ └── RoleInfo.java
│ │ │ ├── struct
│ │ │ │ ├── Area.java
│ │ │ │ ├── Map.java
│ │ │ │ ├── MapTask.java
│ │ │ │ ├── Position.java
│ │ │ │ └── RoleMapData.java
│ │ │ ├── thread
│ │ │ │ ├── MapThread.java
│ │ │ │ └── MapThreadPool.java
│ │ │ └── timer
│ │ │ │ └── ITimer.java
│ │ ├── name
│ │ │ └── manager
│ │ │ │ └── NameManager.java
│ │ └── role
│ │ │ ├── cache
│ │ │ └── RoleCache.java
│ │ │ ├── manager
│ │ │ └── RoleManager.java
│ │ │ └── struct
│ │ │ ├── Role.java
│ │ │ └── RoleSaveData.java
│ ├── logger
│ │ └── GlobalLogger.java
│ ├── manager
│ │ ├── Manager.java
│ │ ├── ManagerPool.java
│ │ └── PriorityEnum.java
│ ├── message
│ │ ├── manager
│ │ │ └── MessageManager.java
│ │ └── util
│ │ │ ├── MessageDispatcher.java
│ │ │ └── MessageUtil.java
│ ├── script
│ │ └── manager
│ │ │ └── ScriptManager.java
│ ├── server
│ │ └── game
│ │ │ ├── GameHandler.java
│ │ │ └── GameServer.java
│ └── thread
│ │ └── manager
│ │ └── ThreadManager.java
│ ├── log4j.xml
│ └── message.xml
└── tools
├── .classpath
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── bin
└── .gitignore
├── config
└── config.xml
├── ftl
├── db
│ └── java
│ │ ├── bean.ftl
│ │ ├── config.ftl
│ │ ├── container.ftl
│ │ ├── dao.ftl
│ │ ├── manager.ftl
│ │ └── mapper.ftl
└── message
│ └── java
│ ├── bean.ftl
│ ├── handler.ftl
│ ├── manager.ftl
│ └── message.ftl
└── src
└── tool
├── db
├── DbOpt.java
├── Generator.java
├── Start.java
└── struct
│ ├── Bean.java
│ ├── Config.java
│ ├── Container.java
│ ├── Dao.java
│ ├── Field.java
│ ├── Manager.java
│ └── Mapper.java
├── ftl
├── FtlManager.java
├── FunctionEnum.java
├── IFtl.java
└── LanguageEnum.java
├── message
├── Generator.java
├── MainUi.java
└── struct
│ ├── Bean.java
│ ├── Field.java
│ ├── Handler.java
│ ├── Manager.java
│ └── Message.java
└── util
├── Config.java
└── StringUtil.java
/core/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/core/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | core
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/core/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.8
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.8
12 |
--------------------------------------------------------------------------------
/core/bin/.gitignore:
--------------------------------------------------------------------------------
1 | /com/
2 |
--------------------------------------------------------------------------------
/core/bin/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/core/src/com/game/message/MessagePool.java:
--------------------------------------------------------------------------------
1 | package com.game.message;
2 |
3 | import java.util.HashMap;
4 |
5 | import org.apache.log4j.Logger;
6 |
7 | import com.game.message.struct.Handler;
8 | import com.game.message.struct.Message;
9 |
10 | public class MessagePool {
11 | private static MessagePool instance = new MessagePool();
12 | private MessagePool() {}
13 | public static MessagePool getInstance() {
14 | return instance;
15 | }
16 |
17 | private Logger logger = Logger.getLogger(this.getClass());
18 |
19 | private HashMap> id2handler = new HashMap>();
20 | private HashMap> id2message = new HashMap>();
21 |
22 | public void register(int id, Class extends Handler> handlerClass, Class extends Message> messageClass) {
23 | id2handler.put(id, handlerClass);
24 | id2message.put(id, messageClass);
25 | }
26 |
27 | public Handler createHandler(int id) {
28 | Class extends Handler> handlerClass = id2handler.get(id);
29 | if (handlerClass == null) {
30 | return null;
31 | }
32 | Handler handler = null;
33 | try {
34 | handler = handlerClass.newInstance();
35 | } catch (InstantiationException e) {
36 | e.printStackTrace();
37 | } catch (IllegalAccessException e) {
38 | e.printStackTrace();
39 | }
40 | return handler;
41 | }
42 |
43 | public Message createMessage(int id) {
44 | Class extends Message> messageClass = id2message.get(id);
45 | if (messageClass == null) {
46 | return null;
47 | }
48 | Message message = null;
49 | try {
50 | message = messageClass.newInstance();
51 | } catch (InstantiationException e) {
52 | logger.error(e, e);
53 | } catch (IllegalAccessException e) {
54 | logger.error(e, e);
55 | }
56 | return message;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/core/src/com/game/message/struct/Bean.java:
--------------------------------------------------------------------------------
1 | package com.game.message.struct;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import org.apache.log4j.Logger;
5 |
6 | import java.io.UnsupportedEncodingException;
7 |
8 | /**
9 | * Created by game on 4/2/14.
10 | */
11 | public abstract class Bean {
12 | private static Logger log = Logger.getLogger(Bean.class);
13 | public abstract boolean read(ByteBuf buf);
14 | public abstract boolean write(ByteBuf buf);
15 |
16 | // byte
17 | public byte readByte(ByteBuf buf) {
18 | return buf.readByte();
19 | }
20 | public void writeByte(ByteBuf buf, byte value) {
21 | buf.writeByte(value);
22 | }
23 |
24 | // short
25 | public short readShort(ByteBuf buf) {
26 | return buf.readShort();
27 | }
28 | public void writeShort(ByteBuf buf, short value) {
29 | buf.writeShort(value);
30 | }
31 |
32 | // int
33 | public int readInt(ByteBuf buf) {
34 | return buf.readInt();
35 | }
36 | public void writeInt(ByteBuf buf, int value) {
37 | buf.writeInt(value);
38 | }
39 |
40 | // long
41 | public long readLong(ByteBuf buf) {
42 | return buf.readLong();
43 | }
44 | public void writeLong(ByteBuf buf, long value) {
45 | buf.writeLong(value);
46 | }
47 |
48 | // string
49 | public String readString(ByteBuf buf) {
50 | int length = buf.readInt();
51 | if (length <= 0) {
52 | return null;
53 | }
54 | if (buf.readableBytes() < length) {
55 | return null;
56 | }
57 | byte[] bytes = new byte[length];
58 | buf.readBytes(bytes);
59 | try {
60 | return new String(bytes, "UTF-8");
61 | } catch (UnsupportedEncodingException e) {
62 | log.error(e, e);
63 | }
64 | return null;
65 | }
66 | public void writeString(ByteBuf buf, String value) {
67 | if (value == null) {
68 | buf.writeInt(0);
69 | return;
70 | }
71 |
72 | try {
73 | byte[] bytes = value.getBytes("UTF-8");
74 | buf.writeInt(bytes.length);
75 | buf.writeBytes(bytes);
76 | } catch (UnsupportedEncodingException e) {
77 | log.error(e, e);
78 | }
79 | }
80 |
81 | // bean
82 | public Bean readBean(ByteBuf buf, Class extends Bean> clazz) {
83 | try{
84 | Bean bean = clazz.newInstance();
85 | bean.read(buf);
86 | return bean;
87 | }catch (Exception e) {
88 | log.error(e, e);
89 | }
90 | return null;
91 | }
92 | public void writeBean(ByteBuf buf, Bean value) {
93 | value.write(buf);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/core/src/com/game/message/struct/Handler.java:
--------------------------------------------------------------------------------
1 | package com.game.message.struct;
2 |
3 | import io.netty.channel.ChannelHandlerContext;
4 |
5 | /**
6 | * Created by game on 3/31/14.
7 | */
8 | public abstract class Handler {
9 | private Message message; // message
10 | private ChannelHandlerContext context;
11 |
12 | public ChannelHandlerContext getContext() {
13 | return context;
14 | }
15 |
16 | public void setContext(ChannelHandlerContext context) {
17 | this.context = context;
18 | }
19 |
20 | public abstract void exec();
21 |
22 | public Message getMessage() {
23 | return message;
24 | }
25 |
26 | public void setMessage(Message message) {
27 | this.message = message;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/core/src/com/game/message/struct/Message.java:
--------------------------------------------------------------------------------
1 | package com.game.message.struct;
2 |
3 | /**
4 | * Created by game on 4/2/14.
5 | */
6 | public abstract class Message extends Bean {
7 | public abstract int getId();
8 | }
9 |
--------------------------------------------------------------------------------
/core/src/com/game/netty/Client.java:
--------------------------------------------------------------------------------
1 | package com.game.netty;
2 |
3 | import io.netty.bootstrap.Bootstrap;
4 | import io.netty.channel.ChannelFuture;
5 | import io.netty.channel.ChannelOption;
6 | import io.netty.channel.EventLoopGroup;
7 | import io.netty.channel.nio.NioEventLoopGroup;
8 | import io.netty.channel.socket.nio.NioSocketChannel;
9 |
10 | import org.apache.log4j.Logger;
11 |
12 | /**
13 | * Created by game on 3/30/14.
14 | */
15 | public abstract class Client extends Netty {
16 | private static Logger logger = Logger.getLogger(Client.class);
17 | // private static
18 |
19 | protected abstract boolean init();
20 | public boolean init(String host, int port) {
21 | if (!init()) {
22 | return false;
23 | }
24 | EventLoopGroup workerGroup = new NioEventLoopGroup();
25 | Runtime.getRuntime().addShutdownHook(new Thread(new StopThread()));
26 |
27 | try {
28 | Bootstrap b = new Bootstrap();
29 | b.group(workerGroup);
30 | b.channel(NioSocketChannel.class);
31 | b.option(ChannelOption.SO_KEEPALIVE, true);
32 | b.handler(getChannelInitializer());
33 |
34 | // Start the client.
35 | ChannelFuture f = b.connect(host, port).sync();
36 |
37 | // Wait until the connection is closed.
38 | f.channel().closeFuture().sync();
39 | } catch (Exception e) {
40 | logger.error(e, e);
41 | return false;
42 | } finally {
43 | workerGroup.shutdownGracefully();
44 | }
45 |
46 | return true;
47 | }
48 |
49 | private class StopThread implements Runnable {
50 | public void run() {
51 | stop();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/core/src/com/game/netty/Netty.java:
--------------------------------------------------------------------------------
1 | package com.game.netty;
2 |
3 | import io.netty.channel.ChannelHandlerAdapter;
4 | import io.netty.channel.ChannelInitializer;
5 | import io.netty.channel.socket.SocketChannel;
6 |
7 | public abstract class Netty extends ChannelHandlerAdapter {
8 | public abstract void stop();
9 | public abstract ChannelInitializer getChannelInitializer();
10 | }
11 |
--------------------------------------------------------------------------------
/core/src/com/game/netty/Server.java:
--------------------------------------------------------------------------------
1 | package com.game.netty;
2 |
3 | import io.netty.bootstrap.ServerBootstrap;
4 | import io.netty.channel.ChannelFuture;
5 | import io.netty.channel.ChannelOption;
6 | import io.netty.channel.EventLoopGroup;
7 | import io.netty.channel.nio.NioEventLoopGroup;
8 | import io.netty.channel.socket.nio.NioServerSocketChannel;
9 |
10 | import org.apache.log4j.Logger;
11 |
12 | public abstract class Server extends Netty {
13 | private static Logger logger = Logger.getLogger(Server.class);
14 |
15 | protected abstract boolean init();
16 | public boolean init(int port) {
17 | if (!init()) {
18 | return false;
19 | }
20 |
21 | Runtime.getRuntime().addShutdownHook(new Thread(new StopThread()));
22 |
23 | EventLoopGroup accepterGroup = new NioEventLoopGroup();
24 | EventLoopGroup clientGroup = new NioEventLoopGroup();
25 |
26 | try {
27 | ServerBootstrap b = new ServerBootstrap();
28 | b.group(accepterGroup, clientGroup)
29 | .channel(NioServerSocketChannel.class)
30 | .childHandler(getChannelInitializer())
31 | .option(ChannelOption.SO_BACKLOG, 128)
32 | .childOption(ChannelOption.SO_KEEPALIVE, true);
33 |
34 | // Bind and start to accept incoming connections.
35 | ChannelFuture f = b.bind(port).sync();
36 |
37 | // Wait until the server socket is closed.
38 | // In this example, this does not happen, but you can do that to gracefully
39 | // shut down your server.
40 | f.channel().closeFuture().sync();
41 | } catch (Exception e) {
42 | logger.error(e, e);
43 | return false;
44 | } finally {
45 | clientGroup.shutdownGracefully();
46 | accepterGroup.shutdownGracefully();
47 | }
48 |
49 | return true;
50 | }
51 |
52 | private class StopThread implements Runnable {
53 | public void run() {
54 | stop();
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/core/src/com/game/netty/coder/Decoder.java:
--------------------------------------------------------------------------------
1 | package com.game.netty.coder;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import io.netty.channel.ChannelHandlerContext;
5 | import io.netty.handler.codec.ByteToMessageDecoder;
6 | import io.netty.util.AttributeKey;
7 |
8 | import java.util.List;
9 |
10 | import org.apache.log4j.Logger;
11 |
12 | import com.game.message.MessagePool;
13 | import com.game.message.struct.Message;
14 |
15 | /**
16 | * Created by Administrator on 2014/4/17.
17 | */
18 | public class Decoder extends ByteToMessageDecoder {
19 | private static Logger logger = Logger.getLogger(Decoder.class);
20 | private static final String MESSAGE_COUNT = "MESSAGE_COUNT";
21 | private static final String MESSAGE_TIME = "MESSAGE_TIME";
22 | private static final int MESSAGE_COUNT_NUM = 30;
23 | private static final int MESSAGE_COUNT_MSEC = 1000;
24 |
25 | @Override
26 | protected void decode(ChannelHandlerContext ctx, ByteBuf in, List