game_machine 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +72 -0
  4. data/Rakefile +38 -0
  5. data/bin/game_machine +79 -0
  6. data/config/cluster.conf +65 -0
  7. data/config/config.example.yml +93 -0
  8. data/config/game_messages.proto +45 -0
  9. data/config/messages.proto +339 -0
  10. data/config/regions.example.yml +9 -0
  11. data/config/standalone.conf +36 -0
  12. data/db/do_not_delete +0 -0
  13. data/game_machine.gemspec +38 -0
  14. data/games/example/boot.rb +6 -0
  15. data/games/example/data/game_data.yml +13 -0
  16. data/games/example/lib/aggressive_npc.rb +176 -0
  17. data/games/example/lib/authentication_handler.rb +69 -0
  18. data/games/example/lib/chatbot.rb +61 -0
  19. data/games/example/lib/combat_controller.rb +145 -0
  20. data/games/example/lib/example_controller.rb +21 -0
  21. data/games/example/lib/game.rb +85 -0
  22. data/games/example/lib/models/attack.rb +9 -0
  23. data/games/example/lib/models/combat_update.rb +11 -0
  24. data/games/example/lib/models/player_command.rb +7 -0
  25. data/games/example/lib/models/user.rb +11 -0
  26. data/games/example/lib/models/vitals.rb +17 -0
  27. data/games/example/lib/npc.rb +111 -0
  28. data/games/example/lib/npc_group.rb +42 -0
  29. data/games/example/lib/npc_movement.rb +116 -0
  30. data/games/example/lib/player_manager.rb +58 -0
  31. data/games/example/lib/player_register.rb +80 -0
  32. data/games/example/lib/tracking_handler.rb +17 -0
  33. data/games/example/lib/zone_manager.rb +57 -0
  34. data/games/preload.rb +8 -0
  35. data/integration_tests/basic_spec.rb +68 -0
  36. data/integration_tests/bot_spec.rb +18 -0
  37. data/integration_tests/chat_spec.rb +45 -0
  38. data/integration_tests/distributed_spec.rb +34 -0
  39. data/integration_tests/entity_tracking_spec.rb +48 -0
  40. data/integration_tests/mono_spec.rb +16 -0
  41. data/integration_tests/objectdb_spec.rb +55 -0
  42. data/integration_tests/tcp_client_spec.rb +71 -0
  43. data/integration_tests/udp_client_spec.rb +61 -0
  44. data/integration_tests/udp_spec.rb +20 -0
  45. data/integration_tests/udt_client_spec.rb +23 -0
  46. data/integration_tests/udt_spec.rb +31 -0
  47. data/java/.gitignore +1 -0
  48. data/java/build.gradle +93 -0
  49. data/java/component.erb +396 -0
  50. data/java/gradle.properties +6 -0
  51. data/java/gradle/wrapper/gradle-wrapper.jar +0 -0
  52. data/java/gradle/wrapper/gradle-wrapper.properties +6 -0
  53. data/java/gradlew +164 -0
  54. data/java/gradlew.bat +90 -0
  55. data/java/local_lib/protostuff-compiler-1.0.7-jarjar.jar +0 -0
  56. data/java/settings.gradle +2 -0
  57. data/java/src/main/java/com/game_machine/core/ActorFactory.java +25 -0
  58. data/java/src/main/java/com/game_machine/core/ActorUtil.java +39 -0
  59. data/java/src/main/java/com/game_machine/core/CommandProxy.java +9 -0
  60. data/java/src/main/java/com/game_machine/core/EntitySerializer.java +66 -0
  61. data/java/src/main/java/com/game_machine/core/EventStreamHandler.java +43 -0
  62. data/java/src/main/java/com/game_machine/core/GameMachineLoader.java +25 -0
  63. data/java/src/main/java/com/game_machine/core/Grid.java +195 -0
  64. data/java/src/main/java/com/game_machine/core/GridValue.java +30 -0
  65. data/java/src/main/java/com/game_machine/core/IActorFactory.java +7 -0
  66. data/java/src/main/java/com/game_machine/core/NetMessage.java +28 -0
  67. data/java/src/main/java/com/game_machine/core/UdpServer.java +97 -0
  68. data/java/src/main/java/com/game_machine/core/UdpServerHandler.java +90 -0
  69. data/java/src/main/resources/game_machine.java.stg +738 -0
  70. data/java/src/main/resources/logback.xml +14 -0
  71. data/java/src/main/resources/logging.properties +3 -0
  72. data/java/src/main/resources/protostuff.properties +7 -0
  73. data/lib/game_machine.rb +85 -0
  74. data/lib/game_machine/actor.rb +7 -0
  75. data/lib/game_machine/actor/base.rb +184 -0
  76. data/lib/game_machine/actor/builder.rb +108 -0
  77. data/lib/game_machine/actor/development.rb +31 -0
  78. data/lib/game_machine/actor/factory.rb +35 -0
  79. data/lib/game_machine/actor/mono_actor.rb +89 -0
  80. data/lib/game_machine/actor/ref.rb +81 -0
  81. data/lib/game_machine/actor/reloadable.rb +98 -0
  82. data/lib/game_machine/actor/system.rb +32 -0
  83. data/lib/game_machine/akka.rb +98 -0
  84. data/lib/game_machine/app_config.rb +49 -0
  85. data/lib/game_machine/application.rb +181 -0
  86. data/lib/game_machine/auth_handlers/base.rb +21 -0
  87. data/lib/game_machine/auth_handlers/public.rb +34 -0
  88. data/lib/game_machine/bot/chat.rb +66 -0
  89. data/lib/game_machine/bot/client.rb +54 -0
  90. data/lib/game_machine/client_manager.rb +204 -0
  91. data/lib/game_machine/clients.rb +4 -0
  92. data/lib/game_machine/clients/client.rb +45 -0
  93. data/lib/game_machine/clients/tcp_client.rb +25 -0
  94. data/lib/game_machine/clients/test_client.rb +151 -0
  95. data/lib/game_machine/clients/udp_client.rb +25 -0
  96. data/lib/game_machine/clients/udt_client.rb +34 -0
  97. data/lib/game_machine/cluster_monitor.rb +115 -0
  98. data/lib/game_machine/commands.rb +23 -0
  99. data/lib/game_machine/commands/base.rb +21 -0
  100. data/lib/game_machine/commands/chat_commands.rb +88 -0
  101. data/lib/game_machine/commands/datastore_commands.rb +60 -0
  102. data/lib/game_machine/commands/grid_commands.rb +35 -0
  103. data/lib/game_machine/commands/message_helper.rb +25 -0
  104. data/lib/game_machine/commands/misc_commands.rb +29 -0
  105. data/lib/game_machine/commands/navigation_commands.rb +24 -0
  106. data/lib/game_machine/commands/player_commands.rb +28 -0
  107. data/lib/game_machine/commands/proxy.rb +16 -0
  108. data/lib/game_machine/console.rb +3 -0
  109. data/lib/game_machine/console/build.rb +74 -0
  110. data/lib/game_machine/console/install.rb +92 -0
  111. data/lib/game_machine/console/server.rb +120 -0
  112. data/lib/game_machine/data_store.rb +52 -0
  113. data/lib/game_machine/data_stores/couchbase.rb +18 -0
  114. data/lib/game_machine/data_stores/mapdb.rb +49 -0
  115. data/lib/game_machine/data_stores/memory.rb +35 -0
  116. data/lib/game_machine/data_stores/redis.rb +46 -0
  117. data/lib/game_machine/endpoints.rb +6 -0
  118. data/lib/game_machine/endpoints/mono_gateway.rb +87 -0
  119. data/lib/game_machine/endpoints/tcp.rb +51 -0
  120. data/lib/game_machine/endpoints/tcp_handler.rb +75 -0
  121. data/lib/game_machine/endpoints/udp.rb +88 -0
  122. data/lib/game_machine/endpoints/udp_incoming.rb +113 -0
  123. data/lib/game_machine/endpoints/udp_outgoing.rb +46 -0
  124. data/lib/game_machine/game_loader.rb +46 -0
  125. data/lib/game_machine/game_systems.rb +14 -0
  126. data/lib/game_machine/game_systems/agents/controller.rb +118 -0
  127. data/lib/game_machine/game_systems/chat.rb +256 -0
  128. data/lib/game_machine/game_systems/chat_manager.rb +108 -0
  129. data/lib/game_machine/game_systems/chat_topic.rb +36 -0
  130. data/lib/game_machine/game_systems/devnull.rb +13 -0
  131. data/lib/game_machine/game_systems/entity_loader.rb +12 -0
  132. data/lib/game_machine/game_systems/entity_tracking.rb +133 -0
  133. data/lib/game_machine/game_systems/local_echo.rb +16 -0
  134. data/lib/game_machine/game_systems/objectdb_proxy.rb +61 -0
  135. data/lib/game_machine/game_systems/private_chat.rb +20 -0
  136. data/lib/game_machine/game_systems/region_manager.rb +91 -0
  137. data/lib/game_machine/game_systems/region_service.rb +94 -0
  138. data/lib/game_machine/game_systems/region_settings.rb +13 -0
  139. data/lib/game_machine/game_systems/remote_echo.rb +14 -0
  140. data/lib/game_machine/game_systems/stress_test.rb +21 -0
  141. data/lib/game_machine/grid.rb +60 -0
  142. data/lib/game_machine/grid_replicator.rb +31 -0
  143. data/lib/game_machine/handlers/authentication.rb +55 -0
  144. data/lib/game_machine/handlers/game.rb +63 -0
  145. data/lib/game_machine/handlers/request.rb +80 -0
  146. data/lib/game_machine/hashring.rb +48 -0
  147. data/lib/game_machine/helpers/game_message.rb +159 -0
  148. data/lib/game_machine/helpers/state_machine.rb +29 -0
  149. data/lib/game_machine/java_lib.rb +51 -0
  150. data/lib/game_machine/logger.rb +39 -0
  151. data/lib/game_machine/message_buffer.rb +58 -0
  152. data/lib/game_machine/message_queue.rb +63 -0
  153. data/lib/game_machine/model.rb +125 -0
  154. data/lib/game_machine/models.rb +3 -0
  155. data/lib/game_machine/models/player_status_update.rb +8 -0
  156. data/lib/game_machine/models/region.rb +9 -0
  157. data/lib/game_machine/mono_server.rb +20 -0
  158. data/lib/game_machine/navigation.rb +4 -0
  159. data/lib/game_machine/navigation/detour.rb +20 -0
  160. data/lib/game_machine/navigation/detour_navmesh.rb +53 -0
  161. data/lib/game_machine/navigation/detour_path.rb +53 -0
  162. data/lib/game_machine/navigation/path.rb +31 -0
  163. data/lib/game_machine/object_db.rb +67 -0
  164. data/lib/game_machine/protobuf.rb +6 -0
  165. data/lib/game_machine/protobuf/game_messages.rb +24 -0
  166. data/lib/game_machine/protobuf/generate.rb +113 -0
  167. data/lib/game_machine/protobuf_extensions/entity_helper.rb +11 -0
  168. data/lib/game_machine/reloadable_monitor.rb +26 -0
  169. data/lib/game_machine/restart_watcher.rb +17 -0
  170. data/lib/game_machine/ruby_extensions/nilclass.rb +10 -0
  171. data/lib/game_machine/ruby_extensions/string.rb +17 -0
  172. data/lib/game_machine/scheduler.rb +23 -0
  173. data/lib/game_machine/securerandom.rb +6 -0
  174. data/lib/game_machine/settings.rb +11 -0
  175. data/lib/game_machine/system_monitor.rb +19 -0
  176. data/lib/game_machine/system_stats.rb +24 -0
  177. data/lib/game_machine/uniqueid.rb +23 -0
  178. data/lib/game_machine/vector.rb +95 -0
  179. data/lib/game_machine/version.rb +3 -0
  180. data/lib/game_machine/write_behind_cache.rb +164 -0
  181. data/mono/bin/csharp/common.xslt +109 -0
  182. data/mono/bin/csharp/csharp.xslt +628 -0
  183. data/mono/bin/csharp/descriptor.proto +533 -0
  184. data/mono/bin/csharp/protobuf-net.dll +0 -0
  185. data/mono/bin/csharp/protobuf-net.pdb +0 -0
  186. data/mono/bin/csharp/protobuf-net.xml +2879 -0
  187. data/mono/bin/csharp/protogen.exe.config +3 -0
  188. data/mono/bin/csharp/protogen.pdb +0 -0
  189. data/mono/bin/csharp/protogen_csharp.exe +0 -0
  190. data/mono/bin/csharp/vb.xslt +745 -0
  191. data/mono/bin/csharp/xml.xslt +26 -0
  192. data/mono/server/Makefile +6 -0
  193. data/mono/server/NLog.config +12 -0
  194. data/mono/server/NLog.dll +0 -0
  195. data/mono/server/actor.cs +37 -0
  196. data/mono/server/build.bat +3 -0
  197. data/mono/server/cscompmgd.dll +0 -0
  198. data/mono/server/iactor.cs +11 -0
  199. data/mono/server/message_router.cs +67 -0
  200. data/mono/server/message_util.cs +29 -0
  201. data/mono/server/messages.cs +1888 -0
  202. data/mono/server/protobuf-net.dll +0 -0
  203. data/mono/server/proxy_client.cs +73 -0
  204. data/mono/server/proxy_server.cs +30 -0
  205. data/mono/server/test_actor.cs +33 -0
  206. data/pathfinding/bin/premake4 +0 -0
  207. data/pathfinding/include/mesh_loader.h +28 -0
  208. data/pathfinding/include/pathfind.h +167 -0
  209. data/pathfinding/main.cpp +39 -0
  210. data/pathfinding/mesh_loader.cpp +108 -0
  211. data/pathfinding/pathfind.cpp +174 -0
  212. data/pathfinding/pathfinder.cs +66 -0
  213. data/pathfinding/premake4.lua +109 -0
  214. data/script/server.sh +109 -0
  215. data/script/watch.sh +11 -0
  216. data/spec/actor/actor_spec.rb +73 -0
  217. data/spec/actor/builder_spec.rb +56 -0
  218. data/spec/actor/ref_spec.rb +83 -0
  219. data/spec/application_spec.rb +7 -0
  220. data/spec/client_manager_spec.rb +171 -0
  221. data/spec/commands/chat_commands_spec.rb +38 -0
  222. data/spec/commands/datastore_commands_spec.rb +91 -0
  223. data/spec/commands/grid_commands_spec.rb +37 -0
  224. data/spec/commands/navigation_commands_spec.rb +51 -0
  225. data/spec/commands/player_commands_spec.rb +48 -0
  226. data/spec/commands_spec.rb +38 -0
  227. data/spec/data_stores/mapdb_spec.rb +46 -0
  228. data/spec/data_stores/redis_spec.rb +44 -0
  229. data/spec/game_systems/agents/controller_spec.rb +84 -0
  230. data/spec/game_systems/agents/test_agent.rb +10 -0
  231. data/spec/game_systems/agents/test_agent_config.rb +29 -0
  232. data/spec/game_systems/chat_manager_spec.rb +66 -0
  233. data/spec/game_systems/chat_spec.rb +187 -0
  234. data/spec/game_systems/entity_tracking_spec.rb +64 -0
  235. data/spec/game_systems/region_manager_spec.rb +138 -0
  236. data/spec/grid_spec.rb +37 -0
  237. data/spec/handlers/authentication_spec.rb +36 -0
  238. data/spec/handlers/game_spec.rb +49 -0
  239. data/spec/handlers/request_spec.rb +65 -0
  240. data/spec/hashring_spec.rb +59 -0
  241. data/spec/integration_helper.rb +120 -0
  242. data/spec/java_grid_spec.rb +89 -0
  243. data/spec/message_buffer_spec.rb +67 -0
  244. data/spec/message_expectations.rb +47 -0
  245. data/spec/message_queue_spec.rb +23 -0
  246. data/spec/misc_spec.rb +71 -0
  247. data/spec/model_spec.rb +103 -0
  248. data/spec/mono_spec.rb +36 -0
  249. data/spec/mono_test.rb +18 -0
  250. data/spec/navigation/detour_navmesh_spec.rb +34 -0
  251. data/spec/navigation/detour_path_spec.rb +25 -0
  252. data/spec/spec_helper.rb +40 -0
  253. data/spec/udp_server_spec.rb +10 -0
  254. data/spec/write_behind_cache_spec.rb +109 -0
  255. data/web/app.rb +131 -0
  256. data/web/config/trinidad.yml +4 -0
  257. data/web/controllers/auth_controller.rb +19 -0
  258. data/web/controllers/base_controller.rb +16 -0
  259. data/web/controllers/index_controller.rb +7 -0
  260. data/web/controllers/log_controller.rb +47 -0
  261. data/web/controllers/messages_controller.rb +59 -0
  262. data/web/controllers/player_register_controller.rb +15 -0
  263. data/web/log/development.log +1339 -0
  264. data/web/tmp/restart.txt +0 -0
  265. data/web/views/game_messages.haml +45 -0
  266. data/web/views/index.haml +6 -0
  267. data/web/views/layout.haml +41 -0
  268. data/web/views/logs.haml +32 -0
  269. data/web/views/player_register.haml +22 -0
  270. data/web/views/player_registered.haml +2 -0
  271. data/web/views/register_layout.haml +22 -0
  272. data/web/views/restart.haml +35 -0
  273. metadata +576 -0
