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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +13 -9
  3. data/config/config.example.yml +8 -1
  4. data/config/game_messages.proto +1 -0
  5. data/config/messages.proto +4 -0
  6. data/games/example/lib/npc.rb +8 -7
  7. data/games/models.rb +3 -0
  8. data/games/models/clan_member.rb +8 -0
  9. data/games/models/clan_profile.rb +9 -0
  10. data/games/models/player.rb +7 -0
  11. data/games/plugins.rb +1 -0
  12. data/games/plugins/team_handler.rb +49 -0
  13. data/games/preload.rb +5 -0
  14. data/java/build.gradle +3 -1
  15. data/java/gradle.properties +1 -1
  16. data/lib/game_machine/actor/base.rb +5 -1
  17. data/lib/game_machine/application.rb +13 -3
  18. data/lib/game_machine/commands/datastore_commands.rb +3 -7
  19. data/lib/game_machine/commands/player_commands.rb +3 -0
  20. data/lib/game_machine/data_store.rb +22 -1
  21. data/lib/game_machine/data_stores/couchbase.rb +18 -1
  22. data/lib/game_machine/endpoints/udp_incoming.rb +0 -1
  23. data/lib/game_machine/game_systems.rb +2 -0
  24. data/lib/game_machine/game_systems/chat.rb +33 -13
  25. data/lib/game_machine/game_systems/chat_manager.rb +24 -3
  26. data/lib/game_machine/game_systems/json_model_persistence.rb +23 -0
  27. data/lib/game_machine/game_systems/region_manager.rb +1 -1
  28. data/lib/game_machine/game_systems/team_manager.rb +421 -0
  29. data/lib/game_machine/handlers/request.rb +4 -0
  30. data/lib/game_machine/model.rb +59 -13
  31. data/lib/game_machine/models.rb +17 -0
  32. data/lib/game_machine/models/create_team.rb +9 -0
  33. data/lib/game_machine/models/destroy_team.rb +8 -0
  34. data/lib/game_machine/models/echo_test.rb +6 -0
  35. data/lib/game_machine/models/end_match.rb +7 -0
  36. data/lib/game_machine/models/find_match.rb +7 -0
  37. data/lib/game_machine/models/join_team.rb +7 -0
  38. data/lib/game_machine/models/leave_team.rb +7 -0
  39. data/lib/game_machine/models/match.rb +9 -0
  40. data/lib/game_machine/models/player_team.rb +9 -0
  41. data/lib/game_machine/models/start_match.rb +8 -0
  42. data/lib/game_machine/models/team.rb +11 -0
  43. data/lib/game_machine/models/team_accept_invite.rb +9 -0
  44. data/lib/game_machine/models/team_invite.rb +8 -0
  45. data/lib/game_machine/models/team_joined.rb +7 -0
  46. data/lib/game_machine/models/team_left.rb +7 -0
  47. data/lib/game_machine/models/teams.rb +7 -0
  48. data/lib/game_machine/models/teams_request.rb +6 -0
  49. data/lib/game_machine/object_db.rb +17 -11
  50. data/lib/game_machine/version.rb +1 -1
  51. data/lib/game_machine/write_behind_cache.rb +1 -1
  52. data/spec/actor/actor_spec.rb +5 -5
  53. data/spec/actor/ref_spec.rb +10 -10
  54. data/spec/client_manager_spec.rb +9 -9
  55. data/spec/commands/chat_commands_spec.rb +1 -1
  56. data/spec/commands/datastore_commands_spec.rb +10 -14
  57. data/spec/commands/navigation_commands_spec.rb +3 -3
  58. data/spec/commands/player_commands_spec.rb +1 -1
  59. data/spec/game_systems/agents/controller_spec.rb +6 -6
  60. data/spec/game_systems/chat_manager_spec.rb +1 -1
  61. data/spec/game_systems/chat_spec.rb +15 -17
  62. data/spec/game_systems/region_manager_spec.rb +31 -21
  63. data/spec/game_systems/team_manager_spec.rb +291 -0
  64. data/spec/grid_spec.rb +11 -1
  65. data/spec/handlers/authentication_spec.rb +1 -10
  66. data/spec/handlers/game_spec.rb +2 -2
  67. data/spec/handlers/request_spec.rb +10 -21
  68. data/spec/hashring_spec.rb +11 -11
  69. data/spec/java_grid_spec.rb +1 -1
  70. data/spec/misc_spec.rb +2 -2
  71. data/spec/model_spec.rb +26 -14
  72. data/spec/write_behind_cache_spec.rb +15 -15
  73. metadata +29 -8
  74. data/lib/game_machine/bot/chat.rb +0 -66
  75. data/lib/game_machine/bot/client.rb +0 -54
  76. data/spec/data_stores/mapdb_spec.rb +0 -46
  77. data/spec/data_stores/redis_spec.rb +0 -44
