game_machine 0.0.11 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +12 -1
- data/Gemfile.lock +32 -47
- data/Rakefile +0 -27
- data/bin/bundle_run.sh +1 -0
- data/bin/game_machine +29 -27
- data/config/cluster.conf +6 -5
- data/config/default.conf +164 -0
- data/config/game_machine.sql +33 -0
- data/config/game_messages.proto +87 -25
- data/config/gamecloud.conf +140 -0
- data/config/messages.proto +46 -53
- data/config/test.conf +149 -0
- data/game_machine.gemspec +10 -5
- data/games/boot.rb +3 -0
- data/games/example/data/game_data.yml +4 -4
- data/games/example/lib/aggressive_npc.rb +1 -1
- data/games/example/lib/game.rb +1 -2
- data/games/example/lib/player_register.rb +1 -1
- data/games/routes.rb +9 -0
- data/games/tutorial/boot.rb +12 -0
- data/games/tutorial/item_manager.rb +256 -0
- data/games/tutorial/object_store.rb +55 -0
- data/games/tutorial/seed.rb +52 -0
- data/games/tutorial/sql_store.rb +30 -0
- data/java/project/build.gradle +134 -0
- data/java/project/component.erb +719 -0
- data/java/{gradle.properties → project/gradle.properties} +1 -1
- data/java/project/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/{gradle → project/gradle}/wrapper/gradle-wrapper.properties +2 -2
- data/java/{gradlew → project/gradlew} +0 -0
- data/java/{gradlew.bat → project/gradlew.bat} +0 -0
- data/java/project/local_lib/AdminUi.jar +0 -0
- data/java/{local_lib/protostuff-compiler-1.0.7-jarjar.jar → project/local_lib/protostuff-compiler-1.0.8-jarjar.jar} +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-freebsd-6.so +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ia64-hpux-11.sl +0 -0
- data/java/project/local_lib/sigar/libsigar-ia64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-pa-hpux-11.sl +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc-aix-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc64-aix-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-s390x-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-sparc-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-sparc64-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-universal-macosx.dylib +0 -0
- data/java/project/local_lib/sigar/libsigar-universal64-macosx.dylib +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-freebsd-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-freebsd-6.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-solaris.so +0 -0
- data/java/project/local_lib/sigar/sigar-amd64-winnt.dll +0 -0
- data/java/project/local_lib/sigar/sigar-x86-winnt.dll +0 -0
- data/java/project/local_lib/sigar/sigar-x86-winnt.lib +0 -0
- data/java/project/model.erb +99 -0
- data/java/{settings.gradle → project/settings.gradle} +0 -0
- data/java/project/src/main/java/com/game_machine/authentication/DefaultAuthenticator.java +28 -0
- data/java/project/src/main/java/com/game_machine/authentication/PlayerAuthenticator.java +6 -0
- data/java/project/src/main/java/com/game_machine/authentication/PublicAuthenticator.java +20 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/ActorFactory.java +0 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/ActorUtil.java +13 -0
- data/java/project/src/main/java/com/game_machine/core/AuthorizedPlayers.java +23 -0
- data/java/project/src/main/java/com/game_machine/core/ClientMessageDecoder.java +36 -0
- data/java/project/src/main/java/com/game_machine/core/ClientMessageEncoder.java +19 -0
- data/java/project/src/main/java/com/game_machine/core/CloudClient.java +298 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/CommandProxy.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/Commands.java +20 -0
- data/java/project/src/main/java/com/game_machine/core/DatastoreCommands.java +43 -0
- data/java/project/src/main/java/com/game_machine/core/DbConnectionPool.java +72 -0
- data/java/project/src/main/java/com/game_machine/core/DefaultMovementVerifier.java +56 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/EntitySerializer.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/EntityTracking.java +119 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/EventStreamHandler.java +1 -1
- data/java/project/src/main/java/com/game_machine/core/GameActor.java +73 -0
- data/java/project/src/main/java/com/game_machine/core/GameMachineLoader.java +43 -0
- data/java/project/src/main/java/com/game_machine/core/GameMessageActor.java +44 -0
- data/java/project/src/main/java/com/game_machine/core/Grid.java +255 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/GridValue.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/Hashring.java +66 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/IActorFactory.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/LocalLinkedBuffer.java +20 -0
- data/java/project/src/main/java/com/game_machine/core/MessageGateway.java +120 -0
- data/java/project/src/main/java/com/game_machine/core/MessagePersister.java +26 -0
- data/java/project/src/main/java/com/game_machine/core/MonoProxy.java +39 -0
- data/java/project/src/main/java/com/game_machine/core/MovementVerifier.java +7 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/NetMessage.java +10 -6
- data/java/project/src/main/java/com/game_machine/core/PersistentMessage.java +9 -0
- data/java/project/src/main/java/com/game_machine/core/PlayerCommands.java +31 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServer.java +100 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServerHandler.java +54 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServerInitializer.java +32 -0
- data/java/project/src/main/java/com/game_machine/core/UdpClient.java +86 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/UdpServer.java +18 -27
- data/java/{src → project/src}/main/java/com/game_machine/core/UdpServerHandler.java +23 -26
- data/java/project/src/main/java/com/game_machine/core/Vector3.java +159 -0
- data/java/project/src/main/java/com/game_machine/orm/models/PlayerItem.java +118 -0
- data/java/project/src/main/java/com/game_machine/orm/models/TestObject.java +110 -0
- data/java/project/src/main/java/com/game_machine/tutorial/LootGenerator.java +26 -0
- data/java/{src → project/src}/main/resources/game_machine.java.stg +3 -1
- data/java/project/src/main/resources/logback.properties +13 -0
- data/java/project/src/main/resources/logback.xml +76 -0
- data/java/{src → project/src}/main/resources/protostuff.properties +0 -0
- data/java/src/main/java/game/MyGameActor.java +26 -0
- data/lib/game_machine.rb +17 -16
- data/lib/game_machine/actor.rb +1 -1
- data/lib/game_machine/actor/base.rb +8 -31
- data/lib/game_machine/actor/builder.rb +5 -6
- data/lib/game_machine/actor/game_actor.rb +55 -0
- data/lib/game_machine/actor/reloadable.rb +6 -1
- data/lib/game_machine/akka.rb +26 -32
- data/lib/game_machine/app_config.rb +39 -26
- data/lib/game_machine/application.rb +56 -62
- data/lib/game_machine/client_manager.rb +14 -8
- data/lib/game_machine/cloud_updater.rb +51 -0
- data/lib/game_machine/cluster_monitor.rb +3 -3
- data/lib/game_machine/commands.rb +1 -1
- data/lib/game_machine/commands/misc_commands.rb +4 -8
- data/lib/game_machine/commands/player_commands.rb +8 -0
- data/lib/game_machine/console.rb +1 -0
- data/lib/game_machine/console/build.rb +57 -24
- data/lib/game_machine/console/bundle.rb +95 -0
- data/lib/game_machine/console/deploy.rb +30 -0
- data/lib/game_machine/console/install.rb +70 -36
- data/lib/game_machine/console/server.rb +2 -69
- data/lib/game_machine/data_store.rb +111 -15
- data/lib/game_machine/data_stores/couchbase.rb +8 -3
- data/lib/game_machine/data_stores/gamecloud.rb +93 -0
- data/lib/game_machine/data_stores/jdbc.rb +98 -0
- data/lib/game_machine/default_handlers.rb +2 -0
- data/lib/game_machine/default_handlers/team_handler.rb +51 -0
- data/lib/game_machine/default_handlers/zone_manager.rb +30 -0
- data/lib/game_machine/endpoints.rb +0 -4
- data/lib/game_machine/endpoints/udp_incoming.rb +13 -5
- data/lib/game_machine/endpoints/udp_outgoing.rb +15 -9
- data/lib/game_machine/game_systems.rb +0 -2
- data/lib/game_machine/game_systems/agents/controller.rb +2 -2
- data/lib/game_machine/game_systems/entity_tracking.rb +0 -3
- data/lib/game_machine/game_systems/region_manager.rb +3 -2
- data/lib/game_machine/game_systems/region_service.rb +2 -2
- data/lib/game_machine/game_systems/remote_echo.rb +10 -0
- data/lib/game_machine/game_systems/team_manager.rb +2 -11
- data/lib/game_machine/grid.rb +5 -18
- data/lib/game_machine/handlers/authentication.rb +1 -9
- data/lib/game_machine/handlers/game.rb +27 -2
- data/lib/game_machine/handlers/player_authentication.rb +87 -0
- data/lib/game_machine/handlers/request.rb +9 -11
- data/lib/game_machine/hocon_config.rb +81 -0
- data/lib/game_machine/java_lib.rb +14 -1
- data/lib/game_machine/logger.rb +10 -23
- data/lib/game_machine/models.rb +1 -0
- data/lib/game_machine/mono_server.rb +6 -1
- data/lib/game_machine/object_db.rb +12 -6
- data/lib/game_machine/protobuf.rb +1 -1
- data/lib/game_machine/protobuf/game_messages.rb +13 -3
- data/lib/game_machine/protobuf/generate.rb +107 -5
- data/lib/game_machine/restart_watcher.rb +1 -1
- data/lib/game_machine/routes.rb +23 -0
- data/lib/game_machine/scheduler.rb +1 -1
- data/lib/game_machine/securerandom.rb +2 -0
- data/lib/game_machine/system_stats.rb +28 -7
- data/lib/game_machine/version.rb +1 -1
- data/lib/game_machine/wavefront_ext.rb +47 -0
- data/lib/game_machine/write_behind_cache.rb +24 -9
- data/mono/server/Makefile +1 -1
- data/mono/server/Newtonsoft.Json.dll +0 -0
- data/mono/server/build.bat +1 -1
- data/mono/server/callable.cs +9 -0
- data/mono/server/echo.cs +17 -0
- data/mono/server/message_router.cs +16 -23
- data/mono/server/messages.cs +1792 -417
- data/mono/server/protobuf-net.dll +0 -0
- data/mono/server/server.cs +120 -0
- data/mono/server/server.exe +0 -0
- data/pathfinding/astar.cpp +149 -0
- data/pathfinding/build.sh +6 -0
- data/pathfinding/build.txt +16 -0
- data/pathfinding/crowd.cpp +194 -0
- data/pathfinding/include/astar.h +49 -0
- data/pathfinding/include/common.h +5 -0
- data/pathfinding/include/crowd.h +43 -0
- data/pathfinding/include/micropather.h +511 -0
- data/pathfinding/include/navmesh.h +114 -0
- data/pathfinding/include/pathfinder.h +24 -0
- data/pathfinding/main.cpp +108 -17
- data/pathfinding/micropather.cpp +1062 -0
- data/pathfinding/navmesh.cpp +408 -0
- data/pathfinding/overrides/DetourCrowd.cpp +1446 -0
- data/pathfinding/overrides/DetourNavMeshQuery.cpp +3551 -0
- data/pathfinding/overrides/DetourNavMeshQuery.h +538 -0
- data/pathfinding/pathfinder.cpp +117 -0
- data/pathfinding/{bin → premake}/premake4 +0 -0
- data/pathfinding/premake/premake4.exe +0 -0
- data/pathfinding/premake4.lua +12 -3
- data/spec/actor/actor_spec.rb +0 -7
- data/spec/client_manager_spec.rb +1 -1
- data/spec/couchproxy_spec.rb +38 -0
- data/spec/entity_persistence_spec.rb +129 -0
- data/spec/game_systems/team_manager_spec.rb +2 -2
- data/spec/hashring_spec.rb +17 -39
- data/spec/java_grid_spec.rb +0 -2
- data/spec/misc_spec.rb +111 -0
- data/spec/mono_spec.rb +50 -3
- data/spec/reliable_message_spec.rb +38 -0
- data/spec/spec_helper.rb +4 -4
- data/spec/spec_helper_minimal.rb +10 -0
- data/web/app.rb +108 -86
- data/web/config/trinidad.yml +1 -0
- data/web/views/add_player.erb +25 -0
- data/web/views/index.erb +0 -0
- data/web/views/layout.erb +48 -0
- data/web/views/login.erb +25 -0
- data/web/views/players.erb +24 -0
- metadata +209 -94
- data/config/config.example.yml +0 -100
- data/config/regions.example.yml +0 -9
- data/games/example/lib/authentication_handler.rb +0 -69
- data/games/models.rb +0 -3
- data/games/models/clan_member.rb +0 -8
- data/games/models/clan_profile.rb +0 -9
- data/games/models/player.rb +0 -7
- data/games/plugins.rb +0 -1
- data/games/plugins/team_handler.rb +0 -49
- data/games/preload.rb +0 -13
- data/java/.gitignore +0 -1
- data/java/build.gradle +0 -95
- data/java/component.erb +0 -396
- data/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/src/main/java/com/game_machine/core/GameMachineLoader.java +0 -25
- data/java/src/main/java/com/game_machine/core/Grid.java +0 -195
- data/java/src/main/resources/logback.xml +0 -14
- data/java/src/main/resources/logging.properties +0 -3
- data/lib/game_machine/actor/mono_actor.rb +0 -89
- data/lib/game_machine/auth_handlers/base.rb +0 -21
- data/lib/game_machine/auth_handlers/public.rb +0 -34
- data/lib/game_machine/endpoints/mono_gateway.rb +0 -87
- data/lib/game_machine/endpoints/tcp.rb +0 -51
- data/lib/game_machine/endpoints/tcp_handler.rb +0 -75
- data/lib/game_machine/endpoints/udp.rb +0 -88
- data/lib/game_machine/game_loader.rb +0 -46
- data/lib/game_machine/game_systems/region_settings.rb +0 -13
- data/lib/game_machine/hashring.rb +0 -48
- data/lib/game_machine/settings.rb +0 -11
- data/mono/server/actor.cs +0 -37
- data/mono/server/iactor.cs +0 -11
- data/mono/server/message_util.cs +0 -29
- data/mono/server/proxy_client.cs +0 -73
- data/mono/server/proxy_server.cs +0 -30
- data/mono/server/test_actor.cs +0 -33
- data/pathfinding/include/pathfind.h +0 -167
- data/pathfinding/pathfind.cpp +0 -174
- data/pathfinding/pathfinder.cs +0 -66
- data/script/server.sh +0 -109
- data/script/watch.sh +0 -11
- data/spec/commands/navigation_commands_spec.rb +0 -51
- data/spec/game_systems/entity_tracking_spec.rb +0 -64
- data/spec/navigation/detour_navmesh_spec.rb +0 -34
- data/spec/navigation/detour_path_spec.rb +0 -25
- data/spec/udp_server_spec.rb +0 -10
- data/web/controllers/auth_controller.rb +0 -19
- data/web/controllers/base_controller.rb +0 -16
- data/web/controllers/index_controller.rb +0 -7
- data/web/controllers/log_controller.rb +0 -47
- data/web/controllers/messages_controller.rb +0 -59
- data/web/controllers/player_register_controller.rb +0 -15
- data/web/views/game_messages.haml +0 -45
- data/web/views/index.haml +0 -6
- data/web/views/layout.haml +0 -41
- data/web/views/logs.haml +0 -32
- data/web/views/player_register.haml +0 -22
- data/web/views/player_registered.haml +0 -2
- data/web/views/register_layout.haml +0 -22
- data/web/views/restart.haml +0 -35
data/config/config.example.yml
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
---
|
2
|
-
development:
|
3
|
-
servers:
|
4
|
-
default:
|
5
|
-
environment: development
|
6
|
-
# Handles requests for matchmaking and custom filtering for teams.
|
7
|
-
# If no team handler is defined defaults are used
|
8
|
-
team_handler: Plugins::TeamHandler
|
9
|
-
# Authorization handler. Public allows any authtoken to be used and
|
10
|
-
# does not check username/password
|
11
|
-
auth_handler: Example::AuthenticationHandler
|
12
|
-
#auth_handler: GameMachine::AuthHandlers::Public
|
13
|
-
# Class that handles user registration via web page
|
14
|
-
player_register_handler: Example::PlayerRegister
|
15
|
-
# Player manager. Receives player status updates
|
16
|
-
player_manager: Example::PlayerManager
|
17
|
-
# Top level actor that handles game messages. Don't change this
|
18
|
-
game_handler: GameMachine::Handlers::Request
|
19
|
-
# Hook for accessing location updates from players (cheat prevention)
|
20
|
-
entity_tracking_handler: Example::TrackingHandler
|
21
|
-
# Size of the router for incoming message from all clients
|
22
|
-
game_handler_routers: 10
|
23
|
-
# Also in the pipeline for all incoming requests, should be set the same as
|
24
|
-
# game_handler_routers
|
25
|
-
request_handler_routers: 10
|
26
|
-
# router size for the udp actor that handles all incoming upd messages
|
27
|
-
udp_routers: 10
|
28
|
-
# What data store the object database will use (one of memory, mapdb, or couchbase)
|
29
|
-
data_store: mapdb
|
30
|
-
# Advanced settings for write behind cache. -1 disables. This is fine for
|
31
|
-
# all but large games with high traffic (hundreds of writes per second)
|
32
|
-
cache_write_interval: -1
|
33
|
-
cache_writes_per_second: -1
|
34
|
-
# Spatial grids. default, aoe, and local_chat are required.
|
35
|
-
# value is grid size, cell size, and update frequency
|
36
|
-
grids:
|
37
|
-
default: 4000, 50, 1
|
38
|
-
aoe: 4000, 5, 1
|
39
|
-
local_chat: 4000, 10, 10
|
40
|
-
# Couchbase config
|
41
|
-
couchbase_bucket: default
|
42
|
-
couchbase_password:
|
43
|
-
couchbase_servers:
|
44
|
-
- http://127.0.0.1:8091/pools
|
45
|
-
http_enabled: true
|
46
|
-
http_host: 0.0.0.0
|
47
|
-
http_port: 3000
|
48
|
-
udp_enabled: true
|
49
|
-
udp_host: 0.0.0.0
|
50
|
-
udp_port: 24130
|
51
|
-
tcp_enabled: true
|
52
|
-
tcp_host: 0.0.0.0
|
53
|
-
tcp_port: 8700
|
54
|
-
akka_host: 127.0.0.1
|
55
|
-
akka_port: 2551
|
56
|
-
# array of seed servers. Required if node is in a cluster
|
57
|
-
seeds: [default,seed01]
|
58
|
-
# Mono server settings
|
59
|
-
mono_enabled: false
|
60
|
-
mono_dll: test_actor.dll
|
61
|
-
mono_gateway_host: 127.0.0.1
|
62
|
-
mono_gateway_port: 8800
|
63
|
-
seed01:
|
64
|
-
environment: development
|
65
|
-
team_handler: Plugins::TeamHandler
|
66
|
-
auth_handler: Example::AuthenticationHandler
|
67
|
-
player_register_handler: Example::PlayerRegister
|
68
|
-
player_manager: Example::PlayerManager
|
69
|
-
game_handler: GameMachine::Handlers::Request
|
70
|
-
entity_tracking_handler: Example::TrackingHandler
|
71
|
-
game_handler_routers: 10
|
72
|
-
request_handler_routers: 10
|
73
|
-
udp_routers: 10
|
74
|
-
data_store: mapdb
|
75
|
-
cache_write_interval: -1
|
76
|
-
cache_writes_per_second: -1
|
77
|
-
grids:
|
78
|
-
default: 4000, 50, 1
|
79
|
-
aoe: 4000, 5, 1
|
80
|
-
local_chat: 4000, 10, 10
|
81
|
-
couchbase_bucket: default
|
82
|
-
couchbase_password:
|
83
|
-
couchbase_servers:
|
84
|
-
- http://127.0.0.1:8091/pools
|
85
|
-
http_enabled: false
|
86
|
-
http_host: 127.0.0.1
|
87
|
-
http_port: 3000
|
88
|
-
udp_enabled: true
|
89
|
-
udp_host: 0.0.0.0
|
90
|
-
udp_port: 24130
|
91
|
-
tcp_enabled: false
|
92
|
-
tcp_host: 0.0.0.0
|
93
|
-
tcp_port: 8700
|
94
|
-
akka_host: 127.0.0.1
|
95
|
-
akka_port: 2551
|
96
|
-
seeds: [default,seed01]
|
97
|
-
mono_enabled: false
|
98
|
-
mono_dll: test_actor.dll
|
99
|
-
mono_gateway_host: 127.0.0.1
|
100
|
-
mono_gateway_port: 8800
|
data/config/regions.example.yml
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
|
2
|
-
# This class is set in the configuration.
|
3
|
-
|
4
|
-
# This is a simple implementation that works together with the built in
|
5
|
-
# user registration and login via http. User data is stored in the object database.
|
6
|
-
|
7
|
-
# The minimum necessary to implement is the authtoken_for method. That method can
|
8
|
-
# block as it is only called once when the client first connects and is cached
|
9
|
-
# internally after that. So you could make an external http call for example.
|
10
|
-
require 'digest/md5'
|
11
|
-
module Example
|
12
|
-
class AuthenticationHandler
|
13
|
-
include Models
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@sessions = {}
|
17
|
-
end
|
18
|
-
|
19
|
-
# Returns true is authorized, false if not
|
20
|
-
def authorize(username,password)
|
21
|
-
GameMachine.logger.info "authorize: #{username} #{password}"
|
22
|
-
if user = User.find(username,5000)
|
23
|
-
GameMachine.logger.info "user: #{user.id} #{user.password}"
|
24
|
-
if password == user.password
|
25
|
-
@sessions[username] = authtoken(username,password)
|
26
|
-
user.authtoken = @sessions[username]
|
27
|
-
user.save
|
28
|
-
return @sessions[username]
|
29
|
-
else
|
30
|
-
GameMachine.logger.info "user: #{user.id} password does not match"
|
31
|
-
false
|
32
|
-
end
|
33
|
-
else
|
34
|
-
GameMachine.logger.info "user: #{username} not found"
|
35
|
-
false
|
36
|
-
end
|
37
|
-
false
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns a session token for a logged in user. This must be a string and
|
41
|
-
# should not be too long, as it gets sent with every message.
|
42
|
-
def authtoken_for(username)
|
43
|
-
if authtoken = @sessions.fetch(username,nil)
|
44
|
-
return authtoken
|
45
|
-
|
46
|
-
# user authenticated on different server, we have to look up their authtoken
|
47
|
-
# and save it in the local sessions hash
|
48
|
-
elsif user = User.find(username)
|
49
|
-
if user.authtoken
|
50
|
-
@sessions[username] = authtoken
|
51
|
-
return user.authtoken
|
52
|
-
else
|
53
|
-
GameMachine.logger.info "Authoken for #{username} is nil"
|
54
|
-
nil
|
55
|
-
end
|
56
|
-
else
|
57
|
-
GameMachine.logger.info "User #{username} not found"
|
58
|
-
nil
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def authtoken(username,password)
|
65
|
-
Digest::MD5.hexdigest("#{username}#{password}#{rand(10000)}")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
data/games/models.rb
DELETED
data/games/models/clan_member.rb
DELETED
data/games/models/player.rb
DELETED
data/games/plugins.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require_relative 'plugins/team_handler'
|
@@ -1,49 +0,0 @@
|
|
1
|
-
|
2
|
-
module Plugins
|
3
|
-
class TeamHandler
|
4
|
-
|
5
|
-
attr_reader :teams
|
6
|
-
def initialize
|
7
|
-
update_teams
|
8
|
-
end
|
9
|
-
|
10
|
-
def update_teams
|
11
|
-
@teams = GameMachine::Models::Teams.find('teams')
|
12
|
-
end
|
13
|
-
|
14
|
-
# Should return a Match object if a match is found, otherwise nil
|
15
|
-
def match!(team_name)
|
16
|
-
GameMachine.logger.info "match! team_name:#{team_name} teams:#{teams}"
|
17
|
-
if team = teams.teams.select {|team| team.name != team_name}.first
|
18
|
-
return GameMachine::Models::StartMatch.new(:team_names => [team_name,team.name])
|
19
|
-
end
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
|
23
|
-
# Called when Game Machine has started the match
|
24
|
-
def match_started(match)
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
# Filter you can apply to the teams list sent to clients
|
29
|
-
# You can add whatever extra fields you want to the TeamsRequest
|
30
|
-
# class on the client and they will show up here.
|
31
|
-
def teams_filter(teams,teams_request)
|
32
|
-
teams
|
33
|
-
end
|
34
|
-
|
35
|
-
# return true if member has rights to create team
|
36
|
-
def can_create_team?(team_name,member)
|
37
|
-
true
|
38
|
-
end
|
39
|
-
|
40
|
-
# return true if member has rights to join team
|
41
|
-
def can_add_member?(team_name,member)
|
42
|
-
true
|
43
|
-
end
|
44
|
-
|
45
|
-
def destroy_on_owner_leave?
|
46
|
-
true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/games/preload.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
|
2
|
-
# If you have things you want loaded before game machine starts up, this
|
3
|
-
# is the place to do it. Examples might be specific handlers, or loading up
|
4
|
-
# static data that needs to be there before the rest of the system starts up.
|
5
|
-
|
6
|
-
# json models that are global accross all games/plugins
|
7
|
-
require_relative 'models'
|
8
|
-
|
9
|
-
# Plugins that extend or work with core Game Machine features
|
10
|
-
require_relative 'plugins'
|
11
|
-
|
12
|
-
# This needs to be loaded before the entity tracking system starts
|
13
|
-
require_relative 'example/lib/tracking_handler'
|
data/java/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
/bin
|
data/java/build.gradle
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
apply plugin: 'java'
|
2
|
-
apply plugin: 'maven'
|
3
|
-
apply plugin: 'eclipse'
|
4
|
-
apply plugin:'application'
|
5
|
-
apply plugin:'scala'
|
6
|
-
|
7
|
-
group = 'game_machine'
|
8
|
-
version = '0.0.1'
|
9
|
-
|
10
|
-
|
11
|
-
description = """"""
|
12
|
-
|
13
|
-
sourceCompatibility = 1.7
|
14
|
-
targetCompatibility = 1.7
|
15
|
-
|
16
|
-
repositories {
|
17
|
-
flatDir(dirs: 'third_party')
|
18
|
-
mavenRepo url: "http://repo.typesafe.com/typesafe/releases/"
|
19
|
-
mavenRepo url: "http://files.couchbase.com/maven2/"
|
20
|
-
mavenRepo url: "http://repo.maven.apache.org/maven2"
|
21
|
-
}
|
22
|
-
|
23
|
-
dependencies {
|
24
|
-
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
|
25
|
-
//compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
|
26
|
-
compile group: 'com.typesafe.akka', name: "akka-actor_$scala_version", version:"$akka_version"
|
27
|
-
compile group: 'com.typesafe.akka', name: "akka-remote_$scala_version", version:"$akka_version"
|
28
|
-
compile group: 'com.typesafe.akka', name: "akka-testkit_$scala_version", version:"$akka_version"
|
29
|
-
//compile group: 'com.typesafe.akka', name: "akka-camel_$scala_version", version:"$akka_version"
|
30
|
-
compile group: 'com.typesafe.akka', name: "akka-kernel_$scala_version", version:"$akka_version"
|
31
|
-
compile group: 'com.typesafe.akka', name: "akka-agent_$scala_version", version:"$akka_version"
|
32
|
-
compile group: 'com.typesafe.akka', name: "akka-contrib_$scala_version", version:"$akka_version"
|
33
|
-
compile group: 'com.typesafe.akka', name: "akka-cluster_$scala_version", version:"$akka_version"
|
34
|
-
//compile group: 'com.typesafe.akka', name: "akka-zeromq_$scala_version", version:"$akka_version"
|
35
|
-
|
36
|
-
compile 'com.dyuproject.protostuff:protostuff-uberjar:1.0.7'
|
37
|
-
compile 'com.dyuproject.protostuff:protostuff:1.0.7'
|
38
|
-
//compile 'com.dyuproject.protostuff:protostuff-compiler:1.0.7'
|
39
|
-
compile 'com.dyuproject.protostuff:protostuff-json:1.0.7'
|
40
|
-
//compile 'com.dyuproject.protostuff:protostuff-yaml:1.0.7'
|
41
|
-
//compile 'com.dyuproject.protostuff:protostuff-xml:1.0.7'
|
42
|
-
|
43
|
-
//compile group: 'com.barchart.udt', name: 'barchart-udt-bundle', version:'2.3.0'
|
44
|
-
compile group: 'com.google.code.findbugs', name: 'jsr305', version:'2.0.1'
|
45
|
-
compile group: 'org.javassist', name: 'javassist', version:'3.17.1-GA'
|
46
|
-
//compile(group: 'io.netty', name: 'netty-all', version:'4.0.11.Final')
|
47
|
-
//compile 'org.apache.camel:camel-jetty:2.10.3'
|
48
|
-
//compile(group: 'couchbase', name: 'couchbase-client', version:'1.4.2')
|
49
|
-
//compile 'com.basho.riak:riak-client:1.4.4'
|
50
|
-
compile 'com.couchbase.client:couchbase-client:1.4.2'
|
51
|
-
compile 'redis.clients:jedis:2.2.1'
|
52
|
-
compile 'org.mapdb:mapdb:1.0.3'
|
53
|
-
compile 'io.netty:netty-testsuite:4.0.20.Final'
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
task wrapper(type: Wrapper) {
|
58
|
-
gradleVersion = '1.7'
|
59
|
-
}
|
60
|
-
task uberjar(type: Jar) {
|
61
|
-
from files(sourceSets.main.output.classesDir)
|
62
|
-
from configurations.runtime.asFileTree.files.collect { zipTree(it) }
|
63
|
-
}
|
64
|
-
|
65
|
-
task codegen(type: Exec) {
|
66
|
-
File templateFile = file('protogen.rb')
|
67
|
-
commandLine 'jruby',templateFile
|
68
|
-
}
|
69
|
-
|
70
|
-
task protogen(type: Exec) {
|
71
|
-
File configFile = file('src/main/resources/protostuff.properties')
|
72
|
-
File jar = file('protostuff-compiler-1.0.7-jarjar.jar')
|
73
|
-
commandLine 'java','-jar',jar,configFile
|
74
|
-
}
|
75
|
-
|
76
|
-
test {
|
77
|
-
useTestNG()
|
78
|
-
//outputs.upToDateWhen { false }
|
79
|
-
testLogging.showStandardStreams = true
|
80
|
-
dependsOn cleanTest
|
81
|
-
testLogging { exceptionFormat "full" }
|
82
|
-
}
|
83
|
-
|
84
|
-
task install_libs(type: Copy) {
|
85
|
-
into "$buildDir/../lib"
|
86
|
-
from configurations.runtime
|
87
|
-
from "$buildDir/libs"
|
88
|
-
}
|
89
|
-
|
90
|
-
task install_libs_ruby(type: Copy) {
|
91
|
-
into "$buildDir/../lib"
|
92
|
-
from configurations.runtime
|
93
|
-
from "$buildDir/libs"
|
94
|
-
}
|
95
|
-
|
data/java/component.erb
DELETED
@@ -1,396 +0,0 @@
|
|
1
|
-
|
2
|
-
package GameMachine.Messages;
|
3
|
-
|
4
|
-
import java.io.Externalizable;
|
5
|
-
import java.io.IOException;
|
6
|
-
import java.io.ObjectInput;
|
7
|
-
import java.io.ObjectOutput;
|
8
|
-
import java.util.ArrayList;
|
9
|
-
import java.util.List;
|
10
|
-
|
11
|
-
import com.dyuproject.protostuff.ByteString;
|
12
|
-
import com.dyuproject.protostuff.GraphIOUtil;
|
13
|
-
import com.dyuproject.protostuff.Input;
|
14
|
-
import com.dyuproject.protostuff.Message;
|
15
|
-
import com.dyuproject.protostuff.Output;
|
16
|
-
import com.dyuproject.protostuff.ProtobufOutput;
|
17
|
-
|
18
|
-
import java.io.ByteArrayOutputStream;
|
19
|
-
import com.dyuproject.protostuff.JsonIOUtil;
|
20
|
-
import com.dyuproject.protostuff.LinkedBuffer;
|
21
|
-
import com.dyuproject.protostuff.ProtobufIOUtil;
|
22
|
-
import com.dyuproject.protostuff.ProtostuffIOUtil;
|
23
|
-
import com.dyuproject.protostuff.runtime.RuntimeSchema;
|
24
|
-
|
25
|
-
import java.util.ArrayList;
|
26
|
-
import java.util.List;
|
27
|
-
import java.util.Map;
|
28
|
-
import GameMachine.Messages.Entity;
|
29
|
-
|
30
|
-
import com.dyuproject.protostuff.Pipe;
|
31
|
-
import com.dyuproject.protostuff.Schema;
|
32
|
-
import com.dyuproject.protostuff.UninitializedMessageException;
|
33
|
-
|
34
|
-
public final class <%=klass%> implements Externalizable, Message<<%=klass%>>, Schema<<%=klass%>>
|
35
|
-
{
|
36
|
-
|
37
|
-
<%- message.nestedEnumGroups.each do |group| -%>
|
38
|
-
public enum <%=group.name %> implements com.dyuproject.protostuff.EnumLite<<%=group.name %>>
|
39
|
-
{
|
40
|
-
<%- group.values.each do |value| -%>
|
41
|
-
<%= "#{value.getName}(#{value.getNumber})" %><%= value.getNumber == (group.values.length - 1) ? ";" : "," %>
|
42
|
-
<%- end -%>
|
43
|
-
|
44
|
-
public final int number;
|
45
|
-
|
46
|
-
private Corpus (int number)
|
47
|
-
{
|
48
|
-
this.number = number;
|
49
|
-
}
|
50
|
-
|
51
|
-
public int getNumber()
|
52
|
-
{
|
53
|
-
return number;
|
54
|
-
}
|
55
|
-
|
56
|
-
public static Corpus valueOf(int number)
|
57
|
-
{
|
58
|
-
switch(number)
|
59
|
-
{
|
60
|
-
<%- group.values.each do |value| -%>
|
61
|
-
case <%= "#{value.getNumber}: return (#{value.getName})" %>;
|
62
|
-
<%- end -%>
|
63
|
-
default: return null;
|
64
|
-
}
|
65
|
-
}
|
66
|
-
}
|
67
|
-
<%- end -%>
|
68
|
-
|
69
|
-
|
70
|
-
public static Schema<<%=klass%>> getSchema()
|
71
|
-
{
|
72
|
-
return DEFAULT_INSTANCE;
|
73
|
-
}
|
74
|
-
|
75
|
-
public static <%=klass%> getDefaultInstance()
|
76
|
-
{
|
77
|
-
return DEFAULT_INSTANCE;
|
78
|
-
}
|
79
|
-
|
80
|
-
static final <%=klass%> DEFAULT_INSTANCE = new <%=klass%>();
|
81
|
-
|
82
|
-
<%- message.getFields.each do |field| -%>
|
83
|
-
<%- if field.isRepeated -%>
|
84
|
-
public List<<%=get_type(field)%>> <%=field.name -%>;
|
85
|
-
<%- else -%>
|
86
|
-
public <%=get_type(field)%> <%=field.name -%>;
|
87
|
-
<%- end -%>
|
88
|
-
<%- end -%>
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
public <%=klass%>()
|
93
|
-
{
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
<%- if klass == 'Entity' -%>
|
99
|
-
public ArrayList<String> componentNames() {
|
100
|
-
ArrayList<String> names = new ArrayList<String>();
|
101
|
-
<%- messages.each do |m| -%>
|
102
|
-
<%- if message.getFields.collect {|f| f.name}.include?(varname(m.getName)) -%>
|
103
|
-
if (this.has<%=m.getName%>()) {
|
104
|
-
names.add(this.<%=varname(m.getName)%>.getClass().getSimpleName());
|
105
|
-
}
|
106
|
-
<%- end -%>
|
107
|
-
<%- end -%>
|
108
|
-
return names;
|
109
|
-
}
|
110
|
-
<%- end -%>
|
111
|
-
|
112
|
-
<%- message.getFields.each do |field| -%>
|
113
|
-
<%- field_name = field.name.slice(0,1).capitalize + field.name.slice(1..-1) -%>
|
114
|
-
|
115
|
-
<%- if field.isRepeated -%>
|
116
|
-
public List<<%=get_type(field)%>> get<%=field_name -%>List() {
|
117
|
-
return <%= field.name %>;
|
118
|
-
}
|
119
|
-
|
120
|
-
public <%=klass%> set<%=field_name %>List(List<<%=get_type(field)%>> <%=field.name%>) {
|
121
|
-
this.<%=field.name%> = <%=field.name%>;
|
122
|
-
return this;
|
123
|
-
}
|
124
|
-
|
125
|
-
public <%=get_type(field) %> get<%=field_name %>(int index) {
|
126
|
-
return <%=field.name%> == null ? null : <%=field.name%>.get(index);
|
127
|
-
}
|
128
|
-
|
129
|
-
public int get<%=field_name %>Count() {
|
130
|
-
return <%=field.name%> == null ? 0 : <%=field.name%>.size();
|
131
|
-
}
|
132
|
-
|
133
|
-
public <%=klass%> add<%=field_name %>(<%=get_type(field) %> <%=field.name%>) {
|
134
|
-
if(this.<%=field.name%> == null)
|
135
|
-
this.<%=field.name%> = new ArrayList<<%=get_type(field) %>>();
|
136
|
-
this.<%=field.name%>.add(<%=field.name%>);
|
137
|
-
return this;
|
138
|
-
}
|
139
|
-
|
140
|
-
<%- else -%>
|
141
|
-
public <%=get_type(field)%> get<%=field_name -%>() {
|
142
|
-
return <%= field.name %>;
|
143
|
-
}
|
144
|
-
|
145
|
-
public <%= field_name == '_EntityId' ? 'void' : klass%> set<%=field_name %>(<%=get_type(field)%> <%=field.name%>) {
|
146
|
-
this.<%=field.name%> = <%=field.name%>;
|
147
|
-
<%= field_name == '_EntityId' ? '' : 'return this;'%>
|
148
|
-
}
|
149
|
-
|
150
|
-
public Boolean has<%=field_name %>() {
|
151
|
-
return <%=field.name%> == null ? false : true;
|
152
|
-
}
|
153
|
-
<%- end -%>
|
154
|
-
<%- end -%>
|
155
|
-
|
156
|
-
|
157
|
-
// java serialization
|
158
|
-
|
159
|
-
public void readExternal(ObjectInput in) throws IOException
|
160
|
-
{
|
161
|
-
GraphIOUtil.mergeDelimitedFrom(in, this, this);
|
162
|
-
}
|
163
|
-
|
164
|
-
public void writeExternal(ObjectOutput out) throws IOException
|
165
|
-
{
|
166
|
-
GraphIOUtil.writeDelimitedTo(out, this, this);
|
167
|
-
}
|
168
|
-
|
169
|
-
// message method
|
170
|
-
|
171
|
-
public Schema<<%=klass%>> cachedSchema()
|
172
|
-
{
|
173
|
-
return DEFAULT_INSTANCE;
|
174
|
-
}
|
175
|
-
|
176
|
-
// schema methods
|
177
|
-
|
178
|
-
public <%=klass%> newMessage()
|
179
|
-
{
|
180
|
-
return new <%=klass%>();
|
181
|
-
}
|
182
|
-
|
183
|
-
public Class<<%=klass%>> typeClass()
|
184
|
-
{
|
185
|
-
return <%=klass%>.class;
|
186
|
-
}
|
187
|
-
|
188
|
-
public String messageName()
|
189
|
-
{
|
190
|
-
return <%=klass%>.class.getSimpleName();
|
191
|
-
}
|
192
|
-
|
193
|
-
public String messageFullName()
|
194
|
-
{
|
195
|
-
return <%=klass%>.class.getName();
|
196
|
-
}
|
197
|
-
|
198
|
-
public boolean isInitialized(<%=klass%> message)
|
199
|
-
{
|
200
|
-
return true;
|
201
|
-
}
|
202
|
-
|
203
|
-
public void mergeFrom(Input input, <%=klass%> message) throws IOException
|
204
|
-
{
|
205
|
-
for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
|
206
|
-
{
|
207
|
-
switch(number)
|
208
|
-
{
|
209
|
-
case 0:
|
210
|
-
return;
|
211
|
-
<%- message.getFields.each do |field| -%>
|
212
|
-
case <%=field.number%>:
|
213
|
-
<%- if field.isRepeated -%>
|
214
|
-
if(message.<%=field.name%> == null)
|
215
|
-
message.<%=field.name%> = new ArrayList<<%=get_type(field)%>>();
|
216
|
-
<%- if field.isMessageField -%>
|
217
|
-
message.<%=field.name%>.add(input.mergeObject(null, <%=get_type(field)%>.getSchema()));
|
218
|
-
<%- elsif field.enumField -%>
|
219
|
-
message.<%=field.name%>.add(<%=get_type(field)%>.valueOf(input.readEnum()));
|
220
|
-
<%- else -%>
|
221
|
-
message.<%=field.name%>.add(input.read<%=field.getClass.getSimpleName%>());
|
222
|
-
<%- end -%>
|
223
|
-
break;
|
224
|
-
<%- else -%>
|
225
|
-
<%- if field.isMessageField -%>
|
226
|
-
message.<%=field.name%> = input.mergeObject(message.<%=field.name%>, <%=get_type(field)%>.getSchema());
|
227
|
-
break;
|
228
|
-
<%- elsif field.enumField -%>
|
229
|
-
message.<%=field.name%> = <%=classname(field.name)%>.valueOf(input.readEnum());
|
230
|
-
break;
|
231
|
-
<%- else -%>
|
232
|
-
message.<%=field.name%> = input.read<%=field.getClass.getSimpleName%>();
|
233
|
-
break;
|
234
|
-
<%- end -%>
|
235
|
-
|
236
|
-
<%- end -%>
|
237
|
-
<%- end -%>
|
238
|
-
|
239
|
-
default:
|
240
|
-
input.handleUnknownField(number, this);
|
241
|
-
}
|
242
|
-
}
|
243
|
-
}
|
244
|
-
|
245
|
-
|
246
|
-
public void writeTo(Output output, <%=klass%> message) throws IOException
|
247
|
-
{
|
248
|
-
<%- message.getFields.each do |field| -%>
|
249
|
-
|
250
|
-
<%- if field.isRequired -%>
|
251
|
-
if(message.<%=field.name%> == null)
|
252
|
-
throw new UninitializedMessageException(message);
|
253
|
-
<%- end %>
|
254
|
-
|
255
|
-
<%- if field.isRepeated -%>
|
256
|
-
if(message.<%=field.name%> != null)
|
257
|
-
{
|
258
|
-
for(<%=get_type(field)%> <%=field.name%> : message.<%=field.name%>)
|
259
|
-
{
|
260
|
-
if(<%=field.name%> != null) {
|
261
|
-
<%- if field.isMessageField -%>
|
262
|
-
output.writeObject(<%=field.number%>, <%=field.name%>, <%=get_type(field)%>.getSchema(), true);
|
263
|
-
<%- elsif field.enumField -%>
|
264
|
-
output.writeEnum(<%=field.number%>, <%=field.name%>.number, true);
|
265
|
-
<%- else -%>
|
266
|
-
output.write<%=field.getClass.getSimpleName%>(<%=field.number%>, <%=field.name%>, true);
|
267
|
-
<%- end -%>
|
268
|
-
}
|
269
|
-
}
|
270
|
-
}
|
271
|
-
<%- else -%>
|
272
|
-
<%- if field.isMessageField -%>
|
273
|
-
if(message.<%=field.name%> != null)
|
274
|
-
output.writeObject(<%=field.number%>, message.<%=field.name%>, <%=get_type(field)%>.getSchema(), false);
|
275
|
-
<%- elsif field.enumField -%>
|
276
|
-
output.writeEnum(<%=field.number%>, message.<%=field.name%>.number, false);
|
277
|
-
<%- else -%>
|
278
|
-
if(message.<%=field.name%> != null)
|
279
|
-
output.write<%=field.getClass.getSimpleName%>(<%=field.number%>, message.<%=field.name%>, false);
|
280
|
-
<%- end -%>
|
281
|
-
|
282
|
-
<%- end -%>
|
283
|
-
<%- end -%>
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
public String getFieldName(int number)
|
288
|
-
{
|
289
|
-
switch(number)
|
290
|
-
{
|
291
|
-
<%- message.getFields.each do |field| -%>
|
292
|
-
case <%=field.number%>: return "<%=field.name%>";
|
293
|
-
<%- end -%>
|
294
|
-
default: return null;
|
295
|
-
}
|
296
|
-
}
|
297
|
-
|
298
|
-
public int getFieldNumber(String name)
|
299
|
-
{
|
300
|
-
final Integer number = __fieldMap.get(name);
|
301
|
-
return number == null ? 0 : number.intValue();
|
302
|
-
}
|
303
|
-
|
304
|
-
private static final java.util.HashMap<String,Integer> __fieldMap = new java.util.HashMap<String,Integer>();
|
305
|
-
static
|
306
|
-
{
|
307
|
-
<%- message.getFields.each do |field| -%>
|
308
|
-
__fieldMap.put("<%=field.name%>", <%=field.number%>);
|
309
|
-
<%- end -%>
|
310
|
-
}
|
311
|
-
|
312
|
-
public static List<String> getFields() {
|
313
|
-
ArrayList<String> fieldNames = new ArrayList<String>();
|
314
|
-
String fieldName = null;
|
315
|
-
Integer i = 1;
|
316
|
-
|
317
|
-
while(true) {
|
318
|
-
fieldName = <%=klass%>.getSchema().getFieldName(i);
|
319
|
-
if (fieldName == null) {
|
320
|
-
break;
|
321
|
-
}
|
322
|
-
fieldNames.add(fieldName);
|
323
|
-
i++;
|
324
|
-
}
|
325
|
-
return fieldNames;
|
326
|
-
}
|
327
|
-
|
328
|
-
public static <%=klass%> parseFrom(byte[] bytes) {
|
329
|
-
<%=klass%> message = new <%=klass%>();
|
330
|
-
ProtobufIOUtil.mergeFrom(bytes, message, RuntimeSchema.getSchema(<%=klass%>.class));
|
331
|
-
return message;
|
332
|
-
}
|
333
|
-
|
334
|
-
public <%=klass%> clone() {
|
335
|
-
byte[] bytes = this.toByteArray();
|
336
|
-
<%=klass%> <%=varname(klass)%> = <%=klass%>.parseFrom(bytes);
|
337
|
-
return <%=varname(klass)%>;
|
338
|
-
}
|
339
|
-
|
340
|
-
public byte[] toByteArray() {
|
341
|
-
return toProtobuf();
|
342
|
-
//return toJson();
|
343
|
-
}
|
344
|
-
|
345
|
-
public byte[] toJson() {
|
346
|
-
boolean numeric = false;
|
347
|
-
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
348
|
-
try {
|
349
|
-
JsonIOUtil.writeTo(out, this, <%=klass%>.getSchema(), numeric);
|
350
|
-
} catch (IOException e) {
|
351
|
-
e.printStackTrace();
|
352
|
-
throw new RuntimeException("Json encoding failed");
|
353
|
-
}
|
354
|
-
return out.toByteArray();
|
355
|
-
}
|
356
|
-
|
357
|
-
public byte[] toPrefixedByteArray() {
|
358
|
-
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
|
359
|
-
Schema<<%=klass%>> schema = RuntimeSchema.getSchema(<%=klass%>.class);
|
360
|
-
|
361
|
-
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
362
|
-
final ProtobufOutput output = new ProtobufOutput(buffer);
|
363
|
-
try
|
364
|
-
{
|
365
|
-
schema.writeTo(output, this);
|
366
|
-
final int size = output.getSize();
|
367
|
-
ProtobufOutput.writeRawVarInt32Bytes(out, size);
|
368
|
-
final int msgSize = LinkedBuffer.writeTo(out, buffer);
|
369
|
-
assert size == msgSize;
|
370
|
-
|
371
|
-
buffer.clear();
|
372
|
-
return out.toByteArray();
|
373
|
-
}
|
374
|
-
catch (IOException e)
|
375
|
-
{
|
376
|
-
throw new RuntimeException("Serializing to a byte array threw an IOException " +
|
377
|
-
"(should never happen).", e);
|
378
|
-
}
|
379
|
-
|
380
|
-
}
|
381
|
-
|
382
|
-
public byte[] toProtobuf() {
|
383
|
-
LinkedBuffer buffer = LinkedBuffer.allocate(8024);
|
384
|
-
byte[] bytes = null;
|
385
|
-
|
386
|
-
try {
|
387
|
-
bytes = ProtobufIOUtil.toByteArray(this, RuntimeSchema.getSchema(<%=klass%>.class), buffer);
|
388
|
-
buffer.clear();
|
389
|
-
} catch (Exception e) {
|
390
|
-
e.printStackTrace();
|
391
|
-
throw new RuntimeException("Protobuf encoding failed");
|
392
|
-
}
|
393
|
-
return bytes;
|
394
|
-
}
|
395
|
-
|
396
|
-
}
|