mooncell 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.overcommit.yml +32 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +10 -0
- data/README.md +138 -0
- data/Rakefile +8 -0
- data/bin/mooncell +8 -0
- data/lib/mooncell.rb +102 -0
- data/lib/mooncell/application.rb +114 -0
- data/lib/mooncell/application_configuration.rb +66 -0
- data/lib/mooncell/cli.rb +16 -0
- data/lib/mooncell/cli/commands.rb +34 -0
- data/lib/mooncell/cli/commands/base.rb +66 -0
- data/lib/mooncell/cli/commands/console.rb +35 -0
- data/lib/mooncell/cli/commands/registry.rb +105 -0
- data/lib/mooncell/cli/commands/server.rb +25 -0
- data/lib/mooncell/cli/commands/version.rb +21 -0
- data/lib/mooncell/command.rb +78 -0
- data/lib/mooncell/configuration.rb +51 -0
- data/lib/mooncell/connection.rb +43 -0
- data/lib/mooncell/connection_pool.rb +39 -0
- data/lib/mooncell/entity.rb +12 -0
- data/lib/mooncell/env.rb +67 -0
- data/lib/mooncell/environment.rb +160 -0
- data/lib/mooncell/loader.rb +62 -0
- data/lib/mooncell/protocol.rb +28 -0
- data/lib/mooncell/protocol/registry.rb +33 -0
- data/lib/mooncell/protocol/websocket.rb +70 -0
- data/lib/mooncell/protocol/websocket/server.rb +78 -0
- data/lib/mooncell/respond.rb +87 -0
- data/lib/mooncell/router.rb +56 -0
- data/lib/mooncell/version.rb +5 -0
- data/mooncell.gemspec +40 -0
- metadata +260 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7174d01ad8172d3b5d85027c3eec815c283d259c5074e0275866d771eb114b94
|
4
|
+
data.tar.gz: e27a4aec091dcc1f904eedd137c258043f1437bbcc4b255fcb7b48c8c9a8ecfa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b34eded1a484213af4a5165432ff6a6b951d6a7c0b389e3da3767626f8608a02b9f121efe5d5b820be361cb44d6c8bc2238c71463b8f5628df2fbdabccad7a2
|
7
|
+
data.tar.gz: 58be9c2e38e8aa483b8d5626426e3607beafd3ea9df0c73283cb8b9ed3a3515d8edd760d79e016f29a6d6c810696cf292fe570ebcdc02dbdc42e97e65e172ef9
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Use this file to configure the Overcommit hooks you wish to use. This will
|
2
|
+
# extend the default configuration defined in:
|
3
|
+
# https://github.com/sds/overcommit/blob/master/config/default.yml
|
4
|
+
#
|
5
|
+
# At the topmost level of this YAML file is a key representing type of hook
|
6
|
+
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
|
7
|
+
# customize each hook, such as whether to only run it on certain files (via
|
8
|
+
# `include`), whether to only display output if it fails (via `quiet`), etc.
|
9
|
+
#
|
10
|
+
# For a complete list of hooks, see:
|
11
|
+
# https://github.com/sds/overcommit/tree/master/lib/overcommit/hook
|
12
|
+
#
|
13
|
+
# For a complete list of options that you can use to customize hooks, see:
|
14
|
+
# https://github.com/sds/overcommit#configuration
|
15
|
+
#
|
16
|
+
# Uncomment the following lines to make the configuration take effect.
|
17
|
+
|
18
|
+
PreCommit:
|
19
|
+
AuthorName:
|
20
|
+
enabled: false
|
21
|
+
RuboCop:
|
22
|
+
enabled: true
|
23
|
+
on_warn: fail # Treat all warnings as failures
|
24
|
+
BundleAudit:
|
25
|
+
enabled: true
|
26
|
+
|
27
|
+
PostCheckout:
|
28
|
+
ALL: # Special hook name that customizes all hooks of this type
|
29
|
+
quiet: true # Change all post-checkout hooks to only display output on failure
|
30
|
+
|
31
|
+
IndexTags:
|
32
|
+
enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at elct9620@frost.tw. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
Mooncell
|
2
|
+
===
|
3
|
+
|
4
|
+
The **Mooncell** is a Domain-Driven Design online game server framework inspired by [Hanami.rb](https://hanamirb.org/).
|
5
|
+
|
6
|
+
An online game usually includes one or more servers but it is hard to share the codebase and support multiple protocols.
|
7
|
+
|
8
|
+
Mooncell split game logic to `libs` and allow shared with other projects, and allow the developer to implement behaviors inside `apps` between servers.
|
9
|
+
|
10
|
+
## Concept
|
11
|
+
|
12
|
+
Currently, Mooncell still under design. Below is the core concept to implement servers with it.
|
13
|
+
|
14
|
+
### Structure
|
15
|
+
|
16
|
+
This is a Map server implements a move command.
|
17
|
+
|
18
|
+
```
|
19
|
+
├── Gemfile
|
20
|
+
├── Gemfile.lock
|
21
|
+
├── apps
|
22
|
+
│ └── map
|
23
|
+
│ ├── application.rb
|
24
|
+
│ ├── commands
|
25
|
+
│ │ └── move.rb
|
26
|
+
│ ├── config
|
27
|
+
│ │ └── routes.rb
|
28
|
+
│ └── responds
|
29
|
+
│ └── move.rb
|
30
|
+
└── config
|
31
|
+
└── environment.rb
|
32
|
+
```
|
33
|
+
|
34
|
+
### Environment
|
35
|
+
|
36
|
+
It defines the shared environment and servers to loaded.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# frozen_string_literal: true
|
40
|
+
|
41
|
+
require 'mooncell/protocol/websocket'
|
42
|
+
|
43
|
+
require_relative '../apps/map/application'
|
44
|
+
|
45
|
+
Mooncell.configure do
|
46
|
+
protocol :websocket
|
47
|
+
|
48
|
+
app Map::Application
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
### Routes
|
53
|
+
|
54
|
+
It defines the command available on the server.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# frozen_string_literal: true
|
58
|
+
|
59
|
+
command 'move', 'Map::Commands::Move'
|
60
|
+
```
|
61
|
+
|
62
|
+
### Command
|
63
|
+
|
64
|
+
Process the command received from the client.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# frozen_string_literal: true
|
68
|
+
|
69
|
+
module Map
|
70
|
+
module Commands
|
71
|
+
class Move
|
72
|
+
include Mooncell::Command
|
73
|
+
|
74
|
+
# Fake Model
|
75
|
+
Player = Struct.new(:id, :x, :y)
|
76
|
+
|
77
|
+
# Expose to respond
|
78
|
+
expose :player
|
79
|
+
|
80
|
+
def call(params)
|
81
|
+
@player = Player.new(params['id'], params['x'], params['y'])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
### Respond
|
89
|
+
|
90
|
+
Return the process result to client.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
# frozen_string_literal: true
|
94
|
+
|
95
|
+
module Map
|
96
|
+
module Responds
|
97
|
+
class Move
|
98
|
+
include Mooncell::Respond
|
99
|
+
|
100
|
+
# Broadcast to all clients
|
101
|
+
broadcast true
|
102
|
+
|
103
|
+
def call(*)
|
104
|
+
{ id: player.id, x: player.x, y: player.y }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
111
|
+
## Installation
|
112
|
+
|
113
|
+
> TODO
|
114
|
+
|
115
|
+
## Usage
|
116
|
+
|
117
|
+
> TODO
|
118
|
+
|
119
|
+
## Development
|
120
|
+
|
121
|
+
> TODO
|
122
|
+
|
123
|
+
## Roadmap
|
124
|
+
|
125
|
+
The first target is to design the architecture to support TCP/WebSocket protocol and allow use JSON or customize serializer.
|
126
|
+
|
127
|
+
* [ ] Naming
|
128
|
+
* [ ] Project Generator
|
129
|
+
|
130
|
+
> TBD
|
131
|
+
|
132
|
+
## Contributing
|
133
|
+
|
134
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/elct9620/mooncell. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
135
|
+
|
136
|
+
## Code of Conduct
|
137
|
+
|
138
|
+
Everyone interacting in the Mooncell project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/elct9620/mooncell/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/mooncell
ADDED
data/lib/mooncell.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mooncell/version'
|
4
|
+
|
5
|
+
# A online game server framework for Ruby
|
6
|
+
#
|
7
|
+
# @since 0.1.0
|
8
|
+
module Mooncell
|
9
|
+
require 'mooncell/command'
|
10
|
+
require 'mooncell/respond'
|
11
|
+
require 'mooncell/entity'
|
12
|
+
require 'mooncell/protocol'
|
13
|
+
|
14
|
+
require 'mooncell/loader'
|
15
|
+
require 'mooncell/environment'
|
16
|
+
require 'mooncell/configuration'
|
17
|
+
require 'mooncell/connection'
|
18
|
+
require 'mooncell/connection_pool'
|
19
|
+
|
20
|
+
require 'mooncell/application'
|
21
|
+
|
22
|
+
# @since 0.1.0
|
23
|
+
# @api private
|
24
|
+
@_mutex = Mutex.new
|
25
|
+
|
26
|
+
# Return current environment
|
27
|
+
#
|
28
|
+
# @return [String] the current environment
|
29
|
+
#
|
30
|
+
# @since 0.3.1
|
31
|
+
#
|
32
|
+
# @see Mooncell::Environment#environment
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# Mooncell.env => "development"
|
36
|
+
def self.env
|
37
|
+
environment.environment
|
38
|
+
end
|
39
|
+
|
40
|
+
# Return application root
|
41
|
+
#
|
42
|
+
# @since 0.1.0
|
43
|
+
def self.root
|
44
|
+
environment.root
|
45
|
+
end
|
46
|
+
|
47
|
+
# Configure the Mooncell
|
48
|
+
#
|
49
|
+
# @param block [Proc] the configuration block
|
50
|
+
#
|
51
|
+
# @since 0.1.0
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# # config/environment.rb
|
55
|
+
#
|
56
|
+
# # ...
|
57
|
+
#
|
58
|
+
# Mooncell.configure do
|
59
|
+
# protocol :websocket
|
60
|
+
# end
|
61
|
+
def self.configure(&block)
|
62
|
+
@_mutex.synchronize do
|
63
|
+
@_configuration = Mooncell::Configuration.new(&block)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Mooncell Configuration
|
68
|
+
#
|
69
|
+
# @return [Mooncell::Configuration] the configuration
|
70
|
+
#
|
71
|
+
# @see Mooncell.configure
|
72
|
+
#
|
73
|
+
# @since 0.1.0
|
74
|
+
# @api private
|
75
|
+
def self.configuration
|
76
|
+
@_mutex.synchronize do
|
77
|
+
raise 'Mooncell not configured' unless defined?(@_configuration)
|
78
|
+
|
79
|
+
@_configuration
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Current environment
|
84
|
+
#
|
85
|
+
# @return [Mooncell::Environment] environment
|
86
|
+
#
|
87
|
+
# @since 0.1.0
|
88
|
+
# @api private
|
89
|
+
def self.environment
|
90
|
+
@environment ||= Environment.new
|
91
|
+
end
|
92
|
+
|
93
|
+
# Check if enable code reloading
|
94
|
+
#
|
95
|
+
# @return [TrueClass,FalseClass] the result of check
|
96
|
+
#
|
97
|
+
# @since 0.1.0
|
98
|
+
# @api private
|
99
|
+
def self.code_reloading?
|
100
|
+
environment.code_reloading?
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mooncell/application_configuration'
|
4
|
+
require 'mooncell/router'
|
5
|
+
|
6
|
+
module Mooncell
|
7
|
+
# Mooncell Application
|
8
|
+
#
|
9
|
+
# @since 0.1.0
|
10
|
+
# @api private
|
11
|
+
class Application
|
12
|
+
# @since 0.1.0
|
13
|
+
# @api private
|
14
|
+
def self.inherited(base)
|
15
|
+
super
|
16
|
+
base.extend ClassMethods
|
17
|
+
end
|
18
|
+
|
19
|
+
# @since 0.1.0
|
20
|
+
# @api private
|
21
|
+
module ClassMethods
|
22
|
+
# @since 0.1.0
|
23
|
+
# @api private
|
24
|
+
def self.extended(base)
|
25
|
+
super
|
26
|
+
base.class_eval do
|
27
|
+
@_lock = Mutex.new
|
28
|
+
|
29
|
+
class << self
|
30
|
+
# @since 0.1.0
|
31
|
+
# @api private
|
32
|
+
attr_reader :configuration
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Application name
|
38
|
+
#
|
39
|
+
# @return [String] the application name
|
40
|
+
#
|
41
|
+
# @since 0.1.0
|
42
|
+
# @api private
|
43
|
+
def app_name
|
44
|
+
@app_name ||=
|
45
|
+
name.split('::').first.downcase
|
46
|
+
end
|
47
|
+
|
48
|
+
# Configure the application
|
49
|
+
#
|
50
|
+
# TODO: Support specify by environment
|
51
|
+
#
|
52
|
+
# @param block [Proc] the configuration block
|
53
|
+
#
|
54
|
+
# @since 0.1.0
|
55
|
+
# @api private
|
56
|
+
def configure(&block)
|
57
|
+
@_lock.synchronize do
|
58
|
+
@configuration = ApplicationConfiguration.new(&block)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# @since 0.1.0
|
64
|
+
# @api private
|
65
|
+
attr_reader :pool, :router
|
66
|
+
|
67
|
+
# Create application instance
|
68
|
+
#
|
69
|
+
# @since 0.1.0
|
70
|
+
# @api private
|
71
|
+
def initialize
|
72
|
+
@pool = ConnectionPool.new
|
73
|
+
@router = Router.new(self)
|
74
|
+
|
75
|
+
# TODO: Add support to reload router
|
76
|
+
setup_router
|
77
|
+
end
|
78
|
+
|
79
|
+
# Run application
|
80
|
+
#
|
81
|
+
# @since 0.1.0
|
82
|
+
# @api private
|
83
|
+
def call(*)
|
84
|
+
protocol = Protocol.get(configuration.protocol)
|
85
|
+
protocol.new(self).start
|
86
|
+
end
|
87
|
+
|
88
|
+
# Return the application configuration
|
89
|
+
#
|
90
|
+
# @return [Mooncell::ApplicationConfiguration] application configuration
|
91
|
+
#
|
92
|
+
# @see Application.configuration
|
93
|
+
#
|
94
|
+
# @since 0.1.0
|
95
|
+
# @api private
|
96
|
+
def configuration
|
97
|
+
self.class.configuration
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
# @since 0.1.0
|
103
|
+
# @api private
|
104
|
+
def setup_router
|
105
|
+
path =
|
106
|
+
Mooncell
|
107
|
+
.environment
|
108
|
+
.apps_path
|
109
|
+
.join(self.class.app_name, 'config', 'routes.rb')
|
110
|
+
code = File.open(path, 'rb:bom|utf-8', &:read)
|
111
|
+
@router.load(code)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|