@@ -61,6 +61,10 @@ module GameMachine
61
61
  ).set_client_connection(message.client_connection)
62
62
  entity.set_player(message.player)
63
63
  ClientManager.find.tell(entity)
64
+
65
+ ## Just for now, need to do this correctly by registering with the client manager
66
+ chat_destroy = MessageLib::ChatDestroy.new.set_player_id(message.player.id)
67
+ GameSystems::ChatManager.find.tell(chat_destroy)
64
68
  end
65
69
 
66
70
  def game_handler
@@ -18,6 +18,14 @@ module GameMachine
18
18
 
19
19
  end
20
20
 
21
+ def delete(id)
22
+ commands.datastore.delete(id)
23
+ end
24
+
25
+ def delete!(id)
26
+ commands.datastore.delete!(id)
27
+ end
28
+
21
29
  def find!(id)
22
30
  scoped_id = scope_for(id)
23
31
  if entity = Commands::Base.commands.datastore.get!(scoped_id)
@@ -44,14 +52,7 @@ module GameMachine
44
52
  json = entity.json_entity.json
45
53
  end
46
54
 
47
- attributes = JSON.parse(json)
48
- if klass = attributes.delete('klass')
49
- model = klass.constantize.new(attributes)
50
- model.id = model.unscoped_id
51
- model
52
- else
53
- raise "Unable to find klass attribute in #{attributes.inspect}"
54
- end
55
+ self.from_hash(JSON.parse(json))
55
56
  end
56
57
 
57
58
  def scope_for(id)
@@ -69,6 +70,48 @@ module GameMachine
69
70
  def id_scope
70
71
  @id_scope
71
72
  end
73
+
74
+ def from_hash(attributes)
75
+ if klass = attributes.delete('klass')
76
+ attributes = attributes.each_with_object({}) do |(k, v), h|
77
+ if v.kind_of?(Hash)
78
+ h[k] = from_hash(v)
79
+ elsif v.kind_of?(Array)
80
+ h[k] = v.collect do |e|
81
+ e.kind_of?(Hash) ? from_hash(e) : e
82
+ end
83
+ else
84
+ h[k] = v
85
+ end
86
+ end
87
+ model = klass.constantize.new(attributes)
88
+ model.id = model.unscoped_id
89
+ model
90
+ else
91
+ OpenStruct.new(attributes)
92
+ end
93
+ end
94
+ end
95
+
96
+
97
+ def as_json
98
+ attributes['id'] = scoped_id
99
+ attributes.merge!(:klass => self.class.name)
100
+ attributes.each_with_object({}) do |(k, v), h|
101
+ if v.kind_of?(OpenStruct)
102
+ h[k] = v.as_json
103
+ elsif v.is_a?(Array)
104
+ h[k] = v.collect do |e|
105
+ e.kind_of?(OpenStruct) ? e.as_json : e
106
+ end
107
+ else
108
+ h[k] = v
109
+ end
110
+ end
111
+ end
112
+
113
+ def to_json
114
+ JSON.generate(as_json)
72
115
  end
