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,91 @@
1
+ require 'spec_helper'
2
+
3
+ module GameMachine
4
+ module Commands
5
+
6
+ describe DatastoreCommands do
7
+
8
+ let(:entity) do
9
+ entity = MessageLib::Entity.new
10
+ entity.set_id('1')
11
+ entity
12
+ end
13
+
14
+ let(:entity2) do
15
+ entity = MessageLib::Entity.new
16
+ entity.set_id('2')
17
+ entity
18
+ end
19
+
20
+ subject{DatastoreCommands.new}
21
+
22
+ before(:each) do
23
+ subject.define_dbproc(:test1) do |current_entity,update_entity|
24
+ expect(update_entity).to eql(entity)
25
+ current_entity
26
+ end
27
+ subject.define_dbproc(:test2) do |current_entity,update_entity|
28
+ current_entity.set_entity_type('dunno')
29
+ current_entity
30
+ end
31
+ end
32
+
33
+ describe "#put" do
34
+ it "sets the value" do
35
+ subject.put(entity).should be_true
36
+ end
37
+ end
38
+
39
+ describe "#dbproc" do
40
+ it "call with entity id and update entity, returns entity" do
41
+ subject.put(entity)
42
+ sleep 0.100
43
+
44
+ result = subject.call_dbproc(:test1, entity.get_id,entity,true)
45
+ result.should be_kind_of(MessageLib::Entity)
46
+ result.get_id.should == entity.get_id
47
+ end
48
+
49
+ it "returns updated entity" do
50
+ subject.put(entity)
51
+ sleep 0.100
52
+
53
+ result = subject.call_dbproc(:test2, entity.get_id,entity,true)
54
+ result.get_entity_type.should == 'dunno'
55
+ end
56
+
57
+ it "returns true when called with blocking=false" do
58
+ subject.put(entity)
59
+ sleep 0.100
60
+
61
+ subject.call_dbproc(:test1, entity.get_id,entity,false).should be_true
62
+ end
63
+
64
+ it "if called with an entity id that does not exist, it creates it" do
65
+ returned_entity = subject.call_dbproc(:test1, 'blah',entity,true)
66
+ expect(returned_entity.id).to eql('blah')
67
+ end
68
+ end
69
+
70
+ describe "#get" do
71
+ it "should return false if object does not exist" do
72
+ subject.get('xx').should be_false
73
+ end
74
+
75
+ it "should return object if exists" do
76
+ subject.put(entity)
77
+ sleep 0.100
78
+ subject.get('1').should == entity
79
+ end
80
+ end
81
+
82
+ describe "#delete" do
83
+ it "removes the entity from the data store" do
84
+ subject.put(entity)
85
+ subject.delete(entity.id)
86
+ subject.get('1').should be_false
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ module GameMachine
4
+ module Commands
5
+ describe GridCommands do
6
+
7
+ subject{GridCommands.new}
8
+
9
+ describe "#find_by_id" do
10
+ it "retrieves a grid value from the grid by id" do
11
+ expect(subject.grid).to receive(:get).with('1')
12
+ subject.find_by_id('1')
13
+ end
14
+ end
15
+
16
+ describe "#track" do
17
+ it "sends entity id and coordinates to the grid" do
18
+ expect(subject.grid).to receive(:set).with('1',1.1,1.2,1.3,'player')
19
+ subject.track('1',1.1,1.2,1.3,'player')
20
+ end
21
+ end
22
+
23
+ describe "#neighbors" do
24
+ it "gets a list of neighbors from the grid with default entity type" do
25
+ expect(subject.grid).to receive(:neighbors).with(1.1,1.2,'player')
26
+ subject.neighbors(1.1,1.2)
27
+ end
28
+
29
+ it "gets a list of neighbors from the grid with explicit entity type" do
30
+ expect(subject.grid).to receive(:neighbors).with(1.1,1.2,'npc')
31
+ subject.neighbors(1.1,1.2,'npc')
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ module GameMachine
4
+ module Commands
5
+ describe NavigationCommands do
6
+
7
+ let(:navmesh) {double("DetourNavmesh", :load_mesh! => true)}
8
+ let(:query_ref) {double("DetourPath")}
9
+
10
+ let(:meshfile) {File.join(GameMachine.app_root,'../data/meshes/test.bin')}
11
+ subject{NavigationCommands.new}
12
+
13
+ before(:each) do
14
+ Navigation::DetourPath.stub(:query_ref).and_return(query_ref)
15
+ Navigation::DetourNavmesh.stub(:create).and_return(navmesh)
16
+ Navigation::DetourNavmesh.stub(:find).and_return(navmesh)
17
+ end
18
+
19
+ describe "#load_navmesh" do
20
+ it "returns a navmesh instance" do
21
+ expect(
22
+ subject.load_navmesh(1,meshfile)
23
+ ).to eql(navmesh)
24
+ end
25
+
26
+ it "calls load_mesh! on navmesh" do
27
+ expect(navmesh).to receive(:load_mesh!)
28
+ subject.load_navmesh(1,meshfile)
29
+ end
30
+
31
+ it "raises an exception of navmesh file does not exist" do
32
+ expect {
33
+ subject.load_navmesh(1,'/blahblah')
34
+ }.to raise_error(/does not exist/)
35
+ end
36
+ end
37
+
38
+ describe "#navmesh" do
39
+ it "returns the navmesh by id" do
40
+ expect(subject.navmesh(1)).to eql(navmesh)
41
+ end
42
+ end
43
+
44
+ describe "#query_ref" do
45
+ it "returns a navmesh query reference" do
46
+ expect(subject.query_ref(1)).to eql(query_ref)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ module GameMachine
4
+ module Commands
5
+
6
+ describe PlayerCommands do
7
+
8
+ let(:entity) do
9
+ entity = MessageLib::Entity.new
10
+ entity.set_id('1')
11
+ entity
12
+ end
13
+
14
+ let(:component) do
15
+ MessageLib::Attack.new
16
+ end
17
+
18
+ let(:actor_ref) {double('Actor::Ref', :tell => true)}
19
+
20
+ subject{PlayerCommands.new}
21
+
22
+ describe "player" do
23
+ describe "#send_message" do
24
+ before(:each) do
25
+ ClientManager.stub(:find).and_return(actor_ref)
26
+ end
27
+
28
+ it "sends component to player wrapped in entity" do
29
+ expect(actor_ref).to receive(:tell).with(kind_of(MessageLib::Entity))
30
+ subject.send_message(component,'1')
31
+ end
32
+
33
+ it "sends entity to player" do
34
+ expect(actor_ref).to receive(:tell).with(kind_of(MessageLib::Entity))
35
+ subject.send_message(MessageLib::Entity.new.set_id('1'),'1')
36
+ end
37
+
38
+ it "raises exception with invalid message" do
39
+ expect {
40
+ subject.send_message('blah','1')
41
+ }.to raise_error(/not a valid object/)
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ module GameMachine
4
+ class CommandTest
5
+ include Commands
6
+ end
7
+
8
+ describe Commands do
9
+
10
+ subject do
11
+ CommandTest.new
12
+ end
13
+
14
+ describe "#commands" do
15
+
16
+ it "should be present on any instance that includes Commands module" do
17
+ expect(subject.commands).to be_a(Commands::Base)
18
+ end
19
+
20
+ it "should have a chat instance" do
21
+ expect(subject.commands.chat).to be_a(Commands::ChatCommands)
22
+ end
23
+
24
+ it "should have a grid instance" do
25
+ expect(subject.commands.grid).to be_a(Commands::GridCommands)
26
+ end
27
+
28
+ it "should have a datastore instance" do
29
+ expect(subject.commands.datastore).to be_a(Commands::DatastoreCommands)
30
+ end
31
+
32
+ it "should have a player instance" do
33
+ expect(subject.commands.player).to be_a(Commands::PlayerCommands)
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ module GameMachine
3
+ module DataStores
4
+ describe Mapdb do
5
+
6
+ after(:each) do
7
+ #DataStore.instance.shutdown
8
+ #DataStore.instance.set_store('memory')
9
+ end
10
+
11
+ subject do
12
+ instance = DataStore.instance
13
+ instance.set_store('mapdb')
14
+ instance
15
+ end
16
+
17
+ let(:entity) do
18
+ MessageLib::Entity.new.set_id('one')
19
+ end
20
+
21
+ describe "iteration" do
22
+ it "returns all entries" do
23
+ subject.set('one','one')
24
+ subject.set('two','two')
25
+ subject.keys.each do |key|
26
+ #puts "KEY= " + subject.get(key)
27
+ end
28
+ end
29
+ end
30
+ describe "get_and_set" do
31
+ it "get should return the value that was set" do
32
+ subject.set('test',entity.to_byte_array)
33
+ entity = MessageLib::Entity.parse_from(subject.get('test'))
34
+ expect(entity.id).to eq('one')
35
+ end
36
+ end
37
+
38
+ describe "#shutdown" do
39
+ it "should return nil" do
40
+ #expect(subject.shutdown).to be_nil
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ module GameMachine
3
+ module DataStores
4
+ describe Redis do
5
+
6
+ after(:each) do
7
+ DataStore.instance.shutdown
8
+ DataStore.instance.set_store('memory')
9
+ end
10
+
11
+ subject do
12
+ instance = DataStore.instance
13
+ instance.set_store('redis')
14
+ instance
15
+ end
16
+
17
+ describe "#get" do
18
+ it "returns the value" do
19
+ subject.set('key','value')
20
+ expect(subject.get('key')).to eql('value')
21
+ end
22
+ end
23
+
24
+ describe "#set" do
25
+ it "returns true" do
26
+ expect(subject.set('key','value')).to be_true
27
+ end
28
+ end
29
+
30
+ describe "#delete" do
31
+ it "returns true" do
32
+ expect(subject.delete('key')).to be_true
33
+ end
34
+ end
35
+
36
+ describe "#shutdown" do
37
+ it "should return nil" do
38
+ expect(subject.shutdown).to be_nil
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+ require_relative 'test_agent_config'
3
+ require_relative 'test_agent'
4
+
5
+ module GameMachine
6
+ module GameSystems
7
+ module Agents
8
+
9
+ describe Controller do
10
+
11
+ let(:agent_config) {TestAgentConfig.new}
12
+
13
+ let(:agents) do
14
+ TestAgentConfig.new.data
15
+ end
16
+
17
+ subject do
18
+ ref = Actor::Builder.new(Controller,agent_config).with_name('controller_test').test_ref
19
+ ref.underlying_actor
20
+ end
21
+
22
+ context "initialization" do
23
+
24
+ it "should correctly set current_agents on start " do
25
+ expect(subject.current_agents).to eq agents
26
+ end
27
+
28
+ it "should create child agents on start" do
29
+ expect(subject.children.size).to eq 5
30
+ end
31
+ end
32
+
33
+ context "receiving messages" do
34
+
35
+ describe "receives a check_config message" do
36
+ it "should reload config if reload! is true" do
37
+ subject
38
+ expect(subject.agent_config).to receive(:reload?).and_return(true)
39
+ expect(subject.agent_config).to receive(:load!)
40
+ expect(subject).to receive(:update_agents)
41
+ subject.on_receive('check_config')
42
+ end
43
+
44
+ it "should not reload config if reload! is false" do
45
+ subject
46
+ expect(subject.agent_config).to receive(:reload?).and_return(false)
47
+ expect(subject.agent_config).to_not receive(:load!)
48
+ expect(subject).to_not receive(:update_agents)
49
+ subject.on_receive('check_config')
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ context "cluster node changes" do
56
+
57
+ it "should destroy children that it is no longer responsible for" do
58
+ my_agents = agents.clone
59
+ my_agents.delete(:agent1)
60
+ my_agents.delete(:agent2)
61
+ subject.stub(:local_agents).and_return(my_agents)
62
+ subject.update_agents
63
+ expect(subject.children.size).to eq 3
64
+ expect(subject.children.has_key?(:agent1)).to be_false
65
+ expect(subject.children.has_key?(:agent2)).to be_false
66
+ end
67
+
68
+ it "should create new children it becomes responsible for" do
69
+ my_agents = agents.clone
70
+ my_agents[:agent6] = 'TestAgent'
71
+ subject.stub(:agent_config).and_return(my_agents)
72
+ subject.stub(:local_agents).and_return(my_agents)
73
+ subject.update_agents
74
+ expect(subject.children.size).to eq 6
75
+ expect(subject.children.has_key?(:agent6)).to be_true
76
+ end
77
+ end
78
+
79
+
80
+ end
81
+
82
+ end
83
+ end
84
+ end