game_machine 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
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,58 @@
1
+
2
+ # We use this for player specific maintenance, such as regenerating health
3
+ module Example
4
+ class PlayerManager < GameMachine::Actor::Base
5
+ include Models
6
+ include GameMachine::Commands
7
+
8
+ attr_reader :player_ids
9
+ def post_init(*args)
10
+ @player_ids = []
11
+ update_player_ids
12
+ schedule_message('update',5,:seconds)
13
+ end
14
+
15
+ # All players currently logged into this node
16
+ def update_player_ids
17
+ @player_ids = GameMachine::ClientManager.local_connections.keys
18
+ end
19
+
20
+ def regen_player_health
21
+ update_player_ids
22
+ player_ids.each do |player_id|
23
+ if vitals = Vitals.find(player_id)
24
+ vitals.health += 5
25
+ if vitals.health > vitals.max_health
26
+ vitals.health = vitals.max_health
27
+ end
28
+ if grid_value = commands.grid.find_by_id(player_id)
29
+ vitals.x = grid_value.x
30
+ vitals.y = grid_value.y
31
+ end
32
+ vitals.save
33
+ commands.player.send_message(vitals,player_id)
34
+ end
35
+ end
36
+ end
37
+
38
+ def on_receive(message)
39
+ if message.is_a?(String)
40
+ if message == 'update'
41
+ regen_player_health
42
+ end
43
+ elsif message.is_a?(GameMachine::Models::PlayerStatusUpdate)
44
+ if vitals = Vitals.find(message.player_id)
45
+ if message.status == 'registered'
46
+ if zone = GameMachine::GameSystems::RegionService.region
47
+ vitals.zone = zone
48
+ vitals.save
49
+ GameMachine.logger.info "#{message.player_id} entered zone #{vitals.zone}"
50
+ end
51
+ elsif message.status == 'unregistered'
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,80 @@
1
+ module Example
2
+ class PlayerRegister
3
+ include Models
4
+
5
+ attr_accessor :params, :errors
6
+ def initialize(params)
7
+ @params = params
8
+ @errors = {}
9
+ end
10
+
11
+ def valid?
12
+ errors.size == 0
13
+ end
14
+
15
+ def add_error(field,message)
16
+ errors[field] ||= []
17
+ errors[field] << message
18
+ end
19
+
20
+ def error
21
+ {'error' => errors}
22
+ end
23
+
24
+ def success(message)
25
+ {'success' => message}
26
+ end
27
+
28
+ # This is called whenever a player is registered
29
+ # It must return a simple hash with a success or error key
30
+ def register!
31
+
32
+ # Create one character at registration time
33
+ password = params['password']
34
+ username = params['username']
35
+ character_name = params['character_name']
36
+
37
+ # make sure user/character do not already exist
38
+ if User.find(username,10000)
39
+ add_error('username','must not already exist')
40
+ return error
41
+ end
42
+
43
+ if username == character_name
44
+ add_error('username','must be different from character name')
45
+ end
46
+
47
+ # Create user
48
+ user = User.new(
49
+ :id => username,
50
+ :password => password,
51
+ )
52
+ if user.password.size > 4
53
+ user.save
54
+ else
55
+ add_error('password', 'length must be > 4')
56
+ end
57
+
58
+ # Create character
59
+ stats = Vitals.new(
60
+ :id => username,
61
+ :max_health => 100,
62
+ :health => 100,
63
+ :defense_skill => 10,
64
+ :offense_skill => 10,
65
+ :entity_type => 'player',
66
+ :x => 500,
67
+ :y => 500,
68
+ :zone => 'zone1'
69
+ )
70
+ stats.save
71
+
72
+ if valid?
73
+ success("Account created!")
74
+ else
75
+ error
76
+ end
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,17 @@
1
+
2
+ # This class is set in the config. Every time the client sends it's location
3
+ # the verify method is called. You can use this to prevent things like speed hacking.
4
+ module Example
5
+ class TrackingHandler
6
+
7
+ # This method must return true for the players location to be saved.
8
+ # If you return false here, the location sent by the player will be discarded
9
+ def verify(entity)
10
+ #vector = entity.vector3
11
+ #player_id = entity.id
12
+ #entity_type = entity.entity_type
13
+ #track_extra = entity.track_entity.track_extra
14
+ true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,57 @@
1
+ # This class is configured in regions.yml, which is a mapping of regions to classes
2
+ # that handle running the region. In this example we use the same class for both
3
+ # of our regions. Our example regions only vary in which npc's are spawned.
4
+ module Example
5
+ class ZoneManager < GameMachine::Actor::Base
6
+
7
+ attr_reader :game_data
8
+ def post_init(*args)
9
+ @game_data = args.first
10
+ @region_up = false
11
+ end
12
+
13
+ def start_zone(zone)
14
+
15
+ # Start our combat controller
16
+ GameMachine::Actor::Builder.new(CombatController).start
17
+
18
+ if zone == 'zone1'
19
+ data = game_data.fetch('zone1')
20
+ spawn_npcs('male',data['male'],Npc)
21
+ spawn_npcs('viking',data['viking'],Npc)
22
+ spawn_npcs('golem',data['golem'],Npc)
23
+ spawn_npcs('worm',data['worm'],AggressiveNpc)
24
+ elsif zone == 'zone2'
25
+ data = game_data.fetch('zone2')
26
+ spawn_npcs('male',data['male'],Npc)
27
+ spawn_npcs('viking',data['viking'],Npc)
28
+ spawn_npcs('golem',data['golem'],Npc)
29
+ spawn_npcs('worm',data['worm'],AggressiveNpc)
30
+ end
31
+ end
32
+
33
+ def spawn_npcs(type,count,klass)
34
+ count.times.map {|i| "#{type}_#{i}"}.each_slice(20).each do |group|
35
+ name = Digest::MD5.hexdigest(group.join(''))
36
+ group.each do |npc_name|
37
+ Game.npcs[npc_name] = name
38
+ end
39
+ GameMachine::Actor::Builder.new(NpcGroup,group,klass).with_name(name).start
40
+ end
41
+ end
42
+
43
+ def on_receive(message)
44
+
45
+ # Region manager pings us every couple of seconds as long as we are alive,
46
+ # it's up to us to determine if we have started the region or not
47
+ if message.is_a?(GameMachine::Models::Region)
48
+ return if @region_up
49
+ @region_up = true
50
+
51
+ zone = message.name
52
+ GameMachine.logger.info "#{self.class.name} Starting region #{zone}"
53
+ start_zone(zone)
54
+ end
55
+ end
56
+ end
57
+ end
data/games/preload.rb ADDED
@@ -0,0 +1,8 @@
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
+
7
+ # This needs to be loaded before the entity tracking system starts
8
+ require_relative 'example/lib/tracking_handler'
@@ -0,0 +1,68 @@
1
+ require 'integration_helper'
2
+
3
+ module GameMachine
4
+
5
+ describe "basic" do
6
+
7
+ let(:client) {Clients::Client.new(:seed01)}
8
+
9
+ context "test" do
10
+
11
+ describe "sending messages to remote actors" do
12
+
13
+ it "there and back again" do
14
+ ref = GameSystems::LocalEcho.find_remote('seed01')
15
+ ref.send_message('blah', :blocking => true, :timeout => 1000).should == 'blah'
16
+ returned_entity = ref.send_message(static_entity, :blocking => true, :timeout => 1000)
17
+ returned_entity.get_id.should == static_entity.get_id
18
+ end
19
+
20
+ it "distributed messaging should return answer" do
21
+ ref = GameSystems::LocalEcho.find_distributed('blah', 'DistributedLocalEcho')
22
+ returned_entity = ref.send_message(static_entity, :blocking => true, :timeout => 1000)
23
+ returned_entity.get_id.should == static_entity.get_id
24
+ end
25
+
26
+ it "udt should get response" do
27
+ bytes = static_client_message.to_byte_array
28
+ Thread.current['s'] ||= Clients::Client.connect_udt
29
+ result = Clients::Client.send_udt(Thread.current['s'],bytes)
30
+ returned_message = ClientMessage.parse_from(result)
31
+ returned_message.get_entity_list.first.id.should == static_entity.id
32
+ end
33
+
34
+ it "udp should get response" do
35
+ bytes = static_client_message.to_byte_array
36
+ c = Clients::Client.new(:seed01)
37
+ c.send_message(bytes)
38
+ message = c.receive_message
39
+ returned_message = ClientMessage.parse_from(message.to_java_bytes)
40
+ returned_message.get_entity_list.first.id.should == static_entity.id
41
+ end
42
+
43
+ it "player should be able to login via http" do
44
+ response = Clients::Client.http_post('/auth',{:username => 'player', :password => 'pass'})
45
+ response = JSON.parse(response)
46
+ response['authtoken'].should == 'authorized'
47
+ end
48
+
49
+ it "write behind cache writes to couchbase" do
50
+ ObjectDb.put(static_entity)
51
+ ObjectDb.get(static_entity.id).id.should == static_entity.id
52
+ end
53
+
54
+ it "echo request" do
55
+ client = Clients::TestClient.start('test2',8200)
56
+ message = Helpers::GameMessage.new('player123')
57
+ message.echo_test('one')
58
+ client.send_to_server(message.client_message)
59
+ expect(client.entity_with_component('EchoTest',0.900)).to be_true
60
+ logout = Helpers::GameMessage.new('player123')
61
+ logout.player_logout
62
+ client.send_to_server(logout.client_message)
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,18 @@
1
+ require 'integration_helper'
2
+
3
+ module GameMachine
4
+
5
+ describe "bot net" do
6
+
7
+ describe "chat client bot" do
8
+ it "starts client" do
9
+ 200.times do |i|
10
+ GameMachine::Bot::Client.start("bot#{i}",8200)
11
+ end
12
+ sleep 20000
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+
@@ -0,0 +1,45 @@
1
+ require 'integration_helper'
2
+ module GameMachine
3
+
4
+ describe "chat" do
5
+
6
+ before(:all) do
7
+ @client = Clients::TestClient.start('test1',8200)
8
+ @client2 = Clients::TestClient.start('test2',8202)
9
+ end
10
+
11
+ after(:all) do
12
+ @client.stop
13
+ @client2.stop
14
+ end
15
+
16
+ it "join chat request sends ChatChannels to client" do
17
+ message = Helpers::GameMessage.new('player1')
18
+ message.join_chat('mygroup')
19
+ @client.send_to_server(message.client_message)
20
+ expect(@client.entity_with_component('ChatChannels')).to be_true
21
+ end
22
+
23
+ it "receive chat message from other player" do
24
+ client_join_message = Helpers::GameMessage.new('player1')
25
+ client_join_message.join_chat('mygroup')
26
+
27
+ client2_join_message = Helpers::GameMessage.new('player2')
28
+ client2_join_message.join_chat('mygroup')
29
+
30
+ chat_message = Helpers::GameMessage.new('player1')
31
+ chat_message.chat_message('group','Chat it up!','mygroup')
32
+
33
+ @client.send_to_server(client_join_message.client_message)
34
+ expect(@client.entity_with_component('ChatChannels')).to be_true
35
+
36
+ @client2.send_to_server(client2_join_message.client_message)
37
+ expect(@client2.entity_with_component('ChatChannels')).to be_true
38
+
39
+ @client.send_to_server(chat_message.client_message)
40
+ expect(@client2.entity_with_component('ChatMessage',1)).to be_true
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,34 @@
1
+ require 'integration_helper'
2
+
3
+ module GameMachine
4
+ describe "basic" do
5
+ let(:client) {Client.new(:seed01)}
6
+
7
+ describe "sending messages to remote actors" do
8
+ it "distributed messaging should return answer" do
9
+ e = entity.clone
10
+ 10.times do |i|
11
+ ref = GameSystems::LocalEcho.find_distributed(i.to_s, 'DistributedLocalEcho')
12
+ returned_entity = ref.send_message(e, :blocking => true, :timeout => 1000)
13
+ returned_entity.get_id.should == e.id
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "stress test" do
19
+ it "distributed stress" do
20
+ e = entity.clone
21
+ measure(10,100000) do
22
+ Thread.current['ref'] ||= GameSystems::LocalEcho.find_distributed(rand(100).to_s,'DistributedLocalEcho')
23
+ returned_entity = Thread.current['ref'].send_message(e, :blocking => true, :timeout => 1000)
24
+ if returned_entity
25
+ returned_entity.id.should == e.id
26
+ else
27
+ puts 'Timeout'
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,48 @@
1
+ require 'integration_helper'
2
+
3
+ def get_neighbors_message(player_id)
4
+ m = GameMachine::Helpers::GameMessage.new(player_id.to_s)
5
+ m.track_entity
6
+ m.get_neighbors
7
+ m.to_entity
8
+ m.current_entity.player.set_x(rand(1000)).set_y(1000)
9
+ m
10
+ end
11
+
12
+ def player_logout(player_id)
13
+ m = GameMachine::Helpers::GameMessage.new(player_id.to_s)
14
+ m.player_logout
15
+ m
16
+ end
17
+
18
+ module GameMachine
19
+ COUNT = JavaLib::AtomicInteger.new
20
+
21
+ describe 'Player tracking' do
22
+
23
+ it "players are tracked" do
24
+ pre = Proc.new do
25
+ player_id = COUNT.increment_and_get
26
+ Thread.current['player_id'] = player_id
27
+ Thread.current['bytes'] = get_neighbors_message(player_id).to_byte_array
28
+ Thread.current['c'] = Clients::UdtClient.new(:seed01)
29
+ Thread.current['c'].connect
30
+ end
31
+
32
+ post = Proc.new do
33
+ player_id = Thread.current['player_id']
34
+ Thread.current['c'].send_message(player_logout(player_id).to_byte_array)
35
+ sleep 0.100
36
+ Thread.current['c'].disconnect
37
+ end
38
+
39
+ measure(100,1000,pre,post) do
40
+ Thread.current['c'].send_message(Thread.current['bytes'])
41
+ res = Thread.current['c'].receive
42
+ client_message = ClientMessage.parse_from(res)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+