73
116
 
74
117
  def attributes
@@ -91,11 +134,6 @@ module GameMachine
91
134
  end
92
135
  end
93
136
 
94
- def to_json
95
- attributes['id'] = scoped_id
96
- JSON.dump(attributes.merge(:klass => self.class.name))
97
- end
98
-
99
137
  def to_entity
100
138
  MessageLib::Entity.new.set_id(scoped_id).set_json_entity(to_json_entity)
101
139
  end
@@ -120,6 +158,14 @@ module GameMachine
120
158
  commands.datastore.put!(to_storage_entity)
121
159
  end
122
160
 
161
+ def destroy
162
+ commands.datastore.delete(scoped_id)
163
+ end
164
+
165
+ def destroy!
166
+ commands.datastore.delete!(scoped_id)
167
+ end
168
+
123
169
  end
124
170
  end
125
171
 
@@ -1,3 +1,20 @@
1
1
 
2
2
  require_relative 'models/region'
3
3
  require_relative 'models/player_status_update'
4
+ require_relative 'models/create_team'
5
+ require_relative 'models/destroy_team'
6
+ require_relative 'models/join_team'
7
+ require_relative 'models/team_accept_invite'
8
+ require_relative 'models/team_invite'
9
+ require_relative 'models/teams'
10
+ require_relative 'models/team'
11
+ require_relative 'models/teams_request'
12
+ require_relative 'models/team_joined'
13
+ require_relative 'models/leave_team'
14
+ require_relative 'models/player_team'
15
+ require_relative 'models/team_left'
16
+ require_relative 'models/echo_test'
17
+ require_relative 'models/find_match'
18
+ require_relative 'models/match'
19
+ require_relative 'models/start_match'
20
+ require_relative 'models/end_match'
@@ -0,0 +1,9 @@
1
+ module GameMachine
2
+ module Models
3
+ class CreateTeam < Model
4
+ attribute :name, String
5
+ attribute :owner, String
6
+ attribute :access, String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module GameMachine
2
+ module Models
3
+ class DestroyTeam < Model
4
+ attribute :name, String
5
+ attribute :owner, String
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module GameMachine
2
+ module Models
3
+ class EchoTest < Model
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module GameMachine
2
+ module Models
3
+ class EndMatch < Model
4
+ attribute :match_id, Array
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module GameMachine
2
+ module Models
3
+ class FindMatch < Model
4
+ attribute :team_name, String
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module GameMachine
2
+ module Models
3
+ class JoinTeam < Model
4
+ attribute :name, String
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module GameMachine
2
+ module Models
3
+ class LeaveTeam < Model
4
+ attribute :name, String
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module GameMachine
2
+ module Models
3
+ class Match < Model
4
+ attribute :teams, String
5
+ attribute :server, String
6
+ attribute :game_handler, String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module GameMachine
2
+ module Models
3
+ class PlayerTeam < Model
4
+ attribute :id, String
5
+ attribute :name, String
6
+ attribute :match_id, String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module GameMachine
2
+ module Models
3
+ class StartMatch < Model
4
+ attribute :team_names, Array
5
+ attribute :game_handler, String
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module GameMachine
2
+ module Models
3
+ class Team < Model
4
+ attribute :name, String
5
+ attribute :owner, String
6
+ attribute :access, String
7
+ attribute :members, Array
8
+ attribute :invite_id, String
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module GameMachine
2
+ module Models
3
+ class TeamAcceptInvite < Model
4
+ attribute :name, String
5
+ attribute :invite_id, String
6
+ attribute :invitee, String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module GameMachine
2
+ module Models
3
+ class TeamInvite < Model
4
+ attribute :name, String
5
+ attribute :invite_id, String
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module GameMachine
2
+ module Models
3
+ class TeamJoined < Model
4
+ attribute :name, String
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module GameMachine
2
+ module Models
3
+ class TeamLeft < Model
4
+ attribute :name, String
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module GameMachine
2
+ module Models
3
+ class Teams < Model
4
+ attribute :teams, Array
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module GameMachine
2
+ module Models
3
+ class TeamsRequest < Model
4
+ end
5
+ end
6
+ end
@@ -3,7 +3,11 @@ module GameMachine
3
3
 
