game_machine 0.0.10 → 0.0.11
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -9
- data/config/config.example.yml +8 -1
- data/config/game_messages.proto +1 -0
- data/config/messages.proto +4 -0
- data/games/example/lib/npc.rb +8 -7
- data/games/models.rb +3 -0
- data/games/models/clan_member.rb +8 -0
- data/games/models/clan_profile.rb +9 -0
- data/games/models/player.rb +7 -0
- data/games/plugins.rb +1 -0
- data/games/plugins/team_handler.rb +49 -0
- data/games/preload.rb +5 -0
- data/java/build.gradle +3 -1
- data/java/gradle.properties +1 -1
- data/lib/game_machine/actor/base.rb +5 -1
- data/lib/game_machine/application.rb +13 -3
- data/lib/game_machine/commands/datastore_commands.rb +3 -7
- data/lib/game_machine/commands/player_commands.rb +3 -0
- data/lib/game_machine/data_store.rb +22 -1
- data/lib/game_machine/data_stores/couchbase.rb +18 -1
- data/lib/game_machine/endpoints/udp_incoming.rb +0 -1
- data/lib/game_machine/game_systems.rb +2 -0
- data/lib/game_machine/game_systems/chat.rb +33 -13
- data/lib/game_machine/game_systems/chat_manager.rb +24 -3
- data/lib/game_machine/game_systems/json_model_persistence.rb +23 -0
- data/lib/game_machine/game_systems/region_manager.rb +1 -1
- data/lib/game_machine/game_systems/team_manager.rb +421 -0
- data/lib/game_machine/handlers/request.rb +4 -0
- data/lib/game_machine/model.rb +59 -13
- data/lib/game_machine/models.rb +17 -0
- data/lib/game_machine/models/create_team.rb +9 -0
- data/lib/game_machine/models/destroy_team.rb +8 -0
- data/lib/game_machine/models/echo_test.rb +6 -0
- data/lib/game_machine/models/end_match.rb +7 -0
- data/lib/game_machine/models/find_match.rb +7 -0
- data/lib/game_machine/models/join_team.rb +7 -0
- data/lib/game_machine/models/leave_team.rb +7 -0
- data/lib/game_machine/models/match.rb +9 -0
- data/lib/game_machine/models/player_team.rb +9 -0
- data/lib/game_machine/models/start_match.rb +8 -0
- data/lib/game_machine/models/team.rb +11 -0
- data/lib/game_machine/models/team_accept_invite.rb +9 -0
- data/lib/game_machine/models/team_invite.rb +8 -0
- data/lib/game_machine/models/team_joined.rb +7 -0
- data/lib/game_machine/models/team_left.rb +7 -0
- data/lib/game_machine/models/teams.rb +7 -0
- data/lib/game_machine/models/teams_request.rb +6 -0
- data/lib/game_machine/object_db.rb +17 -11
- data/lib/game_machine/version.rb +1 -1
- data/lib/game_machine/write_behind_cache.rb +1 -1
- data/spec/actor/actor_spec.rb +5 -5
- data/spec/actor/ref_spec.rb +10 -10
- data/spec/client_manager_spec.rb +9 -9
- data/spec/commands/chat_commands_spec.rb +1 -1
- data/spec/commands/datastore_commands_spec.rb +10 -14
- data/spec/commands/navigation_commands_spec.rb +3 -3
- data/spec/commands/player_commands_spec.rb +1 -1
- data/spec/game_systems/agents/controller_spec.rb +6 -6
- data/spec/game_systems/chat_manager_spec.rb +1 -1
- data/spec/game_systems/chat_spec.rb +15 -17
- data/spec/game_systems/region_manager_spec.rb +31 -21
- data/spec/game_systems/team_manager_spec.rb +291 -0
- data/spec/grid_spec.rb +11 -1
- data/spec/handlers/authentication_spec.rb +1 -10
- data/spec/handlers/game_spec.rb +2 -2
- data/spec/handlers/request_spec.rb +10 -21
- data/spec/hashring_spec.rb +11 -11
- data/spec/java_grid_spec.rb +1 -1
- data/spec/misc_spec.rb +2 -2
- data/spec/model_spec.rb +26 -14
- data/spec/write_behind_cache_spec.rb +15 -15
- metadata +29 -8
- data/lib/game_machine/bot/chat.rb +0 -66
- data/lib/game_machine/bot/client.rb +0 -54
- data/spec/data_stores/mapdb_spec.rb +0 -46
- data/spec/data_stores/redis_spec.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffff1acfb6c6991f5ec1bf5c1c6e4ad06ef0b588
|
4
|
+
data.tar.gz: 32e1d7c2016cd8fe2f1b348b1ef9a01595da26d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2fa98eec04da15ebd1c057675ca5032878d4959b6eef3b2d1f9dc60fc70d5e05df3b185805c695931d63ea963e982197c8a41983350f457344d18b699d4e5f2
|
7
|
+
data.tar.gz: ced35f7f4bc12fae21af3e2ef05dcca6d20692a44ae51133341a5196eb04fd6874e05d523659593df3480ea94e401ecbd9d2d1f56c94a504f5e0df79ba7afc61
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
game_machine (0.0.
|
4
|
+
game_machine (0.0.10)
|
5
5
|
consistent-hashing
|
6
6
|
ffi
|
7
7
|
haml
|
@@ -37,14 +37,18 @@ GEM
|
|
37
37
|
rjack-logback (1.7.0-java)
|
38
38
|
rjack-slf4j (>= 1.6.5, < 1.8)
|
39
39
|
rjack-slf4j (1.7.6.0-java)
|
40
|
-
rspec (
|
41
|
-
rspec-core (~>
|
42
|
-
rspec-expectations (~>
|
43
|
-
rspec-mocks (~>
|
44
|
-
rspec-core (
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
rspec (3.0.0)
|
41
|
+
rspec-core (~> 3.0.0)
|
42
|
+
rspec-expectations (~> 3.0.0)
|
43
|
+
rspec-mocks (~> 3.0.0)
|
44
|
+
rspec-core (3.0.2)
|
45
|
+
rspec-support (~> 3.0.0)
|
46
|
+
rspec-expectations (3.0.2)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.0.0)
|
49
|
+
rspec-mocks (3.0.2)
|
50
|
+
rspec-support (~> 3.0.0)
|
51
|
+
rspec-support (3.0.2)
|
48
52
|
settingslogic (2.0.9)
|
49
53
|
sinatra (1.4.5)
|
50
54
|
rack (~> 1.4)
|
data/config/config.example.yml
CHANGED
@@ -3,6 +3,9 @@ development:
|
|
3
3
|
servers:
|
4
4
|
default:
|
5
5
|
environment: development
|
6
|
+
# Handles requests for matchmaking and custom filtering for teams.
|
7
|
+
# If no team handler is defined defaults are used
|
8
|
+
team_handler: Plugins::TeamHandler
|
6
9
|
# Authorization handler. Public allows any authtoken to be used and
|
7
10
|
# does not check username/password
|
8
11
|
auth_handler: Example::AuthenticationHandler
|
@@ -35,9 +38,10 @@ development:
|
|
35
38
|
aoe: 4000, 5, 1
|
36
39
|
local_chat: 4000, 10, 10
|
37
40
|
# Couchbase config
|
41
|
+
couchbase_bucket: default
|
42
|
+
couchbase_password:
|
38
43
|
couchbase_servers:
|
39
44
|
- http://127.0.0.1:8091/pools
|
40
|
-
#auth_handler: Example::AuthenticationHandler
|
41
45
|
http_enabled: true
|
42
46
|
http_host: 0.0.0.0
|
43
47
|
http_port: 3000
|
@@ -58,6 +62,7 @@ development:
|
|
58
62
|
mono_gateway_port: 8800
|
59
63
|
seed01:
|
60
64
|
environment: development
|
65
|
+
team_handler: Plugins::TeamHandler
|
61
66
|
auth_handler: Example::AuthenticationHandler
|
62
67
|
player_register_handler: Example::PlayerRegister
|
63
68
|
player_manager: Example::PlayerManager
|
@@ -73,6 +78,8 @@ development:
|
|
73
78
|
default: 4000, 50, 1
|
74
79
|
aoe: 4000, 5, 1
|
75
80
|
local_chat: 4000, 10, 10
|
81
|
+
couchbase_bucket: default
|
82
|
+
couchbase_password:
|
76
83
|
couchbase_servers:
|
77
84
|
- http://127.0.0.1:8091/pools
|
78
85
|
http_enabled: false
|
data/config/game_messages.proto
CHANGED
data/config/messages.proto
CHANGED
data/games/example/lib/npc.rb
CHANGED
@@ -69,14 +69,9 @@ module Example
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def get_players
|
72
|
+
@players = {}
|
72
73
|
commands.grid.neighbors(position.x,position.y).each do |player|
|
73
|
-
|
74
|
-
@players[player.id][:vector].x = player.x
|
75
|
-
@players[player.id][:vector].y = player.y
|
76
|
-
@players[player.id][:vector].z = player.z
|
77
|
-
else
|
78
|
-
@players[player.id] = {:id => player.id, :vector => GameMachine::Vector.from(player)}
|
79
|
-
end
|
74
|
+
@players[player.id] = {:id => player.id, :vector => GameMachine::Vector.from(player)}
|
80
75
|
end
|
81
76
|
end
|
82
77
|
|
@@ -91,6 +86,12 @@ module Example
|
|
91
86
|
def pick_random_target
|
92
87
|
@target.x = position.x + rand(-30..30)
|
93
88
|
@target.y = position.y + rand(-30..30)
|
89
|
+
if @target.x < 2 || @target.x > 2045
|
90
|
+
@target.x = rand(5..2045)
|
91
|
+
end
|
92
|
+
if @target.y < 2 || @target.y > 2045
|
93
|
+
@target.x = rand(5..2045)
|
94
|
+
end
|
94
95
|
movement.set_target(@target)
|
95
96
|
end
|
96
97
|
|
data/games/models.rb
ADDED
data/games/plugins.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'plugins/team_handler'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
module Plugins
|
3
|
+
class TeamHandler
|
4
|
+
|
5
|
+
attr_reader :teams
|
6
|
+
def initialize
|
7
|
+
update_teams
|
8
|
+
end
|
9
|
+
|
10
|
+
def update_teams
|
11
|
+
@teams = GameMachine::Models::Teams.find('teams')
|
12
|
+
end
|
13
|
+
|
14
|
+
# Should return a Match object if a match is found, otherwise nil
|
15
|
+
def match!(team_name)
|
16
|
+
GameMachine.logger.info "match! team_name:#{team_name} teams:#{teams}"
|
17
|
+
if team = teams.teams.select {|team| team.name != team_name}.first
|
18
|
+
return GameMachine::Models::StartMatch.new(:team_names => [team_name,team.name])
|
19
|
+
end
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
# Called when Game Machine has started the match
|
24
|
+
def match_started(match)
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
# Filter you can apply to the teams list sent to clients
|
29
|
+
# You can add whatever extra fields you want to the TeamsRequest
|
30
|
+
# class on the client and they will show up here.
|
31
|
+
def teams_filter(teams,teams_request)
|
32
|
+
teams
|
33
|
+
end
|
34
|
+
|
35
|
+
# return true if member has rights to create team
|
36
|
+
def can_create_team?(team_name,member)
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
# return true if member has rights to join team
|
41
|
+
def can_add_member?(team_name,member)
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy_on_owner_leave?
|
46
|
+
true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/games/preload.rb
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
# is the place to do it. Examples might be specific handlers, or loading up
|
4
4
|
# static data that needs to be there before the rest of the system starts up.
|
5
5
|
|
6
|
+
# json models that are global accross all games/plugins
|
7
|
+
require_relative 'models'
|
8
|
+
|
9
|
+
# Plugins that extend or work with core Game Machine features
|
10
|
+
require_relative 'plugins'
|
6
11
|
|
7
12
|
# This needs to be loaded before the entity tracking system starts
|
8
13
|
require_relative 'example/lib/tracking_handler'
|
data/java/build.gradle
CHANGED
@@ -45,7 +45,9 @@ dependencies {
|
|
45
45
|
compile group: 'org.javassist', name: 'javassist', version:'3.17.1-GA'
|
46
46
|
//compile(group: 'io.netty', name: 'netty-all', version:'4.0.11.Final')
|
47
47
|
//compile 'org.apache.camel:camel-jetty:2.10.3'
|
48
|
-
compile(group: 'couchbase', name: 'couchbase-client', version:'1.
|
48
|
+
//compile(group: 'couchbase', name: 'couchbase-client', version:'1.4.2')
|
49
|
+
//compile 'com.basho.riak:riak-client:1.4.4'
|
50
|
+
compile 'com.couchbase.client:couchbase-client:1.4.2'
|
49
51
|
compile 'redis.clients:jedis:2.2.1'
|
50
52
|
compile 'org.mapdb:mapdb:1.0.3'
|
51
53
|
compile 'io.netty:netty-testsuite:4.0.20.Final'
|
data/java/gradle.properties
CHANGED
@@ -113,7 +113,11 @@ module GameMachine
|
|
113
113
|
if message.send_to_player
|
114
114
|
message
|
115
115
|
else
|
116
|
-
|
116
|
+
model = Model.from_entity(message)
|
117
|
+
if message.has_player
|
118
|
+
model.player_id = message.player.id
|
119
|
+
end
|
120
|
+
return model
|
117
121
|
end
|
118
122
|
end
|
119
123
|
message
|
@@ -49,8 +49,12 @@ module GameMachine
|
|
49
49
|
|
50
50
|
def start
|
51
51
|
create_grids
|
52
|
-
|
53
|
-
GameMachine
|
52
|
+
|
53
|
+
unless GameMachine.env == 'test'
|
54
|
+
game_preload
|
55
|
+
GameMachine::Actor::Reloadable.update_paths(true)
|
56
|
+
end
|
57
|
+
|
54
58
|
start_actor_system
|
55
59
|
data_store
|
56
60
|
start_endpoints
|
@@ -62,7 +66,11 @@ module GameMachine
|
|
62
66
|
end
|
63
67
|
|
64
68
|
start_game_systems
|
65
|
-
|
69
|
+
|
70
|
+
unless GameMachine.env == 'test'
|
71
|
+
GameLoader.new.load_all
|
72
|
+
end
|
73
|
+
|
66
74
|
auth_handler
|
67
75
|
start_mono
|
68
76
|
|
@@ -174,6 +182,8 @@ module GameMachine
|
|
174
182
|
Actor::Builder.new(GameSystems::RemoteEcho).with_router(JavaLib::RoundRobinRouter,10).start
|
175
183
|
Actor::Builder.new(GameSystems::StressTest).with_router(JavaLib::RoundRobinRouter,10).start
|
176
184
|
Actor::Builder.new(GameSystems::ChatManager).start
|
185
|
+
Actor::Builder.new(GameSystems::TeamManager).start
|
186
|
+
Actor::Builder.new(GameSystems::JsonModelPersistence).start
|
177
187
|
end
|
178
188
|
|
179
189
|
end
|
@@ -25,18 +25,14 @@ module GameMachine
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def put!(entity)
|
28
|
-
store.set(entity.id,entity
|
28
|
+
store.set(entity.id,entity)
|
29
29
|
end
|
30
30
|
|
31
31
|
def get!(entity_id)
|
32
|
-
|
33
|
-
MessageLib::Entity.parse_from(bytes)
|
34
|
-
else
|
35
|
-
nil
|
36
|
-
end
|
32
|
+
store.get(entity_id)
|
37
33
|
end
|
38
34
|
|
39
|
-
def
|
35
|
+
def delete!(entity_id)
|
40
36
|
store.delete(entity_id)
|
41
37
|
end
|
42
38
|
|
@@ -9,7 +9,7 @@ module GameMachine
|
|
9
9
|
include Singleton
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
-
def_delegators :@store, :
|
12
|
+
def_delegators :@store, :delete, :delete_all, :shutdown, :keys, :dump, :load
|
13
13
|
|
14
14
|
attr_reader :store
|
15
15
|
def initialize
|
@@ -23,6 +23,27 @@ module GameMachine
|
|
23
23
|
connect
|
24
24
|
end
|
25
25
|
|
26
|
+
|
27
|
+
def get(key)
|
28
|
+
value = @store.get(key)
|
29
|
+
return nil if value.nil?
|
30
|
+
if value.is_a?(String)
|
31
|
+
MessageLib::Entity.new.set_id(key).set_json_storage(
|
32
|
+
MessageLib::JsonStorage.new.set_json(value)
|
33
|
+
)
|
34
|
+
else
|
35
|
+
MessageLib::Entity.parse_from(value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def set(key,value)
|
40
|
+
if value.has_json_storage
|
41
|
+
@store.set(key,value.json_storage.json)
|
42
|
+
else
|
43
|
+
@store.set(key,value.to_byte_array)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
26
47
|
private
|
27
48
|
|
28
49
|
def connect
|
@@ -7,7 +7,24 @@ module GameMachine
|
|
7
7
|
def_delegators :@client, :get, :set, :delete, :shutdown
|
8
8
|
|
9
9
|
def connect
|
10
|
-
@client ||= JavaLib::CouchbaseClient.new(
|
10
|
+
@client ||= JavaLib::CouchbaseClient.new(builder)
|
11
|
+
end
|
12
|
+
|
13
|
+
def bucket
|
14
|
+
Application.config.couchbase_bucket || 'default'
|
15
|
+
end
|
16
|
+
|
17
|
+
def password
|
18
|
+
Application.config.couchbase_password || ''
|
19
|
+
end
|
20
|
+
|
21
|
+
def builder
|
22
|
+
@builder ||= JavaLib::CouchbaseConnectionFactoryBuilder.new.
|
23
|
+
buildCouchbaseConnection(
|
24
|
+
servers,
|
25
|
+
bucket.to_java_string,
|
26
|
+
password.to_java_string
|
27
|
+
)
|
11
28
|
end
|
12
29
|
|
13
30
|
def servers
|
@@ -60,7 +60,6 @@ module GameMachine
|
|
60
60
|
:ctx => message.ctx,
|
61
61
|
:client_connection => client_connection
|
62
62
|
}
|
63
|
-
GameMachine.logger.info "#{client.inspect}"
|
64
63
|
self.class.clients[client_message.player.id] = client
|
65
64
|
create_child(client_connection,client,@server,client_message.player.id)
|
66
65
|
end
|
@@ -12,3 +12,5 @@ require_relative 'game_systems/objectdb_proxy'
|
|
12
12
|
require_relative 'game_systems/agents/controller'
|
13
13
|
require_relative 'game_systems/region_manager'
|
14
14
|
require_relative 'game_systems/region_service'
|
15
|
+
require_relative 'game_systems/team_manager'
|
16
|
+
require_relative 'game_systems/json_model_persistence'
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'digest'
|
1
2
|
module GameMachine
|
2
3
|
module GameSystems
|
3
4
|
class Chat < Actor::Base
|
@@ -35,6 +36,11 @@ module GameMachine
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def on_receive(entity)
|
39
|
+
if entity.is_a?(MessageLib::ChatDestroy)
|
40
|
+
leave_all_channels
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
38
44
|
if entity.has_join_chat
|
39
45
|
join_channels(entity.join_chat.get_chat_channel_list)
|
40
46
|
send_status
|
@@ -73,6 +79,15 @@ module GameMachine
|
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
82
|
+
def leave_all_channels
|
83
|
+
channels = MessageLib::ChatChannels.new
|
84
|
+
@subscriptions.each do |name|
|
85
|
+
channel = MessageLib::ChatChannel.new.set_name(name)
|
86
|
+
leave_channel(channel)
|
87
|
+
end
|
88
|
+
get_sender.tell('complete',get_self)
|
89
|
+
end
|
90
|
+
|
76
91
|
def message_queue
|
77
92
|
MessageQueue.find
|
78
93
|
end
|
@@ -84,7 +99,8 @@ module GameMachine
|
|
84
99
|
def create_topic_handler(topic)
|
85
100
|
name = "topic#{chat_id}#{topic}"
|
86
101
|
builder = Actor::Builder.new(GameSystems::ChatTopic,chat_id,registered_as)
|
87
|
-
|
102
|
+
actor_name = Digest::MD5.hexdigest(name)
|
103
|
+
ref = builder.with_parent(context).with_name(actor_name).start
|
88
104
|
actor_ref = Actor::Ref.new(ref,GameSystems::ChatTopic.name)
|
89
105
|
@topic_handlers[topic] = actor_ref
|
90
106
|
end
|
@@ -205,18 +221,22 @@ module GameMachine
|
|
205
221
|
|
206
222
|
def leave_channels(chat_channels)
|
207
223
|
chat_channels.each do |channel|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
224
|
+
leave_channel(channel)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def leave_channel(channel)
|
229
|
+
if topic_handler = topic_handler_for(channel.name)
|
230
|
+
message = MessageLib::Unsubscribe.new.set_topic(channel.name)
|
231
|
+
message_queue.tell(message,topic_handler_for(channel.name).actor)
|
232
|
+
@subscriptions.delete_if {|sub| sub == channel.name}
|
233
|
+
save_subscriptions
|
234
|
+
remove_subscriber(chat_id,channel.name)
|
235
|
+
topic_handler.tell(JavaLib::PoisonPill.get_instance)
|
236
|
+
@topic_handlers.delete(channel.name)
|
237
|
+
delete_channel_flags(channel.name)
|
238
|
+
else
|
239
|
+
GameMachine.logger.info "leave_channel: no topic handler found for #{channel.name}"
|
220
240
|
end
|
221
241
|
end
|
222
242
|
|