├── .gitignore ├── LICENSE ├── README.md ├── game-code-generate ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── snowcattle │ │ └── game │ │ ├── message │ │ ├── logicgenerate │ │ │ ├── enity │ │ │ │ └── CommonPlayer.java │ │ │ ├── http │ │ │ │ └── room │ │ │ │ │ └── client │ │ │ │ │ └── HttpHeartClientMessage.java │ │ │ └── tcp │ │ │ │ └── room │ │ │ │ └── client │ │ │ │ └── RoomHeartClientMessage.java │ │ └── protogenerate │ │ │ ├── common │ │ │ └── GameCommonMessageProBuf.java │ │ │ ├── http │ │ │ └── room │ │ │ │ └── client │ │ │ │ └── GameRoomHttpClientProBuf.java │ │ │ └── tcp │ │ │ └── room │ │ │ └── client │ │ │ └── GameRoomTCPClientProBuf.java │ │ ├── service │ │ └── net │ │ │ ├── GameMessageCommandEnum.java │ │ │ ├── GameMessageCommandFactory.java │ │ │ └── GameMessageCommandIndex.java │ │ └── template │ │ ├── Converter.java │ │ ├── MessageGenerator.java │ │ ├── utils │ │ ├── FileConentFactory.java │ │ ├── FileContent.java │ │ ├── FileContentFactoryImpl.java │ │ └── FileUtils.java │ │ └── xml │ │ ├── FieldObject.java │ │ ├── MacroObject.java │ │ ├── MessageObject.java │ │ └── XmlsLoader.java │ └── resources │ ├── config │ ├── model │ │ ├── http_client.xml │ │ ├── macros.xml │ │ └── room_client.xml │ └── template │ │ ├── macros.vm │ │ ├── templatehttp.vm │ │ └── templatetcp.vm │ └── proto │ ├── common.proto │ ├── http_client.proto │ ├── mac │ └── back.txt │ ├── tcproom-client.proto │ └── windows │ ├── back.txt │ └── protoc.exe ├── game-common ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── snowcattle │ └── game │ ├── common │ ├── IUpdatable.java │ ├── ThreadNameFactory.java │ ├── annotation │ │ ├── AsyncOper.java │ │ ├── AsyncThreadOper.java │ │ ├── BlockingQueueType.java │ │ ├── Comment.java │ │ ├── GlobalEventListenerAnnotation.java │ │ ├── IDictAnnotation.java │ │ ├── MainThreadOper.java │ │ ├── MessageCommandAnnotation.java │ │ ├── NotThreadSafe.java │ │ ├── RpcServiceAnnotation.java │ │ ├── RpcServiceBoEnum.java │ │ ├── SpecialEventListenerAnnotation.java │ │ ├── SyncIoOper.java │ │ ├── SyncOper.java │ │ └── SysI18nString.java │ ├── config │ │ ├── AbstractGameConfigure.java │ │ ├── Config.java │ │ ├── ConfigUtil.java │ │ ├── GameConfigurable.java │ │ ├── GameDynamicPropertiesConfig.java │ │ ├── GameServerConfig.java │ │ ├── GameServerDiffConfig.java │ │ ├── IGameConfig.java │ │ ├── ServerConfig.java │ │ ├── ZooKeeperConfig.java │ │ └── script │ │ │ ├── IScriptEngine.java │ │ │ └── JSScriptManagerImpl.java │ ├── constant │ │ ├── CommonErrorLogInfo.java │ │ ├── DynamicPropertiesEnum.java │ │ ├── GlobalConstants.java │ │ ├── Loggers.java │ │ ├── ServiceName.java │ │ └── SymbolConstants.java │ ├── enums │ │ ├── BOEnum.java │ │ ├── DeliveryGuarantyOption.java │ │ └── NetTypeEnum.java │ ├── exception │ │ ├── CacheConfigException.java │ │ ├── CodecException.java │ │ ├── ConfigException.java │ │ ├── GameHandlerException.java │ │ ├── GameInvalidLogicException.java │ │ ├── IServerServiceException.java │ │ ├── NetMessageException.java │ │ ├── NoEnoughValueException.java │ │ ├── StartUpException.java │ │ ├── TransactionException.java │ │ └── ValueLimitException.java │ ├── scanner │ │ ├── ClassScanner.java │ │ └── PackageScaner.java │ └── util │ │ ├── AES.java │ │ ├── ArgumentList.java │ │ ├── ArrayUtils.java │ │ ├── Assert.java │ │ ├── BeanUtil.java │ │ ├── ByteArrayBitSet.java │ │ ├── CodecUtil.java │ │ ├── CommonUtil.java │ │ ├── ConactString.java │ │ ├── DesEncrypter.java │ │ ├── EnumUtil.java │ │ ├── ErrorsUtil.java │ │ ├── ExecutorUtil.java │ │ ├── FileUtil.java │ │ ├── FloatNumberPropertyArray.java │ │ ├── GenericPropertyArray.java │ │ ├── HttpUtil.java │ │ ├── IKeyWordsFilter.java │ │ ├── IOUtils.java │ │ ├── IntNumberPropertyArray.java │ │ ├── IntStringPair.java │ │ ├── IsoUtils.java │ │ ├── JVMMonitor.java │ │ ├── JdomUtils.java │ │ ├── JsScriptHelper.java │ │ ├── JsonUtils.java │ │ ├── KeyUtil.java │ │ ├── KeyValuePair.java │ │ ├── KeyWordsACFilter.java │ │ ├── LRUHashMap.java │ │ ├── MD5Util.java │ │ ├── MathUtils.java │ │ ├── MemUtils.java │ │ ├── NumberUtil.java │ │ ├── ObjectUtils.java │ │ ├── PropertyArray.java │ │ ├── PropertyRawSet.java │ │ ├── RandomStringGenerator.java │ │ ├── RandomUtil.java │ │ ├── Range.java │ │ ├── RegisterCode.java │ │ ├── ResourcePathUtil.java │ │ ├── ResourceUtil.java │ │ ├── ShootUtils.java │ │ ├── StringPropertyArray.java │ │ ├── StringUtils.java │ │ ├── ThreadPool.java │ │ ├── ThreadUtil.java │ │ ├── TimeMonitor.java │ │ ├── TimeUtils.java │ │ └── UniformRandomChooser.java │ └── service │ └── json │ └── JsonSerializer.java ├── game-core ├── deploy │ ├── build.sh │ ├── config │ │ └── launch.sh │ └── dist.sh ├── pom.xml ├── proto │ ├── common.proto │ ├── http_client.proto │ ├── mac │ │ └── back.txt │ ├── tcponline-server.proto │ ├── tcponline.proto │ ├── udponline.proto │ └── windows │ │ ├── back.txt │ │ └── protoc.exe ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── snowcattle │ │ │ │ └── game │ │ │ │ ├── bootstrap │ │ │ │ ├── GameServer.java │ │ │ │ ├── GameServerRuntime.java │ │ │ │ ├── GamerServerStartFinishedService.java │ │ │ │ ├── ServerStatusLog.java │ │ │ │ ├── ShutdownHook.java │ │ │ │ └── manager │ │ │ │ │ ├── AbstractGameManager.java │ │ │ │ │ ├── AbstractLocalManager.java │ │ │ │ │ ├── GlobalManager.java │ │ │ │ │ ├── ILocalManager.java │ │ │ │ │ ├── LocalMananger.java │ │ │ │ │ ├── ServerServiceManager.java │ │ │ │ │ └── spring │ │ │ │ │ ├── AbstractSpringStart.java │ │ │ │ │ ├── LocalSpringBeanManager.java │ │ │ │ │ ├── LocalSpringServiceManager.java │ │ │ │ │ └── LocalSpringServicerAfterManager.java │ │ │ │ ├── logic │ │ │ │ ├── net │ │ │ │ │ ├── NetMessageProcessLogic.java │ │ │ │ │ └── NetMessageTcpDispatchLogic.java │ │ │ │ └── player │ │ │ │ │ ├── GamePlayer.java │ │ │ │ │ └── IPlayer.java │ │ │ │ ├── message │ │ │ │ ├── auto │ │ │ │ │ ├── common │ │ │ │ │ │ └── CommonMessageProBuf.java │ │ │ │ │ ├── http │ │ │ │ │ │ └── client │ │ │ │ │ │ │ └── OnlineClientHttpProBuf.java │ │ │ │ │ ├── tcp │ │ │ │ │ │ └── online │ │ │ │ │ │ │ ├── client │ │ │ │ │ │ │ └── OnlineTCPClientProBuf.java │ │ │ │ │ │ │ └── server │ │ │ │ │ │ │ └── OnlineTCPServerProBuf.java │ │ │ │ │ └── udp │ │ │ │ │ │ └── online │ │ │ │ │ │ └── OnlineUDPProBuf.java │ │ │ │ ├── handler │ │ │ │ │ ├── AbstractMessageHandler.java │ │ │ │ │ ├── IMessageHandler.java │ │ │ │ │ └── impl │ │ │ │ │ │ ├── common │ │ │ │ │ │ └── CommonHandlerImpl.java │ │ │ │ │ │ ├── http │ │ │ │ │ │ └── HttpHandlerImpl.java │ │ │ │ │ │ └── online │ │ │ │ │ │ ├── OnlineTcpHandlerImpl.java │ │ │ │ │ │ └── OnlineUdpHandleImpl.java │ │ │ │ └── logic │ │ │ │ │ ├── http │ │ │ │ │ └── client │ │ │ │ │ │ └── OnlineHeartClientHttpMessage.java │ │ │ │ │ ├── tcp │ │ │ │ │ ├── common │ │ │ │ │ │ ├── CommonErrorResponseServerMessage.java │ │ │ │ │ │ └── CommonResponseServerMessage.java │ │ │ │ │ └── online │ │ │ │ │ │ ├── client │ │ │ │ │ │ ├── OnlineHeartClientTcpMessage.java │ │ │ │ │ │ └── OnlineLoginClientTcpMessage.java │ │ │ │ │ │ └── server │ │ │ │ │ │ └── OnlineLoginServerTcpMessage.java │ │ │ │ │ └── udp │ │ │ │ │ └── online │ │ │ │ │ └── OnlineHeartClientUDPMessage.java │ │ │ │ └── service │ │ │ │ ├── IServerService.java │ │ │ │ ├── IService.java │ │ │ │ ├── Reloadable.java │ │ │ │ ├── async │ │ │ │ ├── AsyncCall.java │ │ │ │ └── pool │ │ │ │ │ ├── AsyncThreadPool.java │ │ │ │ │ └── AsyncThreadService.java │ │ │ │ ├── check │ │ │ │ └── LifeCycleCheckService.java │ │ │ │ ├── classes │ │ │ │ └── loader │ │ │ │ │ ├── DefaultClassLoader.java │ │ │ │ │ ├── DynamicGameClassLoader.java │ │ │ │ │ └── FileClassLoader.java │ │ │ │ ├── config │ │ │ │ └── GameServerConfigService.java │ │ │ │ ├── dict │ │ │ │ ├── DictArrayMaps.java │ │ │ │ ├── DictCollectionEnum.java │ │ │ │ ├── DictMap.java │ │ │ │ ├── DictService.java │ │ │ │ ├── IDict.java │ │ │ │ └── IDictCollections.java │ │ │ │ ├── event │ │ │ │ ├── GameAsyncEventService.java │ │ │ │ ├── SingleEventConstants.java │ │ │ │ ├── impl │ │ │ │ │ ├── SessionRegisterEvent.java │ │ │ │ │ ├── SessionUnRegisterEvent.java │ │ │ │ │ └── SingleRunEvent.java │ │ │ │ └── listener │ │ │ │ │ ├── SessionRegisterEventListener.java │ │ │ │ │ ├── SessionUnRegisterEventListener.java │ │ │ │ │ └── SingleRunEventListener.java │ │ │ │ ├── limit │ │ │ │ └── AtomicLimitNumber.java │ │ │ │ ├── lookup │ │ │ │ ├── AbstractLongLookUpService.java │ │ │ │ ├── GamePlayerLoopUpService.java │ │ │ │ ├── IChannleLookUpService.java │ │ │ │ ├── ILongId.java │ │ │ │ ├── ILongLookUpService.java │ │ │ │ ├── NetTcpSessionLoopUpService.java │ │ │ │ └── cache │ │ │ │ │ └── EhcacheService.java │ │ │ │ ├── message │ │ │ │ ├── AbstractNetMessage.java │ │ │ │ ├── AbstractNetProtoBufHttpMessage.java │ │ │ │ ├── AbstractNetProtoBufMessage.java │ │ │ │ ├── AbstractNetProtoBufTcpMessage.java │ │ │ │ ├── AbstractNetProtoBufUdpMessage.java │ │ │ │ ├── INetMessage.java │ │ │ │ ├── NetHttpMessageHead.java │ │ │ │ ├── NetMessageBody.java │ │ │ │ ├── NetMessageHead.java │ │ │ │ ├── NetProtoBufMessageBody.java │ │ │ │ ├── NetUdpMessageHead.java │ │ │ │ ├── command │ │ │ │ │ ├── MessageCommand.java │ │ │ │ │ ├── MessageCommandEnum.java │ │ │ │ │ ├── MessageCommandFactory.java │ │ │ │ │ └── MessageCommandIndex.java │ │ │ │ ├── decoder │ │ │ │ │ ├── INetProtoBufHttpMessageDecoderFactory.java │ │ │ │ │ ├── INetProtoBufMessageDecoderFactory.java │ │ │ │ │ ├── INetProtoBufTcpMessageDecoderFactory.java │ │ │ │ │ ├── INetProtoBufUdpMessageDecoderFactory.java │ │ │ │ │ ├── NetProtoBufHttpMessageDecoderFactory.java │ │ │ │ │ ├── NetProtoBufMessageTCPDecoder.java │ │ │ │ │ ├── NetProtoBufMessageUDPDecoder.java │ │ │ │ │ ├── NetProtoBufTcpMessageDecoderFactory.java │ │ │ │ │ ├── NetProtoBufUdpMessageDecoderFactory.java │ │ │ │ │ └── RpcDecoder.java │ │ │ │ ├── encoder │ │ │ │ │ ├── INetProtoBufHttpMessageEncoderFactory.java │ │ │ │ │ ├── INetProtoBufMessageEncoderFactory.java │ │ │ │ │ ├── INetProtoBufTcpMessageEncoderFactory.java │ │ │ │ │ ├── INetProtoBufUdpMessageEncoderFactory.java │ │ │ │ │ ├── NetProtoBufHttpMessageEncoderFactory.java │ │ │ │ │ ├── NetProtoBufMessageTCPEncoder.java │ │ │ │ │ ├── NetProtoBufMessageUDPEncoder.java │ │ │ │ │ ├── NetProtoBufTcpMessageEncoderFactory.java │ │ │ │ │ ├── NetProtoBufUdpMessageEncoderFactory.java │ │ │ │ │ └── RpcEncoder.java │ │ │ │ ├── facade │ │ │ │ │ ├── GameFacade.java │ │ │ │ │ └── IFacade.java │ │ │ │ ├── factory │ │ │ │ │ ├── ITcpMessageFactory.java │ │ │ │ │ ├── IUdpMessageFactory.java │ │ │ │ │ └── TcpMessageFactory.java │ │ │ │ ├── process │ │ │ │ │ ├── INetProtoBufMessageProcess.java │ │ │ │ │ └── NetProtoBufMessageProcess.java │ │ │ │ └── registry │ │ │ │ │ └── MessageRegistry.java │ │ │ │ ├── net │ │ │ │ ├── AbstractNettyServerService.java │ │ │ │ ├── LocalNetService.java │ │ │ │ ├── SdNetConfig.java │ │ │ │ ├── broadcast │ │ │ │ │ ├── GameTcpBroadCastService.java │ │ │ │ │ └── IBroadCastService.java │ │ │ │ ├── http │ │ │ │ │ ├── AbstractNettyHttpServerService.java │ │ │ │ │ ├── GameNetProtoMessageHttpServerChannelInitializer.java │ │ │ │ │ ├── GameNettyHttpServerService.java │ │ │ │ │ ├── NetHttpServerConfig.java │ │ │ │ │ ├── SdHttpServerConfig.java │ │ │ │ │ └── handler │ │ │ │ │ │ ├── HttpServerHandler.java │ │ │ │ │ │ └── async │ │ │ │ │ │ └── AsyncNettyHttpHandlerService.java │ │ │ │ ├── proxy │ │ │ │ │ ├── NetProxyConfig.java │ │ │ │ │ ├── ProxyRule.java │ │ │ │ │ ├── ProxyTcpBackChannelInitializer.java │ │ │ │ │ ├── ProxyTcpFrontedChannelInitializer.java │ │ │ │ │ ├── ProxyTcpServerService.java │ │ │ │ │ ├── SdProxyConfig.java │ │ │ │ │ └── handler │ │ │ │ │ │ ├── ProxyBackendHandler.java │ │ │ │ │ │ └── ProxyFrontendHandler.java │ │ │ │ ├── ssl │ │ │ │ │ └── SSLService.java │ │ │ │ ├── tcp │ │ │ │ │ ├── AbstractNettyTcpServerService.java │ │ │ │ │ ├── AbstractServerService.java │ │ │ │ │ ├── GameNetProtoMessageTcpServerChannelInitializer.java │ │ │ │ │ ├── GameNetRPCChannleInitializer.java │ │ │ │ │ ├── GameNettyRPCService.java │ │ │ │ │ ├── GameNettyTcpServerService.java │ │ │ │ │ ├── MessageAttributeEnum.java │ │ │ │ │ ├── RpcRequest.java │ │ │ │ │ ├── RpcResponse.java │ │ │ │ │ ├── handler │ │ │ │ │ │ ├── AbstractGameNetMessageTcpServerHandler.java │ │ │ │ │ │ ├── GameLoggingHandler.java │ │ │ │ │ │ ├── GameNetMessageTcpServerHandler.java │ │ │ │ │ │ ├── GameNetRPCServerHandler.java │ │ │ │ │ │ └── async │ │ │ │ │ │ │ ├── AsyncNettyGameNetMessageTcpServerHandler.java │ │ │ │ │ │ │ └── AsyncNettyTcpHandlerService.java │ │ │ │ │ ├── pipeline │ │ │ │ │ │ ├── DefaultTcpServerPipeLine.java │ │ │ │ │ │ ├── DefaultUdpServerPipeLine.java │ │ │ │ │ │ ├── IServerPipeLine.java │ │ │ │ │ │ └── factory │ │ │ │ │ │ │ ├── DefaultTcpServerPipelineFactory.java │ │ │ │ │ │ │ ├── DefaultUdpServerPipelineFactory.java │ │ │ │ │ │ │ └── IServerPipelineFactory.java │ │ │ │ │ ├── process │ │ │ │ │ │ ├── GameTcpMessageProcessor.java │ │ │ │ │ │ ├── GameUdpMessageOrderProcessor.java │ │ │ │ │ │ ├── GameUdpMessageProcessor.java │ │ │ │ │ │ ├── IMessageProcessor.java │ │ │ │ │ │ ├── ITcpMessageProcessor.java │ │ │ │ │ │ ├── QueueMessageExecutorProcessor.java │ │ │ │ │ │ └── QueueTcpMessageExecutorProcessor.java │ │ │ │ │ └── session │ │ │ │ │ │ ├── INetMessageSender.java │ │ │ │ │ │ ├── ISession.java │ │ │ │ │ │ ├── NettySession.java │ │ │ │ │ │ ├── NettyTcpNetMessageSender.java │ │ │ │ │ │ ├── NettyTcpSession.java │ │ │ │ │ │ ├── TcpNetState.java │ │ │ │ │ │ ├── TcpNetStateUpdate.java │ │ │ │ │ │ └── builder │ │ │ │ │ │ ├── ISessionBuilder.java │ │ │ │ │ │ ├── NettyTcpSessionBuilder.java │ │ │ │ │ │ └── NettyUdpSessionBuilder.java │ │ │ │ ├── udp │ │ │ │ │ ├── AbstractNettyUdpServerService.java │ │ │ │ │ ├── GameNetProtoMessageUdpServerChannelInitializer.java │ │ │ │ │ ├── GameNettyUdpServerService.java │ │ │ │ │ ├── NetUdpServerConfig.java │ │ │ │ │ ├── SdUdpServerConfig.java │ │ │ │ │ ├── handler │ │ │ │ │ │ └── GameNetMessageUdpServerHandler.java │ │ │ │ │ └── session │ │ │ │ │ │ ├── NettyUdpNetMessageSender.java │ │ │ │ │ │ └── NettyUdpSession.java │ │ │ │ └── websocket │ │ │ │ │ ├── AbstractNettyWebSocketServerService.java │ │ │ │ │ ├── GameNetProtoMessageWebSocketServerChannelInitializer.java │ │ │ │ │ ├── GameNettyWebSocketServerService.java │ │ │ │ │ ├── NetWebSocketServerConfig.java │ │ │ │ │ ├── SdWebSocketServerConfig.java │ │ │ │ │ └── handler │ │ │ │ │ ├── WebSocketServerHandler.java │ │ │ │ │ └── async │ │ │ │ │ ├── AsyncNettyWebSocketHandlerExecutorService.java │ │ │ │ │ └── AsyncWebSocketFrameServerHandler.java │ │ │ │ ├── rpc │ │ │ │ ├── client │ │ │ │ │ ├── AbstractRpcConnectManager.java │ │ │ │ │ ├── AsyncRPCCallback.java │ │ │ │ │ ├── RPCFuture.java │ │ │ │ │ ├── RPCFutureService.java │ │ │ │ │ ├── RpcClientConnectService.java │ │ │ │ │ ├── RpcContextHolder.java │ │ │ │ │ ├── RpcContextHolderObject.java │ │ │ │ │ ├── RpcProxyService.java │ │ │ │ │ ├── RpcRequestFactory.java │ │ │ │ │ ├── ZookeeperRpcServiceDiscovery.java │ │ │ │ │ ├── impl │ │ │ │ │ │ ├── DbRpcConnnectMananger.java │ │ │ │ │ │ ├── GameRpcConnecetMananger.java │ │ │ │ │ │ └── WorldRpcConnectManager.java │ │ │ │ │ ├── net │ │ │ │ │ │ ├── RpcClient.java │ │ │ │ │ │ ├── RpcClientConnection.java │ │ │ │ │ │ ├── RpcClientHandler.java │ │ │ │ │ │ ├── RpcClientInitializer.java │ │ │ │ │ │ └── RpcServerConnectTask.java │ │ │ │ │ └── proxy │ │ │ │ │ │ ├── AsyncRpcProxy.java │ │ │ │ │ │ ├── IAsyncRpcProxy.java │ │ │ │ │ │ └── ObjectProxy.java │ │ │ │ ├── serialize │ │ │ │ │ ├── IRpcSerialize.java │ │ │ │ │ └── protostuff │ │ │ │ │ │ └── ProtostuffSerializeI.java │ │ │ │ ├── server │ │ │ │ │ ├── RemoteRpcHandlerService.java │ │ │ │ │ ├── RpcHandlerThreadPool.java │ │ │ │ │ ├── RpcMethodRegistry.java │ │ │ │ │ ├── RpcNodeInfo.java │ │ │ │ │ ├── RpcServerRegisterConfig.java │ │ │ │ │ ├── RpcSystemConfig.java │ │ │ │ │ ├── SdRpcServiceProvider.java │ │ │ │ │ ├── SdServer.java │ │ │ │ │ └── zookeeper │ │ │ │ │ │ ├── ZooKeeperNodeBoEnum.java │ │ │ │ │ │ ├── ZooKeeperNodeInfo.java │ │ │ │ │ │ └── ZookeeperRpcServiceRegistry.java │ │ │ │ └── service │ │ │ │ │ ├── client │ │ │ │ │ └── HelloService.java │ │ │ │ │ └── server │ │ │ │ │ └── HelloServiceImpl.java │ │ │ │ ├── time │ │ │ │ ├── SystemTimeService.java │ │ │ │ ├── Time.java │ │ │ │ └── TimeService.java │ │ │ │ ├── update │ │ │ │ └── NettyTcpSerssionUpdate.java │ │ │ │ └── uuid │ │ │ │ └── LongIdGenerator.java │ │ └── resources │ │ │ ├── bean │ │ │ └── applicationContext.xml │ │ │ ├── dynamic_config.properties │ │ │ ├── game_server.cfg.js │ │ │ ├── game_server_diff.cfg.js │ │ │ ├── http-server.xml │ │ │ ├── log4j.properties │ │ │ ├── proxy-server.xml │ │ │ ├── rpc-server-register.xml │ │ │ ├── rpc-service-register.xml │ │ │ ├── udp-server.xml │ │ │ ├── websocket-server.xml │ │ │ └── zookeeper.properties │ └── test │ │ ├── java │ │ └── com │ │ │ └── snowcattle │ │ │ └── game │ │ │ ├── TestStartUp.java │ │ │ ├── common │ │ │ ├── codec │ │ │ │ ├── client │ │ │ │ │ ├── CodeCClient.java │ │ │ │ │ └── CodeCStringClientChannelInitializer.java │ │ │ │ └── server │ │ │ │ │ ├── CodeServer.java │ │ │ │ │ ├── CodeServerChannelInitializer.java │ │ │ │ │ ├── CodeSocketServerHandler.java │ │ │ │ │ ├── CodeSocketTwoServerHandler.java │ │ │ │ │ └── TwoStringDecoder.java │ │ │ ├── collections │ │ │ │ └── ArrayTest.java │ │ │ ├── dict │ │ │ │ └── DictServiceTest.java │ │ │ ├── ehcache │ │ │ │ ├── Data.java │ │ │ │ └── EacacheTest.java │ │ │ ├── http │ │ │ │ ├── HttpSnoopClient.java │ │ │ │ ├── HttpSnoopClientHandler.java │ │ │ │ ├── HttpSnoopClientInitializer.java │ │ │ │ ├── HttpSnoopServer.java │ │ │ │ ├── HttpSnoopServerHandler.java │ │ │ │ └── HttpSnoopServerInitializer.java │ │ │ ├── lock │ │ │ │ └── ReadWriteLockTest.java │ │ │ ├── lookuptest │ │ │ │ └── lookup.java │ │ │ ├── reflect │ │ │ │ └── ReflectTest.java │ │ │ ├── socket │ │ │ │ ├── client │ │ │ │ │ ├── ClientChannleInitializer.java │ │ │ │ │ ├── EchoClient.java │ │ │ │ │ ├── EchoClientHandler.java │ │ │ │ │ ├── EchoStringSocketClientHandler.java │ │ │ │ │ ├── LenghtStringClientHandler.java │ │ │ │ │ ├── LengthStringClientChannleInitializer.java │ │ │ │ │ ├── NetMessageClientChannelInitializer.java │ │ │ │ │ ├── NetMessageClientHandler.java │ │ │ │ │ └── StringClientChannelInitializer.java │ │ │ │ ├── message │ │ │ │ │ ├── INetMessageDecoderFactory.java │ │ │ │ │ ├── INetMessageEncoderFactory.java │ │ │ │ │ ├── NetMessageEncodeTest.java │ │ │ │ │ ├── NetMessageEncoderFactory.java │ │ │ │ │ ├── NetMessageTCPDecoder.java │ │ │ │ │ ├── NetMessageTcpEncoder.java │ │ │ │ │ └── NetTcpMessageDecoderFactory.java │ │ │ │ └── server │ │ │ │ │ ├── EchoServer.java │ │ │ │ │ ├── EchoSocketServerHandler.java │ │ │ │ │ ├── LenghtStringSocketServerHandler.java │ │ │ │ │ ├── LengthStringDecoder.java │ │ │ │ │ ├── LengthStringServerChannelInitializer.java │ │ │ │ │ ├── NetMessageServerChannleInitializer.java │ │ │ │ │ ├── NetMessageSocketServerHandler.java │ │ │ │ │ ├── ServerChannelInitializer.java │ │ │ │ │ └── StringServerChannelInitializer.java │ │ │ ├── template │ │ │ │ ├── ChileTemplate.java │ │ │ │ ├── JdbcDaoSupport.java │ │ │ │ ├── SuperTemplate.java │ │ │ │ ├── Test.java │ │ │ │ └── UserDao.java │ │ │ ├── thread │ │ │ │ ├── join │ │ │ │ │ ├── ThreadTester.java │ │ │ │ │ ├── ThreadTesterA.java │ │ │ │ │ └── ThreadTesterB.java │ │ │ │ ├── lock │ │ │ │ │ └── ConditionTest.java │ │ │ │ ├── pool │ │ │ │ │ ├── QueuePoolExecutorTest.java │ │ │ │ │ └── TestWorker.java │ │ │ │ └── sync │ │ │ │ │ ├── SingleLock.java │ │ │ │ │ ├── TwinsLock.java │ │ │ │ │ └── TwinsLockTest.java │ │ │ ├── timer │ │ │ │ ├── ScheduledThreadPoolExecutorTest.java │ │ │ │ └── TimerTest.java │ │ │ ├── udp │ │ │ │ ├── client │ │ │ │ │ ├── EchoJdkUdpClient.java │ │ │ │ │ ├── EchoNettyUdpClient.java │ │ │ │ │ ├── UdpClientChannelInitializer.java │ │ │ │ │ ├── UdpHandler.java │ │ │ │ │ ├── UdpProtoBufClientChannelInitializer.java │ │ │ │ │ └── UdpProtoBufHandler.java │ │ │ │ └── server │ │ │ │ │ ├── EchoServer.java │ │ │ │ │ ├── EchoServerHandler.java │ │ │ │ │ ├── JavaUDPServer.java │ │ │ │ │ ├── UdpChannelInitializer.java │ │ │ │ │ └── UdpProtoBufServerChannelInitializer.java │ │ │ ├── util │ │ │ │ ├── DateFormatTest.java │ │ │ │ ├── RandomStringGeneratorTest.java │ │ │ │ └── concurrent │ │ │ │ │ └── ConcurrentMapTest.java │ │ │ ├── uuid │ │ │ │ └── SnowflakeIdWorker.java │ │ │ ├── websocket │ │ │ │ ├── benchmarkserver │ │ │ │ │ ├── WebSocketServer.java │ │ │ │ │ ├── WebSocketServerBenchmarkPage.java │ │ │ │ │ ├── WebSocketServerHandler.java │ │ │ │ │ ├── WebSocketServerInitializer.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── client │ │ │ │ │ ├── WebSocketClient.java │ │ │ │ │ └── WebSocketClientHandler.java │ │ │ │ ├── server │ │ │ │ │ ├── WebSocketFrameHandler.java │ │ │ │ │ ├── WebSocketIndexPageHandler.java │ │ │ │ │ ├── WebSocketServer.java │ │ │ │ │ ├── WebSocketServerIndexPage.java │ │ │ │ │ ├── WebSocketServerInitializer.java │ │ │ │ │ └── package-info.java │ │ │ │ └── websocket.html │ │ │ └── zookeeper │ │ │ │ ├── Carutor │ │ │ │ ├── Carutor2.java │ │ │ │ └── CuratorListenerUtils.java │ │ │ │ └── zkclient │ │ │ │ ├── Listener.java │ │ │ │ ├── RetryConnect.java │ │ │ │ ├── Test.java │ │ │ │ └── ZookperTest.java │ │ │ ├── extend │ │ │ ├── GameManager.java │ │ │ ├── GameServerEx.java │ │ │ ├── GlobalManagerEx.java │ │ │ ├── LocalSpringBeanGameManager.java │ │ │ └── LocalSpringServiceGameManager.java │ │ │ ├── jdbc │ │ │ ├── Test.java │ │ │ ├── entity │ │ │ │ └── Order.java │ │ │ ├── mapper │ │ │ │ └── OrderMapper.java │ │ │ └── service │ │ │ │ ├── IOrderService.java │ │ │ │ └── impl │ │ │ │ └── OrderService.java │ │ │ ├── net │ │ │ └── client │ │ │ │ ├── http │ │ │ │ ├── GameHttpClient.java │ │ │ │ ├── GameHttpClientHandler.java │ │ │ │ └── GameHttpClientInitializer.java │ │ │ │ ├── proxy │ │ │ │ └── ProxyClient.java │ │ │ │ ├── rpc │ │ │ │ ├── HelloCallbackTest.java │ │ │ │ ├── HelloServiceTest.java │ │ │ │ ├── stresstest │ │ │ │ │ └── HelloServiceStressTest.java │ │ │ │ └── zookeeper │ │ │ │ │ └── ZookeeperTest.java │ │ │ │ ├── tcp │ │ │ │ ├── GameClient.java │ │ │ │ ├── GameClientChannleInitializer.java │ │ │ │ └── GameClientHandler.java │ │ │ │ ├── udp │ │ │ │ └── GameNettyUdpClient.java │ │ │ │ └── websocket │ │ │ │ ├── GameWebSocketClient.java │ │ │ │ └── GameWebSocketClientHandler.java │ │ │ ├── service │ │ │ └── dict │ │ │ │ └── entity │ │ │ │ ├── Bullet.java │ │ │ │ └── RoleSkill.java │ │ │ └── tps │ │ │ └── rpc │ │ │ ├── RpcTpsRunable.java │ │ │ ├── mutil │ │ │ └── MutilTest.java │ │ │ └── single │ │ │ └── SingleTest.java │ │ └── resources │ │ ├── back_up │ │ └── log4j_back.properties │ │ ├── bean │ │ ├── applicationContext.xml │ │ ├── db-applicationContext-redis.xml │ │ └── db_applicationContext_datasource.xml │ │ ├── db_jdbc.properties │ │ ├── dict │ │ ├── bullet │ │ │ └── d_bullet.wg │ │ ├── dict.wg │ │ └── status │ │ │ └── d_role_skill.wg │ │ ├── dynamic_config.properties │ │ ├── ehcache.xml │ │ ├── game_server.cfg.js │ │ ├── game_server_diff.cfg.js │ │ ├── log4j.properties │ │ ├── mybatis3 │ │ ├── mappers │ │ │ └── orderMapper.xml │ │ └── sqlMapConfig.xml │ │ ├── rpc-server-register.xml │ │ ├── rpc-service-register.xml │ │ ├── sql │ │ └── init.sql │ │ ├── udp-server.xml │ │ ├── websocket-server.xml │ │ └── zookeeper.properties └── tools │ └── excelToCode │ ├── config │ └── config.py │ └── python │ ├── LICENSE │ ├── README.md │ ├── codegen │ ├── __init__.py │ ├── base_code_gen.py │ └── java_code_gen.py │ ├── doc │ ├── how-to-config.md │ ├── how-to-create-excel.md │ └── images │ │ ├── config-header@2x.png │ │ ├── direct-header@2x.png │ │ └── excel.png │ ├── exporters │ ├── __init__.py │ ├── base_exporter.py │ ├── config_exporter.py │ ├── direct_exporter.py │ └── mix_exporter.py │ ├── gen_header_with_openpyxl.py │ ├── gen_header_with_xlrd.py │ ├── generate_code.py │ ├── generate_header.py │ ├── install_package.py │ ├── load_configure.py │ ├── logtool.py │ ├── main.py │ ├── numfmt.py │ ├── openpyxl_extend.py │ ├── parsers │ ├── __init__.py │ ├── base_parser.py │ ├── config_parser.py │ └── direct_parser.py │ ├── postprocess │ ├── __init__.py │ ├── base_processor.py │ ├── java_file_enum_processor.py │ └── java_file_list_processor.py │ ├── sample │ ├── config.py │ ├── excels │ │ └── example.xlsx │ ├── export.bat │ ├── export.sh │ └── export │ │ ├── java │ │ ├── code │ │ │ ├── DictEnum.java │ │ │ └── DictExample.java │ │ └── data │ │ │ ├── d_example.wg │ │ │ └── dict.wg │ │ └── xtemp │ │ ├── configures.py │ │ ├── example.py │ │ └── files.py │ ├── tps │ ├── __init__.py │ └── tp0.py │ ├── util.py │ ├── writers │ ├── __init__.py │ ├── base_writer.py │ ├── java_writer.py │ ├── json_writer.py │ ├── lua_writer.py │ └── py_writer.py │ └── xlsconfig.py ├── game-db ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── snowcattle │ │ │ └── game │ │ │ └── db │ │ │ ├── common │ │ │ ├── DbServiceName.java │ │ │ ├── GlobalConstants.java │ │ │ ├── Loggers.java │ │ │ ├── annotation │ │ │ │ ├── AsyncEntityOperation.java │ │ │ │ ├── DbMapper.java │ │ │ │ ├── DbOperation.java │ │ │ │ ├── EntitySave.java │ │ │ │ ├── FieldSave.java │ │ │ │ └── MethodSaveProxy.java │ │ │ └── enums │ │ │ │ └── DbOperationEnum.java │ │ │ ├── entity │ │ │ ├── AbstractEntity.java │ │ │ ├── BaseLongIDEntity.java │ │ │ ├── BaseStringIDEntity.java │ │ │ ├── IEntity.java │ │ │ └── ISoftDeleteEntity.java │ │ │ ├── service │ │ │ ├── async │ │ │ │ ├── AsyncDbOperationCenter.java │ │ │ │ ├── AsyncDbRegisterCenter.java │ │ │ │ ├── AsyncEntityWrapper.java │ │ │ │ ├── thread │ │ │ │ │ ├── AsyncDbOperation.java │ │ │ │ │ └── AsyncDbOperationMonitor.java │ │ │ │ └── transaction │ │ │ │ │ ├── entity │ │ │ │ │ └── AsyncDBSaveTransactionEntity.java │ │ │ │ │ └── factory │ │ │ │ │ ├── DbGameTransactionCauseFactory.java │ │ │ │ │ ├── DbGameTransactionEntityCauseFactory.java │ │ │ │ │ ├── DbGameTransactionEntityFactory.java │ │ │ │ │ └── DbGameTransactionKeyFactory.java │ │ │ ├── common │ │ │ │ ├── service │ │ │ │ │ └── IDbService.java │ │ │ │ └── uuid │ │ │ │ │ ├── IUUIDService.java │ │ │ │ │ └── SnowFlakeUUIDService.java │ │ │ ├── config │ │ │ │ └── DbConfig.java │ │ │ ├── entity │ │ │ │ ├── AsyncOperationRegistry.java │ │ │ │ ├── EntityKeyShardingStrategyEnum.java │ │ │ │ ├── EntityService.java │ │ │ │ └── IEntityService.java │ │ │ ├── jdbc │ │ │ │ └── mapper │ │ │ │ │ └── IDBMapper.java │ │ │ ├── proxy │ │ │ │ ├── EntityAysncServiceProxy.java │ │ │ │ ├── EntityAysncServiceProxyFactory.java │ │ │ │ ├── EntityProxy.java │ │ │ │ ├── EntityProxyFactory.java │ │ │ │ ├── EntityProxyWrapper.java │ │ │ │ ├── EntityServiceProxy.java │ │ │ │ └── EntityServiceProxyFactory.java │ │ │ └── redis │ │ │ │ ├── AsyncRedisKeyEnum.java │ │ │ │ ├── AsyncSave.java │ │ │ │ ├── RedisInterface.java │ │ │ │ ├── RedisKeyEnum.java │ │ │ │ ├── RedisListInterface.java │ │ │ │ ├── RedisPageInterface.java │ │ │ │ └── RedisService.java │ │ │ ├── sharding │ │ │ ├── AbstractShardingTable.java │ │ │ ├── CustomerContextHolder.java │ │ │ ├── DataSourceType.java │ │ │ ├── DynamicDataSource.java │ │ │ ├── EntityServiceShardingStrategy.java │ │ │ └── ShardingTable.java │ │ │ └── util │ │ │ ├── EntityUtils.java │ │ │ └── PageUtils.java │ └── resources │ │ ├── bean │ │ ├── db-applicationContext-redis.xml │ │ ├── db_applicationContext.xml │ │ └── db_applicationContext_datasource.xml │ │ ├── db_jdbc.properties │ │ ├── log4j.properties │ │ └── mybatis3 │ │ ├── mappers │ │ └── orderMapper.xml │ │ └── sqlMapConfig.xml │ └── test │ ├── java │ └── com │ │ └── snowcattle │ │ └── game │ │ └── db │ │ └── service │ │ ├── common │ │ ├── aop │ │ │ ├── AOPTest.java │ │ │ ├── MyInterceptor.java │ │ │ ├── Person.java │ │ │ ├── PersonService.java │ │ │ └── PersonServiceBean.java │ │ ├── cache │ │ │ ├── ObjectTest.java │ │ │ └── redisTest.java │ │ ├── cglib │ │ │ ├── CglibProxy.java │ │ │ ├── DoCGLib.java │ │ │ └── SayHello.java │ │ ├── entity │ │ │ ├── ProxyTest.java │ │ │ └── TestEntity.java │ │ ├── fastjson │ │ │ ├── Status.java │ │ │ ├── StatusDeserializer.java │ │ │ ├── Test.java │ │ │ └── map │ │ │ │ ├── Bar.java │ │ │ │ ├── Foo.java │ │ │ │ └── Test.java │ │ ├── redis │ │ │ ├── RedisPop.java │ │ │ ├── RedisPush.java │ │ │ └── Test.java │ │ ├── uuid │ │ │ ├── Snowflake.java │ │ │ ├── SnowflakeIdWorker.java │ │ │ └── SnowflakeTest.java │ │ └── wrapper │ │ │ └── TestWrapper.java │ │ └── jdbc │ │ ├── entity │ │ ├── MoreOrder.java │ │ ├── Order.java │ │ └── Tocken.java │ │ ├── mapper │ │ ├── MoreOrderMapper.java │ │ ├── OrderMapper.java │ │ └── TockenMapper.java │ │ ├── service │ │ ├── entity │ │ │ ├── IMoreOrderService.java │ │ │ ├── IOrderService.java │ │ │ ├── ITockenService.java │ │ │ └── impl │ │ │ │ ├── MoreOrderService.java │ │ │ │ ├── OrderService.java │ │ │ │ └── TockenService.java │ │ └── operation │ │ │ └── OrderServiceOperation.java │ │ └── test │ │ ├── TestConstants.java │ │ ├── longEntity │ │ ├── onetomore │ │ │ ├── JdbcAsyncCacheTest.java │ │ │ ├── JdbcCacheTest.java │ │ │ └── JdbcTest.java │ │ └── onetoone │ │ │ ├── JdbcAsyncCacheTest.java │ │ │ ├── JdbcCacheTest.java │ │ │ └── JdbcTest.java │ │ ├── stringEntity │ │ └── onetoone │ │ │ ├── JdbcAsyncCacheTest.java │ │ │ ├── JdbcCacheTest.java │ │ │ └── JdbcTest.java │ │ └── tps │ │ ├── mutilthread │ │ ├── SaveRunable.java │ │ ├── async │ │ │ └── AsyncCacheTest.java │ │ └── sync │ │ │ ├── CacheTest.java │ │ │ └── NoCacheTest.java │ │ └── singleThread │ │ ├── JdbcBatchOriginTest.java │ │ └── JdbcTest.java │ └── resources │ ├── bean │ ├── db-applicationContext-redis.xml │ ├── db_applicationContext.xml │ └── db_applicationContext_datasource.xml │ ├── db_jdbc.properties │ ├── log4j.properties │ ├── mybatis3 │ ├── mappers │ │ ├── moreOrderMapper.xml │ │ ├── orderMapper.xml │ │ └── tockenMapper.xml │ └── sqlMapConfig.xml │ └── sql │ └── init.sql ├── game-executor ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── snowcattle │ │ │ └── game │ │ │ └── executor │ │ │ ├── common │ │ │ ├── UpdateExecutorEnum.java │ │ │ └── utils │ │ │ │ ├── CommonErrorInfo.java │ │ │ │ ├── Constants.java │ │ │ │ ├── Loggers.java │ │ │ │ └── SystemPropertyUtil.java │ │ │ ├── event │ │ │ ├── AbstractEvent.java │ │ │ ├── AbstractEventListener.java │ │ │ ├── CycleEvent.java │ │ │ ├── EventBus.java │ │ │ ├── EventParam.java │ │ │ ├── EventType.java │ │ │ ├── SingleEvent.java │ │ │ ├── common │ │ │ │ ├── IEvent.java │ │ │ │ ├── IEventBus.java │ │ │ │ ├── IEventListener.java │ │ │ │ └── constant │ │ │ │ │ └── EventTypeEnum.java │ │ │ ├── factory │ │ │ │ └── CycleDisruptorEventFactory.java │ │ │ ├── handler │ │ │ │ └── CycleEventHandler.java │ │ │ ├── impl │ │ │ │ ├── event │ │ │ │ │ ├── CreateEvent.java │ │ │ │ │ ├── FinishEvent.java │ │ │ │ │ ├── FinishedEvent.java │ │ │ │ │ ├── ReadFinishEvent.java │ │ │ │ │ ├── ReadyCreateEvent.java │ │ │ │ │ └── UpdateEvent.java │ │ │ │ └── listener │ │ │ │ │ ├── CreateEventListener.java │ │ │ │ │ ├── DispatchCreateEventListener.java │ │ │ │ │ ├── DispatchFinishEventListener.java │ │ │ │ │ ├── DispatchUpdateEventListener.java │ │ │ │ │ ├── FinishEventListener.java │ │ │ │ │ ├── ReadyCreateEventListener.java │ │ │ │ │ ├── ReadyFinishEventListener.java │ │ │ │ │ └── UpdateEventListener.java │ │ │ └── service │ │ │ │ ├── AsyncEventService.java │ │ │ │ └── SingleEventWork.java │ │ │ └── update │ │ │ ├── cache │ │ │ ├── UpdateEventCacheFactory.java │ │ │ ├── UpdateEventCacheService.java │ │ │ └── UpdateEventPoolFactory.java │ │ │ ├── entity │ │ │ ├── AbstractUpdate.java │ │ │ ├── IUpdate.java │ │ │ └── NullWeakUpUpdate.java │ │ │ ├── pool │ │ │ ├── DisruptorExecutorService.java │ │ │ ├── IUpdateExecutor.java │ │ │ ├── UpdateBindExecutorService.java │ │ │ ├── UpdateExecutorService.java │ │ │ └── excutor │ │ │ │ ├── BindThreadUpdateExecutorService.java │ │ │ │ ├── DelegatedExecutorService.java │ │ │ │ ├── EventExecutor.java │ │ │ │ ├── FinalizableDelegatedExecutorService.java │ │ │ │ └── OrderedEventExecutor.java │ │ │ ├── service │ │ │ ├── NotifyTask.java │ │ │ ├── UpdateNotifyService.java │ │ │ └── UpdateService.java │ │ │ └── thread │ │ │ ├── dispatch │ │ │ ├── BindNotifyDisptachThread.java │ │ │ ├── DispatchThread.java │ │ │ ├── DisruptorDispatchThread.java │ │ │ └── LockSupportDisptachThread.java │ │ │ ├── listener │ │ │ └── LockSupportUpdateFutureListener.java │ │ │ └── update │ │ │ ├── LockSupportUpdateFuture.java │ │ │ ├── LockSupportUpdateFutureThread.java │ │ │ ├── UpdateThread.java │ │ │ └── bind │ │ │ ├── AbstractBindingUpdateThread.java │ │ │ └── BindingUpdateThread.java │ └── resources │ │ └── log4j.properties │ └── test │ ├── java │ └── com │ │ └── snowcattle │ │ └── game │ │ └── executor │ │ ├── TestLockSupport.java │ │ ├── common │ │ └── cache │ │ │ └── CacheTest.java │ │ ├── event │ │ ├── aysnc │ │ │ ├── AsyncEventServiceTest.java │ │ │ ├── SingleRunEvent.java │ │ │ ├── SingleRunEventListener.java │ │ │ └── TestConstants.java │ │ └── syns │ │ │ └── SynsEventBusTest.java │ │ └── update │ │ ├── async │ │ ├── AsyncUpdateBusTest.java │ │ ├── IntegerUpdate.java │ │ ├── TestCreateEvent.java │ │ └── TestUpdateEvent.java │ │ ├── asyncnotify │ │ └── AsyncNotifyUpdateTest.java │ │ └── disruptor │ │ └── DisruptorTest.java │ └── resources │ └── log4j.properties ├── pom.xml └── qrcode.png /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *.tar.gz 3 | logs/ 4 | .DS_Store 5 | .idea 6 | *.iml 7 | dist 8 | *.pyc 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NettyGameServer 2 | 3 | - 使用netty4.X实现的手机游戏服务器,支持tcp,udp,http,websocket链接,采用protobuf自定义协议栈进行网络通信,支持rpc远程调用,使用mybatis3支持db存储分库分表,支持异步mysql存储,db保存时同步更新reids缓存。 4 | - 使用ExcelToCode工程,将excel数据生成java类和json数据字典,DictService直接读取json,减少数据字典部分代码。 5 | - 使用game-executor工程,增加游戏内的异步事件全局服务,支持事件sharding,均衡的异步执行事件逻辑 6 | - 使用netty的proxy模式,增加网关代理转发 7 | ## [Wiki/文档](https://github.com/jwpttcg66/NettyGameServer/wiki) 8 | 9 | ## 源码工具链接 10 | - [ExcelToCode 数据字典生成](https://github.com/youlanhai/ExcelToCode) 11 | - [GameShardingDb 游戏数据库](https://github.com/jwpttcg66/GameShardingDb) 12 | - [GameThreadPool 游戏常用线程池](https://github.com/jwpttcg66/GameThreadPool) 13 | - [game-executor 游戏常用循环调度执行器](https://github.com/jwpttcg66/game-executor) 14 | - [GameCodeGenerate 工具(包含新版本数据字典生成)](https://github.com/jwpttcg66/GameCodeGenerate) 15 | - [redis-game-transaction 事务](https://github.com/jwpttcg66/redis-game-transaction) 16 | 17 | #### 贡献源码&合作&交流 18 | 19 | - 作者qq 330258845 20 | - QQ群:310158485(已满) 513178622 21 | 22 | ![avatar](https://github.com/jwpttcg66/NettyGameServer/blob/master/qrcode.png) 23 | -------------------------------------------------------------------------------- /game-code-generate/src/main/java/com/snowcattle/game/message/logicgenerate/enity/CommonPlayer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.message.logicgenerate.enity; 2 | 3 | /** 4 | * 玩家 5 | * 6 | * @author CodeGenerator, don't modify this file please. 7 | */ 8 | 9 | public class CommonPlayer { 10 | /**id*/ 11 | private long id; 12 | /**name*/ 13 | private String name; 14 | 15 | public void setId(long id){ 16 | this.id = id; 17 | } 18 | public long getId(){ 19 | return this.id; 20 | } 21 | public void setName(String name){ 22 | this.name = name; 23 | } 24 | public String getName(){ 25 | return this.name; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /game-code-generate/src/main/java/com/snowcattle/game/service/net/GameMessageCommandIndex.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net; 2 | 3 | /** 4 | * Created by jiangwenping on 17/5/8. 5 | * 消息协议号索引 6 | */ 7 | public final class GameMessageCommandIndex { 8 | public static final int ONLINE_HEART_CLIENT_TCP_MESSAGE = 1001; 9 | public static final int COMMON_RESPONSE_MESSAGE = 1002; 10 | public static final int COMMON_ERROR_RESPONSE_MESSAGE = 1003; 11 | public static final int HTTP_HEART_CLIENT_MESSAGE = 1004; 12 | 13 | private GameMessageCommandIndex() { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-code-generate/src/main/java/com/snowcattle/game/template/utils/FileConentFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.template.utils; 2 | 3 | public interface FileConentFactory { 4 | FileContent create(String fileName, String content, String filePath); 5 | } 6 | -------------------------------------------------------------------------------- /game-code-generate/src/main/java/com/snowcattle/game/template/utils/FileContent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.template.utils; 2 | 3 | 4 | public class FileContent { 5 | private String fileName; 6 | private String content; 7 | private String filePath; 8 | 9 | public String getFileName() { 10 | return fileName; 11 | } 12 | public void setFileName(String fileName) { 13 | this.fileName = fileName; 14 | } 15 | public String getContent() { 16 | return content; 17 | } 18 | public void setContent(String content) { 19 | this.content = content; 20 | } 21 | public String getFilePath() { 22 | return filePath; 23 | } 24 | public void setFilePath(String filePath) { 25 | this.filePath = filePath; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /game-code-generate/src/main/java/com/snowcattle/game/template/utils/FileContentFactoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.template.utils; 2 | 3 | public class FileContentFactoryImpl implements FileConentFactory { 4 | @Override 5 | public FileContent create(String fileName, String content, String filePath) { 6 | FileContent fileContent = new FileContent(); 7 | fileContent.setFileName(fileName); 8 | fileContent.setContent(content); 9 | fileContent.setFilePath(filePath); 10 | return fileContent; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /game-code-generate/src/main/java/com/snowcattle/game/template/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.template.utils; 2 | 3 | 4 | import java.io.File; 5 | import java.io.FileWriter; 6 | import java.io.IOException; 7 | 8 | public final class FileUtils{ 9 | private FileUtils() { 10 | } 11 | 12 | public static void writeToFile(FileContent fileContent) throws IOException{ 13 | File file = new File(fileContent.getFilePath()+fileContent.getFileName()); 14 | if(!file.exists()){ 15 | File folder = file.getParentFile(); 16 | if(!folder.exists()){ 17 | folder.mkdirs(); 18 | } 19 | file.createNewFile(); 20 | }else{ 21 | file.delete(); 22 | file.createNewFile(); 23 | } 24 | System.out.println(file.getAbsolutePath()); 25 | FileWriter writer = new FileWriter(file); 26 | writer.write(fileContent.getContent()); 27 | writer.flush(); 28 | writer.close(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /game-code-generate/src/main/resources/config/model/http_client.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /game-code-generate/src/main/resources/config/model/macros.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /game-code-generate/src/main/resources/config/model/room_client.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /game-code-generate/src/main/resources/proto/common.proto: -------------------------------------------------------------------------------- 1 | option java_package = "com.snowcattle.game.message.protogenerate.common"; 2 | option java_outer_classname = "GameCommonMessageProBuf"; 3 | 4 | message CommonPlayerProBuf 5 | { 6 | required int64 playerId = 1; 7 | required string name = 2; 8 | } 9 | 10 | message CommonRoomPlayerProBuf 11 | { 12 | required int64 playerId = 1; 13 | required string name = 2; 14 | required int32 charaId = 3; 15 | } 16 | 17 | message Vector3ProBuf 18 | { 19 | required float x = 1; 20 | required float y = 2; 21 | required float z = 3; 22 | } 23 | 24 | message Vector4ProBuf 25 | { 26 | required float x = 1; 27 | required float y = 2; 28 | required float z = 3; 29 | required float w = 4; 30 | } 31 | 32 | message GameEndSinglePlayerProBuf{ 33 | required int32 camp = 1; 34 | required int32 score = 2; 35 | } 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /game-code-generate/src/main/resources/proto/http_client.proto: -------------------------------------------------------------------------------- 1 | option java_package = "com.snowcattle.game.message.protogenerate.http.room.client"; 2 | option java_outer_classname = "GameRoomHttpClientProBuf"; 3 | 4 | import "common.proto"; 5 | 6 | /*心跳协议*/ 7 | message RoomHeartHttpClientProBuf 8 | { 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /game-code-generate/src/main/resources/proto/mac/back.txt: -------------------------------------------------------------------------------- 1 | sudo protoc -I=/Users/jiangwenping/data/wolf-shoot-server-workspace/NettyGameServer/game-code-generate/src/main/resources/proto/ --java_out=/Users/jiangwenping/data/wolf-shoot-server-workspace/NettyGameServer/game-code-generate/src/main/java /Users/jiangwenping/data/wolf-shoot-server-workspace/NettyGameServer/game-code-generate/src/main/resources/proto/*.proto -------------------------------------------------------------------------------- /game-code-generate/src/main/resources/proto/tcproom-client.proto: -------------------------------------------------------------------------------- 1 | option java_package = "com.snowcattle.game.message.protogenerate.tcp.room.client"; 2 | option java_outer_classname = "GameRoomTCPClientProBuf"; 3 | 4 | import "common.proto"; 5 | 6 | /*心跳协议*/ 7 | message RoomHeartTCPClientProBuf 8 | { 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /game-code-generate/src/main/resources/proto/windows/back.txt: -------------------------------------------------------------------------------- 1 | 2 | C:\Users\B053-mac\Desktop\windws\server\proto\windows>protoc.exe -I C:\Users\B053-mac\Desktop\windws\server\proto --java_out=C:\Users\B053-mac\Desktop\windws\server\src C:\Users\B053-mac\Desktop\windws\server\proto\map.proto 3 | 4 | sudo protoc -I=/Users/b053-mac/data/IDEA-clover-200-workspace/game_server/proto/ --java_out=/Users/b053-mac/data/IDEA-clover-200-workspace/game_server/src /Users/b053-mac/data/IDEA-clover-200-workspace/game_server/proto/room.proto 5 | 6 | sudo protoc -I=/Users/jwp/data/wolfshoot-workspace/Server-Code/proto/ --java_out=/Users/jwp/data/wolfshoot-workspace/Server-Code/src/main/java /Users/jwp/data/wolfshoot-workspace/Server-Code/proto/common.proto -------------------------------------------------------------------------------- /game-code-generate/src/main/resources/proto/windows/protoc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwpttcg66/NettyGameServer/6ef370c1116bdc617578d496d5d0a578da736084/game-code-generate/src/main/resources/proto/windows/protoc.exe -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/IUpdatable.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common; 2 | 3 | /** 4 | * Created by jwp on 2017/2/9. 5 | * 游戏的update接口 6 | */ 7 | public interface IUpdatable { 8 | public boolean update(); 9 | } 10 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/AsyncOper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 11 | * 异步操作 12 | * 13 | * 14 | * 15 | */ 16 | @Documented 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target(ElementType.METHOD) 19 | public @interface AsyncOper { 20 | } 21 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/AsyncThreadOper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 11 | * 在异步线程中的操作 12 | * 13 | * 14 | * @see {@link MainThreadOper} 15 | * 16 | */ 17 | @Documented 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Target(ElementType.METHOD) 20 | public @interface AsyncThreadOper { 21 | } 22 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/BlockingQueueType.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | /** 4 | * Created by jwp on 2017/3/8. 5 | */ 6 | public enum BlockingQueueType { 7 | LINKED_BLOCKING_QUEUE("LinkedBlockingQueue"), 8 | ARRAY_BLOCKING_QUEUE("ArrayBlockingQueue"), 9 | SYNCHRONOUS_QUEUE("SynchronousQueue"); 10 | 11 | private final String value; 12 | 13 | private BlockingQueueType(String value) { 14 | this.value = value; 15 | } 16 | 17 | public String getValue() { 18 | return value; 19 | } 20 | 21 | public static BlockingQueueType fromString(String value) { 22 | for (BlockingQueueType type : BlockingQueueType.values()) { 23 | if (type.getValue().equalsIgnoreCase(value.trim())) { 24 | return type; 25 | } 26 | } 27 | 28 | throw new IllegalArgumentException("Mismatched type with value=" + value); 29 | } 30 | 31 | public String toString() { 32 | return value; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/Comment.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 注释 10 | * 11 | * 12 | * 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target({ElementType.FIELD,ElementType.TYPE}) 16 | public @interface Comment { 17 | 18 | /** 19 | * 注释内容 20 | */ 21 | String content(); 22 | } 23 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/GlobalEventListenerAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * Created by jiangwenping on 2017/5/22. 9 | * 全局事件监听器注解 10 | */ 11 | @Target(ElementType.TYPE) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Component 14 | public @interface GlobalEventListenerAnnotation { 15 | } -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/IDictAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Created by jiangwenping on 17/5/9. 7 | */ 8 | @Documented 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target(ElementType.METHOD) 11 | public @interface IDictAnnotation { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/MainThreadOper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 11 | * 在主线程中的操作 12 | * 13 | * 14 | * @see {@link AsyncThreadOper} 15 | * 16 | */ 17 | @Documented 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Target(ElementType.METHOD) 20 | public @interface MainThreadOper { 21 | } 22 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/MessageCommandAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Documented 10 | public @interface MessageCommandAnnotation { 11 | /** 12 | * @return 13 | */ 14 | int command(); 15 | } 16 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/NotThreadSafe.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 线程不安全的实现 11 | * 12 | * 13 | * 14 | */ 15 | @Documented 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target({ ElementType.METHOD, ElementType.TYPE }) 18 | public @interface NotThreadSafe { 19 | } 20 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/RpcServiceAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * Created by jwp on 2017/3/7. 12 | */ 13 | @Target(ElementType.TYPE) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Component 16 | public @interface RpcServiceAnnotation { 17 | Class value(); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/RpcServiceBoEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import com.snowcattle.game.common.enums.BOEnum; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | /** 12 | * Created by jiangwenping on 17/4/26. 13 | */ 14 | @Target(ElementType.TYPE) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Component 17 | public @interface RpcServiceBoEnum { 18 | BOEnum bo(); 19 | } 20 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/SpecialEventListenerAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | *特殊事件监听器 12 | */ 13 | @Target(ElementType.TYPE) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Component 16 | public @interface SpecialEventListenerAnnotation { 17 | int listener(); 18 | } 19 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/SyncIoOper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 同步操作 11 | * 12 | * 13 | * 14 | */ 15 | @Documented 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target(ElementType.METHOD) 18 | public @interface SyncIoOper { 19 | } 20 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/SyncOper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 同步操作 11 | * 12 | * 13 | * 14 | */ 15 | @Documented 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target(ElementType.METHOD) 18 | public @interface SyncOper { 19 | } 20 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/annotation/SysI18nString.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 系统提示用多语言 10 | * 11 | * 12 | * 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target(ElementType.FIELD) 16 | public @interface SysI18nString { 17 | /** 18 | * 多语言内容 19 | */ 20 | String content(); 21 | 22 | /** 23 | * 多语言参数注释 24 | */ 25 | String comment() default ""; 26 | } 27 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/config/Config.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.config; 2 | 3 | /** 4 | * 配置接口,用于提供系统配置内容 5 | * 6 | * 7 | */ 8 | public interface Config { 9 | /** 10 | * 取得系统配置的版本号,该版本号不代表程序的真实版本号,只是声明的版本号 11 | */ 12 | public abstract String getVersion(); 13 | 14 | /** 15 | * 校验配置参数是否符合有效 16 | * 17 | * @exception IllegalArgumentException 18 | * 如果有参数配置错误,会抛出此异常 19 | */ 20 | public abstract void validate(); 21 | 22 | /** 23 | * 是否是调试模式 24 | * 25 | * @return 26 | */ 27 | public boolean getIsDebug(); 28 | 29 | } -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/config/GameConfigurable.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.config; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/22. 5 | */ 6 | public interface GameConfigurable { 7 | public String getProperty(String key, String defaultVal); 8 | public int getProperty(String key, int defaultVal); 9 | public boolean getProperty(String key, boolean defaultVal); 10 | public long getProperty(String key, long defaultVal); 11 | } -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/config/GameDynamicPropertiesConfig.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.config; 2 | 3 | 4 | /** 5 | * @author jwp 6 | * 游戏动态配置 7 | */ 8 | public class GameDynamicPropertiesConfig extends AbstractGameConfigure { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/config/IGameConfig.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.config; 2 | 3 | /** 4 | * @author b053-mac 5 | * 游戏配置 6 | */ 7 | public interface IGameConfig { 8 | 9 | public void loadConfig(String filePath) throws Exception ; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/config/ZooKeeperConfig.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.config; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/30. 5 | * zookeeper配置服务 6 | */ 7 | public class ZooKeeperConfig extends AbstractGameConfigure { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/constant/DynamicPropertiesEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.constant; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/22. 5 | * 动态属性 6 | */ 7 | public enum DynamicPropertiesEnum { 8 | udp_message_tocken_check_flag, 9 | ; 10 | } 11 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/constant/SymbolConstants.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.constant; 2 | 3 | /** 4 | * Created by jiangwenping on 2017/6/6. 5 | * 常用符号 6 | */ 7 | public final class SymbolConstants { 8 | public static final String SEMICOLON=";";//分号 9 | public static final String SEMICOLON_REG=";|;";//分号 10 | public static final String COLON=":";//冒号 11 | public static final String COLON_REG=":|:";//冒号 12 | public static final String COMMA=","; 13 | public static final String COMMA_REG=",|,"; 14 | public static final String XIEGANG_REG="/"; 15 | public static final String SHUXIAN_REG="|"; 16 | public static final String UNDERLINE_REG="_"; 17 | public static final String JINGHAO_REG="#"; 18 | public static final String AT_REG="@"; 19 | 20 | private SymbolConstants() { 21 | } 22 | } -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/enums/BOEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.enums; 2 | 3 | /** 4 | * @author C172 5 | * BO 服务器对象类型 6 | */ 7 | public enum BOEnum { 8 | 9 | //网关 10 | PROXY(1), 11 | //世界 12 | WORLD(2), 13 | //游戏 14 | GAME(3), 15 | //db 16 | DB(4), 17 | ; 18 | private int boId; 19 | 20 | BOEnum(int boId) { 21 | this.boId = boId; 22 | } 23 | 24 | public int getBoId() { 25 | return boId; 26 | } 27 | 28 | public void setBoId(int boId) { 29 | this.boId = boId; 30 | } 31 | } -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/enums/DeliveryGuarantyOption.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.enums; 2 | 3 | /** 4 | * Created by jwp on 2017/2/9. 5 | */ 6 | public enum DeliveryGuarantyOption 7 | { 8 | /** 9 | * socket 10 | */ 11 | RELIABLE(0), 12 | /** 13 | * udp 14 | */ 15 | FAST(1); 16 | final int guaranty; 17 | 18 | DeliveryGuarantyOption(int guaranty) 19 | { 20 | this.guaranty = guaranty; 21 | } 22 | 23 | public int getGuaranty(){ 24 | return guaranty; 25 | } 26 | } -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/enums/NetTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.enums; 2 | 3 | /** 4 | * Created by jiangwenping on 2017/7/3. 5 | * 网络类型 6 | */ 7 | public enum NetTypeEnum { 8 | HTTP, 9 | WEBSOCKET, 10 | TCP, 11 | UDP 12 | ; 13 | } 14 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/CacheConfigException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | /** 4 | * 初始化cache 5 | * 6 | */ 7 | public class CacheConfigException extends ConfigException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | /** 12 | * 13 | * @param cacheName cache名称 14 | * @param errorInfo 错误 15 | */ 16 | public CacheConfigException(String cacheName, 17 | String errorInfo) { 18 | super(String.format("[%s]%s", cacheName , errorInfo)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/CodecException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/8. 5 | */ 6 | public class CodecException extends Exception { 7 | private static final long serialVersionUID = 1L; 8 | 9 | public CodecException(String name){ 10 | super(name); 11 | } 12 | public CodecException(String name,Throwable t){ 13 | super(name,t); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/ConfigException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | /** 4 | * 适用于读取配置文件时产生的异常 5 | * 6 | */ 7 | public class ConfigException extends RuntimeException { 8 | /** */ 9 | private static final long serialVersionUID = 1L; 10 | 11 | public ConfigException(String msg) { 12 | super(msg); 13 | } 14 | 15 | public ConfigException(Exception e) { 16 | super(e); 17 | } 18 | 19 | public ConfigException(String msg, Exception e) { 20 | super(msg, e); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/GameHandlerException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | /** 4 | * @author C172 5 | * 游戏处理错误 6 | */ 7 | public class GameHandlerException extends Exception { 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | public static final int COMMON_ERROR_STATE = 6000; 12 | public static final int COMMON_ERROR_MAX_CONNECT_TCP_SESSION_NUMBER = 6001; 13 | private int serial; 14 | 15 | public GameHandlerException(String name){ 16 | super(name); 17 | } 18 | public GameHandlerException(String name,Throwable t){ 19 | super(name,t); 20 | } 21 | 22 | public GameHandlerException(Exception e){ 23 | super(e); 24 | } 25 | 26 | public GameHandlerException(Exception e, int serial){ 27 | super(e); 28 | this.serial = serial; 29 | } 30 | 31 | public int getSerial() { 32 | return serial; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/GameInvalidLogicException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | 4 | /** 5 | * 不合法的逻辑异常,用于程序的逻辑判断时处理不应该发生的情况。 6 | * 当非法情况发生时,应该可以清晰的记录异常的详细信息,所以构造函数必须提供详细的异常描述。 7 | */ 8 | public final class GameInvalidLogicException extends Exception { 9 | 10 | /** */ 11 | private static final long serialVersionUID = 552982663377276317L; 12 | 13 | /** 14 | * 构造一个不合法的逻辑异常。 15 | * @param message 异常的详细描述。 16 | */ 17 | public GameInvalidLogicException(String message) { 18 | super(message); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/IServerServiceException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | /** 4 | * 当服务处理失败的时候抛出该异常 5 | */ 6 | public class IServerServiceException extends Exception { 7 | 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1L; 12 | 13 | public IServerServiceException(String name){ 14 | super(name); 15 | } 16 | public IServerServiceException(String name,Throwable t){ 17 | super(name,t); 18 | } 19 | } -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/NetMessageException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | /** 4 | * Created by jwp on 2017/2/9. 5 | * 网络消息发送异常 6 | */ 7 | public class NetMessageException extends Exception { 8 | private static final long serialVersionUID = 1L; 9 | 10 | public NetMessageException(String name){ 11 | super(name); 12 | } 13 | public NetMessageException(String name, Throwable t){ 14 | super(name,t); 15 | } 16 | 17 | public NetMessageException(Throwable t){ 18 | super(t); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/NoEnoughValueException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | public class NoEnoughValueException extends Exception { 4 | 5 | private static final long serialVersionUID = 8289893876272871973L; 6 | 7 | public NoEnoughValueException() { 8 | } 9 | 10 | public NoEnoughValueException(String message) { 11 | super(message); 12 | } 13 | 14 | public NoEnoughValueException(Throwable cause) { 15 | super(cause); 16 | } 17 | 18 | public NoEnoughValueException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/StartUpException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/13. 5 | */ 6 | public class StartUpException extends Exception{ 7 | /** 8 | * 9 | */ 10 | private static final long serialVersionUID = 1L; 11 | 12 | public StartUpException(String name){ 13 | super(name); 14 | } 15 | public StartUpException(String name,Throwable t){ 16 | super(name,t); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/TransactionException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | public class TransactionException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = -7019206205634720119L; 6 | 7 | public TransactionException(){ 8 | super(); 9 | } 10 | 11 | public TransactionException(String msg){ 12 | super(msg); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/exception/ValueLimitException.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.exception; 2 | 3 | public class ValueLimitException extends Exception { 4 | 5 | private static final long serialVersionUID = 9133877059467765978L; 6 | } 7 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/scanner/ClassScanner.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.scanner; 2 | 3 | 4 | /** 5 | * @author C172 6 | * 消息扫描器 7 | */ 8 | public class ClassScanner { 9 | public String[] scannerPackage(String namespace, String ext) throws Exception 10 | { 11 | String[] files = new PackageScaner().scanNamespaceFiles(namespace, ext, false, true); 12 | return files; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/BeanUtil.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by jiangwenping on 17/3/1. 10 | */ 11 | @Service 12 | public class BeanUtil implements ApplicationContextAware { 13 | 14 | private static ApplicationContext ctx; 15 | @Override 16 | public void setApplicationContext(ApplicationContext arg0)throws BeansException { 17 | ctx = arg0; 18 | } 19 | 20 | public static Object getBean(String beanName) { 21 | if(ctx == null){ 22 | throw new NullPointerException(); 23 | } 24 | return ctx.getBean(beanName); 25 | } 26 | 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/IKeyWordsFilter.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | /** 4 | * 关键词过滤接口 5 | * 6 | * 7 | */ 8 | public interface IKeyWordsFilter { 9 | 10 | /** 11 | * 使用关键字列表进行初始化 12 | * 13 | * @param keyWords 14 | * 关键字列表 15 | * @return 是否初始化成功,成功true,否则false 16 | */ 17 | public abstract boolean initialize(String[] keyWords); 18 | 19 | /** 20 | * 过滤关键词 21 | * 22 | * @param s 23 | * 要被处理的字符串 24 | * @return 处理完毕的被过滤的字符串 25 | */ 26 | public abstract String filt(String s); 27 | 28 | /** 29 | * 检测输入的消息是否有关键字 30 | * 31 | * @param inputMsg 32 | * 要检测的消息 33 | * @return 若有返回true,否则false 34 | */ 35 | public abstract boolean contain(String inputMsg); 36 | 37 | } -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/IOUtils.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | import java.io.DataOutput; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | public final class IOUtils { 8 | private IOUtils() { 9 | } 10 | 11 | public static void writeLengthString(DataOutput dout, String content, 12 | String charset) throws IOException { 13 | if (content == null) { 14 | content = ""; 15 | } 16 | byte[] buf = content.getBytes(charset); 17 | dout.writeShort(buf.length); 18 | dout.write(buf); 19 | } 20 | 21 | /** 22 | * 关闭输入流,并忽略任何异常 23 | * @param in 24 | */ 25 | public static void closeInputStream(InputStream in) { 26 | if (in != null) { 27 | try { 28 | in.close(); 29 | } catch (Exception ignore) { 30 | } 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/IntStringPair.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | public class IntStringPair { 4 | 5 | private int key; 6 | private String value; 7 | 8 | public IntStringPair(int key,String value){ 9 | this.key = key; 10 | this.value = value; 11 | } 12 | 13 | public int getKey() { 14 | return key; 15 | } 16 | 17 | public void setKey(int key) { 18 | this.key = key; 19 | } 20 | 21 | public String getValue() { 22 | return value; 23 | } 24 | 25 | public void setValue(String value) { 26 | this.value = value; 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/JsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | 4 | import com.alibaba.fastjson.JSON; 5 | import com.alibaba.fastjson.JSONException; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * Created by jwp on 2017/2/28. 11 | */ 12 | public final class JsonUtils { 13 | 14 | private JsonUtils() { 15 | } 16 | 17 | /** 18 | * 获取json字符串 19 | * @param map 20 | * @return 21 | */ 22 | public static String getJsonStr(Map map){ 23 | return JSON.toJSONString(map); 24 | } 25 | 26 | @SuppressWarnings("unchecked") 27 | public static Map getMapFromJson(String json) throws JSONException{ 28 | return JSON.parseObject(json, Map.class); 29 | } 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/KeyUtil.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | import java.util.UUID; 4 | 5 | /** 6 | * 产生各种key的工具类 7 | * 8 | * 9 | * 10 | */ 11 | public final class KeyUtil { 12 | /** Key的长度 */ 13 | public static final int KEY_LEN = 32; 14 | 15 | private KeyUtil() { 16 | } 17 | 18 | /** 19 | * 产生一个UUID的Key 20 | * 21 | * @return 22 | */ 23 | public static String UUIDKey() { 24 | return toShortKey(genUUIDKey()); 25 | } 26 | 27 | /** 28 | * 生成UUID字符串 29 | * 30 | * @return 31 | */ 32 | static String genUUIDKey() { 33 | return UUID.randomUUID().toString(); 34 | } 35 | 36 | /** 37 | * 去掉UUID的字符串中的"-"符号,以取得较短的key值 38 | * 39 | * @param key 40 | * @return 41 | */ 42 | static String toShortKey(String key) { 43 | return key.substring(0, 8) + key.substring(9, 13) + key.substring(14, 18) + key.subSequence(19, 23) 44 | + key.substring(24); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/MemUtils.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | public final class MemUtils { 4 | 5 | private MemUtils() { 6 | } 7 | 8 | public static long getUsedMemoryMB() { 9 | return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024; 10 | } 11 | 12 | public static long getFreeMemoryMB() { 13 | return (Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory()) / 1048576; 14 | } 15 | 16 | public static long getTotalMemoryMB() { 17 | return Runtime.getRuntime().maxMemory() / 1048576; 18 | } 19 | 20 | public static String memoryInfo() { 21 | long freeMem = getFreeMemoryMB(); 22 | long totalMem = getTotalMemoryMB(); 23 | return "Free memory " + freeMem + " Mb of " + totalMem + " Mb"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/Range.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | 4 | public class Range> { 5 | 6 | private T min; 7 | 8 | private T max; 9 | 10 | private Range(){ 11 | } 12 | 13 | public Range(T min, T max){ 14 | this(); 15 | setMin(min); 16 | setMax(max); 17 | } 18 | 19 | public T getMin() { 20 | return min; 21 | } 22 | 23 | public void setMin(T min) { 24 | this.min = min; 25 | } 26 | 27 | public T getMax() { 28 | return max; 29 | } 30 | 31 | public void setMax(T max) { 32 | this.max = max; 33 | } 34 | 35 | 36 | /** 37 | * 若value -> [min, max)返回true 38 | */ 39 | public boolean contains(T value){ 40 | return value.compareTo(min) >= 0 && value.compareTo(max) < 0; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/ResourcePathUtil.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | public final class ResourcePathUtil { 4 | 5 | private ResourcePathUtil() { 6 | } 7 | 8 | /** 9 | * 在指定资源路径找到给定资源文件,并返回资源文件的完整路径 10 | * 查找顺序如下 11 | * 1. 查找目标.jar的压缩包内路径 12 | * 2. 在程序的启动目录查找 13 | * @param resourceFileName 14 | * @return 15 | */ 16 | public static String getRootPathWithoutSlash(String resourceFileName){ 17 | try{ 18 | String result = ResourcePathUtil.class.getResource('/' + resourceFileName).getPath(); 19 | return result; 20 | } 21 | catch(Exception e){ 22 | return System.getProperty("user.dir") + '/' + resourceFileName; 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/common/util/TimeMonitor.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | import com.snowcattle.game.common.constant.Loggers; 4 | import org.slf4j.Logger; 5 | 6 | /** 7 | * 时间监测器,用于调试过程 8 | * 9 | * 10 | */ 11 | public class TimeMonitor { 12 | private final Logger logger = Loggers.timeMonitorLogger; 13 | private final boolean isDebug; 14 | public static final TimeMonitor DEBUG = new TimeMonitor(true); 15 | 16 | private long start = 0; 17 | 18 | public TimeMonitor(boolean isDebug) { 19 | this.isDebug = isDebug; 20 | } 21 | 22 | public void _s() { 23 | if (isDebug) { 24 | start = System.currentTimeMillis(); 25 | } 26 | } 27 | 28 | public void _e(String p) { 29 | if (isDebug) { 30 | long e = System.currentTimeMillis(); 31 | if(logger.isDebugEnabled()) { 32 | logger.debug(p + " time:" + (e - start) + "ms"); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /game-common/src/main/java/com/snowcattle/game/service/json/JsonSerializer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.json; 2 | 3 | /** 4 | * 将对象中的数据转化成json格式字符串的转化器 5 | */ 6 | public interface JsonSerializer { 7 | 8 | /** 9 | * 序列化 10 | * 将obj对象中的相关数据取出,串行化为json字符串 11 | * @return 12 | */ 13 | String serialize(); 14 | 15 | /** 16 | * 反序列化 17 | * 将json字符串里的信息抽取,反馈到对象中 18 | * @param pack 19 | */ 20 | void deserialize(String pack); 21 | } 22 | -------------------------------------------------------------------------------- /game-core/deploy/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #### config 3 | file_end=`date +_v1.0_%Y%m%d_%H%M` 4 | target_path=target 5 | 6 | #### buid 7 | cd ../ 8 | mvn clean package -Dmaven.test.skip=true 9 | 10 | #### tar 11 | mkdir bin/temp 12 | mv ${target_path}/lib bin/temp/ 13 | mv ${target_path}/resource bin/temp/ 14 | cp bin/config/launch.sh bin/temp/ 15 | 16 | cd bin/temp 17 | tar -zcvf netty_game_server${file_end}.tar.gz ./* 18 | mv netty_game_server${file_end}.tar.gz ../ 19 | cd .. 20 | #### clean 21 | rm -rf temp 22 | cd .. 23 | mvn clean 24 | -------------------------------------------------------------------------------- /game-core/deploy/dist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | file_name=$1 4 | mkdir dist 5 | tar -zxvf ${file_name} -C dist 6 | cd dist 7 | sh launch.sh start 8 | -------------------------------------------------------------------------------- /game-core/proto/common.proto: -------------------------------------------------------------------------------- 1 | option java_package = "com.snowcattle.game.message.auto.common"; 2 | option java_outer_classname = "CommonMessageProBuf"; 3 | 4 | message CommonResponseServerProBuf 5 | { 6 | 7 | } 8 | 9 | 10 | message CommonErrorResponseServerProBuf 11 | { 12 | required int32 state = 1; 13 | optional string arg = 2; //错误参数,格式:xx,xxx,xxxx 14 | } 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /game-core/proto/http_client.proto: -------------------------------------------------------------------------------- 1 | option java_package = "com.snowcattle.game.message.auto.http.client"; 2 | option java_outer_classname = "OnlineClientHttpProBuf"; 3 | 4 | import "common.proto"; 5 | 6 | /*心跳协议*/ 7 | message OnlineHeartClientHttpProBuf 8 | { 9 | required int32 id = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /game-core/proto/tcponline-server.proto: -------------------------------------------------------------------------------- 1 | option java_package = "com.snowcattle.game.message.auto.tcp.online.server"; 2 | option java_outer_classname = "OnlineTCPServerProBuf"; 3 | 4 | message OnlineHeartTCPServerProBuf 5 | { 6 | required int64 playerId = 1; 7 | required int32 tocken = 2; 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /game-core/proto/tcponline.proto: -------------------------------------------------------------------------------- 1 | option java_package = "com.snowcattle.game.message.auto.tcp.online.client"; 2 | option java_outer_classname = "OnlineTCPClientProBuf"; 3 | 4 | message OnlineHeartTCPClientProBuf 5 | { 6 | required int32 id = 1; 7 | } 8 | 9 | message OnlineLoginTCPClientProBuf 10 | { 11 | required int32 id = 1; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /game-core/proto/udponline.proto: -------------------------------------------------------------------------------- 1 | option java_package = "com.snowcattle.game.message.auto.udp.online"; 2 | option java_outer_classname = "OnlineUDPProBuf"; 3 | 4 | message OnlineHeartUDPProBuf 5 | { 6 | required int32 id = 1; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /game-core/proto/windows/back.txt: -------------------------------------------------------------------------------- 1 | 2 | C:\Users\B053-mac\Desktop\windws\server\proto\windows>protoc.exe -I C:\Users\B053-mac\Desktop\windws\server\proto --java_out=C:\Users\B053-mac\Desktop\windws\server\src C:\Users\B053-mac\Desktop\windws\server\proto\map.proto 3 | 4 | sudo protoc -I=/Users/b053-mac/data/IDEA-clover-200-workspace/game_server/proto/ --java_out=/Users/b053-mac/data/IDEA-clover-200-workspace/game_server/src /Users/b053-mac/data/IDEA-clover-200-workspace/game_server/proto/room.proto 5 | 6 | sudo protoc -I=/Users/jwp/data/wolfshoot-workspace/Server-Code/proto/ --java_out=/Users/jwp/data/wolfshoot-workspace/Server-Code/src/main/java /Users/jwp/data/wolfshoot-workspace/Server-Code/proto/common.proto -------------------------------------------------------------------------------- /game-core/proto/windows/protoc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwpttcg66/NettyGameServer/6ef370c1116bdc617578d496d5d0a578da736084/game-core/proto/windows/protoc.exe -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/bootstrap/ShutdownHook.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.bootstrap; 2 | 3 | import com.snowcattle.game.common.util.Assert; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | /** 7 | * Created by jiangwenping on 16/11/18. 8 | */ 9 | public class ShutdownHook implements Runnable { 10 | 11 | ClassPathXmlApplicationContext classPathXmlApplicationContext; 12 | 13 | public ShutdownHook(ClassPathXmlApplicationContext classPathXmlApplicationContext) { 14 | Assert.notNull(classPathXmlApplicationContext, "The 'beanfactory' argument must not be null."); 15 | this.classPathXmlApplicationContext = classPathXmlApplicationContext; 16 | } 17 | 18 | public void run() { //重写Runnable中的run方法并在此销毁bean 19 | this.classPathXmlApplicationContext.destroy(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/bootstrap/manager/AbstractGameManager.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.bootstrap.manager; 2 | 3 | /** 4 | * Created by jwp on 2017/5/6. 5 | * 游戏拓展使用 6 | */ 7 | public abstract class AbstractGameManager extends AbstractLocalManager{ 8 | 9 | } 10 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/bootstrap/manager/ILocalManager.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.bootstrap.manager; 2 | 3 | /** 4 | * Created by jwp on 2017/2/4. 5 | */ 6 | public interface ILocalManager { 7 | 8 | public T get(Class clazz); 9 | 10 | public void create(Class clazz, Class inter) throws Exception; 11 | 12 | public void add(Object service, Class inter); 13 | 14 | public void shutdown(); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/logic/player/IPlayer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.logic.player; 2 | 3 | import com.snowcattle.game.service.net.tcp.session.NettyTcpNetMessageSender; 4 | 5 | /** 6 | * Created by jiangwenping on 17/2/20. 7 | */ 8 | public interface IPlayer { 9 | public long getPlayerId(); 10 | public int getPlayerUdpTocken(); 11 | public NettyTcpNetMessageSender getNettyTcpNetMessageSender(); 12 | } 13 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/message/handler/IMessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.message.handler; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | /** 6 | * Created by jiangwenping on 17/2/8. 7 | */ 8 | public interface IMessageHandler { 9 | public Method getMessageHandler(int command); 10 | } 11 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/IServerService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service; 2 | 3 | /** 4 | * Created by jwp on 2017/2/4. 5 | * 服务器启动服务 6 | */ 7 | public interface IServerService { 8 | 9 | public String getServiceId(); 10 | 11 | public boolean initialize(); 12 | 13 | public boolean startService() throws Exception; 14 | public boolean stopService() throws Exception; 15 | 16 | public void release(); 17 | 18 | public byte getState(); 19 | public boolean isRunning(); 20 | } 21 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/IService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service; 2 | 3 | /** 4 | * Created by jwp on 2017/2/4. 5 | * 基础服务 6 | */ 7 | public interface IService { 8 | public String getId(); 9 | public void startup() throws Exception; 10 | public void shutdown() throws Exception; 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/Reloadable.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/7. 5 | * 可重新加载的对象接口 6 | */ 7 | public interface Reloadable { 8 | public void reload() throws Exception ; 9 | } -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/async/AsyncCall.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.async; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/19. 5 | * 异步线程调用 6 | */ 7 | public interface AsyncCall extends Runnable{ 8 | public void call() throws Exception; 9 | } 10 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/async/pool/AsyncThreadPool.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.async.pool; 2 | 3 | import com.snowcattle.game.service.async.AsyncCall; 4 | 5 | import java.util.concurrent.Future; 6 | 7 | /** 8 | * Created by jiangwenping on 17/4/19. 9 | * 异步线程池 10 | */ 11 | public interface AsyncThreadPool { 12 | public Future submit(AsyncCall asyncCall); 13 | } 14 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/dict/DictCollectionEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.dict; 2 | 3 | /** 4 | * Created by jiangwenping on 17/5/9. 5 | * 数据字典集合类型 6 | */ 7 | public enum DictCollectionEnum { 8 | /** 9 | * 唯一 10 | */ 11 | unique, 12 | /** 13 | * 数组 14 | */ 15 | array, 16 | ; 17 | } 18 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/dict/DictMap.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.dict; 2 | 3 | import java.util.Collection; 4 | import java.util.Map; 5 | import java.util.concurrent.ConcurrentHashMap; 6 | 7 | /** 8 | * Created by jiangwenping on 17/5/9. 9 | * map形数据字典,每个唯一 10 | */ 11 | public class DictMap implements IDictCollections{ 12 | 13 | //存放map形数据字典 14 | private final Map dictMap; 15 | 16 | public DictMap(){ 17 | this.dictMap = new ConcurrentHashMap<>(); 18 | } 19 | 20 | public void put(int id, IDict iDict){ 21 | this.dictMap.put(id, iDict); 22 | } 23 | 24 | /** 25 | * 获取数据字典 26 | * @param id 27 | * @return 28 | */ 29 | public IDict getDict(int id){ 30 | return dictMap.get(id); 31 | } 32 | 33 | public Collection getAllDicts(){ 34 | return dictMap.values(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/dict/IDict.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.dict; 2 | 3 | /** 4 | * Created by jiangwenping on 17/5/8. 5 | * 整个数据字典的子类 6 | */ 7 | public interface IDict { 8 | public int getID(); 9 | } 10 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/dict/IDictCollections.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.dict; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * Created by jiangwenping on 17/5/9. 7 | * 数据字典集合 8 | */ 9 | public interface IDictCollections { 10 | /** 11 | * 获取所有数据字典 12 | * @return 13 | */ 14 | public Collection getAllDicts(); 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/event/SingleEventConstants.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.event; 2 | 3 | import com.snowcattle.game.executor.event.EventType; 4 | 5 | /** 6 | * Created by jiangwenping on 2017/5/22. 7 | */ 8 | public final class SingleEventConstants { 9 | public static final EventType singleRunEventType = new EventType(1001); 10 | public static final EventType sessionRegister = new EventType(1002); 11 | public static final EventType sessionUnRegister = new EventType(1003); 12 | 13 | private SingleEventConstants() { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/event/impl/SessionRegisterEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.event.impl; 2 | 3 | import com.snowcattle.game.executor.event.EventParam; 4 | import com.snowcattle.game.executor.event.SingleEvent; 5 | import com.snowcattle.game.service.event.SingleEventConstants; 6 | 7 | /** 8 | * Created by jiangwenping on 2017/5/22. 9 | * 网络链接事件建立 10 | */ 11 | public class SessionRegisterEvent extends SingleEvent{ 12 | 13 | public SessionRegisterEvent(Long eventId, long shardingId, EventParam... parms) { 14 | super(SingleEventConstants.sessionRegister, eventId, shardingId, parms); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/event/impl/SessionUnRegisterEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.event.impl; 2 | 3 | import com.snowcattle.game.executor.event.EventParam; 4 | import com.snowcattle.game.executor.event.SingleEvent; 5 | import com.snowcattle.game.service.event.SingleEventConstants; 6 | 7 | /** 8 | * Created by jiangwenping on 2017/5/22. 9 | * 网络链接断开 10 | */ 11 | public class SessionUnRegisterEvent extends SingleEvent { 12 | public SessionUnRegisterEvent( Long eventId, long shardingId, EventParam... parms) { 13 | super(SingleEventConstants.sessionUnRegister, eventId, shardingId, parms); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/event/impl/SingleRunEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.event.impl; 2 | 3 | import com.snowcattle.game.executor.event.EventParam; 4 | import com.snowcattle.game.executor.event.EventType; 5 | import com.snowcattle.game.executor.event.SingleEvent; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * Created by jiangwenping on 2017/5/22. 11 | */ 12 | public class SingleRunEvent extends SingleEvent { 13 | public SingleRunEvent(EventType eventType, Serializable eventId, long shardingId, EventParam[] parms) { 14 | super(eventType, eventId, shardingId, parms); 15 | } 16 | 17 | private long runId; 18 | 19 | public long getRunId() { 20 | return runId; 21 | } 22 | 23 | public void setRunId(long runId) { 24 | this.runId = runId; 25 | } 26 | 27 | @Override 28 | public void call() { 29 | runId++; 30 | 31 | System.out.println("runId" + runId + " Id" + getShardingId() ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/event/listener/SessionRegisterEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.event.listener; 2 | 3 | import com.snowcattle.game.common.annotation.GlobalEventListenerAnnotation; 4 | import com.snowcattle.game.executor.event.AbstractEventListener; 5 | import com.snowcattle.game.service.event.SingleEventConstants; 6 | 7 | /** 8 | * Created by jiangwenping on 2017/5/22. 9 | */ 10 | @GlobalEventListenerAnnotation 11 | public class SessionRegisterEventListener extends AbstractEventListener { 12 | 13 | @Override 14 | public void initEventType() { 15 | register(SingleEventConstants.sessionRegister); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/event/listener/SessionUnRegisterEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.event.listener; 2 | 3 | import com.snowcattle.game.common.annotation.GlobalEventListenerAnnotation; 4 | import com.snowcattle.game.executor.event.AbstractEventListener; 5 | import com.snowcattle.game.service.event.SingleEventConstants; 6 | 7 | /** 8 | * Created by jiangwenping on 2017/5/22. 9 | */ 10 | @GlobalEventListenerAnnotation 11 | public class SessionUnRegisterEventListener extends AbstractEventListener{ 12 | @Override 13 | public void initEventType() { 14 | register(SingleEventConstants.sessionUnRegister); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/event/listener/SingleRunEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.event.listener; 2 | 3 | import com.snowcattle.game.common.annotation.GlobalEventListenerAnnotation; 4 | import com.snowcattle.game.executor.event.AbstractEventListener; 5 | import com.snowcattle.game.service.event.SingleEventConstants; 6 | 7 | /** 8 | * Created by jiangwenping on 2017/5/22. 9 | * 10 | */ 11 | @GlobalEventListenerAnnotation 12 | public class SingleRunEventListener extends AbstractEventListener { 13 | @Override 14 | public void initEventType() { 15 | register(SingleEventConstants.singleRunEventType); 16 | } 17 | } -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/limit/AtomicLimitNumber.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.limit; 2 | 3 | import java.util.concurrent.atomic.AtomicLong; 4 | 5 | /** 6 | * Created by jiangwenping on 2017/6/28. 7 | * 原子计数器 8 | */ 9 | public class AtomicLimitNumber { 10 | 11 | /** 12 | * 原子数量 13 | */ 14 | private final AtomicLong atomicLong; 15 | 16 | public AtomicLimitNumber() { 17 | this.atomicLong = new AtomicLong(); 18 | } 19 | 20 | public long increment(){ 21 | return this.atomicLong.incrementAndGet(); 22 | } 23 | 24 | public long decrement(){ 25 | return this.atomicLong.decrementAndGet(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/lookup/GamePlayerLoopUpService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.lookup; 2 | 3 | import com.snowcattle.game.logic.player.GamePlayer; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * Created by jiangwenping on 17/2/21. 8 | * 玩家查找服务 9 | */ 10 | @Service 11 | public class GamePlayerLoopUpService extends AbstractLongLookUpService{ 12 | 13 | } -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/lookup/IChannleLookUpService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.lookup; 2 | 3 | import com.snowcattle.game.service.net.tcp.session.NettySession; 4 | import com.snowcattle.game.service.net.tcp.session.NettyTcpSession; 5 | 6 | /** 7 | * Created by jiangwenping on 17/2/13. 8 | */ 9 | public interface IChannleLookUpService { 10 | 11 | /** 12 | * 查找 13 | * @param sessionId 14 | * @return 15 | */ 16 | public NettySession lookup(long sessionId); 17 | 18 | /** 19 | * 增加 20 | * @param nettyTcpSession 21 | */ 22 | public boolean addNettySession(NettyTcpSession nettyTcpSession); 23 | 24 | /** 25 | * 移除 26 | * @param nettyTcpSession 27 | * @return 28 | */ 29 | public boolean removeNettySession(NettyTcpSession nettyTcpSession); 30 | } 31 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/lookup/ILongId.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.lookup; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/21. 5 | * 6 | */ 7 | public interface ILongId { 8 | public long longId(); 9 | } 10 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/lookup/ILongLookUpService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.lookup; 2 | 3 | /** 4 | * Created by jwp on 2017/2/10. 5 | * 提供查询服务 6 | */ 7 | public interface ILongLookUpService { 8 | 9 | /** 10 | * 查找 11 | * @param id 12 | * @return 13 | */ 14 | T lookup(long id); 15 | 16 | /** 17 | * 增加 18 | * @param t 19 | */ 20 | void addT(T t); 21 | 22 | /** 23 | * 移除 24 | * @param t 25 | * @return 26 | */ 27 | boolean removeT(T t); 28 | 29 | /** 30 | * 清除所有 31 | */ 32 | void clear(); 33 | } 34 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/AbstractNetProtoBufHttpMessage.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message; 2 | 3 | /** 4 | * Created by jiangwenping on 2017/9/28. 5 | */ 6 | public abstract class AbstractNetProtoBufHttpMessage extends AbstractNetProtoBufMessage{ 7 | 8 | public AbstractNetProtoBufHttpMessage(){ 9 | super(); 10 | setNetMessageHead(new NetHttpMessageHead()); 11 | setNetMessageBody(new NetProtoBufMessageBody()); 12 | initHeadCmd(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/AbstractNetProtoBufTcpMessage.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message; 2 | 3 | /** 4 | * Created by jwp on 2017/2/17. 5 | */ 6 | public abstract class AbstractNetProtoBufTcpMessage extends AbstractNetProtoBufMessage{ 7 | 8 | public AbstractNetProtoBufTcpMessage(){ 9 | super(); 10 | setNetMessageBody(new NetProtoBufMessageBody()); 11 | initHeadCmd(); 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/INetMessage.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message; 2 | 3 | /** 4 | * Created by jwp on 2017/2/17. 5 | * 基础协议 6 | */ 7 | public interface INetMessage { 8 | public NetMessageHead getNetMessageHead(); 9 | public NetMessageBody getNetMessageBody(); 10 | } 11 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/NetHttpMessageHead.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message; 2 | 3 | /** 4 | * Created by jiangwenping on 2017/9/28. 5 | * http消息头部 6 | */ 7 | public class NetHttpMessageHead extends NetMessageHead { 8 | 9 | private long playerId; 10 | private String tocken=""; 11 | 12 | public long getPlayerId() { 13 | return playerId; 14 | } 15 | 16 | public void setPlayerId(long playerId) { 17 | this.playerId = playerId; 18 | } 19 | 20 | public String getTocken() { 21 | return tocken; 22 | } 23 | 24 | public void setTocken(String tocken) { 25 | this.tocken = tocken; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/NetMessageBody.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message; 2 | 3 | /** 4 | * Created by jwp on 2017/1/24. 5 | */ 6 | public class NetMessageBody { 7 | 8 | /** 9 | * 存储数据 10 | */ 11 | private byte[] bytes; 12 | 13 | public byte[] getBytes() { 14 | return bytes; 15 | } 16 | 17 | public void setBytes(byte[] bytes) { 18 | this.bytes = bytes; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/NetProtoBufMessageBody.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message; 2 | 3 | import com.google.protobuf.AbstractMessage; 4 | 5 | /** 6 | * Created by jwp on 2017/1/26. 7 | * protobuf的messagebody实体 8 | */ 9 | public class NetProtoBufMessageBody extends NetMessageBody { 10 | 11 | //将字节读取为protobuf的抽象对象 12 | private AbstractMessage abstractMessage; 13 | 14 | public AbstractMessage getAbstractMessage() { 15 | return abstractMessage; 16 | } 17 | 18 | public void setAbstractMessage(AbstractMessage abstractMessage) { 19 | this.abstractMessage = abstractMessage; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/NetUdpMessageHead.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/20. 5 | * udp需要加入playerId跟tocken 6 | */ 7 | public class NetUdpMessageHead extends NetMessageHead{ 8 | private long playerId; 9 | private int tocken; 10 | 11 | public long getPlayerId() { 12 | return playerId; 13 | } 14 | 15 | public void setPlayerId(long playerId) { 16 | this.playerId = playerId; 17 | } 18 | 19 | public int getTocken() { 20 | return tocken; 21 | } 22 | 23 | public void setTocken(int tocken) { 24 | this.tocken = tocken; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/command/MessageCommandFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.command; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * Created by jiangwenping on 2017/5/10. 7 | */ 8 | @Service 9 | public class MessageCommandFactory { 10 | 11 | public MessageCommand[] getAllCommands(){ 12 | MessageCommandEnum[] set = MessageCommandEnum.values(); 13 | MessageCommand[] messageCommands = new MessageCommand[set.length]; 14 | for(int i = 0; i< set.length; i++){ 15 | MessageCommandEnum messageCommandEnum = set[i]; 16 | MessageCommand messageCommand = new MessageCommand(messageCommandEnum.command_id, messageCommandEnum.bo_id, messageCommandEnum.is_need_filter); 17 | messageCommands[i] = messageCommand; 18 | } 19 | 20 | return messageCommands; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/command/MessageCommandIndex.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.command; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/20. 5 | */ 6 | public final class MessageCommandIndex { 7 | // 8 | public static final int ONLINE_HEART_CLIENT_TCP_MESSAGE = 1; 9 | public static final int COMMON_RESPONSE_MESSAGE = 2; 10 | public static final int COMMON_ERROR_RESPONSE_MESSAGE = 3; 11 | public static final int ONLINE_HEART_CLIENT_UDP_MESSAGE = 4; 12 | public static final int ONLINE_LOGIN_TCP_CLIENT_MESSAGE = 5; 13 | public static final int ONLINE_LOGIN_TCP_SERVER_MESSAGE = 6; 14 | public static final int ONLINE_HEART_HTTP_CLIENT_MESSAGE = 7; 15 | public static final int ONLINE_HEART_HTTP_SERVER_MESSAGE = 8; 16 | 17 | private MessageCommandIndex() { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/decoder/INetProtoBufHttpMessageDecoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.decoder; 2 | 3 | /** 4 | * Created by jiangwenping on 2017/9/28. 5 | */ 6 | public interface INetProtoBufHttpMessageDecoderFactory extends INetProtoBufMessageDecoderFactory{ 7 | } 8 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/decoder/INetProtoBufMessageDecoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.decoder; 2 | 3 | import com.snowcattle.game.common.exception.CodecException; 4 | import com.snowcattle.game.service.message.AbstractNetProtoBufMessage; 5 | import io.netty.buffer.ByteBuf; 6 | 7 | /** 8 | * Created by jiangwenping on 2017/9/28. 9 | */ 10 | public interface INetProtoBufMessageDecoderFactory { 11 | public AbstractNetProtoBufMessage praseMessage(ByteBuf byteBuf) throws CodecException; 12 | } 13 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/decoder/INetProtoBufTcpMessageDecoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.decoder; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/3. 5 | */ 6 | public interface INetProtoBufTcpMessageDecoderFactory extends INetProtoBufMessageDecoderFactory{ 7 | } 8 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/decoder/INetProtoBufUdpMessageDecoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.decoder; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/20. 5 | */ 6 | public interface INetProtoBufUdpMessageDecoderFactory extends INetProtoBufMessageDecoderFactory{ 7 | } 8 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/encoder/INetProtoBufHttpMessageEncoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.encoder; 2 | 3 | /** 4 | * Created by jiangwenping on 2017/9/28. 5 | */ 6 | public interface INetProtoBufHttpMessageEncoderFactory extends INetProtoBufMessageEncoderFactory{ 7 | } 8 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/encoder/INetProtoBufMessageEncoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.encoder; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetProtoBufMessage; 4 | import io.netty.buffer.ByteBuf; 5 | 6 | /** 7 | * Created by jiangwenping on 2017/9/28. 8 | */ 9 | public interface INetProtoBufMessageEncoderFactory { 10 | public ByteBuf createByteBuf(AbstractNetProtoBufMessage netMessage) throws Exception; 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/encoder/INetProtoBufTcpMessageEncoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.encoder; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/8. 5 | */ 6 | public interface INetProtoBufTcpMessageEncoderFactory extends INetProtoBufMessageEncoderFactory{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/encoder/INetProtoBufUdpMessageEncoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.encoder; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/20. 5 | */ 6 | public interface INetProtoBufUdpMessageEncoderFactory extends INetProtoBufMessageEncoderFactory { 7 | } 8 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/facade/IFacade.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.facade; 2 | 3 | import com.snowcattle.game.common.exception.GameHandlerException; 4 | import com.snowcattle.game.service.message.AbstractNetMessage; 5 | 6 | /** 7 | * Created by jiangwenping on 17/2/8. 8 | */ 9 | public interface IFacade { 10 | public AbstractNetMessage dispatch(AbstractNetMessage message) throws GameHandlerException; 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/factory/ITcpMessageFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.factory; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | 5 | /** 6 | * Created by jwp on 2017/2/10. 7 | * 协议工厂 8 | */ 9 | public interface ITcpMessageFactory { 10 | public AbstractNetMessage createCommonErrorResponseMessage(int serial, int state, String tip); 11 | public AbstractNetMessage createCommonErrorResponseMessage(int serial, int state); 12 | public AbstractNetMessage createCommonResponseMessage(int serial); 13 | } 14 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/factory/IUdpMessageFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.factory; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetProtoBufUdpMessage; 4 | 5 | /** 6 | * Created by jiangwenping on 17/2/22. 7 | */ 8 | public interface IUdpMessageFactory { 9 | public AbstractNetProtoBufUdpMessage createCommonErrorResponseMessage(int serial, int state); 10 | public AbstractNetProtoBufUdpMessage createCommonResponseMessage(int serial); 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/message/process/INetProtoBufMessageProcess.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.message.process; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | 5 | /** 6 | * Created by jwp on 2017/2/9. 7 | */ 8 | public interface INetProtoBufMessageProcess { 9 | public void processNetMessage(); 10 | public void addNetMessage(AbstractNetMessage abstractNetMessage); 11 | public void close(); 12 | } 13 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/AbstractNettyServerService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net; 2 | 3 | import com.snowcattle.game.service.net.tcp.AbstractServerService; 4 | 5 | import java.net.InetSocketAddress; 6 | 7 | /** 8 | * Created by jwp on 2017/2/4. 9 | * 抽象的tcp服务 10 | */ 11 | public abstract class AbstractNettyServerService extends AbstractServerService { 12 | 13 | protected int serverPort; 14 | protected InetSocketAddress serverAddress; 15 | 16 | 17 | public AbstractNettyServerService(String serviceId, int serverPort) { 18 | super(serviceId); 19 | this.serverPort = serverPort; 20 | this.serverAddress = new InetSocketAddress(serverPort); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/broadcast/IBroadCastService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.broadcast; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | 5 | /** 6 | * Created by jiangwenping on 2017/11/14. 7 | */ 8 | public interface IBroadCastService { 9 | public void broadcastMessage(long sessionId, AbstractNetMessage NetMessage); 10 | } 11 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/http/GameNettyHttpServerService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.http; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | 5 | /** 6 | * Created by jiangwenping on 2017/7/3. 7 | * http服务 8 | */ 9 | public class GameNettyHttpServerService extends AbstractNettyHttpServerService{ 10 | public GameNettyHttpServerService(String serviceId, int serverPort, String bossTreadName, String workThreadName, ChannelInitializer channelInitializer) { 11 | super(serviceId, serverPort, bossTreadName, workThreadName, channelInitializer); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/http/SdHttpServerConfig.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.http; 2 | 3 | import com.snowcattle.game.service.net.SdNetConfig; 4 | import org.jdom2.DataConversionException; 5 | import org.jdom2.Element; 6 | 7 | /** 8 | * Created by jiangwenping on 2017/7/3. 9 | */ 10 | public class SdHttpServerConfig extends SdNetConfig{ 11 | 12 | private int handleThreadSize; 13 | 14 | public void load(Element element) throws DataConversionException { 15 | super.load(element); 16 | handleThreadSize = Integer.valueOf(element.getChildTextTrim("handleThreadSize")); 17 | } 18 | 19 | public int getHandleThreadSize() { 20 | return handleThreadSize; 21 | } 22 | 23 | public void setHandleThreadSize(int handleThreadSize) { 24 | this.handleThreadSize = handleThreadSize; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/proxy/ProxyTcpServerService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.proxy; 2 | 3 | import com.snowcattle.game.service.net.tcp.AbstractNettyTcpServerService; 4 | import io.netty.channel.ChannelInitializer; 5 | 6 | /** 7 | * Created by jiangwenping on 2017/6/9. 8 | * 网络代理服务,用于支持网关 9 | */ 10 | public class ProxyTcpServerService extends AbstractNettyTcpServerService{ 11 | 12 | public ProxyTcpServerService(String serviceId, int serverPort, String bossTreadName, String workThreadName, ChannelInitializer channelInitializer) { 13 | super(serviceId, serverPort, bossTreadName, workThreadName, channelInitializer); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/GameNettyRPCService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | 5 | /** 6 | * Created by jwp on 2017/3/7. 7 | * 增加rpc服务 8 | */ 9 | public class GameNettyRPCService extends AbstractNettyTcpServerService{ 10 | 11 | public GameNettyRPCService(String serviceId, int serverPort, String bossTreadName, String workThreadName, ChannelInitializer channelInitializer) { 12 | super(serviceId, serverPort, bossTreadName, workThreadName, channelInitializer); 13 | } 14 | 15 | @Override 16 | public boolean startService() throws Exception{ 17 | boolean flag = super.startService(); 18 | return flag; 19 | } 20 | 21 | @Override 22 | public boolean stopService() throws Exception{ 23 | boolean flag = super.stopService(); 24 | return flag; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/GameNettyTcpServerService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | 5 | /** 6 | * Created by jiangwenping on 17/2/7. 7 | * 游戏里的的tcp服务 8 | * 9 | */ 10 | public class GameNettyTcpServerService extends AbstractNettyTcpServerService { 11 | 12 | public GameNettyTcpServerService(String serviceId, int serverPort, String bossThreadName, String workThreadName, ChannelInitializer channelInitializer) { 13 | super(serviceId, serverPort, bossThreadName, workThreadName, channelInitializer); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/MessageAttributeEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp; 2 | 3 | /** 4 | * @author jwp 5 | * message附带参数 6 | */ 7 | public enum MessageAttributeEnum { 8 | 9 | /** 10 | * tcp跟udp使用 11 | */ 12 | DISPATCH_SESSION, 13 | 14 | /** 15 | * http使用 16 | */ 17 | DISPATCH_HTTP_REQUEST, 18 | 19 | ; 20 | } 21 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/RpcResponse.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp; 2 | 3 | /** 4 | * Created by jwp on 2017/3/7. 5 | * rpc的返回对象 6 | */ 7 | public class RpcResponse { 8 | 9 | private String requestId; 10 | private String error; 11 | private Object result; 12 | 13 | public boolean isError() { 14 | return error != null; 15 | } 16 | 17 | public String getRequestId() { 18 | return requestId; 19 | } 20 | 21 | public void setRequestId(String requestId) { 22 | this.requestId = requestId; 23 | } 24 | 25 | public String getError() { 26 | return error; 27 | } 28 | 29 | public void setError(String error) { 30 | this.error = error; 31 | } 32 | 33 | public Object getResult() { 34 | return result; 35 | } 36 | 37 | public void setResult(Object result) { 38 | this.result = result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/pipeline/IServerPipeLine.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.pipeline; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | import io.netty.channel.Channel; 5 | 6 | /** 7 | * Created by jiangwenping on 17/2/13. 8 | */ 9 | public interface IServerPipeLine { 10 | public void dispatchAction(Channel channel, AbstractNetMessage abstractNetMessage); 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/pipeline/factory/DefaultTcpServerPipelineFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.pipeline.factory; 2 | 3 | 4 | import com.snowcattle.game.service.net.tcp.pipeline.DefaultTcpServerPipeLine; 5 | import com.snowcattle.game.service.net.tcp.pipeline.IServerPipeLine; 6 | 7 | /** 8 | * Created by jiangwenping on 17/2/14. 9 | */ 10 | public class DefaultTcpServerPipelineFactory implements IServerPipelineFactory { 11 | @Override 12 | public IServerPipeLine createServerPipeLine() { 13 | return new DefaultTcpServerPipeLine(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/pipeline/factory/DefaultUdpServerPipelineFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.pipeline.factory; 2 | 3 | import com.snowcattle.game.service.net.tcp.pipeline.DefaultUdpServerPipeLine; 4 | import com.snowcattle.game.service.net.tcp.pipeline.IServerPipeLine; 5 | 6 | /** 7 | * Created by jiangwenping on 17/2/20. 8 | */ 9 | public class DefaultUdpServerPipelineFactory implements IServerPipelineFactory{ 10 | @Override 11 | public IServerPipeLine createServerPipeLine() { 12 | return new DefaultUdpServerPipeLine(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/pipeline/factory/IServerPipelineFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.pipeline.factory; 2 | 3 | 4 | import com.snowcattle.game.service.net.tcp.pipeline.IServerPipeLine; 5 | 6 | /** 7 | * Created by jiangwenping on 17/2/14. 8 | */ 9 | public interface IServerPipelineFactory { 10 | public IServerPipeLine createServerPipeLine(); 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/process/IMessageProcessor.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.process; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | 5 | /** 6 | * Created by jiangwenping on 17/2/13. 7 | */ 8 | public interface IMessageProcessor { 9 | /** 10 | * 启动消息处理器 11 | */ 12 | public void start(); 13 | 14 | /** 15 | * 停止消息处理器 16 | */ 17 | public void stop(); 18 | 19 | /** 20 | * 向消息队列投递消息 21 | * 22 | * @param msg 23 | */ 24 | public void put(AbstractNetMessage msg); 25 | 26 | /** 27 | * 判断队列是否已经达到上限了 28 | * @return 29 | */ 30 | public boolean isFull(); 31 | } 32 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/process/ITcpMessageProcessor.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.process; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | 5 | /** 6 | * Created by jiangwenping on 17/2/20. 7 | */ 8 | public interface ITcpMessageProcessor extends IMessageProcessor{ 9 | 10 | /** 11 | * 向消息队列投递消息 12 | * 直接投递到对象processor上面 13 | * @param msg 14 | */ 15 | public void directPutTcpMessage(AbstractNetMessage msg); 16 | } 17 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/session/INetMessageSender.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.session; 2 | 3 | import com.snowcattle.game.common.exception.NetMessageException; 4 | import com.snowcattle.game.service.message.AbstractNetMessage; 5 | 6 | /** 7 | * Created by jwp on 2017/2/9. 8 | * 消息处理器 9 | */ 10 | public interface INetMessageSender { 11 | /** 12 | * 发送消息 13 | * @param abstractNetMessage 14 | * @return 15 | */ 16 | boolean sendMessage(AbstractNetMessage abstractNetMessage) throws NetMessageException; 17 | 18 | /** 19 | * 关闭 20 | */ 21 | void close() throws NetMessageException; 22 | } 23 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/session/ISession.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.session; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | 5 | /** 6 | * Created by jwp on 2017/2/9. 7 | * 封装会话的业务逻辑 8 | */ 9 | public interface ISession { 10 | 11 | /** 12 | * 判断当前会话是否处于连接状态 13 | * 14 | * @return 15 | */ 16 | public boolean isConnected(); 17 | 18 | /** 19 | * @param msg 20 | */ 21 | public void write(AbstractNetMessage msg) throws Exception; 22 | 23 | /** 24 | * 25 | */ 26 | public void close(boolean immediately); 27 | 28 | /** 29 | * 出现异常时是否关闭连接 30 | * 31 | * @return 32 | */ 33 | public boolean closeOnException(); 34 | 35 | public void write(byte[] msg) throws Exception; 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/session/TcpNetState.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.session; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/21. 5 | */ 6 | public enum TcpNetState { 7 | //链接状态 8 | CONNECTED, 9 | //掉线中 10 | DISCONNECTING, 11 | //掉线 12 | DISCONNECTED, 13 | //销毁 14 | DESTROY; 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/session/builder/ISessionBuilder.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.session.builder; 2 | 3 | import com.snowcattle.game.service.net.tcp.session.ISession; 4 | import io.netty.channel.Channel; 5 | 6 | /** 7 | * Created by jwp on 2017/2/9. 8 | */ 9 | public interface ISessionBuilder { 10 | public ISession buildSession(Channel channel); 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/session/builder/NettyTcpSessionBuilder.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.session.builder; 2 | 3 | import com.snowcattle.game.service.net.tcp.session.ISession; 4 | import com.snowcattle.game.service.net.tcp.session.NettyTcpSession; 5 | import io.netty.channel.Channel; 6 | import io.netty.util.AttributeKey; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * Created by jwp on 2017/2/9. 11 | * 创造tcpsession 同时标记channel上的sessionId 12 | */ 13 | @Service 14 | public class NettyTcpSessionBuilder implements ISessionBuilder { 15 | 16 | public static final AttributeKey channel_session_id = AttributeKey 17 | .valueOf("channel_session_id"); 18 | 19 | @Override 20 | public ISession buildSession(Channel channel) { 21 | NettyTcpSession nettyTcpSession = new NettyTcpSession(channel); 22 | channel.attr(channel_session_id).set(nettyTcpSession.getSessionId()); 23 | return nettyTcpSession ; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/tcp/session/builder/NettyUdpSessionBuilder.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.tcp.session.builder; 2 | 3 | import com.snowcattle.game.service.net.tcp.session.ISession; 4 | import com.snowcattle.game.service.net.udp.session.NettyUdpSession; 5 | import io.netty.channel.Channel; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by jwp on 2017/2/17. 10 | * udp session的生成器 11 | */ 12 | @Service 13 | public class NettyUdpSessionBuilder implements ISessionBuilder { 14 | @Override 15 | public ISession buildSession(Channel channel) { 16 | return new NettyUdpSession(channel); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/udp/GameNettyUdpServerService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.udp; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | 5 | /** 6 | * Created by jwp on 2017/2/17. 7 | * udp启动服务 8 | */ 9 | public class GameNettyUdpServerService extends AbstractNettyUdpServerService { 10 | public GameNettyUdpServerService(String serviceId, int serverPort, String threadNameFactoryName, ChannelInitializer channelInitializer) { 11 | super(serviceId, serverPort, threadNameFactoryName, channelInitializer); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/udp/session/NettyUdpSession.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.udp.session; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | import com.snowcattle.game.service.net.tcp.session.NettySession; 5 | import io.netty.channel.Channel; 6 | 7 | /** 8 | * Created by jwp on 2017/2/16. 9 | * netty的udp session 10 | */ 11 | public class NettyUdpSession extends NettySession { 12 | 13 | private final NettyUdpNetMessageSender nettyUdpNetMessageSender; 14 | public NettyUdpSession(Channel channel) { 15 | super(channel); 16 | this.nettyUdpNetMessageSender = new NettyUdpNetMessageSender(this); 17 | } 18 | 19 | public void write(AbstractNetMessage msg) throws Exception { 20 | if (msg != null) { 21 | channel.writeAndFlush(msg).sync(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/net/websocket/GameNettyWebSocketServerService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.net.websocket; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | 5 | /** 6 | * Created by jiangwenping on 2017/11/8. 7 | * websocket服务 8 | */ 9 | public class GameNettyWebSocketServerService extends AbstractNettyWebSocketServerService{ 10 | public GameNettyWebSocketServerService(String serviceId, int serverPort, String bossTreadName, String workThreadName, ChannelInitializer channelInitializer) { 11 | super(serviceId, serverPort, bossTreadName, workThreadName, channelInitializer); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/client/AsyncRPCCallback.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.client; 2 | 3 | /** 4 | */ 5 | public interface AsyncRPCCallback { 6 | 7 | void success(Object result); 8 | 9 | void fail(Exception e); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/client/RpcContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.client; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/13. 5 | * rpc 服务器列表选择 6 | */ 7 | public final class RpcContextHolder { 8 | 9 | private static final ThreadLocal contextHolder = new ThreadLocal(); 10 | 11 | private RpcContextHolder() { 12 | } 13 | 14 | public static RpcContextHolderObject getContext() { 15 | return contextHolder.get(); 16 | } 17 | /** 18 | * 通过字符串选择数据源 19 | * @param rpcContextHolderObject 20 | */ 21 | public static void setContextHolder(RpcContextHolderObject rpcContextHolderObject) { 22 | contextHolder.set(rpcContextHolderObject); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/client/RpcContextHolderObject.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.client; 2 | 3 | import com.snowcattle.game.common.enums.BOEnum; 4 | 5 | /** 6 | * Created by jiangwenping on 17/3/15. 7 | */ 8 | public class RpcContextHolderObject { 9 | 10 | private BOEnum boEnum; 11 | private int ServerId; 12 | 13 | public RpcContextHolderObject(BOEnum boEnum, int serverId) { 14 | this.boEnum = boEnum; 15 | ServerId = serverId; 16 | } 17 | 18 | public BOEnum getBoEnum() { 19 | return boEnum; 20 | } 21 | 22 | public void setBoEnum(BOEnum boEnum) { 23 | this.boEnum = boEnum; 24 | } 25 | 26 | public int getServerId() { 27 | return ServerId; 28 | } 29 | 30 | public void setServerId(int serverId) { 31 | ServerId = serverId; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/client/impl/DbRpcConnnectMananger.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.client.impl; 2 | 3 | import com.snowcattle.game.service.rpc.client.AbstractRpcConnectManager; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * Created by jiangwenping on 17/3/15. 8 | * db rpc 9 | */ 10 | @Service 11 | public class DbRpcConnnectMananger extends AbstractRpcConnectManager { 12 | } 13 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/client/impl/GameRpcConnecetMananger.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.client.impl; 2 | 3 | import com.snowcattle.game.service.rpc.client.AbstractRpcConnectManager; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * Created by jiangwenping on 17/3/15. 8 | * 游戏rpc manger 9 | */ 10 | @Service 11 | public class GameRpcConnecetMananger extends AbstractRpcConnectManager { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/client/impl/WorldRpcConnectManager.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.client.impl; 2 | 3 | import com.snowcattle.game.service.rpc.client.AbstractRpcConnectManager; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * Created by jiangwenping on 17/3/15. 8 | * 世界rpc 9 | */ 10 | @Service 11 | public class WorldRpcConnectManager extends AbstractRpcConnectManager { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/client/proxy/IAsyncRpcProxy.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.client.proxy; 2 | 3 | import com.snowcattle.game.service.rpc.client.RPCFuture; 4 | 5 | /** 6 | * Created by jwp on 2017/3/9. 7 | */ 8 | public interface IAsyncRpcProxy { 9 | public RPCFuture call(String funcName, Object... args); 10 | } 11 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/serialize/IRpcSerialize.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.serialize; 2 | 3 | /** 4 | * Created by jwp on 2017/3/8. 5 | * rpc对象序列化 6 | */ 7 | public interface IRpcSerialize { 8 | 9 | public byte[] serialize(T obj); 10 | 11 | public T deserialize(byte[] data, Class cls); 12 | } 13 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/server/RpcNodeInfo.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.server; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/1. 5 | */ 6 | public class RpcNodeInfo { 7 | 8 | /** 9 | * 服务器id 10 | */ 11 | private String serverId; 12 | private String host; 13 | private String port; 14 | 15 | public String getServerId() { 16 | return serverId; 17 | } 18 | 19 | public void setServerId(String serverId) { 20 | this.serverId = serverId; 21 | } 22 | 23 | public String getHost() { 24 | return host; 25 | } 26 | 27 | public void setHost(String host) { 28 | this.host = host; 29 | } 30 | 31 | public String getPort() { 32 | return port; 33 | } 34 | 35 | public void setPort(String port) { 36 | this.port = port; 37 | } 38 | 39 | public int getIntPort(){ 40 | return Integer.parseInt(port); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/server/RpcSystemConfig.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.server; 2 | 3 | /** 4 | * Created by jwp on 2017/3/8. 5 | */ 6 | public final class RpcSystemConfig { 7 | public static final String SystemPropertyThreadPoolRejectedPolicyAttr = "com.newlandframework.rpc.parallel.rejected.policy"; 8 | public static final String SystemPropertyThreadPoolQueueNameAttr = "com.newlandframework.rpc.parallel.queue"; 9 | public static final int PARALLEL = Math.max(2, Runtime.getRuntime().availableProcessors()); 10 | 11 | private static boolean monitorServerSupport = false; 12 | 13 | private RpcSystemConfig() { 14 | } 15 | 16 | public static boolean isMonitorServerSupport() { 17 | return monitorServerSupport; 18 | } 19 | 20 | public static void setMonitorServerSupport(boolean jmxSupport) { 21 | monitorServerSupport = jmxSupport; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/server/zookeeper/ZooKeeperNodeBoEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.server.zookeeper; 2 | 3 | import com.snowcattle.game.common.enums.BOEnum; 4 | 5 | /** 6 | * Created by jiangwenping on 17/3/31. 7 | */ 8 | public enum ZooKeeperNodeBoEnum { 9 | WORLD(BOEnum.WORLD, "/world_registry_adress"), 10 | GAME(BOEnum.GAME, "/game_registry_adress"), 11 | DB(BOEnum.DB, "/db_registry_adress"), 12 | ; 13 | private BOEnum boEnum; 14 | private String rootPath; 15 | 16 | ZooKeeperNodeBoEnum(BOEnum boEnum, String rootPath) { 17 | this.boEnum = boEnum; 18 | this.rootPath = rootPath; 19 | } 20 | 21 | public BOEnum getBoEnum() { 22 | return boEnum; 23 | } 24 | 25 | public void setBoEnum(BOEnum boEnum) { 26 | this.boEnum = boEnum; 27 | } 28 | 29 | public String getRootPath() { 30 | return rootPath; 31 | } 32 | 33 | public void setRootPath(String rootPath) { 34 | this.rootPath = rootPath; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/service/client/HelloService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.service.client; 2 | 3 | /** 4 | * Created by jwp on 2017/3/7. 5 | */ 6 | public interface HelloService { 7 | String hello(String name); 8 | } 9 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/rpc/service/server/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.rpc.service.server; 2 | 3 | import com.snowcattle.game.common.annotation.RpcServiceAnnotation; 4 | import com.snowcattle.game.common.annotation.RpcServiceBoEnum; 5 | import com.snowcattle.game.common.enums.BOEnum; 6 | import com.snowcattle.game.service.rpc.service.client.HelloService; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * Created by jwp on 2017/3/7. 11 | */ 12 | @RpcServiceAnnotation(HelloService.class) 13 | @RpcServiceBoEnum(bo = BOEnum.WORLD) 14 | @Repository 15 | public class HelloServiceImpl implements HelloService { 16 | 17 | @Override 18 | public String hello(String name) { 19 | return "Hello! " + name; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/time/TimeService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.time; 2 | 3 | /** 4 | * 提供时间相关的服务 5 | * 6 | * 7 | */ 8 | public interface TimeService { 9 | /** 10 | * 当前时间 11 | * 12 | * @return 13 | */ 14 | public long now(); 15 | 16 | /** 17 | * 更新当前时间,只有在当前时间服务使用了缓存策略的情况下才需要调用此方法 18 | */ 19 | public void update(); 20 | 21 | /** 22 | * 是否到达某个时间 23 | * 24 | * @param sometime 25 | * @return 26 | */ 27 | public boolean timeUp(long sometime); 28 | 29 | /** 30 | * 获取指定时间与当前时间的时间差 31 | * 32 | * @param sometime 33 | * @return 34 | */ 35 | public long getInterval(long sometime); 36 | 37 | /** 38 | * 获取时间偏移量 39 | * 40 | * @return 41 | * 42 | */ 43 | public long getOffset(); 44 | 45 | /** 46 | * 设置时间偏移量 47 | * 48 | * @param value 单位: 毫秒 49 | */ 50 | public void setOffset(long value); 51 | } 52 | -------------------------------------------------------------------------------- /game-core/src/main/java/com/snowcattle/game/service/uuid/LongIdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.service.uuid; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import java.util.concurrent.atomic.AtomicLong; 6 | /** 7 | * Created by jwp on 2017/2/9. 8 | * sessionId生成器 9 | */ 10 | @Service 11 | public class LongIdGenerator { 12 | 13 | protected AtomicLong id_gen = new AtomicLong(0); 14 | 15 | public long generateId(){ 16 | return id_gen.incrementAndGet(); 17 | } 18 | } -------------------------------------------------------------------------------- /game-core/src/main/resources/bean/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /game-core/src/main/resources/dynamic_config.properties: -------------------------------------------------------------------------------- 1 | udp_message_tocken_check_flag=false -------------------------------------------------------------------------------- /game-core/src/main/resources/game_server_diff.cfg.js: -------------------------------------------------------------------------------- 1 | config.version="0.2.0.1"; 2 | //每秒钟处理消息数量 3 | config.session_prcoss_message_max_size=10; 4 | //异步通讯链接保持活跃时间(秒) 5 | config.rpcTcpHeartKeepAliveTime=60*60*24; 6 | //是否启动zookeeper 7 | config.zookeeperFlag=false; 8 | -------------------------------------------------------------------------------- /game-core/src/main/resources/http-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http_server 5 | 11001 6 | 127.0.0.1 7 | 10200 8 | false 9 | 300 10 | 11 | -------------------------------------------------------------------------------- /game-core/src/main/resources/proxy-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | proxy-gate 5 | 11001 6 | 127.0.0.1 7 | 9090 8 | 9 | 10 | 127.0.0.1 11 | 7090 12 | 13 | 14 | -------------------------------------------------------------------------------- /game-core/src/main/resources/rpc-server-register.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /game-core/src/main/resources/rpc-service-register.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /game-core/src/main/resources/udp-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | udp_server 5 | 11001 6 | 127.0.0.1 7 | 10090 8 | 1 9 | true 10 | 11 | -------------------------------------------------------------------------------- /game-core/src/main/resources/websocket-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | web_socket_server 5 | 11001 6 | 127.0.0.1 7 | 10300 8 | true 9 | 300 10 | 11 | -------------------------------------------------------------------------------- /game-core/src/main/resources/zookeeper.properties: -------------------------------------------------------------------------------- 1 | # zookeeper server 2 | registry.address=127.0.0.1:2181 -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/codec/server/CodeSocketTwoServerHandler.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.codec.server; 2 | 3 | import io.netty.channel.ChannelHandlerContext; 4 | import io.netty.channel.SimpleChannelInboundHandler; 5 | 6 | /** 7 | * Created by jiangwenping on 2017/11/13. 8 | */ 9 | public class CodeSocketTwoServerHandler extends SimpleChannelInboundHandler { 10 | 11 | @Override 12 | protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { 13 | Thread.sleep(1000L); 14 | // ctx.writeAndFlush(msg); 15 | System.out.println("服务端收到:"+msg); 16 | } 17 | 18 | 19 | @Override 20 | public void channelReadComplete(ChannelHandlerContext ctx) { 21 | ctx.flush(); 22 | } 23 | 24 | @Override 25 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { 26 | // Close the connection when an exception is raised. 27 | cause.printStackTrace(); 28 | ctx.close(); 29 | } 30 | 31 | 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/codec/server/TwoStringDecoder.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.codec.server; 2 | 3 | import io.netty.channel.ChannelHandlerContext; 4 | import io.netty.handler.codec.MessageToMessageDecoder; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by jiangwenping on 2017/11/14. 10 | */ 11 | public class TwoStringDecoder extends MessageToMessageDecoder { 12 | 13 | @Override 14 | protected void decode(ChannelHandlerContext ctx, String msg, List out) throws Exception { 15 | out.add("二次编码" + msg); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/collections/ArrayTest.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.collections; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * Created by jiangwenping on 2017/6/22. 7 | */ 8 | public final class ArrayTest { 9 | public static void main(String[] args) { 10 | int a = Integer.valueOf("123"); 11 | System.out.println(a); 12 | 13 | byte[] bytes = {1,4,3}; 14 | Arrays.sort(bytes); 15 | System.out.println(Arrays.toString(bytes)); 16 | 17 | char[] chars = {'d','3', 'e'}; 18 | String dest = Arrays.toString(chars); 19 | System.out.println(dest); 20 | char[] charDest = Arrays.copyOf(chars, 2); 21 | System.out.println(charDest); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/socket/client/ClientChannleInitializer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.socket.client; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | import io.netty.channel.socket.nio.NioSocketChannel; 5 | import io.netty.handler.codec.LineBasedFrameDecoder; 6 | import io.netty.handler.codec.string.StringDecoder; 7 | import io.netty.handler.codec.string.StringEncoder; 8 | 9 | /** 10 | * Created by jwp on 2017/1/23. 11 | */ 12 | public class ClientChannleInitializer extends ChannelInitializer { 13 | @Override 14 | protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { 15 | nioSocketChannel.pipeline().addLast(new LineBasedFrameDecoder(1024)); 16 | nioSocketChannel.pipeline().addLast(new StringDecoder()); 17 | nioSocketChannel.pipeline().addLast(new StringEncoder()); 18 | nioSocketChannel.pipeline().addLast(new EchoClientHandler()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/socket/client/LengthStringClientChannleInitializer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.socket.client; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | import io.netty.channel.socket.nio.NioSocketChannel; 5 | import io.netty.handler.codec.LengthFieldBasedFrameDecoder; 6 | import io.netty.handler.codec.string.StringDecoder; 7 | 8 | /** 9 | * Created by jiangwenping on 17/1/24. 10 | */ 11 | public class LengthStringClientChannleInitializer extends ChannelInitializer { 12 | @Override 13 | protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { 14 | short maxLength = Short.MAX_VALUE; 15 | nioSocketChannel.pipeline().addLast(new LengthFieldBasedFrameDecoder(maxLength, 0, 4)); 16 | nioSocketChannel.pipeline().addLast(new StringDecoder()); 17 | // nioSocketChannel.pipeline().addLast(new StringEncoder()); 18 | nioSocketChannel.pipeline().addLast(new LenghtStringClientHandler()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/socket/client/StringClientChannelInitializer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.socket.client; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | import io.netty.channel.socket.nio.NioSocketChannel; 5 | import io.netty.handler.codec.LineBasedFrameDecoder; 6 | import io.netty.handler.codec.string.StringDecoder; 7 | import io.netty.handler.codec.string.StringEncoder; 8 | 9 | /** 10 | * Created by jwp on 2017/1/23. 11 | */ 12 | public class StringClientChannelInitializer extends ChannelInitializer{ 13 | @Override 14 | protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { 15 | nioSocketChannel.pipeline().addLast(new LineBasedFrameDecoder(1024)); 16 | nioSocketChannel.pipeline().addLast(new StringDecoder()); 17 | nioSocketChannel.pipeline().addLast(new StringEncoder()); 18 | nioSocketChannel.pipeline().addLast(new EchoStringSocketClientHandler()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/socket/message/INetMessageDecoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.socket.message; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | import io.netty.buffer.ByteBuf; 5 | 6 | /** 7 | * Created by jwp on 2017/1/26. 8 | */ 9 | public interface INetMessageDecoderFactory { 10 | public AbstractNetMessage praseMessage(ByteBuf byteBuf); 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/socket/message/INetMessageEncoderFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.socket.message; 2 | 3 | import com.snowcattle.game.service.message.AbstractNetMessage; 4 | import io.netty.buffer.ByteBuf; 5 | 6 | /** 7 | * Created by jwp on 2017/1/26. 8 | */ 9 | public interface INetMessageEncoderFactory { 10 | public ByteBuf createByteBuf(AbstractNetMessage abstractNetMessage); 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/socket/message/NetMessageTCPDecoder.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.socket.message; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.handler.codec.MessageToMessageDecoder; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by jwp on 2017/1/24. 11 | * 网络消息解码普通消息不带protobuf 12 | */ 13 | public class NetMessageTCPDecoder extends MessageToMessageDecoder { 14 | 15 | private final INetMessageDecoderFactory iNetMessageDecoderFactory; 16 | 17 | public NetMessageTCPDecoder() { 18 | this.iNetMessageDecoderFactory = new NetTcpMessageDecoderFactory(); 19 | } 20 | 21 | @Override 22 | protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List out) throws Exception { 23 | out.add(iNetMessageDecoderFactory.praseMessage(msg)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/socket/server/LengthStringDecoder.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.socket.server; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.handler.codec.string.StringDecoder; 6 | import io.netty.util.CharsetUtil; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by jwp on 2017/1/24. 12 | */ 13 | public class LengthStringDecoder extends StringDecoder { 14 | @Override 15 | protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List out) throws Exception { 16 | out.add(msg.toString(CharsetUtil.UTF_8)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/socket/server/ServerChannelInitializer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.socket.server; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | import io.netty.channel.ChannelPipeline; 5 | import io.netty.channel.socket.nio.NioSocketChannel; 6 | 7 | /** 8 | * Created by jwp on 2017/1/23. 9 | */ 10 | public class ServerChannelInitializer extends ChannelInitializer { 11 | @Override 12 | protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { 13 | ChannelPipeline channelPipLine = nioSocketChannel.pipeline(); 14 | // channelPipLine.addLast(new LineBasedFrameDecoder(1024)); 15 | // channelPipLine.addLast(new StringDecoder()); 16 | // channelPipLine.addLast(new StringEncoder()); 17 | channelPipLine.addLast(new EchoSocketServerHandler()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/socket/server/StringServerChannelInitializer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.socket.server; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | import io.netty.channel.ChannelPipeline; 5 | import io.netty.channel.socket.nio.NioSocketChannel; 6 | import io.netty.handler.codec.LineBasedFrameDecoder; 7 | import io.netty.handler.codec.string.StringDecoder; 8 | import io.netty.handler.codec.string.StringEncoder; 9 | 10 | /** 11 | * Created by jwp on 2017/1/23. 12 | */ 13 | public class StringServerChannelInitializer extends ChannelInitializer { 14 | @Override 15 | protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { 16 | ChannelPipeline channelPipLine = nioSocketChannel.pipeline(); 17 | channelPipLine.addLast(new LineBasedFrameDecoder(1024)); 18 | channelPipLine.addLast(new StringDecoder()); 19 | channelPipLine.addLast(new StringEncoder()); 20 | channelPipLine.addLast(new EchoSocketServerHandler()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/template/JdbcDaoSupport.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.template; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | 5 | /** 6 | * Created by jiangwenping on 17/4/10. 7 | */ 8 | 9 | public abstract class JdbcDaoSupport { 10 | 11 | private final Class clazz; 12 | 13 | @SuppressWarnings("unchecked") 14 | protected JdbcDaoSupport() { 15 | Class classes = getClass(); 16 | clazz = (Class) ((ParameterizedType) getClass() 17 | .getGenericSuperclass()).getActualTypeArguments()[0]; 18 | System.out.println(clazz.getSimpleName()); 19 | } 20 | } -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/template/SuperTemplate.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.template; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/10. 5 | */ 6 | public class SuperTemplate { 7 | } 8 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/template/Test.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.template; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/10. 5 | */ 6 | public final class Test { 7 | 8 | public static void main(String[] args) { 9 | // ChileTemplate chileTemplate = new ChileTemplate(); 10 | ChileTemplate chileTemplate = new ChileTemplate(); 11 | System.out.println(chileTemplate.getTClass(0)); 12 | 13 | UserDao dao = new UserDao(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/template/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.template; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/10. 5 | */ 6 | 7 | public class UserDao extends JdbcDaoSupport { 8 | } 9 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/thread/join/ThreadTester.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.thread.join; 2 | 3 | /** 4 | * Created by jwp on 2017/4/12. 5 | */ 6 | public final class ThreadTester { 7 | public static void main(String[] args) throws InterruptedException { 8 | Thread t1 = new Thread(new ThreadTesterA()); 9 | Thread t2 = new Thread(new ThreadTesterB()); 10 | t1.start(); 11 | t1.join(); // wait t1 to be finished 12 | t2.start(); 13 | t2.join(); // in this program, this may be removed 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/thread/join/ThreadTesterA.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.thread.join; 2 | 3 | /** 4 | * Created by jwp on 2017/4/12. 5 | */ 6 | class ThreadTesterA implements Runnable { 7 | 8 | private int counter; 9 | 10 | @Override 11 | public void run() { 12 | while (counter <= 1000) { 13 | System.out.println("Counter = " + counter + ' '); 14 | counter++; 15 | try { 16 | Thread.sleep(1); 17 | } catch (InterruptedException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | System.out.println(); 22 | } 23 | } -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/thread/join/ThreadTesterB.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.thread.join; 2 | 3 | /** 4 | * Created by jwp on 2017/4/12. 5 | */ 6 | class ThreadTesterB implements Runnable { 7 | 8 | private int i; 9 | 10 | @Override 11 | public void run() { 12 | while (i <= 1000) { 13 | System.out.println("i = " + i + ' '); 14 | i++; 15 | try { 16 | Thread.sleep(1); 17 | } catch (InterruptedException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | System.out.println(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/thread/lock/ConditionTest.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.thread.lock; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.util.concurrent.locks.Condition; 5 | import java.util.concurrent.locks.ReentrantLock; 6 | 7 | /** 8 | * Created by jiangwenping on 17/3/13. 9 | */ 10 | public class ConditionTest { 11 | 12 | public ReentrantLock reentrantLock; 13 | public Condition condition; 14 | public static void main(String[] args) throws InterruptedException { 15 | ConditionTest conditionTest = new ConditionTest(); 16 | conditionTest.reentrantLock = new ReentrantLock(); 17 | conditionTest.condition = conditionTest.reentrantLock.newCondition(); 18 | conditionTest.reentrantLock.lock(); 19 | conditionTest.condition.signalAll(); 20 | conditionTest.condition.await(6000, TimeUnit.MILLISECONDS); 21 | conditionTest.reentrantLock.unlock(); 22 | System.out.println("done"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/thread/pool/TestWorker.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.thread.pool; 2 | 3 | 4 | import com.snowcattle.game.thread.worker.AbstractWork; 5 | 6 | /** 7 | * Created by jiangwenping on 17/3/10. 8 | */ 9 | public class TestWorker extends AbstractWork { 10 | 11 | private final int i; 12 | 13 | public TestWorker(int i) { 14 | this.i = i; 15 | } 16 | 17 | @Override 18 | public void run() { 19 | System.out.println(i); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/timer/TimerTest.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.timer; 2 | 3 | import java.util.Timer; 4 | import java.util.TimerTask; 5 | 6 | /** 7 | * Created by jiangwenping on 17/3/27. 8 | */ 9 | public final class TimerTest { 10 | public static void main(String[] args) { 11 | Timer timer = new Timer(); 12 | timer.schedule(new TestTimeTask(), 0, 10); 13 | } 14 | 15 | } 16 | 17 | class TestTimeTask extends TimerTask{ 18 | 19 | private int i = 0; 20 | @Override 21 | public void run() { 22 | i++; 23 | System.out.println("测试" + i + "时间" + System.currentTimeMillis()); 24 | try { 25 | Thread.sleep(30 * 1000L); 26 | } catch (InterruptedException e) { 27 | e.printStackTrace(); 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/udp/client/UdpClientChannelInitializer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.udp.client; 2 | 3 | import io.netty.channel.ChannelHandlerContext; 4 | import io.netty.channel.ChannelInitializer; 5 | import io.netty.channel.ChannelPipeline; 6 | import io.netty.channel.socket.nio.NioDatagramChannel; 7 | 8 | /** 9 | * Created by jiangwenping on 17/2/16. 10 | */ 11 | public class UdpClientChannelInitializer extends ChannelInitializer { 12 | @Override 13 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 14 | super.channelActive(ctx); 15 | } 16 | 17 | @Override 18 | protected void initChannel(NioDatagramChannel ch) throws Exception { 19 | ChannelPipeline cp = ch.pipeline(); 20 | cp.addLast("handler", new UdpHandler()); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/util/RandomStringGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util; 2 | 3 | /** 4 | * Created by jiangwenping on 17/2/6. 5 | */ 6 | public final class RandomStringGeneratorTest { 7 | public static void main(String[] args) { 8 | String string = new RandomStringGenerator().generateRandomString(10); 9 | System.out.println(string); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/util/concurrent/ConcurrentMapTest.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.util.concurrent; 2 | 3 | import java.util.concurrent.ConcurrentHashMap; 4 | 5 | /** 6 | * Created by jiangwenping on 2017/11/23. 7 | */ 8 | public final class ConcurrentMapTest { 9 | public static void main(String[] args) { 10 | ConcurrentHashMap hashMap = new ConcurrentHashMap<>(); 11 | for(int i = 0; i< 1000; i++){ 12 | Integer integer = hashMap.putIfAbsent(i, i); 13 | System.out.println(integer); 14 | Integer value = hashMap.putIfAbsent(i, i); 15 | System.out.println(value); 16 | } 17 | 18 | 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/common/zookeeper/zkclient/RetryConnect.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.common.zookeeper.zkclient; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | import org.I0Itec.zkclient.ZkClient; 6 | 7 | public class RetryConnect implements Callable{ 8 | private final String path; 9 | private ZkClient zk; 10 | 11 | public RetryConnect(String path, ZkClient zk) { 12 | super(); 13 | this.path = path; 14 | //this.zk = zk; 15 | } 16 | 17 | @Override 18 | public String call() throws Exception { 19 | zk = new ZkClient("127.0.0.1:2181"); 20 | return "success"; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/extend/GameServerEx.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.extend; 2 | 3 | import com.snowcattle.game.bootstrap.GameServer; 4 | 5 | /** 6 | * Created by jwp on 2017/5/5. 7 | */ 8 | public class GameServerEx extends GameServer{ 9 | 10 | public static void main(String[] args) { 11 | GameServerEx gameServerEx = new GameServerEx(); 12 | GlobalManagerEx globalManagerEx = new GlobalManagerEx(); 13 | gameServerEx.setGlobalManager(globalManagerEx); 14 | gameServerEx.startServer(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/extend/LocalSpringBeanGameManager.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.extend; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * Created by jwp on 2017/5/6. 7 | */ 8 | @Service 9 | public class LocalSpringBeanGameManager { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/extend/LocalSpringServiceGameManager.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.extend; 2 | 3 | import com.snowcattle.game.bootstrap.manager.spring.AbstractSpringStart; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * Created by jwp on 2017/5/6. 8 | */ 9 | @Service 10 | public class LocalSpringServiceGameManager extends AbstractSpringStart { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/jdbc/mapper/OrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.jdbc.mapper; 2 | 3 | 4 | 5 | import com.snowcattle.game.db.service.jdbc.mapper.IDBMapper; 6 | import com.snowcattle.game.jdbc.entity.Order; 7 | 8 | /** 9 | * Created by jiangwenping on 17/3/6. 10 | */ 11 | public interface OrderMapper extends IDBMapper{ 12 | 13 | } 14 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/jdbc/service/IOrderService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.jdbc.service; 2 | 3 | 4 | import java.util.List; 5 | 6 | import com.snowcattle.game.jdbc.entity.Order; 7 | 8 | /** 9 | * Created by jiangwenping on 17/3/20. 10 | */ 11 | public interface IOrderService { 12 | public long insertOrder(Order order); 13 | public Order getOrder(long userId, long id); 14 | public List getOrderList(long userId); 15 | void updateOrder(Order order); 16 | void deleteOrder(Order order); 17 | 18 | public List insertOrderList(List order); 19 | public void updateOrderList(List order); 20 | public void deleteOrderList(List order); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /game-core/src/test/java/com/snowcattle/game/net/client/proxy/ProxyClient.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.net.client.proxy; 2 | 3 | import com.snowcattle.game.TestStartUp; 4 | import com.snowcattle.game.bootstrap.manager.LocalMananger; 5 | import com.snowcattle.game.bootstrap.manager.spring.LocalSpringServiceManager; 6 | import com.snowcattle.game.net.client.tcp.GameClient; 7 | import com.snowcattle.game.service.message.registry.MessageRegistry; 8 | 9 | /** 10 | * Created by jiangwenping on 2017/6/28. 11 | */ 12 | public class ProxyClient extends GameClient { 13 | public static void main(String[] args) throws Exception { 14 | TestStartUp.startUpWithSpring(); 15 | LocalSpringServiceManager localSpringServiceManager = LocalMananger.getInstance().getLocalSpringServiceManager(); 16 | localSpringServiceManager.setMessageRegistry(LocalMananger.getInstance().get(MessageRegistry.class)); 17 | 18 | new GameClient().connect("127.0.0.1", 9090); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /game-core/src/test/resources/db_jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc-driver=com.mysql.jdbc.Driver 2 | 3 | ################### DataSource Configuration ########################## 4 | jdbc-url-0=jdbc:mysql://localhost:3306/db_0?useUnicode=true&characterEncoding=utf8 5 | jdbc-user-0=root 6 | jdbc-password-0=123456 7 | 8 | jdbc-url-1=jdbc:mysql://localhost:3306/db_1?useUnicode=true&characterEncoding=utf8 9 | jdbc-user-1=root 10 | jdbc-password-1=123456 11 | 12 | jdbc-url-2=jdbc:mysql://localhost:3306/db_2?useUnicode=true&characterEncoding=utf8 13 | jdbc-user-2=root 14 | jdbc-password-2=123456 -------------------------------------------------------------------------------- /game-core/src/test/resources/dict/dict.wg: -------------------------------------------------------------------------------- 1 | { 2 | "package" : "com.snowcattle.game.service.dict.entity", 3 | "dict" : [ 4 | ["BULLET_BULLET", "dict/bullet/d_bullet.wg", "Bullet"], 5 | ["STATUS_ROLE_SKILL", "dict/status/d_role_skill.wg", "RoleSkill"], 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /game-core/src/test/resources/dynamic_config.properties: -------------------------------------------------------------------------------- 1 | udp_message_tocken_check_flag=false -------------------------------------------------------------------------------- /game-core/src/test/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | java.lang.String 8 | java.lang.String 9 | 100 10 | 11 | -------------------------------------------------------------------------------- /game-core/src/test/resources/game_server_diff.cfg.js: -------------------------------------------------------------------------------- 1 | config.version="0.2.0.1"; 2 | //房间等待掉线时间(ms) 3 | config.roomPlayerDisconnectTime=60000; 4 | //房间生命周期(s) 5 | config.roomLifcCycleTime=60 * 60 * 2; 6 | //每秒钟处理消息数量 7 | config.session_prcoss_message_max_size=10; 8 | //异步通讯链接保持活跃时间(秒) 9 | config.rpcTcpHeartKeepAliveTime=60*60*24; 10 | //是否启动zookeeper 11 | config.zookeeperFlag=false; 12 | -------------------------------------------------------------------------------- /game-core/src/test/resources/rpc-server-register.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /game-core/src/test/resources/rpc-service-register.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /game-core/src/test/resources/udp-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | udp_server 5 | 11001 6 | 127.0.0.1 7 | 10090 8 | 1 9 | true 10 | 11 | -------------------------------------------------------------------------------- /game-core/src/test/resources/websocket-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | web_socket_server 5 | 11001 6 | 127.0.0.1 7 | 10300 8 | false 9 | 300 10 | 11 | -------------------------------------------------------------------------------- /game-core/src/test/resources/zookeeper.properties: -------------------------------------------------------------------------------- 1 | # zookeeper server 2 | registry.address=127.0.0.1:2181 -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/codegen/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from java_code_gen import JavaCodeGen 3 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/doc/images/config-header@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwpttcg66/NettyGameServer/6ef370c1116bdc617578d496d5d0a578da736084/game-core/tools/excelToCode/python/doc/images/config-header@2x.png -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/doc/images/direct-header@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwpttcg66/NettyGameServer/6ef370c1116bdc617578d496d5d0a578da736084/game-core/tools/excelToCode/python/doc/images/direct-header@2x.png -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/doc/images/excel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwpttcg66/NettyGameServer/6ef370c1116bdc617578d496d5d0a578da736084/game-core/tools/excelToCode/python/doc/images/excel.png -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/exporters/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from direct_exporter import DirectExporter 3 | from config_exporter import ConfigExporter 4 | from mix_exporter import MixExporter 5 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/generate_code.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | import sys 4 | import xlsconfig 5 | import util 6 | 7 | import codegen 8 | 9 | def generate_code(): 10 | print "=== 生成代码类文件 ..." 11 | 12 | configure_file_path = os.path.join(xlsconfig.TEMP_PATH, "configures.py") 13 | if not os.path.exists(configure_file_path): 14 | return log_error("配置文件'%s'不存在", configure_file_path) 15 | 16 | sys.path.insert(0, xlsconfig.TEMP_PATH) 17 | configure_module = util.import_file("configures") 18 | sys.path.remove(xlsconfig.TEMP_PATH) 19 | 20 | for key, cfg in configure_module.configures.iteritems(): 21 | _generate(cfg["types"], key) 22 | 23 | def _generate(config, module_name): 24 | for generator_info in xlsconfig.CODE_GENERATORS: 25 | cls = getattr(codegen, generator_info["class"]) 26 | output_path = generator_info["file_path"] 27 | 28 | gen = cls(config, module_name, output_path, generator_info) 29 | gen.run() 30 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/logtool.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import sys 3 | import os 4 | 5 | out = sys.stdout 6 | ENCODING = out.encoding 7 | print "enviroment encoding:", ENCODING 8 | 9 | def native_str_with_encoding(v): 10 | tp = type(v) 11 | if v == str: 12 | v = v.decode("utf-8") 13 | elif v != unicode: 14 | v = str(v).decode("utf-8") 15 | return v.encode(ENCODING) 16 | 17 | def native_str_utf8(v): 18 | tp = type(v) 19 | if v == unicode: 20 | v = v.encode("utf-8") 21 | elif v != str: 22 | v = str(v) 23 | return v 24 | 25 | def log_with_encoding(*args): 26 | for i, v in enumerate(args): 27 | args[i] = native_str_with_encoding(v) 28 | 29 | args.append("\n") 30 | out.write(" ".join(args)) 31 | 32 | def log_utf8(*args): 33 | for i, v in enumerate(args): 34 | args[i] = native_str_utf8(v) 35 | 36 | args.append("\n") 37 | out.write(" ".join(args)) 38 | 39 | log = log_utf8 40 | native_str = native_str_utf8 41 | 42 | if ENCODING and ENCODING.lower() != "utf-8": 43 | log = log_with_encoding 44 | native_str = native_str_with_encoding 45 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/parsers/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from direct_parser import DirectParser 3 | from config_parser import ConfigParser 4 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/postprocess/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from java_file_enum_processor import JavaFileEnumProcessor 3 | from java_file_list_processor import JavaFileListProcessor 4 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/postprocess/base_processor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | class BaseProcessor(object): 4 | 5 | def __init__(self, exporter, generator_info): 6 | super(BaseProcessor, self).__init__() 7 | 8 | self.exporter = exporter 9 | self.generator_info = generator_info 10 | 11 | def run(self): 12 | pass 13 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/sample/excels/example.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwpttcg66/NettyGameServer/6ef370c1116bdc617578d496d5d0a578da736084/game-core/tools/excelToCode/python/sample/excels/example.xlsx -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/sample/export.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | python ..\main.py --gen-code --export config.py 4 | 5 | pause 6 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/sample/export.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | python ../main.py --gen-code --export config.py 4 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/sample/export/java/code/DictEnum.java: -------------------------------------------------------------------------------- 1 | // 此文件由导表工具自动生成,禁止手动修改。 2 | 3 | package com.snowcattle.game.wolfshoot.service.dict.entity; 4 | 5 | public enum DictEnum { 6 | EXAMPLE, // 这是一张范例表 7 | }; 8 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/sample/export/java/data/d_example.wg: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "class" : "Example", 4 | "multiKey" : false, 5 | "header" : [ 6 | ["编号", "描述", "掉落关卡", "名称", "品质"], 7 | ["ID", "describe", "drops", "name", "quality"] 8 | ], 9 | "body" : [ 10 | {"ID" : 1, "describe" : "切菜用的", "drops" : "1,2,3,4", "name" : "菜刀", "quality" : 1}, 11 | {"ID" : 2, "drops" : "2", "name" : "上方宝剑", "quality" : 5}, 12 | {"ID" : 3, "name" : "偃月弯刀"} 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/sample/export/java/data/dict.wg: -------------------------------------------------------------------------------- 1 | { 2 | "package" : "com.snowcattle.game.wolfshoot.service.dict.entity", 3 | "dict" : [ 4 | ["EXAMPLE", "dict/d_example.wg", "DictExample"] 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/sample/export/xtemp/configures.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | configures = { 4 | "example": {"arguments": {"describe": "这是一张范例表", "multiKey": False, "version": 100, }, "types": {"ID": (0, "ID", "编号", "int", ), "describe": (2, "describe", "描述", "String", ), "drops": (4, "drops", "掉落关卡", "String", ), "name": (1, "name", "名称", "String", ), "quality": (3, "quality", "品质", "int", ), }, }, 5 | } 6 | 7 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/sample/export/xtemp/example.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | path = "example" 4 | 5 | info = { 6 | "arguments": {"describe": "这是一张范例表", "multiKey": False, "version": 100, }, 7 | "infile": "example.xlsx", 8 | "key_name": "ID", 9 | "multi_key": False, 10 | "outfile": "example", 11 | "parser": "example", 12 | "sheet_types": {"main_sheet": {"ID": (0, "ID", "编号", "int", ), "describe": (2, "describe", "描述", "String", ), "drops": (4, "drops", "掉落关卡", "String", ), "name": (1, "name", "名称", "String", ), "quality": (3, "quality", "品质", "int", ), }, }, 13 | } 14 | 15 | main_sheet = { 16 | 1: {"describe": "切菜用的", "drops": "1,2,3,4", "name": "菜刀", "quality": 1, }, 17 | 2: {"drops": "2", "name": "上方宝剑", "quality": 5, }, 18 | 3: {"name": "偃月弯刀", }, 19 | } 20 | 21 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/sample/export/xtemp/files.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | main_sheet = { 4 | "example": "example", 5 | } 6 | 7 | -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/tps/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwpttcg66/NettyGameServer/6ef370c1116bdc617578d496d5d0a578da736084/game-core/tools/excelToCode/python/tps/__init__.py -------------------------------------------------------------------------------- /game-core/tools/excelToCode/python/writers/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from base_writer import BaseWriter 4 | from lua_writer import LuaWriter 5 | from py_writer import PyWriter 6 | from json_writer import JsonWriter 7 | from java_writer import JavaWriter 8 | -------------------------------------------------------------------------------- /game-db/README.md: -------------------------------------------------------------------------------- 1 | # GameShardingDb 2 | 基于spring-sharding-mybaits集成redis缓存的游戏分布式存储框架.支持将对象序列化到队列里,异步存储。 使用spring集成mybatis3垂直和水平分库mysql.使用模版编程,采用代理模式,采集变化的字段,自动完成拼写sql,降低数据库落地难度 3 | 集成Mybatis-PageHelper分页,大数据量可以分批查询,提升查询速度 4 | 5 | 将同步存储底层落地抽象为EntityService, 具体存储服务可继承EntityService 6 | 7 | ### [使用手册](https://github.com/jwpttcg66/GameShardingDb/wiki) 8 | 9 | ### 参考demo为test下jdbc 10 | 11 | #### 贡献源码&合作&交流 12 | 13 | - 作者qq 330258845 14 | - QQ群:310158485 15 | 16 | 17 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/common/DbServiceName.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.common; 2 | 3 | /** 4 | * Created by jwp on 2017/4/18. 5 | */ 6 | public final class DbServiceName { 7 | public static final String uuidService = "uuidService"; 8 | public static final String asyncDbRegisterCenter = "asyncDbRegisterCenter"; 9 | public static final String asyncDbOperationCenter = "asyncDbOperationCenter"; 10 | public static final String asyncOperationRegistry = "asyncOperationRegistry"; 11 | 12 | private DbServiceName() { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/common/Loggers.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.common; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * Created by jwp on 2017/2/28. 8 | */ 9 | public final class Loggers { 10 | /** 数据库相关的日志 */ 11 | public static final Logger dbLogger = LoggerFactory.getLogger("db"); 12 | /** 数据库启动的日志 */ 13 | public static final Logger dbServerLogger = LoggerFactory.getLogger("dbServer"); 14 | 15 | /** 数据实体代理的日志 */ 16 | public static final Logger dbProxyLogger = LoggerFactory.getLogger("dbProxy"); 17 | /** 数据实体服务代理的日志 */ 18 | public static final Logger dbServiceProxyLogger = LoggerFactory.getLogger("dbServiceProxy"); 19 | 20 | /** 数据实体存储异常的日志 */ 21 | public static final Logger dbErrorLogger = LoggerFactory.getLogger("dbError"); 22 | 23 | private Loggers() { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/common/annotation/AsyncEntityOperation.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.common.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by jwp on 2017/4/12. 10 | * 异步存储操作 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.TYPE) 14 | public @interface AsyncEntityOperation { 15 | String bean(); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/common/annotation/DbMapper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.common.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Created by jwp on 2017/3/24. 7 | * 映射到mybatis db 8 | */ 9 | @Inherited 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Target(ElementType.TYPE) 12 | public @interface DbMapper { 13 | /** 14 | * @return 15 | */ 16 | Class mapper(); 17 | } 18 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/common/annotation/DbOperation.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.common.annotation; 2 | 3 | import com.snowcattle.game.db.common.enums.DbOperationEnum; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * Created by jwp on 2017/3/23. 12 | * 数据存储操作 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target(ElementType.METHOD) 16 | public @interface DbOperation { 17 | /** 18 | * @return 19 | */ 20 | DbOperationEnum operation(); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/common/annotation/EntitySave.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.common.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by jiangwenping on 17/3/16. 10 | * 此对象需要存储 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.TYPE) 14 | public @interface EntitySave { 15 | } 16 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/common/annotation/FieldSave.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.common.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by jiangwenping on 17/3/16. 10 | * 说明这个字段需要存储到db 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.FIELD) 14 | public @interface FieldSave { 15 | } 16 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/common/annotation/MethodSaveProxy.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.common.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by jiangwenping on 17/3/16. 10 | * 类需要使用代理 会通过此注解,注入到代理对象的变化集合里 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.METHOD) 14 | public @interface MethodSaveProxy { 15 | /** 16 | * @return 17 | */ 18 | String proxy(); 19 | } 20 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/common/enums/DbOperationEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.common.enums; 2 | 3 | /** 4 | * Created by jwp on 2017/3/23. 5 | * 数据存储操作 6 | */ 7 | public enum DbOperationEnum { 8 | insert, 9 | update, 10 | query, 11 | queryList, 12 | delete, 13 | insertBatch, 14 | updateBatch, 15 | deleteBatch, 16 | ; 17 | } 18 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/entity/BaseLongIDEntity.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.entity; 2 | 3 | 4 | import com.snowcattle.game.db.common.annotation.EntitySave; 5 | import com.snowcattle.game.db.common.annotation.FieldSave; 6 | import com.snowcattle.game.db.common.annotation.MethodSaveProxy; 7 | 8 | /** 9 | * Created by jiangwenping on 17/4/5. 10 | */ 11 | @EntitySave 12 | public class BaseLongIDEntity extends AbstractEntity { 13 | 14 | private static final long serialVersionUID = 4306013556612810860L; 15 | @FieldSave 16 | private Long id; 17 | 18 | @Override 19 | public Long getId() { 20 | return id; 21 | } 22 | 23 | 24 | @MethodSaveProxy(proxy="id") 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/entity/BaseStringIDEntity.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.entity; 2 | 3 | import com.snowcattle.game.db.common.annotation.EntitySave; 4 | import com.snowcattle.game.db.common.annotation.FieldSave; 5 | import com.snowcattle.game.db.common.annotation.MethodSaveProxy; 6 | 7 | /** 8 | * Created by sunmosh on 2017/4/5. 9 | */ 10 | @EntitySave 11 | public class BaseStringIDEntity extends AbstractEntity { 12 | 13 | private static final long serialVersionUID = 4165629356522195369L; 14 | @FieldSave 15 | private String id; 16 | 17 | @Override 18 | public String getId() { 19 | return id; 20 | } 21 | 22 | @MethodSaveProxy(proxy="id") 23 | @Override 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/entity/IEntity.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by jiangwenping on 17/3/16. 7 | * 基本的数据存储对象 8 | */ 9 | public interface IEntity extends Serializable { 10 | public ID getId(); 11 | public void setId(ID id); 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/entity/ISoftDeleteEntity.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | /** 7 | * Created by jiangwenping on 17/3/16. 8 | * 所有对象都是先设置删除时间,删除标志,设置缓存,然后同步db异步操作执行删除后,执行回调,然后删除缓存 9 | * 缓存获取对象的时候,需要过滤已经删除的对象 10 | */ 11 | public interface ISoftDeleteEntity extends IEntity { 12 | public boolean isDeleted(); 13 | public void setDeleted(boolean deleted); 14 | public Date getDeleteTime(); 15 | public void setDeleteTime(Date deleteTime); 16 | } 17 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/async/transaction/factory/DbGameTransactionCauseFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.async.transaction.factory; 2 | 3 | import com.redis.transaction.enums.GameTransactionCause; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * Created by jiangwenping on 17/4/13. 8 | */ 9 | @Service 10 | public class DbGameTransactionCauseFactory { 11 | public GameTransactionCause asyncDbSave = new GameTransactionCause("asyncDbSave"); 12 | 13 | public GameTransactionCause getAsyncDbSave() { 14 | return asyncDbSave; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/async/transaction/factory/DbGameTransactionEntityCauseFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.async.transaction.factory; 2 | 3 | import com.redis.transaction.enums.GameTransactionEntityCause; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * Created by jwp on 2017/4/12. 8 | */ 9 | @Service 10 | public class DbGameTransactionEntityCauseFactory { 11 | 12 | public final GameTransactionEntityCause asyncDbSave = new GameTransactionEntityCause("asyncDbSave"); 13 | 14 | public GameTransactionEntityCause getAsyncDbSave() { 15 | return asyncDbSave; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/async/transaction/factory/DbGameTransactionKeyFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.async.transaction.factory; 2 | 3 | import com.redis.config.GlobalConstants; 4 | import com.redis.transaction.enums.GameTransactionEntityCause; 5 | import com.redis.transaction.factory.GameTransactionKeyFactory; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by jwp on 2017/4/12. 10 | */ 11 | @Service 12 | public class DbGameTransactionKeyFactory extends GameTransactionKeyFactory { 13 | /** 14 | * 获取玩家锁 15 | * @param cause 16 | * @return 17 | */ 18 | public String getPlayerTransactionEntityKey(GameTransactionEntityCause cause, String redisKey, String union){ 19 | return redisKey + cause.getCause() + GlobalConstants.Strings.commonSplitString + union; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/common/service/IDbService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.service; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/17. 5 | */ 6 | public interface IDbService { 7 | public String getDbServiceName(); 8 | public void startup() throws Exception; 9 | public void shutdown() throws Exception; 10 | } 11 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/common/uuid/IUUIDService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.uuid; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/16. 5 | */ 6 | public interface IUUIDService { 7 | public long nextId(); 8 | } 9 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/entity/EntityKeyShardingStrategyEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.entity; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/21. 5 | * 分配策略 6 | */ 7 | public enum EntityKeyShardingStrategyEnum { 8 | ID, 9 | USER_ID, 10 | ; 11 | } 12 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/jdbc/mapper/IDBMapper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.jdbc.mapper; 2 | 3 | import com.snowcattle.game.db.entity.IEntity; 4 | import org.apache.ibatis.session.RowBounds; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * Created by jiangwenping on 17/3/21. 11 | * 基础mapper 12 | */ 13 | public interface IDBMapper { 14 | public long insertEntity(T entity); 15 | public IEntity getEntity(T entity); 16 | public List getEntityList(T entity); 17 | public List getEntityList(T entity, RowBounds rowBounds); 18 | 19 | /** 20 | * 直接查找db,无缓存 21 | * @param map 22 | * @return 23 | */ 24 | public List filterList(Map map); 25 | 26 | /** 27 | * 直接查找db,无缓存 28 | * @param map 29 | * @return 30 | */ 31 | public List filterList(Map map, RowBounds rowBounds); 32 | 33 | public void updateEntityByMap(Map map); 34 | public void deleteEntity(T entity); 35 | } 36 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/proxy/EntityProxyWrapper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.proxy; 2 | 3 | import com.snowcattle.game.db.entity.AbstractEntity; 4 | 5 | /** 6 | * Created by jwp on 2017/3/16. 7 | * 代理封装 8 | */ 9 | public class EntityProxyWrapper { 10 | 11 | private EntityProxy entityProxy; 12 | 13 | public EntityProxyWrapper(EntityProxy entityProxy) { 14 | this.entityProxy = entityProxy; 15 | } 16 | 17 | public EntityProxy getEntityProxy() { 18 | return entityProxy; 19 | } 20 | 21 | public void setEntityProxy(EntityProxy entityProxy) { 22 | this.entityProxy = entityProxy; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/redis/AsyncRedisKeyEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.redis; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/6. 5 | * 异步处处的redis key 6 | */ 7 | public enum AsyncRedisKeyEnum { 8 | ASYNC_DB("ay_db#"), 9 | ; 10 | 11 | private final String key; 12 | 13 | AsyncRedisKeyEnum(String key){ 14 | this.key = key; 15 | } 16 | 17 | public static AsyncRedisKeyEnum getAsyncRedisKeyEnum(String key){ 18 | AsyncRedisKeyEnum result = null; 19 | for(AsyncRedisKeyEnum temp: AsyncRedisKeyEnum.values()){ 20 | if(temp.getKey().equals(key)){ 21 | result = temp; 22 | break; 23 | } 24 | } 25 | return result; 26 | } 27 | 28 | public String getKey(){ 29 | return this.key; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/redis/AsyncSave.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.redis; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/29. 5 | * 异步存储 6 | */ 7 | public interface AsyncSave { 8 | } 9 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/redis/RedisInterface.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.redis; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/16. 5 | * 默认保存为map, 保证更新不会被覆盖 6 | */ 7 | public interface RedisInterface { 8 | public String getUnionKey(); 9 | public String getRedisKeyEnumString(); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/redis/RedisKeyEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.redis; 2 | 3 | 4 | 5 | /** 6 | * 缓存键值 7 | */ 8 | public enum RedisKeyEnum { 9 | 10 | PLAYER("pr#"), 11 | TOCKEN("tk#"), 12 | ASYNC_PLAYER("ay_pr"), 13 | ; 14 | 15 | private final String key; 16 | 17 | RedisKeyEnum(String key){ 18 | this.key = key; 19 | } 20 | 21 | public static RedisKeyEnum geRedisKeyEnum(String key){ 22 | RedisKeyEnum result = null; 23 | for(RedisKeyEnum temp: RedisKeyEnum.values()){ 24 | if(temp.getKey().equals(key)){ 25 | result = temp; 26 | break; 27 | } 28 | } 29 | return result; 30 | } 31 | 32 | public String getKey(){ 33 | return this.key; 34 | } 35 | } -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/redis/RedisListInterface.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.redis; 2 | 3 | 4 | 5 | /** 6 | * 列表类型的缓存对象 7 | * 8 | */ 9 | public interface RedisListInterface{ 10 | public String getShardingKey(); 11 | public String getRedisKeyEnumString(); 12 | 13 | /** 14 | * 列表对象的子唯一主键属性 15 | */ 16 | public String getSubUniqueKey(); 17 | } 18 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/service/redis/RedisPageInterface.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.redis; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author b053-mac 7 | * redis分页数据接口 8 | * 分页接口 需要额外填写zset 需要提供key,score 9 | */ 10 | public interface RedisPageInterface { 11 | public RedisKeyEnum getPageRedisKeyEnum(); 12 | public Serializable getScore(); 13 | } 14 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/sharding/AbstractShardingTable.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.sharding; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/20. 5 | */ 6 | public abstract class AbstractShardingTable { 7 | 8 | private Integer sharding_table_index; 9 | 10 | public Integer getSharding_table_index() { 11 | return sharding_table_index; 12 | } 13 | 14 | public void setSharding_table_index(Integer sharding_table_index) { 15 | this.sharding_table_index = sharding_table_index; 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/sharding/CustomerContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.sharding; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * Created by jiangwenping on 17/3/6. 7 | */ 8 | @Service 9 | public final class CustomerContextHolder { 10 | 11 | private static final ThreadLocal contextHolder = new ThreadLocal(); 12 | 13 | private CustomerContextHolder() { 14 | } 15 | 16 | 17 | public static String getCustomerType() { 18 | return contextHolder.get(); 19 | } 20 | /** 21 | * 通过字符串选择数据源 22 | * @param customerType 23 | */ 24 | public static void setCustomerType(String customerType) { 25 | contextHolder.set(customerType); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/sharding/DataSourceType.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.sharding; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/6. 5 | */ 6 | public enum DataSourceType { 7 | jdbc_player_db, 8 | ; 9 | } 10 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/sharding/DynamicDataSource.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.sharding; 2 | 3 | import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; 4 | 5 | /** 6 | * Created by jiangwenping on 17/3/6. 7 | */ 8 | 9 | public class DynamicDataSource extends AbstractRoutingDataSource { 10 | @Override 11 | protected Object determineCurrentLookupKey() { 12 | return CustomerContextHolder.getCustomerType(); 13 | } 14 | } -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/sharding/ShardingTable.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.sharding; 2 | 3 | /** 4 | * Created by jiangwenping on 17/3/20. 5 | * 基础实现shardingTable 6 | */ 7 | public class ShardingTable extends AbstractShardingTable { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /game-db/src/main/java/com/snowcattle/game/db/util/PageUtils.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.util; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by jwp on 2017/3/22. 7 | */ 8 | public final class PageUtils { 9 | private PageUtils() { 10 | } 11 | 12 | /** 13 | * 截取某列表的部分数据 14 | * @param 15 | * @param list 16 | * @param skip 17 | * @param pageSize 18 | */ 19 | public static List getSubListPage(List list, int skip, int pageSize) { 20 | if(list==null||list.isEmpty()){ 21 | return null; 22 | } 23 | int startIndex = skip; 24 | int endIndex = skip+pageSize; 25 | if(startIndex>endIndex||startIndex>list.size()){ 26 | return null; 27 | } 28 | if(endIndex>list.size()){ 29 | endIndex = list.size(); 30 | } 31 | return list.subList(startIndex, endIndex); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /game-db/src/main/resources/db_jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc-driver=com.mysql.jdbc.Driver 2 | 3 | ################### DataSource Configuration ########################## 4 | jdbc-url-0=jdbc:mysql://192.168.0.211:3306/db_0?useUnicode=true&characterEncoding=utf8 5 | jdbc-user-0=root 6 | jdbc-password-0=123456 7 | 8 | jdbc-url-1=jdbc:mysql://192.168.0.211:3306/db_1?useUnicode=true&characterEncoding=utf8 9 | jdbc-user-1=root 10 | jdbc-password-1=123456 11 | 12 | jdbc-url-2=jdbc:mysql://192.168.0.211:3306/db_2?useUnicode=true&characterEncoding=utf8 13 | jdbc-user-2=root 14 | jdbc-password-2=123456 -------------------------------------------------------------------------------- /game-db/src/main/resources/mybatis3/mappers/orderMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | INSERT INTO `t_order_${sharding_table_index}` (order_id, user_id, status) 9 | VALUES (#{orderId},#{userId},#{status}) 10 | 11 | 12 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/aop/AOPTest.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.aop; 2 | 3 | /** 4 | * Created by jwp on 2017/3/22. 5 | */ 6 | public class AOPTest { 7 | 8 | // static PersonService personService; 9 | // @BeforeClass 10 | // public static void setUpBeforeClass() throws Exception { 11 | // ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(new String[]{"bean/*.xml"}); 12 | // personService = (PersonService) classPathXmlApplicationContext.getBean("personServiceBean"); 13 | // } 14 | // @Test 15 | // public void saveTest() { 16 | // personService.save(new Person()); 17 | // } 18 | // 19 | // @AfterClass 20 | // public static void tearDownAfterClass() throws Exception { 21 | // } 22 | } 23 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/aop/Person.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.aop; 2 | 3 | /** 4 | * Created by jwp on 2017/3/22. 5 | */ 6 | public class Person { 7 | private Long id; 8 | private String name; 9 | 10 | public Long getId() { 11 | return id; 12 | } 13 | 14 | public void setId(Long id) { 15 | this.id = id; 16 | } 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/aop/PersonService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.aop; 2 | 3 | /** 4 | * Created by jwp on 2017/3/22. 5 | */ 6 | public interface PersonService { 7 | public void save(Person person); 8 | } 9 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/aop/PersonServiceBean.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.aop; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * Created by jwp on 2017/3/22. 7 | */ 8 | @Service("personService") 9 | public class PersonServiceBean implements PersonService { 10 | private String user; 11 | 12 | public String getUser() { 13 | return user; 14 | } 15 | 16 | public void setUser(String user) { 17 | this.user = user; 18 | } 19 | 20 | public PersonServiceBean() { 21 | } 22 | 23 | public PersonServiceBean(String user) { 24 | super(); 25 | this.user = user; 26 | } 27 | 28 | public void save(Person person) { 29 | System.out.println("执行PerServiceBean的save方法"); 30 | //throw new RuntimeException("======"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/cache/ObjectTest.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.cache; 2 | 3 | import com.snowcattle.game.db.entity.AbstractEntity; 4 | import com.snowcattle.game.db.service.jdbc.entity.Order; 5 | 6 | /** 7 | * Created by jwp on 2017/3/28. 8 | */ 9 | public final class ObjectTest { 10 | 11 | public static void main(String[] args) throws InterruptedException { 12 | int maxSize = 1000000; 13 | AbstractEntity[] abstractEntity = new AbstractEntity[maxSize]; 14 | for(int i = 0; i < 1000000; i++){ 15 | Order order = new Order(); 16 | order.setId((long)i); 17 | order.setUserId(10); 18 | order.setStatus(String.valueOf(i)); 19 | abstractEntity[i] = order; 20 | } 21 | 22 | Thread.sleep(10000000); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/cglib/DoCGLib.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.cglib; 2 | 3 | /** 4 | * Created by jwp on 2017/3/3. 5 | */ 6 | public final class DoCGLib { 7 | public static void main(String[] args) { 8 | CglibProxy proxy = new CglibProxy(); 9 | //通过生成子类的方式创建代理类 10 | SayHello proxyImp = (SayHello)proxy.getProxy(SayHello.class); 11 | proxyImp.say(); 12 | } 13 | } -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/cglib/SayHello.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.cglib; 2 | 3 | /** 4 | * Created by jwp on 2017/3/3. 5 | */ 6 | public class SayHello { 7 | public void say(){ 8 | System.out.println("hello everyone"); 9 | } 10 | } -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/entity/TestEntity.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.entity; 2 | 3 | import com.snowcattle.game.db.entity.BaseLongIDEntity; 4 | 5 | /** 6 | * Created by jwp on 2017/3/16. 7 | */ 8 | public class TestEntity extends BaseLongIDEntity { 9 | 10 | private static final long serialVersionUID = -7157884788511223454L; 11 | } 12 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/fastjson/Status.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.fastjson; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/6. 5 | */ 6 | public enum Status { 7 | 8 | Ready(10), 9 | 10 | Completed(20); 11 | 12 | private final int value; 13 | 14 | private Status(int value) { 15 | this.value = value; 16 | } 17 | 18 | public static Status create(String value) { 19 | return valueOf(value); 20 | } 21 | 22 | public static int value(Status status){ 23 | return status.value; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/common/fastjson/StatusDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.common.fastjson; 2 | 3 | import com.alibaba.fastjson.parser.DefaultJSONParser; 4 | import com.alibaba.fastjson.parser.JSONLexer; 5 | import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer; 6 | 7 | import java.lang.reflect.Type; 8 | 9 | /** 10 | * Created by jiangwenping on 17/4/6. 11 | */ 12 | public class StatusDeserializer implements ObjectDeserializer { 13 | 14 | public T deserialze(DefaultJSONParser parser, Type type, 15 | Object fieldName) { 16 | JSONLexer lexer = parser.getLexer(); 17 | String value = lexer.stringVal(); 18 | return (T) Status.create(value); 19 | } 20 | 21 | public int getFastMatchToken() { 22 | // TODO Auto-generated method stub 23 | return 0; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/jdbc/mapper/MoreOrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.jdbc.mapper; 2 | 3 | import com.snowcattle.game.db.service.jdbc.entity.MoreOrder; 4 | 5 | /** 6 | * Created by jiangwenping on 17/4/14. 7 | */ 8 | public interface MoreOrderMapper extends IDBMapper{ 9 | 10 | } 11 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/jdbc/mapper/OrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.jdbc.mapper; 2 | 3 | 4 | import com.snowcattle.game.db.service.jdbc.entity.Order; 5 | 6 | /** 7 | * Created by jiangwenping on 17/3/6. 8 | */ 9 | public interface OrderMapper extends IDBMapper{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/jdbc/mapper/TockenMapper.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.jdbc.mapper; 2 | 3 | import com.snowcattle.game.db.service.jdbc.entity.Tocken; 4 | 5 | /** 6 | * Created by sunmosh on 2017/4/5. 7 | */ 8 | public interface TockenMapper extends IDBMapper{ 9 | } 10 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/jdbc/service/entity/IMoreOrderService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.jdbc.service.entity; 2 | 3 | import com.snowcattle.game.db.service.jdbc.entity.MoreOrder; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by jiangwenping on 17/4/5. 9 | */ 10 | public interface IMoreOrderService { 11 | public List getMoreOrderList(MoreOrder moreOrder); 12 | public void insertMoreOrderList(List orderList); 13 | 14 | public long insertMoreOrder(MoreOrder moreOrder); 15 | public MoreOrder getMoreOrder(long userId, long id); 16 | public List getMoreOrderList(long userId); 17 | public List getMoreOrderList(long userId, String status); 18 | void updateMoreOrder(MoreOrder order); 19 | void deleteMoreOrder(MoreOrder order); 20 | public void updateMoreOrderList(List orderList); 21 | public void deleteMoreOrderList(List orderList); 22 | } 23 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/jdbc/service/entity/IOrderService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.jdbc.service.entity; 2 | 3 | import com.snowcattle.game.db.service.jdbc.entity.Order; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by jiangwenping on 17/3/20. 9 | */ 10 | public interface IOrderService { 11 | public long insertOrder(Order order); 12 | public Order getOrder(long userId, long id); 13 | public List getOrderList(long userId); 14 | public List getOrderList(long userId, String status); 15 | void updateOrder(Order order); 16 | void deleteOrder(Order order); 17 | 18 | public List insertOrderList(List order); 19 | public void updateOrderList(List order); 20 | public void deleteOrderList(List order); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/jdbc/service/entity/ITockenService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.jdbc.service.entity; 2 | 3 | import com.snowcattle.game.db.service.jdbc.entity.Tocken; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by sunmosh on 2017/4/5. 9 | */ 10 | public interface ITockenService { 11 | public long insertTocken(Tocken Tocken); 12 | public Tocken getTocken(long userId, String id); 13 | public List getTockenList(long userId); 14 | void updateTocken(Tocken Tocken); 15 | void deleteTocken(Tocken Tocken); 16 | } 17 | -------------------------------------------------------------------------------- /game-db/src/test/java/com/snowcattle/game/db/service/jdbc/test/TestConstants.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.db.service.jdbc.test; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/14. 5 | */ 6 | public final class TestConstants { 7 | 8 | public static long userId = 98999; 9 | public static long id = 3603; 10 | public static int batchStart = 120000000; 11 | public static int saveSize = 5000; 12 | public static String stringId = String.valueOf(id); 13 | 14 | private TestConstants() { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /game-db/src/test/resources/db_jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc-driver=com.mysql.jdbc.Driver 2 | 3 | ################### DataSource Configuration ########################## 4 | jdbc-url-0=jdbc:mysql://localhost:3306/db_0?useUnicode=true&characterEncoding=utf8 5 | jdbc-user-0=root 6 | jdbc-password-0=123456 7 | 8 | jdbc-url-1=jdbc:mysql://localhost:3306/db_1?useUnicode=true&characterEncoding=utf8 9 | jdbc-user-1=root 10 | jdbc-password-1=123456 11 | 12 | jdbc-url-2=jdbc:mysql://localhost:3306/db_2?useUnicode=true&characterEncoding=utf8 13 | jdbc-user-2=root 14 | jdbc-password-2=123456 -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/common/UpdateExecutorEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.common; 2 | 3 | /** 4 | * Created by jiangwenping on 17/4/25. 5 | * 更新器执行类型 6 | */ 7 | public enum UpdateExecutorEnum { 8 | /*使用locksupport方式*/ 9 | locksupport, 10 | /*使用绑定线程*/ 11 | bindThread, 12 | /**使用disruptor*/ 13 | disruptor, 14 | ; 15 | } 16 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/common/utils/CommonErrorInfo.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.common.utils; 2 | 3 | /** 4 | * Created by jiangwenping on 17/1/11. 5 | */ 6 | public final class CommonErrorInfo { 7 | 8 | /** 线程被中断 */ 9 | public static final String THRAD_ERR_INTERRUPTED = "THR.ERR.INTRRUPTED"; 10 | 11 | /** 消息处理时发生未知的异常 */ 12 | public static final String EVENT_PRO_ERROR = "EVENT.PRO.ERR"; 13 | /** 消息处理时收到空的消息 */ 14 | public static final String EVENT_PRO_NULL_MSG = "EVENT.PRO.ERR.NULL.MSG"; 15 | 16 | private CommonErrorInfo() { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/common/utils/Loggers.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.common.utils; 2 | 3 | 4 | import org.slf4j.Logger; 5 | 6 | import org.slf4j.LoggerFactory; 7 | 8 | /** 9 | * Created by jiangwenping on 17/1/11. 10 | */ 11 | public final class Loggers { 12 | /** Server相关的日志 */ 13 | public static final Logger gameExecutorError = (Logger) LoggerFactory.getLogger("gameExecutorError"); 14 | /** Server相关的日志 */ 15 | public static final Logger gameExecutorUtil = (Logger) LoggerFactory.getLogger("gameExecutorUtil"); 16 | /** Server相关的日志 */ 17 | public static final Logger gameExecutorEvent = (Logger) LoggerFactory.getLogger("gameExecutorEvent"); 18 | 19 | private Loggers() { 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/AbstractEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event; 2 | 3 | import com.snowcattle.game.executor.event.common.IEvent; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by jiangwenping on 17/1/9. 9 | */ 10 | public abstract class AbstractEvent implements IEvent { 11 | 12 | private EventType eventType; 13 | private EventParam[] eventParamps; 14 | private ID id; 15 | 16 | public void setEventType(EventType eventType) { 17 | this.eventType = eventType; 18 | } 19 | 20 | public EventType getEventType() { 21 | return this.eventType; 22 | } 23 | 24 | public EventParam[] getParams() { 25 | return this.eventParamps; 26 | } 27 | 28 | public void setParams(EventParam... eventParams) { 29 | this.eventParamps = eventParams; 30 | } 31 | 32 | public ID getId() { 33 | return id; 34 | } 35 | 36 | public void setId(ID id) { 37 | this.id = id; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/EventParam.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event; 2 | 3 | /** 4 | * Created by jiangwenping on 17/1/6. 5 | * 事件参数 6 | */ 7 | public class EventParam { 8 | 9 | private T t; 10 | 11 | public EventParam(T t) { 12 | this.t = t; 13 | } 14 | 15 | public T getT() { 16 | return t; 17 | } 18 | 19 | public void setT(T t) { 20 | this.t = t; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/EventType.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event; 2 | 3 | /** 4 | * Created by jiangwenping on 17/1/6. 5 | * 事件类型 6 | */ 7 | public class EventType { 8 | 9 | private int index; 10 | 11 | public EventType(int index) { 12 | this.index = index; 13 | } 14 | 15 | public int getIndex() { 16 | return index; 17 | } 18 | 19 | public void setIndex(int index) { 20 | this.index = index; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/SingleEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by jwp on 2017/5/5. 7 | * 单次循环的事件 8 | */ 9 | public class SingleEvent extends AbstractEvent { 10 | 11 | //用于线程分片的shardingId 12 | private Long shardingId; 13 | 14 | public SingleEvent(EventType eventType, ID eventId, long shardingId, EventParam... parms){ 15 | setEventType(eventType); 16 | setParams(parms); 17 | setId(eventId); 18 | this.shardingId = shardingId; 19 | } 20 | 21 | public Long getShardingId() { 22 | return shardingId; 23 | } 24 | 25 | public void setShardingId(Long shardingId) { 26 | this.shardingId = shardingId; 27 | } 28 | 29 | @Override 30 | public void call() { 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/common/IEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.common; 2 | 3 | import com.snowcattle.game.executor.event.EventParam; 4 | import com.snowcattle.game.executor.event.EventType; 5 | 6 | /** 7 | * Created by jiangwenping on 17/1/6. 8 | * 事件定义 9 | */ 10 | public interface IEvent{ 11 | public void setEventType(EventType eventType); 12 | public EventType getEventType(); 13 | public EventParam[] getParams(); 14 | public void setParams(EventParam... eventParams); 15 | public void call(); 16 | } 17 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/common/IEventBus.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.common; 2 | 3 | import com.snowcattle.game.executor.event.AbstractEventListener; 4 | 5 | /** 6 | * Created by jiangwenping on 17/1/6. 7 | * ⌚ 8 | */ 9 | public interface IEventBus { 10 | public void addEventListener(AbstractEventListener listene); 11 | public void removeEventListener(AbstractEventListener listene); 12 | public void clearEventListener(); 13 | public void addEvent(IEvent event); 14 | public void handleEvent(); 15 | public void handleSingleEvent(IEvent event) throws Exception; 16 | public void clearEvent(); 17 | public void clear(); 18 | } 19 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/common/IEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.common; 2 | 3 | import com.snowcattle.game.executor.event.EventType; 4 | 5 | /** 6 | * Created by jiangwenping on 17/1/6. 7 | * 事件监听器 8 | */ 9 | public interface IEventListener { 10 | 11 | public void register(EventType eventType); 12 | public boolean containEventType(EventType eventType); 13 | public void fireEvent(IEvent event); 14 | } 15 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/common/constant/EventTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.common.constant; 2 | 3 | /** 4 | * Created by jiangwenping on 17/1/9. 5 | * 事件类型 6 | */ 7 | public enum EventTypeEnum { 8 | /** 9 | * 创建 10 | */ 11 | CREATE, 12 | 13 | /** 14 | * 更新 15 | */ 16 | UPDATE, 17 | 18 | /** 19 | * 完成 20 | */ 21 | FINISH, 22 | 23 | 24 | /** 25 | * 准备创建 26 | */ 27 | REDAY_CREATE, 28 | 29 | /** 30 | * 准备结束 31 | */ 32 | REDAY_FINISH, 33 | 34 | /** 35 | * 结束 36 | */ 37 | FINISHED, 38 | ; 39 | } 40 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/factory/CycleDisruptorEventFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.factory; 2 | 3 | import com.lmax.disruptor.EventFactory; 4 | import com.snowcattle.game.executor.event.CycleEvent; 5 | 6 | /** 7 | * Created by jiangwenping on 17/4/24. 8 | */ 9 | public class CycleDisruptorEventFactory implements EventFactory { 10 | 11 | @Override 12 | public CycleEvent newInstance() { 13 | return new CycleEvent(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/event/CreateEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.event; 2 | 3 | import com.snowcattle.game.executor.event.CycleEvent; 4 | import com.snowcattle.game.executor.event.EventParam; 5 | import com.snowcattle.game.executor.event.EventType; 6 | import com.snowcattle.game.executor.common.utils.Loggers; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * Created by jiangwenping on 17/1/11. 12 | * dispatch thread使用 13 | */ 14 | public class CreateEvent extends CycleEvent { 15 | 16 | public CreateEvent(EventType eventType,ID eventId, EventParam... parms){ 17 | // setEventType(eventType); 18 | // setParams(parms); 19 | super(eventType, eventId, parms); 20 | } 21 | 22 | public void call() { 23 | if(Loggers.gameExecutorUtil.isDebugEnabled()){ 24 | EventParam[] eventParams = getParams(); 25 | Loggers.gameExecutorUtil.debug("create event " + eventParams[0].getT()); 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/event/FinishEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.event; 2 | 3 | import com.snowcattle.game.executor.event.CycleEvent; 4 | import com.snowcattle.game.executor.event.EventParam; 5 | import com.snowcattle.game.executor.event.EventType; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * Created by jiangwenping on 17/1/11. 11 | * dispatch 使用 12 | */ 13 | public class FinishEvent extends CycleEvent { 14 | public FinishEvent(EventType eventType, ID eventId,EventParam... parms){ 15 | // setEventType(eventType); 16 | // setParams(parms); 17 | super(eventType, eventId, parms); 18 | } 19 | 20 | public void call() { 21 | // EventParam[] eventParams = getParams(); 22 | // System.out.println(eventParams[0].getT() + "float"+ eventParams[1].getT()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/event/FinishedEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.event; 2 | 3 | import com.snowcattle.game.executor.event.CycleEvent; 4 | import com.snowcattle.game.executor.event.EventParam; 5 | import com.snowcattle.game.executor.event.EventType; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * Created by jiangwenping on 17/2/21. 11 | * updateService使用 12 | */ 13 | public class FinishedEvent extends CycleEvent { 14 | 15 | public FinishedEvent(EventType eventType, ID eventId, EventParam... parms){ 16 | super(eventType, eventId, parms); 17 | } 18 | 19 | public void call() { 20 | // EventParam[] eventParams = getParams(); 21 | // System.out.println(eventParams[0].getT() + "float"+ eventParams[1].getT()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/event/ReadFinishEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.event; 2 | 3 | import com.snowcattle.game.executor.event.CycleEvent; 4 | import com.snowcattle.game.executor.event.EventParam; 5 | import com.snowcattle.game.executor.event.EventType; 6 | 7 | /** 8 | * Created by jiangwenping on 17/1/16. 9 | * updateService使用 10 | */ 11 | public class ReadFinishEvent extends CycleEvent { 12 | 13 | //是否是内部销毁 内部销毁才会销毁缓存 14 | private boolean innerUpdateFlag; 15 | 16 | public ReadFinishEvent(EventType eventType, long eventId, EventParam... parms){ 17 | super(eventType, eventId, parms); 18 | } 19 | 20 | public void call() { 21 | 22 | } 23 | 24 | public boolean isInnerUpdateFlag() { 25 | return innerUpdateFlag; 26 | } 27 | 28 | public void setInnerUpdateFlag(boolean innerUpdateFlag) { 29 | this.innerUpdateFlag = innerUpdateFlag; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/event/ReadyCreateEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.event; 2 | 3 | import com.snowcattle.game.executor.event.CycleEvent; 4 | import com.snowcattle.game.executor.event.EventParam; 5 | import com.snowcattle.game.executor.event.EventType; 6 | 7 | /** 8 | * Created by jiangwenping on 17/1/16. 9 | * updateService使用 10 | */ 11 | public class ReadyCreateEvent extends CycleEvent { 12 | 13 | public ReadyCreateEvent(EventType eventType, long eventId, EventParam... parms){ 14 | super(eventType, eventId, parms); 15 | } 16 | 17 | public void call() { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/listener/CreateEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.listener; 2 | 3 | import com.snowcattle.game.executor.common.utils.Constants; 4 | import com.snowcattle.game.executor.event.AbstractEventListener; 5 | 6 | /** 7 | * Created by jiangwenping on 17/1/9. 8 | * 创建监听器 9 | */ 10 | public class CreateEventListener extends AbstractEventListener { 11 | 12 | @Override 13 | public void initEventType() { 14 | register(Constants.EventTypeConstans.createEventType); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/listener/FinishEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.listener; 2 | 3 | import com.snowcattle.game.executor.common.utils.Constants; 4 | import com.snowcattle.game.executor.event.AbstractEventListener; 5 | 6 | /** 7 | * Created by jiangwenping on 17/1/11. 8 | * 完成监听器 9 | */ 10 | public class FinishEventListener extends AbstractEventListener { 11 | 12 | @Override 13 | public void initEventType() { 14 | register(Constants.EventTypeConstans.finishEventType); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/listener/ReadyCreateEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.listener; 2 | 3 | import com.snowcattle.game.executor.event.AbstractEventListener; 4 | import com.snowcattle.game.executor.common.utils.Constants; 5 | 6 | /** 7 | * Created by jiangwenping on 17/1/16. 8 | */ 9 | public class ReadyCreateEventListener extends AbstractEventListener { 10 | @Override 11 | public void initEventType() { 12 | register(Constants.EventTypeConstans.readyCreateEventType); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/listener/ReadyFinishEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.listener; 2 | 3 | import com.snowcattle.game.executor.event.AbstractEventListener; 4 | import com.snowcattle.game.executor.common.utils.Constants; 5 | 6 | /** 7 | * Created by jiangwenping on 17/1/16. 8 | */ 9 | public class ReadyFinishEventListener extends AbstractEventListener { 10 | @Override 11 | public void initEventType() { 12 | register(Constants.EventTypeConstans.readyFinishEventType); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/impl/listener/UpdateEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.impl.listener; 2 | 3 | import com.snowcattle.game.executor.common.utils.Constants; 4 | import com.snowcattle.game.executor.event.AbstractEventListener; 5 | 6 | /** 7 | * Created by jiangwenping on 17/1/11. 8 | * 更新监听器 9 | */ 10 | public class UpdateEventListener extends AbstractEventListener { 11 | 12 | @Override 13 | public void initEventType() { 14 | register(Constants.EventTypeConstans.updateEventType); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/event/service/SingleEventWork.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.service; 2 | 3 | import com.snowcattle.game.executor.common.utils.Loggers; 4 | import com.snowcattle.game.executor.event.EventBus; 5 | import com.snowcattle.game.executor.event.SingleEvent; 6 | import com.snowcattle.game.thread.worker.AbstractWork; 7 | 8 | /** 9 | * Created by jwp on 2017/5/5. 10 | * 单事件worker 11 | */ 12 | public class SingleEventWork extends AbstractWork{ 13 | 14 | private final EventBus eventBus; 15 | private final SingleEvent singleEvent; 16 | 17 | public SingleEventWork(EventBus eventBus, SingleEvent singleEvent) { 18 | this.eventBus = eventBus; 19 | this.singleEvent = singleEvent; 20 | } 21 | 22 | @Override 23 | public void run() { 24 | try { 25 | eventBus.handleSingleEvent(singleEvent); 26 | }catch (Exception e){ 27 | Loggers.gameExecutorError.error(e.toString(), e); 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/cache/UpdateEventCacheFactory.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.cache; 2 | 3 | import com.snowcattle.game.executor.event.impl.event.UpdateEvent; 4 | import org.apache.commons.pool2.PooledObjectFactory; 5 | import org.apache.commons.pool2.impl.GenericObjectPool; 6 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; 7 | 8 | /** 9 | * Created by jiangwenping on 17/4/26. 10 | * updateevent因为使用太频繁,使用commonpool2缓存 11 | */ 12 | public class UpdateEventCacheFactory extends GenericObjectPool { 13 | 14 | public UpdateEventCacheFactory(PooledObjectFactory factory, GenericObjectPoolConfig config) { 15 | super(factory, config); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/entity/AbstractUpdate.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by jwp on 2017/1/19. 7 | * 基本的抽象 8 | */ 9 | public abstract class AbstractUpdate implements IUpdate { 10 | 11 | private static final long serialVersionUID = 7863793589498350565L; 12 | //是否存放标志 13 | private boolean activeFlag = true; 14 | //标示id 15 | private ID updateId; 16 | 17 | @Override 18 | public boolean isActive() { 19 | return activeFlag; 20 | } 21 | 22 | @Override 23 | public void setActive(boolean activeFlag) { 24 | this.activeFlag = activeFlag; 25 | } 26 | 27 | @Override 28 | public ID getUpdateId() { 29 | return updateId; 30 | } 31 | 32 | public void setUpdateId(ID updateId) { 33 | this.updateId = updateId; 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/entity/IUpdate.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by jiangwenping on 17/1/9. 7 | * 基础循环接口 8 | */ 9 | public interface IUpdate extends Serializable { 10 | public void update(); 11 | public ID getUpdateId(); 12 | public boolean isActive(); 13 | public void setActive(boolean activeFlag); 14 | } 15 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/entity/NullWeakUpUpdate.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.entity; 2 | 3 | /** 4 | * Created by jwp on 2017/2/24. 5 | * 空的weakup对象 6 | */ 7 | public class NullWeakUpUpdate extends AbstractUpdate{ 8 | 9 | private static final long serialVersionUID = 8323340750934621540L; 10 | 11 | @Override 12 | public void update() { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/pool/IUpdateExecutor.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.pool; 2 | 3 | import com.snowcattle.game.executor.update.thread.dispatch.DispatchThread; 4 | import com.snowcattle.game.executor.update.entity.IUpdate; 5 | 6 | /** 7 | * Created by jwp on 2017/2/23. 8 | * 执行一个update 9 | */ 10 | public interface IUpdateExecutor { 11 | public void executorUpdate(DispatchThread dispatchThread, IUpdate iUpdate, boolean firstFlag, int updateExcutorIndex); 12 | public void startup(); 13 | public void shutdown(); 14 | } 15 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/pool/excutor/EventExecutor.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.pool.excutor; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | 5 | /** 6 | * Created by jwp on 2017/2/23. 7 | * 事件执行器 8 | */ 9 | public interface EventExecutor extends ExecutorService { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/pool/excutor/FinalizableDelegatedExecutorService.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.pool.excutor; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | 5 | /** 6 | * Created by jwp on 2017/2/23. 7 | */ 8 | class FinalizableDelegatedExecutorService extends DelegatedExecutorService { 9 | FinalizableDelegatedExecutorService(ExecutorService executor) { 10 | super(executor); 11 | } 12 | 13 | protected void finalize() { 14 | shutdown(); 15 | } 16 | } -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/pool/excutor/OrderedEventExecutor.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.pool.excutor; 2 | 3 | /** 4 | * Created by jwp on 2017/2/23. 5 | * 顺序的事件执行器 6 | */ 7 | public interface OrderedEventExecutor extends EventExecutor{ 8 | } 9 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/service/NotifyTask.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.service; 2 | 3 | import java.util.TimerTask; 4 | 5 | /** 6 | * Created by jwp on 2017/3/28. 7 | * 任务通知 8 | */ 9 | public class NotifyTask extends TimerTask { 10 | 11 | private final UpdateService updateService; 12 | 13 | public NotifyTask(UpdateService updateService) { 14 | this.updateService = updateService; 15 | } 16 | 17 | @Override 18 | public void run() { 19 | updateService.notifyRun(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /game-executor/src/main/java/com/snowcattle/game/executor/update/thread/dispatch/BindNotifyDisptachThread.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.thread.dispatch; 2 | 3 | import com.snowcattle.game.executor.event.EventBus; 4 | import com.snowcattle.game.executor.update.pool.UpdateBindExecutorService; 5 | 6 | /** 7 | * Created by jwp on 2017/2/23. 8 | */ 9 | public class BindNotifyDisptachThread extends LockSupportDisptachThread{ 10 | 11 | public BindNotifyDisptachThread(EventBus eventBus, UpdateBindExecutorService updateBindExcutorService 12 | , int cycleSleepTime, long minCycleTime) { 13 | super(eventBus, updateBindExcutorService, cycleSleepTime, minCycleTime); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /game-executor/src/test/java/com/snowcattle/game/executor/event/aysnc/SingleRunEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.aysnc; 2 | 3 | import com.snowcattle.game.executor.event.EventParam; 4 | import com.snowcattle.game.executor.event.EventType; 5 | import com.snowcattle.game.executor.event.SingleEvent; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * Created by jwp on 2017/5/5. 11 | */ 12 | public class SingleRunEvent extends SingleEvent{ 13 | public SingleRunEvent(EventType eventType, Serializable eventId, long shardingId, EventParam[] parms) { 14 | super(eventType, eventId, shardingId, parms); 15 | } 16 | 17 | private long runId; 18 | 19 | public long getRunId() { 20 | return runId; 21 | } 22 | 23 | public void setRunId(long runId) { 24 | this.runId = runId; 25 | } 26 | 27 | @Override 28 | public void call() { 29 | runId++; 30 | 31 | System.out.println("runId" + runId + " Id" + getShardingId() ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /game-executor/src/test/java/com/snowcattle/game/executor/event/aysnc/SingleRunEventListener.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.aysnc; 2 | 3 | import com.snowcattle.game.executor.event.AbstractEventListener; 4 | 5 | /** 6 | * Created by jwp on 2017/5/5. 7 | */ 8 | public class SingleRunEventListener extends AbstractEventListener { 9 | @Override 10 | public void initEventType() { 11 | register(TestConstants.singleRunEventType); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /game-executor/src/test/java/com/snowcattle/game/executor/event/aysnc/TestConstants.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.event.aysnc; 2 | 3 | import com.snowcattle.game.executor.event.EventType; 4 | 5 | /** 6 | * Created by jwp on 2017/5/5. 7 | */ 8 | public final class TestConstants { 9 | 10 | public static EventType singleRunEventType = new EventType(1001); 11 | 12 | private TestConstants() { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /game-executor/src/test/java/com/snowcattle/game/executor/update/async/TestCreateEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.async; 2 | 3 | import com.snowcattle.game.executor.event.EventParam; 4 | import com.snowcattle.game.executor.event.EventType; 5 | import com.snowcattle.game.executor.event.impl.event.CreateEvent; 6 | 7 | /** 8 | * Created by jiangwenping on 17/1/12. 9 | */ 10 | public class TestCreateEvent extends CreateEvent { 11 | public TestCreateEvent(EventType eventType, EventParam... parms) { 12 | super(eventType, parms); 13 | } 14 | 15 | public void call() { 16 | EventParam[] eventParams = getParams(); 17 | int a = (int) eventParams[0].getT(); 18 | if(a %1000 == 0) { 19 | System.out.println(eventParams[0].getT() + "float" + eventParams[1].getT()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /game-executor/src/test/java/com/snowcattle/game/executor/update/async/TestUpdateEvent.java: -------------------------------------------------------------------------------- 1 | package com.snowcattle.game.executor.update.async; 2 | 3 | import com.snowcattle.game.executor.event.EventParam; 4 | import com.snowcattle.game.executor.event.EventType; 5 | import com.snowcattle.game.executor.event.impl.event.UpdateEvent; 6 | 7 | /** 8 | * Created by jiangwenping on 17/1/12. 9 | */ 10 | public class TestUpdateEvent extends UpdateEvent { 11 | 12 | public TestUpdateEvent(EventType eventType, EventParam... parms) { 13 | super(eventType, parms); 14 | } 15 | 16 | public void call() { 17 | EventParam[] eventParams = getParams(); 18 | int a = (int) eventParams[0].getT(); 19 | System.out.println(eventParams[0].getT() + "float" + eventParams[1].getT()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /qrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwpttcg66/NettyGameServer/6ef370c1116bdc617578d496d5d0a578da736084/qrcode.png --------------------------------------------------------------------------------