@@ -0,0 +1,16 @@
1
+ require 'integration_helper'
2
+
3
+ module GameMachine
4
+
5
+ describe MonoTest do
6
+
7
+ it "runs ok" do
8
+ 100000.times do
9
+ MonoTest.find.tell(Helpers::GameMessage.new('test').to_byte_array)
10
+ #MonoTest.find_remote('seed01').tell(Helpers::GameMessage.new('test').to_byte_array)
11
+ end
12
+ end
13
+ end
14
+
15
+ end
16
+
@@ -0,0 +1,55 @@
1
+
2
+ require 'integration_helper'
3
+ require_relative '../spec/boot.rb'
4
+
5
+ module GameMachine
6
+ describe ObjectDb do
7
+
8
+ describe "stress" do
9
+
10
+ it "stress with small payload" do
11
+ measure(10,10000) do
12
+ e = entity
13
+ id = e.id
14
+ ObjectDb.put(e)
15
+ if returned_entity = ObjectDb.get(id)
16
+ returned_entity.id.should == id
17
+ end
18
+ end
19
+ end
20
+
21
+ it "stress get" do
22
+ measure(10,10000) do
23
+ e = entity
24
+ id = e.id
25
+ if returned_entity = ObjectDb.get(id)
26
+ returned_entity.id.should == id
27
+ end
28
+ end
29
+ end
30
+
31
+ it "stress dbproc" do
32
+ measure(10,10000) do
33
+ e = entity
34
+ id = e.id
35
+ if returned_entity = ObjectDb.call_dbproc(:update, e.id,true)
36
+ returned_entity.id.should == id
37
+ end
38
+ end
39
+ end
40
+
41
+ it "stress with large payload" do
42
+ measure(10,10000) do
43
+ e = large_entity
44
+ id = e.id
45
+ ObjectDb.put(e)
46
+ if returned_entity = ObjectDb.get(id)
47
+ returned_entity.id.should == id
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+
@@ -0,0 +1,71 @@
1
+ require 'integration_helper'
2
+ ENV['GAME_ENV'] = 'test'
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'game_machine'
7
+ rescue LoadError
8
+ require_relative '../lib/game_machine'
9
+ end
10
+
11
+ def echo_test
12
+ GameMachine::MessageLib::EchoTest.new.set_message('testing')
13
+ end
14
+
15
+ def entity
16
+ GameMachine::MessageLib::Entity.new.set_id('1').set_echo_test(echo_test)
17
+ end
18
+
19
+ def message_for(client_message)
20
+ String.from_java_bytes(client_message.to_prefixed_byte_array)
21
+ end
22
+
23
+ def player_for(id)
24
+ GameMachine::MessageLib::Player.new.set_id(id).set_name(id).
25
+ set_authtoken('authorized')
26
+ end
27
+
28
+ def client_message_for(player)
29
+ GameMachine::MessageLib::ClientMessage.new.add_entity(entity).
30
+ set_player(player)
31
+ end
32
+
33
+ module GameMachine
34
+
35
+ describe 'tcp client' do
36
+
37
+
38
+ describe "sending and receiving messages" do
39
+ it "should receive reply" do
40
+ threads = []
41
+ 1.times do |i|
42
+ threads << Thread.new do
43
+ player = player_for("player_#{i}")
44
+ Application.auth_handler.add_user(player.id,player.authtoken)
45
+ message = message_for(client_message_for(player))
46
+ client = Clients::TcpClient.new('localhost',8700)
47
+ results = []
48
+ count = 0
49
+ 100000.times do
50
+ #sleep 0.100
51
+ results << Benchmark.realtime do
52
+ client.send_message(message)
53
+ if bytes = client.receive_message.to_java_bytes
54
+ #client_message = MessageLib::ClientMessage.parse_from(bytes)
55
+ end
56
+ end
57
+ count += 1
58
+ if count > 1000
59
+ puts "Number = #{results.number} Average #{results.mean} Standard deviation #{results.standard_deviation}"
60
+ count = 0
61
+ results = []
62
+ end
63
+ end
64
+ puts "Number = #{results.number} Average #{results.mean} Standard deviation #{results.standard_deviation}"
65
+ end
66
+ end
67
+ threads.map(&:join)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,61 @@
1
+
2
+ ENV['GAME_ENV'] = 'test'
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'game_machine'
7
+ rescue LoadError
8
+ require_relative '../lib/game_machine'
9
+ end
10
+ module GameMachine
11
+
12
+ describe 'udt client' do
13
+
14
+ let(:player) do
15
+ Player.new.set_id('player').set_name('player').
16
+ set_authtoken('authorized')
17
+ end
18
+
19
+ let(:echo_test) do
20
+ EchoTest.new.set_message('testing')
21
+ end
22
+
23
+ let(:entity) do
24
+ MessageLib::Entity.new.set_id('1').set_echo_test(echo_test)
25
+ end
26
+
27
+ let(:client_message) do
28
+ ClientMessage.new.add_entity(entity).
29
+ set_player(player)
30
+ end
31
+
32
+ let(:message) do
33
+ String.from_java_bytes(client_message.to_byte_array)
34
+ end
35
+
36
+ let(:logout_message) do
37
+ String.from_java_bytes(
38
+ client_message.set_player_logout(
39
+ PlayerLogout.new.set_player_id('player')
40
+ ).to_byte_array
41
+ )
42
+ end
43
+
44
+ let(:client) {Clients::UdpClient.new(:seed01)}
45
+
46
+
47
+ describe "sending and receiving messages" do
48
+ it "should receive reply" do
49
+ 1.times do
50
+ client.send_message(message)
51
+ if bytes = client.receive_message.to_java_bytes
52
+ client_message = ClientMessage.parse_from(bytes)
53
+ #puts client_message.client_connection.id
54
+ #puts client_message.client_connection.gateway
55
+ client.send_message(logout_message)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,20 @@
1
+ require 'integration_helper'
2
+
3
+ module GameMachine
4
+ describe "udp" do
5
+
6
+ describe "sending messages via udp" do
7
+ it "should do" do
8
+ measure(10,10000) do
9
+ Thread.current['bytes'] ||= client_message.to_byte_array
10
+ Thread.current['c'] ||= Clients::Client.new(:seed01)
11
+ Thread.current['c'].send_message(Thread.current['bytes'])
12
+ message = Thread.current['c'].receive_message
13
+ ClientMessage.parse_from(message.to_java_bytes)
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+
@@ -0,0 +1,23 @@
1
+ require 'integration_helper'
2
+
3
+ module GameMachine
4
+
5
+ describe "basic" do
6
+ let(:client) {Clients::UdtClient.new(:seed01)}
7
+
8
+ describe "Sending and receiving messages" do
9
+ it "works" do
10
+ message = Helpers::GameMessage.new('player')
11
+ message.echo_test('hi')
12
+ client.connect
13
+ client.send_message(message.to_byte_array)
14
+ result = client.receive
15
+ logout = Helpers::GameMessage.new('player')
16
+ logout.player_logout
17
+ client.send_message(logout.to_byte_array)
18
+ client.disconnect
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ require 'integration_helper'
2
+
3
+ module GameMachine
4
+ describe "basic" do
5
+ let(:client) {Client.new(:seed01)}
6
+
7
+ describe "udt" do
8
+
9
+ it "stress with small payload" do
10
+ measure(10,10000) do
11
+ Thread.current['bytes'] ||= client_message.to_byte_array
12
+ Thread.current['s'] ||= Clients::Client.connect_udt
13
+ result = Clients::Client.send_udt(Thread.current['s'],Thread.current['bytes'])
14
+ ClientMessage.parse_from(result)
15
+ end
16
+ end
17
+
18
+ it "stress with large payload" do
19
+ measure(10,10000) do
20
+ Thread.current['bytes'] ||= client_message.to_byte_array
21
+ Thread.current['s'] ||= Clients::Client.connect_udt
22
+ result = Clients::Client.send_udt(Thread.current['s'],Thread.current['bytes'])
23
+ ClientMessage.parse_from(result)
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
31
+
data/java/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /bin
data/java/build.gradle ADDED
@@ -0,0 +1,93 @@
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.1.7')
49
+ compile 'redis.clients:jedis:2.2.1'
50
+ compile 'org.mapdb:mapdb:1.0.3'
51
+ compile 'io.netty:netty-testsuite:4.0.20.Final'
52
+
53
+ }
54
+
55
+ task wrapper(type: Wrapper) {
56
+ gradleVersion = '1.7'
57
+ }
58
+ task uberjar(type: Jar) {
59
+ from files(sourceSets.main.output.classesDir)
60
+ from configurations.runtime.asFileTree.files.collect { zipTree(it) }
61
+ }
62
+
63
+ task codegen(type: Exec) {
64
+ File templateFile = file('protogen.rb')
65
+ commandLine 'jruby',templateFile
66
+ }
67
+
68
+ task protogen(type: Exec) {
69
+ File configFile = file('src/main/resources/protostuff.properties')
70
+ File jar = file('protostuff-compiler-1.0.7-jarjar.jar')
71
+ commandLine 'java','-jar',jar,configFile
72
+ }
73
+
74
+ test {
75
+ useTestNG()
76
+ //outputs.upToDateWhen { false }
77
+ testLogging.showStandardStreams = true
78
+ dependsOn cleanTest
79
+ testLogging { exceptionFormat "full" }
80
+ }
81
+
82
+ task install_libs(type: Copy) {
83
+ into "$buildDir/../lib"
84
+ from configurations.runtime
85
+ from "$buildDir/libs"
86
+ }
87
+
88
+ task install_libs_ruby(type: Copy) {
89
+ into "$buildDir/../lib"
90
+ from configurations.runtime
91
+ from "$buildDir/libs"
92
+ }
93
+
@@ -0,0 +1,396 @@
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
+ }