com.github.jiayaoguang:gameserver-scene

gameserver是一个游戏服务器框架,让游戏服务器开发更简单。


Keywords
game, game-development, game-server, gameserver, http, http-server, java, netty, protobuf
License
FSFAP

Documentation

游戏服务器

Java CI License Maven

Maven

<dependency>
    <groupId>com.github.jiayaoguang</groupId>
    <artifactId>gameserver-core</artifactId>
    <version>0.1.1</version>
</dependency>

english introduction

简介

  • 这是一个通用游戏服务器框架
  • 服务器以consumer 为运行单位,consumer 可以本地运行和调用,也可远程调用
  • consumer可以在单独的线程运行,也可以多个consumer运行在一个线程
  • 不同的consumer通信支持远程方法调用并异步返回,也可以通过发布事件的方法通信

Features

  • 消息支持 protobuf、json、自定义 的数据类型,支持压缩、加密操作
  • 网页http 请求
  • 轻量级远程调用、依赖注入
  • 不重启更新
  • mysql对象关系映射及异步存储
  • 定时事件
  • 消息转发代理,添加消息转发代理服务器无需修改代码,只需让客户端改为连接转发代理服务器即可
  • 消息传递支持 MQ,socket , websocket
  • 远程方法调用 example , 同步非阻塞调用 example

服务器示例项目 | 客户端示例项目

构建处理 protoBuf数据的服务器例子:

public class PingServer {
    public static void main(String[] args) throws Exception {
        GameServerBootstrap bootstarp = new GameServerBootstrap();
        bootstarp.registerSocketEvent(101, new PingProcessor());
        bootstarp.registerSendEventIdByProto(102, p_test.p_scene_sm_response_pong.class);
        //开端口服务
        bootstarp.addTcpConnector(8080);
        bootstarp.start();
    }

    public static class PingProcessor extends ProtoProcessor<p_sm_scene_request_ping> {

        @Override
        public void process(Session session, p_sm_scene_request_ping msg) {
            System.out.println("ok , i see ping");
            session.writeMessage(p_test.p_scene_sm_response_pong.newBuilder());
        }
    }
}

http例子代码:

public class HttpServerDemo01
{
    public static void main ( String[] args ) throws Exception 
    {
    	
    	
    	GameServerBootstrap bootstarp = new GameServerBootstrap();
        
        bootstarp.addHttpProcessor(new HttpProcessor("/index") {
			
			@Override
			public void service(Request request, Response response) {

				response.writeAndFlush( "<html><head></head><body><div align='center'><h1>Hello world!</h1></div><body></html>" );
				
			}
		} );
        
        bootstarp.addHttpConnector(8080);
        
        bootstarp.start();
    }
}

更多例子请在test包查看


License

Apache License, Version 2.0 Copyright (C) Apache Software Foundation