4
4
  class << self
5
5
  def dbprocs
6
- @dbprocs ||= java.util.concurrent.ConcurrentHashMap.new
6
+ if @dbprocs
7
+ @dbprocs
8
+ else
9
+ @dbprocs = java.util.concurrent.ConcurrentHashMap.new
10
+ end
7
11
  end
8
12
  end
9
13
 
@@ -31,9 +35,7 @@ module GameMachine
31
35
  def get_entity(entity_id)
32
36
  entity = entities.fetch(entity_id,nil)
33
37
  if entity.nil?
34
- if bytes = store.get(entity_id)
35
- entity = MessageLib::Entity.parse_from(bytes)
36
- end
38
+ entity = store.get(entity_id)
37
39
  end
38
40
  entity
39
41
  end
@@ -43,14 +45,18 @@ module GameMachine
43
45
  procname = message.get_update_method.to_sym
44
46
  current_entity_id = message.get_current_entity_id
45
47
  update_entity = message.get_update_entity
46
- unless current_entity = get_entity(current_entity_id)
47
- current_entity = MessageLib::Entity.new.set_id(current_entity_id)
48
+ current_entity = get_entity(current_entity_id)
49
+ if self.class.dbprocs.has_key?(procname)
50
+ dbproc = self.class.dbprocs[procname]
51
+ returned_entity = dbproc.call(
52
+ current_entity_id,current_entity,update_entity
53
+ )
54
+ set_entity(returned_entity)
55
+ sender.tell(returned_entity || false)
56
+ else
57
+ GameMachine.logger.warn("Unable to find dbproc #{procname}")
48
58
  end
49
- returned_entity = self.class.dbprocs[procname].call(
50
- current_entity,update_entity
51
- )
52
- set_entity(returned_entity)
53
- sender.tell(returned_entity || false)
59
+
54
60
  elsif message.is_a?(MessageLib::ObjectdbPut)
55
61
  set_entity(message.get_entity)
56
62
  sender.tell(true)
@@ -1,3 +1,3 @@
1
1
  module GameMachine
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
@@ -137,7 +137,7 @@ module GameMachine
137
137
  enqueue(message.id)
138
138
  else
139
139
  message = swap_if_queued_exists(message)
140
- @store.set(message.id, message.to_byte_array)
140
+ @store.set(message.id, message)
141
141
  @last_write = current_time
142
142
  set_updated_at(message)
143
143
  end
@@ -27,13 +27,13 @@ module GameMachine
27
27
 
28
28
  it "registeres the class in the system manager" do
29
29
  Actor::Base.aspect(aspect)
30
- expect(Application.registered.include?(Actor::Base)).to be_true
30
+ expect(Application.registered.include?(Actor::Base)).to be_truthy
31
31
  end
32
32
  end
33
33
 
34
34
  describe "#sender" do
35
35
  it "returns an actor ref" do
36
- subject.sender.should be_kind_of(Actor::Ref)
36
+ expect(subject.sender).to be_kind_of(Actor::Ref)
37
37
  end
38
38
  end
39
39
 
@@ -49,21 +49,21 @@ module GameMachine
49
49
  describe "#find_remote" do
50
50
  it "should return ref with correctly formatted path" do
51
51
  actor_ref = GameSystems::LocalEcho.find_remote('default','test')
52
- actor_ref.path.match(/akka.tcp:\/\/cluster@localhost:2551\/user\/test/).should be_true
52
+ expect(actor_ref.path.match(/akka.tcp:\/\/cluster@localhost:2551\/user\/test/)).to be_truthy
53
53
  end
54
54
  end
55
55
 
56
56
  describe "#find" do
