game_machine 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +72 -0
- data/Rakefile +38 -0
- data/bin/game_machine +79 -0
- data/config/cluster.conf +65 -0
- data/config/config.example.yml +93 -0
- data/config/game_messages.proto +45 -0
- data/config/messages.proto +339 -0
- data/config/regions.example.yml +9 -0
- data/config/standalone.conf +36 -0
- data/db/do_not_delete +0 -0
- data/game_machine.gemspec +38 -0
- data/games/example/boot.rb +6 -0
- data/games/example/data/game_data.yml +13 -0
- data/games/example/lib/aggressive_npc.rb +176 -0
- data/games/example/lib/authentication_handler.rb +69 -0
- data/games/example/lib/chatbot.rb +61 -0
- data/games/example/lib/combat_controller.rb +145 -0
- data/games/example/lib/example_controller.rb +21 -0
- data/games/example/lib/game.rb +85 -0
- data/games/example/lib/models/attack.rb +9 -0
- data/games/example/lib/models/combat_update.rb +11 -0
- data/games/example/lib/models/player_command.rb +7 -0
- data/games/example/lib/models/user.rb +11 -0
- data/games/example/lib/models/vitals.rb +17 -0
- data/games/example/lib/npc.rb +111 -0
- data/games/example/lib/npc_group.rb +42 -0
- data/games/example/lib/npc_movement.rb +116 -0
- data/games/example/lib/player_manager.rb +58 -0
- data/games/example/lib/player_register.rb +80 -0
- data/games/example/lib/tracking_handler.rb +17 -0
- data/games/example/lib/zone_manager.rb +57 -0
- data/games/preload.rb +8 -0
- data/integration_tests/basic_spec.rb +68 -0
- data/integration_tests/bot_spec.rb +18 -0
- data/integration_tests/chat_spec.rb +45 -0
- data/integration_tests/distributed_spec.rb +34 -0
- data/integration_tests/entity_tracking_spec.rb +48 -0
- data/integration_tests/mono_spec.rb +16 -0
- data/integration_tests/objectdb_spec.rb +55 -0
- data/integration_tests/tcp_client_spec.rb +71 -0
- data/integration_tests/udp_client_spec.rb +61 -0
- data/integration_tests/udp_spec.rb +20 -0
- data/integration_tests/udt_client_spec.rb +23 -0
- data/integration_tests/udt_spec.rb +31 -0
- data/java/.gitignore +1 -0
- data/java/build.gradle +93 -0
- data/java/component.erb +396 -0
- data/java/gradle.properties +6 -0
- data/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/java/gradlew +164 -0
- data/java/gradlew.bat +90 -0
- data/java/local_lib/protostuff-compiler-1.0.7-jarjar.jar +0 -0
- data/java/settings.gradle +2 -0
- data/java/src/main/java/com/game_machine/core/ActorFactory.java +25 -0
- data/java/src/main/java/com/game_machine/core/ActorUtil.java +39 -0
- data/java/src/main/java/com/game_machine/core/CommandProxy.java +9 -0
- data/java/src/main/java/com/game_machine/core/EntitySerializer.java +66 -0
- data/java/src/main/java/com/game_machine/core/EventStreamHandler.java +43 -0
- data/java/src/main/java/com/game_machine/core/GameMachineLoader.java +25 -0
- data/java/src/main/java/com/game_machine/core/Grid.java +195 -0
- data/java/src/main/java/com/game_machine/core/GridValue.java +30 -0
- data/java/src/main/java/com/game_machine/core/IActorFactory.java +7 -0
- data/java/src/main/java/com/game_machine/core/NetMessage.java +28 -0
- data/java/src/main/java/com/game_machine/core/UdpServer.java +97 -0
- data/java/src/main/java/com/game_machine/core/UdpServerHandler.java +90 -0
- data/java/src/main/resources/game_machine.java.stg +738 -0
- data/java/src/main/resources/logback.xml +14 -0
- data/java/src/main/resources/logging.properties +3 -0
- data/java/src/main/resources/protostuff.properties +7 -0
- data/lib/game_machine.rb +85 -0
- data/lib/game_machine/actor.rb +7 -0
- data/lib/game_machine/actor/base.rb +184 -0
- data/lib/game_machine/actor/builder.rb +108 -0
- data/lib/game_machine/actor/development.rb +31 -0
- data/lib/game_machine/actor/factory.rb +35 -0
- data/lib/game_machine/actor/mono_actor.rb +89 -0
- data/lib/game_machine/actor/ref.rb +81 -0
- data/lib/game_machine/actor/reloadable.rb +98 -0
- data/lib/game_machine/actor/system.rb +32 -0
- data/lib/game_machine/akka.rb +98 -0
- data/lib/game_machine/app_config.rb +49 -0
- data/lib/game_machine/application.rb +181 -0
- data/lib/game_machine/auth_handlers/base.rb +21 -0
- data/lib/game_machine/auth_handlers/public.rb +34 -0
- data/lib/game_machine/bot/chat.rb +66 -0
- data/lib/game_machine/bot/client.rb +54 -0
- data/lib/game_machine/client_manager.rb +204 -0
- data/lib/game_machine/clients.rb +4 -0
- data/lib/game_machine/clients/client.rb +45 -0
- data/lib/game_machine/clients/tcp_client.rb +25 -0
- data/lib/game_machine/clients/test_client.rb +151 -0
- data/lib/game_machine/clients/udp_client.rb +25 -0
- data/lib/game_machine/clients/udt_client.rb +34 -0
- data/lib/game_machine/cluster_monitor.rb +115 -0
- data/lib/game_machine/commands.rb +23 -0
- data/lib/game_machine/commands/base.rb +21 -0
- data/lib/game_machine/commands/chat_commands.rb +88 -0
- data/lib/game_machine/commands/datastore_commands.rb +60 -0
- data/lib/game_machine/commands/grid_commands.rb +35 -0
- data/lib/game_machine/commands/message_helper.rb +25 -0
- data/lib/game_machine/commands/misc_commands.rb +29 -0
- data/lib/game_machine/commands/navigation_commands.rb +24 -0
- data/lib/game_machine/commands/player_commands.rb +28 -0
- data/lib/game_machine/commands/proxy.rb +16 -0
- data/lib/game_machine/console.rb +3 -0
- data/lib/game_machine/console/build.rb +74 -0
- data/lib/game_machine/console/install.rb +92 -0
- data/lib/game_machine/console/server.rb +120 -0
- data/lib/game_machine/data_store.rb +52 -0
- data/lib/game_machine/data_stores/couchbase.rb +18 -0
- data/lib/game_machine/data_stores/mapdb.rb +49 -0
- data/lib/game_machine/data_stores/memory.rb +35 -0
- data/lib/game_machine/data_stores/redis.rb +46 -0
- data/lib/game_machine/endpoints.rb +6 -0
- data/lib/game_machine/endpoints/mono_gateway.rb +87 -0
- data/lib/game_machine/endpoints/tcp.rb +51 -0
- data/lib/game_machine/endpoints/tcp_handler.rb +75 -0
- data/lib/game_machine/endpoints/udp.rb +88 -0
- data/lib/game_machine/endpoints/udp_incoming.rb +113 -0
- data/lib/game_machine/endpoints/udp_outgoing.rb +46 -0
- data/lib/game_machine/game_loader.rb +46 -0
- data/lib/game_machine/game_systems.rb +14 -0
- data/lib/game_machine/game_systems/agents/controller.rb +118 -0
- data/lib/game_machine/game_systems/chat.rb +256 -0
- data/lib/game_machine/game_systems/chat_manager.rb +108 -0
- data/lib/game_machine/game_systems/chat_topic.rb +36 -0
- data/lib/game_machine/game_systems/devnull.rb +13 -0
- data/lib/game_machine/game_systems/entity_loader.rb +12 -0
- data/lib/game_machine/game_systems/entity_tracking.rb +133 -0
- data/lib/game_machine/game_systems/local_echo.rb +16 -0
- data/lib/game_machine/game_systems/objectdb_proxy.rb +61 -0
- data/lib/game_machine/game_systems/private_chat.rb +20 -0
- data/lib/game_machine/game_systems/region_manager.rb +91 -0
- data/lib/game_machine/game_systems/region_service.rb +94 -0
- data/lib/game_machine/game_systems/region_settings.rb +13 -0
- data/lib/game_machine/game_systems/remote_echo.rb +14 -0
- data/lib/game_machine/game_systems/stress_test.rb +21 -0
- data/lib/game_machine/grid.rb +60 -0
- data/lib/game_machine/grid_replicator.rb +31 -0
- data/lib/game_machine/handlers/authentication.rb +55 -0
- data/lib/game_machine/handlers/game.rb +63 -0
- data/lib/game_machine/handlers/request.rb +80 -0
- data/lib/game_machine/hashring.rb +48 -0
- data/lib/game_machine/helpers/game_message.rb +159 -0
- data/lib/game_machine/helpers/state_machine.rb +29 -0
- data/lib/game_machine/java_lib.rb +51 -0
- data/lib/game_machine/logger.rb +39 -0
- data/lib/game_machine/message_buffer.rb +58 -0
- data/lib/game_machine/message_queue.rb +63 -0
- data/lib/game_machine/model.rb +125 -0
- data/lib/game_machine/models.rb +3 -0
- data/lib/game_machine/models/player_status_update.rb +8 -0
- data/lib/game_machine/models/region.rb +9 -0
- data/lib/game_machine/mono_server.rb +20 -0
- data/lib/game_machine/navigation.rb +4 -0
- data/lib/game_machine/navigation/detour.rb +20 -0
- data/lib/game_machine/navigation/detour_navmesh.rb +53 -0
- data/lib/game_machine/navigation/detour_path.rb +53 -0
- data/lib/game_machine/navigation/path.rb +31 -0
- data/lib/game_machine/object_db.rb +67 -0
- data/lib/game_machine/protobuf.rb +6 -0
- data/lib/game_machine/protobuf/game_messages.rb +24 -0
- data/lib/game_machine/protobuf/generate.rb +113 -0
- data/lib/game_machine/protobuf_extensions/entity_helper.rb +11 -0
- data/lib/game_machine/reloadable_monitor.rb +26 -0
- data/lib/game_machine/restart_watcher.rb +17 -0
- data/lib/game_machine/ruby_extensions/nilclass.rb +10 -0
- data/lib/game_machine/ruby_extensions/string.rb +17 -0
- data/lib/game_machine/scheduler.rb +23 -0
- data/lib/game_machine/securerandom.rb +6 -0
- data/lib/game_machine/settings.rb +11 -0
- data/lib/game_machine/system_monitor.rb +19 -0
- data/lib/game_machine/system_stats.rb +24 -0
- data/lib/game_machine/uniqueid.rb +23 -0
- data/lib/game_machine/vector.rb +95 -0
- data/lib/game_machine/version.rb +3 -0
- data/lib/game_machine/write_behind_cache.rb +164 -0
- data/mono/bin/csharp/common.xslt +109 -0
- data/mono/bin/csharp/csharp.xslt +628 -0
- data/mono/bin/csharp/descriptor.proto +533 -0
- data/mono/bin/csharp/protobuf-net.dll +0 -0
- data/mono/bin/csharp/protobuf-net.pdb +0 -0
- data/mono/bin/csharp/protobuf-net.xml +2879 -0
- data/mono/bin/csharp/protogen.exe.config +3 -0
- data/mono/bin/csharp/protogen.pdb +0 -0
- data/mono/bin/csharp/protogen_csharp.exe +0 -0
- data/mono/bin/csharp/vb.xslt +745 -0
- data/mono/bin/csharp/xml.xslt +26 -0
- data/mono/server/Makefile +6 -0
- data/mono/server/NLog.config +12 -0
- data/mono/server/NLog.dll +0 -0
- data/mono/server/actor.cs +37 -0
- data/mono/server/build.bat +3 -0
- data/mono/server/cscompmgd.dll +0 -0
- data/mono/server/iactor.cs +11 -0
- data/mono/server/message_router.cs +67 -0
- data/mono/server/message_util.cs +29 -0
- data/mono/server/messages.cs +1888 -0
- data/mono/server/protobuf-net.dll +0 -0
- data/mono/server/proxy_client.cs +73 -0
- data/mono/server/proxy_server.cs +30 -0
- data/mono/server/test_actor.cs +33 -0
- data/pathfinding/bin/premake4 +0 -0
- data/pathfinding/include/mesh_loader.h +28 -0
- data/pathfinding/include/pathfind.h +167 -0
- data/pathfinding/main.cpp +39 -0
- data/pathfinding/mesh_loader.cpp +108 -0
- data/pathfinding/pathfind.cpp +174 -0
- data/pathfinding/pathfinder.cs +66 -0
- data/pathfinding/premake4.lua +109 -0
- data/script/server.sh +109 -0
- data/script/watch.sh +11 -0
- data/spec/actor/actor_spec.rb +73 -0
- data/spec/actor/builder_spec.rb +56 -0
- data/spec/actor/ref_spec.rb +83 -0
- data/spec/application_spec.rb +7 -0
- data/spec/client_manager_spec.rb +171 -0
- data/spec/commands/chat_commands_spec.rb +38 -0
- data/spec/commands/datastore_commands_spec.rb +91 -0
- data/spec/commands/grid_commands_spec.rb +37 -0
- data/spec/commands/navigation_commands_spec.rb +51 -0
- data/spec/commands/player_commands_spec.rb +48 -0
- data/spec/commands_spec.rb +38 -0
- data/spec/data_stores/mapdb_spec.rb +46 -0
- data/spec/data_stores/redis_spec.rb +44 -0
- data/spec/game_systems/agents/controller_spec.rb +84 -0
- data/spec/game_systems/agents/test_agent.rb +10 -0
- data/spec/game_systems/agents/test_agent_config.rb +29 -0
- data/spec/game_systems/chat_manager_spec.rb +66 -0
- data/spec/game_systems/chat_spec.rb +187 -0
- data/spec/game_systems/entity_tracking_spec.rb +64 -0
- data/spec/game_systems/region_manager_spec.rb +138 -0
- data/spec/grid_spec.rb +37 -0
- data/spec/handlers/authentication_spec.rb +36 -0
- data/spec/handlers/game_spec.rb +49 -0
- data/spec/handlers/request_spec.rb +65 -0
- data/spec/hashring_spec.rb +59 -0
- data/spec/integration_helper.rb +120 -0
- data/spec/java_grid_spec.rb +89 -0
- data/spec/message_buffer_spec.rb +67 -0
- data/spec/message_expectations.rb +47 -0
- data/spec/message_queue_spec.rb +23 -0
- data/spec/misc_spec.rb +71 -0
- data/spec/model_spec.rb +103 -0
- data/spec/mono_spec.rb +36 -0
- data/spec/mono_test.rb +18 -0
- data/spec/navigation/detour_navmesh_spec.rb +34 -0
- data/spec/navigation/detour_path_spec.rb +25 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/udp_server_spec.rb +10 -0
- data/spec/write_behind_cache_spec.rb +109 -0
- data/web/app.rb +131 -0
- data/web/config/trinidad.yml +4 -0
- data/web/controllers/auth_controller.rb +19 -0
- data/web/controllers/base_controller.rb +16 -0
- data/web/controllers/index_controller.rb +7 -0
- data/web/controllers/log_controller.rb +47 -0
- data/web/controllers/messages_controller.rb +59 -0
- data/web/controllers/player_register_controller.rb +15 -0
- data/web/log/development.log +1339 -0
- data/web/tmp/restart.txt +0 -0
- data/web/views/game_messages.haml +45 -0
- data/web/views/index.haml +6 -0
- data/web/views/layout.haml +41 -0
- data/web/views/logs.haml +32 -0
- data/web/views/player_register.haml +22 -0
- data/web/views/player_registered.haml +2 -0
- data/web/views/register_layout.haml +22 -0
- data/web/views/restart.haml +35 -0
- metadata +576 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
module GameMachine
|
2
|
+
module Handlers
|
3
|
+
class Game < Actor::Base
|
4
|
+
include Commands
|
5
|
+
|
6
|
+
attr_reader :destinations
|
7
|
+
def post_init(*args)
|
8
|
+
@destinations = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def on_receive(message)
|
13
|
+
if message.is_a?(MessageLib::ClientMessage)
|
14
|
+
if message.get_entity_list
|
15
|
+
dispatch_entities(message.get_entity_list)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
unhandled(message)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def dispatch_entities(entities)
|
25
|
+
entities.each do |entity|
|
26
|
+
if entity.save
|
27
|
+
entity = GameSystems::ObjectDbProxy.save_entity(entity)
|
28
|
+
end
|
29
|
+
|
30
|
+
if entity.has_destination
|
31
|
+
unless actor_ref = destinations.fetch(entity.destination,nil)
|
32
|
+
destination = entity.destination.gsub('/','::')
|
33
|
+
actor_ref = Actor::Base.find(destination)
|
34
|
+
destinations[entity.destination] = actor_ref
|
35
|
+
end
|
36
|
+
entity.set_destination(nil)
|
37
|
+
actor_ref.tell(entity)
|
38
|
+
GameMachine.logger.debug("RouteToDestination: #{entity.id} #{destination}")
|
39
|
+
next
|
40
|
+
end
|
41
|
+
|
42
|
+
# TODO: Optimize this
|
43
|
+
component_names = entity.component_names
|
44
|
+
GameMachine.logger.debug("Dispatch: #{entity} #{component_names.to_a.inspect}")
|
45
|
+
next if component_names.empty?
|
46
|
+
Application.registered.each do |klass|
|
47
|
+
dispatched = false
|
48
|
+
klass.aspects.each do |aspect|
|
49
|
+
next if dispatched
|
50
|
+
if (aspect & component_names).size == aspect.size
|
51
|
+
GameMachine.logger.debug "Routing #{entity} via #{aspect} #{component_names} to #{klass}"
|
52
|
+
klass.find.tell(entity)
|
53
|
+
dispatched = true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module GameMachine
|
2
|
+
module Handlers
|
3
|
+
class Request < Actor::Base
|
4
|
+
include Commands
|
5
|
+
|
6
|
+
def post_init(*args)
|
7
|
+
@auth_handler = Authentication.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def on_receive(message)
|
11
|
+
if message.is_a?(MessageLib::ClientMessage)
|
12
|
+
if message.has_player_logout
|
13
|
+
if Authentication.authenticated?(message.player)
|
14
|
+
unregister_client(message)
|
15
|
+
commands.misc.player_status_change(message.player.id,:unregistered)
|
16
|
+
end
|
17
|
+
elsif message.has_player
|
18
|
+
update_entities(message)
|
19
|
+
if Authentication.authenticated?(message.player)
|
20
|
+
game_handler.tell(message)
|
21
|
+
else
|
22
|
+
if @auth_handler.authenticate!(message.player)
|
23
|
+
register_client(message)
|
24
|
+
commands.misc.player_status_change(message.player.id,:registered)
|
25
|
+
game_handler.tell(message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
else
|
29
|
+
unhandled(message)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
unhandled(message)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def register_client(message)
|
39
|
+
GameMachine.logger.info "Register #{message.player.id}"
|
40
|
+
player_id = message.player.id
|
41
|
+
client_id = message.client_connection.id
|
42
|
+
#GameMachine.logger.info "player_id=#{message.player.id} client_id=#{client_id}"
|
43
|
+
register = MessageLib::ClientManagerRegister.new.
|
44
|
+
set_register_type('client').set_name(client_id)
|
45
|
+
entity = MessageLib::Entity.new.set_id(client_id).
|
46
|
+
set_client_manager_register(register).set_client_connection(
|
47
|
+
message.client_connection
|
48
|
+
)
|
49
|
+
entity.set_player(message.player)
|
50
|
+
ClientManager.find.ask(entity,5000)
|
51
|
+
end
|
52
|
+
|
53
|
+
def unregister_client(message)
|
54
|
+
GameMachine.logger.info "Unregister #{message.player.id}"
|
55
|
+
player_id = message.player.id
|
56
|
+
client_id = message.client_connection.id
|
57
|
+
Authentication.unregister_player(player_id)
|
58
|
+
entity = MessageLib::Entity.new.set_id(client_id).set_client_manager_unregister(
|
59
|
+
MessageLib::ClientManagerUnregister.new.set_register_type('client').
|
60
|
+
set_name(client_id)
|
61
|
+
).set_client_connection(message.client_connection)
|
62
|
+
entity.set_player(message.player)
|
63
|
+
ClientManager.find.tell(entity)
|
64
|
+
end
|
65
|
+
|
66
|
+
def game_handler
|
67
|
+
@game_handler ||= Handlers::Game.find
|
68
|
+
end
|
69
|
+
|
70
|
+
def update_entities(message)
|
71
|
+
if message.get_entity_list
|
72
|
+
message.get_entity_list.each do |entity|
|
73
|
+
entity.set_player(message.player)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'consistent_hashing'
|
2
|
+
|
3
|
+
module GameMachine
|
4
|
+
class Hashring
|
5
|
+
|
6
|
+
RING_SIZE = 24
|
7
|
+
REPLICAS = 3
|
8
|
+
|
9
|
+
attr_reader :buckets
|
10
|
+
|
11
|
+
def self.create_actor_ring(name,ring_size=RING_SIZE)
|
12
|
+
buckets = (0..ring_size).map {|r| "#{name}#{r}"}
|
13
|
+
new(buckets)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(buckets)
|
17
|
+
@buckets = buckets
|
18
|
+
@ring = ConsistentHashing::Ring.new(@buckets,REPLICAS)
|
19
|
+
end
|
20
|
+
|
21
|
+
def points
|
22
|
+
@ring.points
|
23
|
+
end
|
24
|
+
|
25
|
+
def nodes
|
26
|
+
@ring.nodes
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_bucket(bucket)
|
30
|
+
if @buckets.include?(bucket)
|
31
|
+
@buckets.delete_if {|b| b == bucket}
|
32
|
+
@ring.delete(bucket)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_bucket(bucket)
|
37
|
+
unless @buckets.include?(bucket)
|
38
|
+
@ring << bucket
|
39
|
+
@buckets << bucket
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def bucket_for(value)
|
44
|
+
@ring.node_for(value)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
module GameMachine
|
2
|
+
module Helpers
|
3
|
+
class GameMessage
|
4
|
+
CHARS = [*('a'..'z'),*('0'..'9')].flatten
|
5
|
+
STR = Array.new(100) {|i| CHARS.sample}.join
|
6
|
+
STR2 = Array.new(1000) {|i| CHARS.sample}.join
|
7
|
+
|
8
|
+
attr_reader :player_id, :client_message
|
9
|
+
|
10
|
+
def initialize(player_id,default_entity_id=nil)
|
11
|
+
@player_id = player_id
|
12
|
+
@current_entity_id = default_entity_id || 'default'
|
13
|
+
@client_message = create_client_message(@player_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_byte_array
|
17
|
+
client_message.to_byte_array
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_to_player
|
21
|
+
client_message.send_to_player
|
22
|
+
end
|
23
|
+
|
24
|
+
def entities
|
25
|
+
client_message.get_entity_list.to_a
|
26
|
+
end
|
27
|
+
|
28
|
+
def has_entity?(id)
|
29
|
+
entities.select {|entity| entity.id == id}.first ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
def current_entity
|
33
|
+
unless has_entity?(@current_entity_id)
|
34
|
+
add_entity(@current_entity_id)
|
35
|
+
end
|
36
|
+
entities.select {|entity| entity.id == @current_entity_id}.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def entity(id)
|
40
|
+
@current_entity_id = id
|
41
|
+
current_entity
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_entity
|
45
|
+
current_entity.set_player(client_message.player)
|
46
|
+
end
|
47
|
+
|
48
|
+
def error_message(code,message)
|
49
|
+
client_message.set_error_message(
|
50
|
+
MessageLib::ErrorMessage.new.set_code(code).set_message(message)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def client_disconnect(client_id,gateway)
|
55
|
+
client_message.set_client_disconnect(
|
56
|
+
MessageLib::ClientDisconnect.new.set_client_connection(
|
57
|
+
client_connection(client_id,gateway)
|
58
|
+
)
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def player_logout
|
63
|
+
client_message.set_player_logout(
|
64
|
+
MessageLib::PlayerLogout.new.set_player_id(@player_id)
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def track_entity
|
69
|
+
current_entity.set_track_entity(
|
70
|
+
MessageLib::TrackEntity.new.set_value(true)
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_neighbors(search_radius=nil)
|
75
|
+
component = MessageLib::GetNeighbors.new
|
76
|
+
component.set_value(true)
|
77
|
+
if search_radius
|
78
|
+
component.set_search_radius(search_radius)
|
79
|
+
end
|
80
|
+
current_entity.set_get_neighbors(component)
|
81
|
+
end
|
82
|
+
|
83
|
+
def neighbors(players,npcs)
|
84
|
+
current_entity.set_neighbors(
|
85
|
+
MessageLib::Neighbors.new.set_player_list(players).set_npc_list(npcs)
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def player_move(x,y)
|
90
|
+
current_entity.set_player_move(
|
91
|
+
MessageLib::PlayerMove.new.set_target(
|
92
|
+
MessageLib::Target.new.set_x(x).set_y(y)
|
93
|
+
)
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
def client_connection(client_id,gateway)
|
98
|
+
MessageLib::ClientConnection.new.set_id(client_id).set_gateway(gateway)
|
99
|
+
end
|
100
|
+
|
101
|
+
def chat_channels(names)
|
102
|
+
channels = MessageLib::ChatChannels.new
|
103
|
+
names.each do |name|
|
104
|
+
channels.add_chat_channel(chat_channel(name))
|
105
|
+
end
|
106
|
+
current_entity.set_chat_channels(channels)
|
107
|
+
end
|
108
|
+
|
109
|
+
def chat_channel(topic,flags='')
|
110
|
+
MessageLib::ChatChannel.new.set_name(topic).set_flags(flags)
|
111
|
+
end
|
112
|
+
|
113
|
+
def chat_message(type,message_text,topic)
|
114
|
+
message = MessageLib::ChatMessage.new
|
115
|
+
message.set_chat_channel(
|
116
|
+
chat_channel(topic)
|
117
|
+
)
|
118
|
+
message.set_message(message_text)
|
119
|
+
message.set_type(type)
|
120
|
+
current_entity.set_chat_message(message)
|
121
|
+
end
|
122
|
+
|
123
|
+
def join_chat(topic,flags='')
|
124
|
+
current_entity.set_join_chat(
|
125
|
+
MessageLib::JoinChat.new.add_chat_channel(chat_channel(topic,flags))
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
def leave_chat(topic)
|
130
|
+
current_entity.set_leave_chat(
|
131
|
+
MessageLib::LeaveChat.new.add_chat_channel(chat_channel(topic))
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
def echo_test(value)
|
136
|
+
current_entity.set_echo_test(MessageLib::EchoTest.new.set_message(value))
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def create_client_message(player_id)
|
142
|
+
client_message = MessageLib::ClientMessage.new
|
143
|
+
client_message.set_player(player(player_id))
|
144
|
+
end
|
145
|
+
|
146
|
+
def add_entity(id)
|
147
|
+
client_message.add_entity(MessageLib::Entity.new.set_id(id))
|
148
|
+
end
|
149
|
+
|
150
|
+
def player(player_id)
|
151
|
+
player = MessageLib::Player.new.
|
152
|
+
set_id(player_id).
|
153
|
+
set_name(player_id).
|
154
|
+
set_authtoken('authorized')
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module GameMachine
|
2
|
+
module Helpers
|
3
|
+
module StateMachine
|
4
|
+
|
5
|
+
def load_state(id, &block)
|
6
|
+
@actor_states[id] ||= @initial_state
|
7
|
+
self.state = @actor_states[id]
|
8
|
+
if block_given?
|
9
|
+
yield
|
10
|
+
save_state(id)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def save_state(id)
|
15
|
+
@actor_states[id] = self.state
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy_state(id)
|
19
|
+
@actor_states.delete(id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize_states
|
23
|
+
@actor_states = {}
|
24
|
+
initialize_state_machines
|
25
|
+
@initial_state = self.state.dup
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module GameMachine
|
2
|
+
|
3
|
+
module MessageLib
|
4
|
+
include_package 'GameMachine.Messages'
|
5
|
+
end
|
6
|
+
|
7
|
+
module RedisLib
|
8
|
+
include_package 'redis.clients.jedis'
|
9
|
+
include_package 'redis.clients.jedis.exceptions'
|
10
|
+
include_package 'redis.clients.util'
|
11
|
+
end
|
12
|
+
|
13
|
+
module ZeromqLib
|
14
|
+
include_package 'akka.zeromq'
|
15
|
+
end
|
16
|
+
|
17
|
+
module ProtoLib
|
18
|
+
include_package 'com.dyuproject.protostuff'
|
19
|
+
end
|
20
|
+
|
21
|
+
module JavaLib
|
22
|
+
java_import 'akka.cluster.ClusterEvent'
|
23
|
+
java_import 'akka.contrib.pattern.ClusterSingletonManager'
|
24
|
+
java_import 'akka.contrib.pattern.ClusterSingletonProxy'
|
25
|
+
include_package 'akka.serialization'
|
26
|
+
include_package 'com.typesafe.config'
|
27
|
+
include_package 'akka.actor'
|
28
|
+
include_package 'akka.io'
|
29
|
+
include_package 'akka.util'
|
30
|
+
include_package 'akka.pattern'
|
31
|
+
include_package 'akka.testkit'
|
32
|
+
include_package 'akka.cluster'
|
33
|
+
include_package 'akka.routing'
|
34
|
+
include_package 'akka.serialization'
|
35
|
+
include_package 'akka.contrib.pattern'
|
36
|
+
include_package 'akka.event'
|
37
|
+
include_package 'akka.camel.javaapi'
|
38
|
+
include_package 'akka.camel'
|
39
|
+
java_import 'com.game_machine.core.Grid'
|
40
|
+
include_package 'com.game_machine.core'
|
41
|
+
include_package 'java.net'
|
42
|
+
include_package 'java.util.concurrent.atomic'
|
43
|
+
include_package 'scala.concurrent.duration'
|
44
|
+
include_package 'scala.concurrent'
|
45
|
+
include_package 'java.io.Serializable'
|
46
|
+
include_package 'java.util'
|
47
|
+
include_package 'java.io'
|
48
|
+
include_package 'com.couchbase.client'
|
49
|
+
include_package 'io.netty.channel'
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rjack-logback'
|
2
|
+
|
3
|
+
module GameMachine
|
4
|
+
module Logger
|
5
|
+
|
6
|
+
LOGGER = RJack::SLF4J[ 'game_machine' ]
|
7
|
+
|
8
|
+
def stdout(message)
|
9
|
+
unless ENV['GAME_ENV'] == 'test'
|
10
|
+
print "#{message}\n"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def logfile
|
15
|
+
File.join(ENV['APP_ROOT'], 'log',"#{ENV['GAME_ENV']}.log")
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure_logging
|
19
|
+
RJack::Logback.configure do
|
20
|
+
console = RJack::Logback::ConsoleAppender.new do |a|
|
21
|
+
end
|
22
|
+
|
23
|
+
file = RJack::Logback::FileAppender.new(logfile) do |a|
|
24
|
+
end
|
25
|
+
|
26
|
+
RJack::Logback.root.add_appender( file )
|
27
|
+
RJack::Logback.root.level = RJack::Logback::INFO
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def logger
|
32
|
+
LOGGER
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
GameMachine.send(:extend, GameMachine::Logger)
|
39
|
+
GameMachine.configure_logging
|