57
57
  it "should return ref with correctly formatted path" do
58
58
  actor_ref = GameSystems::LocalEcho.find('test')
59
- actor_ref.path.match(/\/user\/test/).should be_true
59
+ expect(actor_ref.path.match(/\/user\/test/)).to be_truthy
60
60
  end
61
61
  end
62
62
 
63
63
  describe "#add_hashring" do
64
64
  it "adds the hashring and returns it" do
65
65
  expect(Actor::Base.add_hashring('test','ring')).to eq(Actor::Base.hashring('test'))
66
- Actor::Base.hashring('test').should == 'ring'
66
+ expect(Actor::Base.hashring('test')).to eq('ring')
67
67
  end
68
68
  end
69
69
 
@@ -14,26 +14,26 @@ module GameMachine
14
14
 
15
15
  describe "#initialize" do
16
16
  it "sets the path" do
17
- Actor::Ref.new('test').path.should == 'test'
17
+ expect(Actor::Ref.new('test').path).to eq('test')
18
18
  end
19
19
  end
20
20
 
21
21
  describe "#ask" do
22
22
  it "should accept an actor ref" do
23
23
  ref = Actor::Ref.new(local_echo.get_self)
24
- ref.ask('test',1000).should == 'test'
24
+ expect(ref.ask('test',1000)).to eq('test')
25
25
  end
26
26
 
27
27
  it "should accept a path" do
28
28
  Actor::Builder.new(GameSystems::LocalEcho).with_name('echotest3').start
29
29
  ref = GameSystems::LocalEcho.find('echotest3')
30
- ref.ask('test',1000).should == 'test'
30
+ expect(ref.ask('test',1000)).to eq('test')
31
31
  end
32
32
  end
33
33
 
34
34
  describe "#tell" do
35
35
  it 'sender argument is optional' do
36
- subject.tell('test').should be_true
36
+ expect(subject.tell('test')).to be_truthy
37
37
  end
38
38
 
39
39
  it "should accept a path" do
@@ -49,34 +49,34 @@ module GameMachine
49
49
  describe "#send_message" do
50
50
 
51
51
  it "default should call tell with message and nil sender" do
52
- subject.should_receive(:tell).with('test',nil)
52
+ expect(subject).to receive(:tell).with('test',nil)
53
53
  subject.send_message('test')
54
54
  end
55
55
 
56
56
  it "blocking=true should call ask with message and default timeout" do
57
- subject.should_receive(:ask).with('test',100)
57
+ expect(subject).to receive(:ask).with('test',100)
58
58
  subject.send_message('test', :blocking => true)
59
59
  end
60
60
 
61
61
  it "sender option should be passed to tell" do
62
- subject.should_receive(:tell).with('test','sender')
62
+ expect(subject).to receive(:tell).with('test','sender')
63
63
  subject.send_message('test',:sender => 'sender')
64
64
  end
65
65
 
66
66
  it "timeout option should be passed to ask" do
67
- subject.should_receive(:ask).with('test',2)
67
+ expect(subject).to receive(:ask).with('test',2)
68
68
  subject.send_message('test', :timeout => 2, :blocking => true)
69
69
  end
70
70
 
71
71
  it "should get returned message" do
72
72
  Actor::Builder.new(GameSystems::LocalEcho).with_name('echotest2').start
73
73
  ref = GameSystems::LocalEcho.find('echotest2')
74
- ref.send_message('hi', :blocking => true, :timeout => 1000).should == 'hi'
74
+ expect(ref.send_message('hi', :blocking => true, :timeout => 1000)).to eq('hi')
75
75
  end
76
76
 
77
77
  it "should return false on timeout" do
78
78
  ref = GameSystems::LocalEcho.find('blah')
79
- ref.send_message('hi', :blocking => true, :timeout => 1).should be_false
79
+ expect(ref.send_message('hi', :blocking => true, :timeout => 1)).to be_falsey
80
80
  end
81
81
  end
82
82
  end