rubypitaya 3.3.7 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9de06df9189f69c78f1c03512f6fada275ee1bdcd590ffe1810da2b62dce14f6
4
- data.tar.gz: 5848c25207a857715972ff3cef0f705e30872a1b2bb702ccf89d41e3f49035dc
3
+ metadata.gz: a3416fbf6a02d6e883d1f97b9f4c6ca36e246043ff2541ef690cc13170cdd727
4
+ data.tar.gz: 961e1d3f9a24f416e3a37ef422358dfc6a89677f369816999550c7d76215c571
5
5
  SHA512:
6
- metadata.gz: 35c5eb0d8a9d3bb497159ba40517126d8749f5d467fa4b632f75d07de5f4692ba848a72540ed375a976853713fe7d6c6900b7aee177ccafecb2e548d8782c327
7
- data.tar.gz: 33ec57d8e7f46efe56804806d086d2708a1a9912469fc23a85a03b6927047460cb11f2f96dcdcfae195539b3f980d783f69ceda3f0ad852de07b6cdb752e0442
6
+ metadata.gz: 3892526f8d71b6a11448309ac6c1176a698ca46cfcda9b2c49a5860a2ed5913ffa285cc736ad39a23d480d6aebbd4ad8ea3a7352f2cd5cf8a48f2956ec02339f
7
+ data.tar.gz: c57731543e86c6c161ead30fc84800f1c60c7895d18722ec47018da758736cd5d8cd1c5a6616a31307e910e838636587f701e1e37d76301e85fb44f1b2a6795a
@@ -1,12 +1,12 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '3.3.7'
3
+ gem 'rubypitaya', '3.4.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.14.1'
7
- gem 'rspec', '3.10.0'
8
- gem 'listen', '3.7.0'
9
- gem 'bundler', '2.2.22'
10
- gem 'cucumber', '7.0.0'
7
+ gem 'rspec', '3.11.0'
8
+ gem 'listen', '3.7.1'
9
+ gem 'bundler', '2.2.32'
10
+ gem 'cucumber', '7.1.0'
11
11
  gem 'sinatra-contrib', '2.1.0'
12
12
  end
@@ -103,7 +103,7 @@ GEM
103
103
  rspec-support (~> 3.10.0)
104
104
  rspec-support (3.10.3)
105
105
  ruby2_keywords (0.0.5)
106
- rubypitaya (3.3.7)
106
+ rubypitaya (3.4.0)
107
107
  activerecord (= 6.1.4.1)
108
108
  etcdv3 (= 0.11.4)
109
109
  google-protobuf (= 3.18.1)
@@ -143,7 +143,7 @@ DEPENDENCIES
143
143
  listen (= 3.7.0)
144
144
  pry (= 0.14.1)
145
145
  rspec (= 3.10.0)
146
- rubypitaya (= 3.3.7)
146
+ rubypitaya (= 3.4.0)
147
147
  sinatra-contrib (= 2.1.0)
148
148
 
149
149
  BUNDLED WITH
@@ -13,6 +13,8 @@ run:
13
13
  ## Build project
14
14
  build:
15
15
  @docker-compose build
16
+ @echo "Copying vendor folder ..."
17
+ @sh -c "FOLDER=$(notdir $(shell pwd)); CONTAINER="\$${FOLDER}_rubypitaya"; docker cp \$$(docker create \$${CONTAINER}):/app/rubypitaya/vendor ."
16
18
 
17
19
  ## Run ruby irb console
18
20
  console:
@@ -41,7 +43,7 @@ test-cucumber:
41
43
  ## Update gems dependencies on Gemfile.lock
42
44
  update-dependencies:
43
45
  @rm -f Gemfile.lock
44
- @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:3.0.2 bundle install
46
+ @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:3.0.3 bundle install
45
47
 
46
48
  ## + Improve metagame
47
49
 
@@ -26,6 +26,7 @@ mongo:
26
26
  user: 'user'
27
27
  pass: 'password'
28
28
  database: admin
29
+ enabled: true
29
30
 
30
31
  http:
31
32
  auth:
@@ -1,4 +1,4 @@
1
- FROM ruby:3.0.2-slim
1
+ FROM ruby:3.0.3-slim
2
2
 
3
3
  ENV LANG=C.UTF-8
4
4
  ENV LC_ALL=C.UTF-8
@@ -18,6 +18,7 @@ COPY Gemfile Gemfile.lock ./
18
18
  RUN bundle config --global jobs 4 && \
19
19
  bundle config --global set clean 'true' \
20
20
  bundle config --global git.allow_insecure true && \
21
+ bundle config set path './vendor/bundle' && \
21
22
  bundle install
22
23
 
23
24
  COPY . .
@@ -1,4 +1,4 @@
1
- FROM ruby:3.0.2-slim as builder
1
+ FROM ruby:3.0.3-slim as builder
2
2
 
3
3
  RUN apt update && \
4
4
  apt install -y --no-install-recommends \
@@ -29,7 +29,7 @@ RUN rm -rf /usr/local/bundle/cache && \
29
29
 
30
30
  # RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
31
31
 
32
- FROM ruby:3.0.2-slim
32
+ FROM ruby:3.0.3-slim
33
33
 
34
34
  ENV LANG=C.UTF-8
35
35
  ENV LC_ALL=C.UTF-8
@@ -79,8 +79,8 @@ services:
79
79
  dockerfile: 'docker/dev/Dockerfile'
80
80
  working_dir: '/app/rubypitaya'
81
81
  volumes:
82
- - '.:/app/rubypitaya'
83
- - '/var/run/docker.sock:/var/run/docker.sock'
82
+ - .:/app/rubypitaya
83
+ - /app/rubypitaya/vendor
84
84
  ports:
85
85
  - '80:4567'
86
86
  environment:
@@ -6,4 +6,39 @@ data:
6
6
  nginx.conf: "events {\n worker_connections 1024;\n}\n\nstream {\n server
7
7
  {\n listen {{ .Values.gameserver.externalport.first }}-{{ .Values.gameserver.externalport.last }};\n \n resolver kube-dns.kube-system.svc.cluster.local
8
8
  valid=5s;\n\n proxy_pass gameserver-$server_port.gameserver.{{ .Values.namespace }}.svc.cluster.local:{{ .Values.gameserver.gameport }};\n
9
- \ }\n}\n"
9
+ \ }\n}\n"
10
+
11
+ # {{- $initialValue := int .Values.gameserver.externalport.first }}
12
+ # {{- $finalValue := add .Values.gameserver.externalport.last 1 }}
13
+ # {{- $finalValue = int $finalValue }}
14
+ # apiVersion: v1
15
+ # kind: ConfigMap
16
+ # metadata:
17
+ # name: nginx-config
18
+ # data:
19
+ # nginx.conf: |
20
+ # events {
21
+ # worker_connections 1024;
22
+ # }
23
+ #
24
+ # stream {
25
+ # map $server_port $server_number {
26
+ # {{- range untilStep $initialValue $finalValue 1 }}
27
+ # {{- $port := . }}
28
+ # {{- $number := sub $port $initialValue }}
29
+ # {{ $port }} {{ $number }};
30
+ # {{- end }}
31
+ # }
32
+ #
33
+ # server {
34
+ # listen {{ .Values.gameserver.externalport.first }}-{{ .Values.gameserver.externalport.last }};
35
+ #
36
+ # resolver kube-dns.kube-system.svc.cluster.local valid=5s;
37
+ #
38
+ # proxy_pass gameserver-$server_number.gameserver.{{ .Values.namespace }}.svc.cluster.local:{{ .Values.gameserver.gameport }};
39
+ # }
40
+ # }
41
+
42
+ # map $server_port $stack_number {
43
+ # ~\d\d(.+)$ $1;
44
+ # }
@@ -72,13 +72,14 @@ module RubyPitaya
72
72
  @database_connector = DatabaseConnector.new(@database_config, @log)
73
73
  @database_connector.connect
74
74
 
75
+ @mongo_enabled = @setup['rubypitaya.mongo.enabled']
75
76
  @mongo_address = @setup['rubypitaya.mongo.url']
76
77
  @mongo_user = @setup['rubypitaya.mongo.user']
77
78
  @mongo_password = @setup['rubypitaya.mongo.pass']
78
79
  @mongo_database_name = @setup['rubypitaya.mongo.database']
79
80
  @mongo_connector = MongoConnector.new(@mongo_address, @mongo_user,
80
81
  @mongo_password, @mongo_database_name)
81
- @mongo_connector.connect
82
+ @mongo_connector.connect if @mongo_enabled
82
83
 
83
84
  @session = Session.new
84
85
  @postman = Postman.new(@nats_connector)
@@ -147,6 +148,7 @@ module RubyPitaya
147
148
  @log.info "Server shutting down..."
148
149
 
149
150
  @etcd_connector.disconnect
151
+ @nats_connector.disconnect
150
152
  @database_connector.disconnect
151
153
 
152
154
  exit(0)
@@ -193,6 +195,12 @@ module RubyPitaya
193
195
  code: error.code,
194
196
  message: error.message
195
197
  }
198
+ rescue Exception => error
199
+ @log.error "INTERNAL ERROR: #{error.class} | #{error.message}} \n #{error.backtrace.join("\n")}"
200
+ response = {
201
+ code: StatusCodes::CODE_INTERNAL_ERROR,
202
+ message: StatusCodes::MESSAGE_INTERNAL_ERROR,
203
+ }
196
204
  end
197
205
 
198
206
  delta_time_seconds = ((Time.now.to_f - start_time_seconds) * 1000).round(2)
@@ -19,28 +19,41 @@ module RubyPitaya
19
19
  @server_uuid = server_uuid
20
20
  @server_name = server_name
21
21
  @nats_address = nats_address
22
+ @nats = nil
23
+ @subscribe = nil
22
24
  end
23
25
 
24
26
  def connect
25
- NATS.start(:servers => [@nats_address]) do |nc|
27
+ self.disconnect
26
28
 
27
- NATS.subscribe(subscribe_topic) do |message, reply, a, b|
28
- request = NatsRequest.decode(message).to_h
29
+ @nats = NATS.connect(servers: [@nats_address])
30
+ @subscribe = @nats.subscribe(subscribe_topic)
29
31
 
30
- Fiber.new do
31
- response = yield request
32
+ loop do
33
+ message = @subscribe.pending_queue.pop
34
+ @subscribe.synchronize do
35
+ @subscribe.pending_size -= message.data.size
36
+ end
32
37
 
33
- nats_response = NatsResponse.new(data: response.to_json)
38
+ request = NatsRequest.decode(message.data).to_h
34
39
 
35
- response = NatsResponse.encode(nats_response)
40
+ response = yield request
36
41
 
37
- NATS.publish(reply, response)
38
- end.resume
39
- end
42
+ nats_response = NatsResponse.new(data: response.to_json)
43
+ response = NatsResponse.encode(nats_response)
40
44
 
45
+ @nats.publish(message.reply, response)
41
46
  end
42
47
  end
43
48
 
49
+ def disconnect
50
+ @subscribe.unsubscribe unless @subscribe.nil?
51
+ @nats.close unless @nats.nil?
52
+
53
+ @nats = nil
54
+ @subscribe = nil
55
+ end
56
+
44
57
  def push_to_frontend(session, message_route, payload)
45
58
  frontend_topic = get_frontend_topic(session.frontend_id)
46
59
 
@@ -67,9 +80,9 @@ module RubyPitaya
67
80
 
68
81
  request = NatsRequest.encode(nats_request)
69
82
 
70
- nats_response = NATS.request(frontend_topic, request)
83
+ nats_response = @nats.request(frontend_topic, request)
71
84
 
72
- response = NatsResponse.decode(nats_response).to_h
85
+ response = NatsResponse.decode(nats_response.data).to_h
73
86
 
74
87
  response
75
88
  end
@@ -83,7 +96,7 @@ module RubyPitaya
83
96
  data: payload.to_json,
84
97
  )
85
98
 
86
- NATS.publish(user_topic, nats_push)
99
+ @nats.publish(user_topic, nats_push)
87
100
 
88
101
  0
89
102
  end
@@ -11,6 +11,10 @@ module RubyPitaya
11
11
  CODE_ACTION_NOT_FOUND = 'RP-002'
12
12
  CODE_NOT_AUTHENTICATED = 'RP-003'
13
13
  CODE_AUTHENTICATION_ERROR = 'RP-004'
14
+ CODE_INTERNAL_ERROR = 'RP-005'
15
+
16
+ # Error messages
17
+ MESSAGE_INTERNAL_ERROR = 'Internal server error'
14
18
 
15
19
  class Connector
16
20
  CODE_UNKNOWN = 'PIT-000'
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '3.3.7'
2
+ VERSION = '3.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubypitaya
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.7
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luciano Prestes Cavalcanti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-28 00:00:00.000000000 Z
11
+ date: 2022-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.3
19
+ version: 1.3.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.3
26
+ version: 1.3.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,131 +39,131 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 13.0.6
41
41
  - !ruby/object:Gem::Dependency
42
- name: nats
42
+ name: mongo
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.11.0
47
+ version: 2.17.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.11.0
54
+ version: 2.17.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: mongo
56
+ name: redis
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.16.0
61
+ version: 4.6.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.16.0
68
+ version: 4.6.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: redis
70
+ name: etcdv3
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 4.5.1
75
+ version: 0.11.5
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 4.5.1
82
+ version: 0.11.5
83
83
  - !ruby/object:Gem::Dependency
84
- name: etcdv3
84
+ name: ostruct
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 0.11.4
89
+ version: 0.5.3
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 0.11.4
96
+ version: 0.5.3
97
97
  - !ruby/object:Gem::Dependency
98
- name: ostruct
98
+ name: sinatra
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.4.0
103
+ version: 2.1.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.4.0
110
+ version: 2.1.0
111
111
  - !ruby/object:Gem::Dependency
112
- name: sinatra
112
+ name: webrick
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 2.1.0
117
+ version: 1.7.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 2.1.0
124
+ version: 1.7.0
125
125
  - !ruby/object:Gem::Dependency
126
- name: webrick
126
+ name: nats-pure
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 1.7.0
131
+ version: 2.0.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 1.7.0
138
+ version: 2.0.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: activerecord
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 6.1.4.1
145
+ version: 7.0.2
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 6.1.4.1
152
+ version: 7.0.2
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: google-protobuf
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 3.18.1
159
+ version: 3.19.4
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: 3.18.1
166
+ version: 3.19.4
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: pry
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -184,56 +184,56 @@ dependencies:
184
184
  requirements:
185
185
  - - '='
186
186
  - !ruby/object:Gem::Version
187
- version: 3.10.0
187
+ version: 3.11.0
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - '='
193
193
  - !ruby/object:Gem::Version
194
- version: 3.10.0
194
+ version: 3.11.0
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: listen
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - '='
200
200
  - !ruby/object:Gem::Version
201
- version: 3.7.0
201
+ version: 3.7.1
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - '='
207
207
  - !ruby/object:Gem::Version
208
- version: 3.7.0
208
+ version: 3.7.1
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: bundler
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - '='
214
214
  - !ruby/object:Gem::Version
215
- version: 2.2.22
215
+ version: 2.2.32
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - '='
221
221
  - !ruby/object:Gem::Version
222
- version: 2.2.22
222
+ version: 2.2.32
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: cucumber
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - '='
228
228
  - !ruby/object:Gem::Version
229
- version: 7.0.0
229
+ version: 7.1.0
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - '='
235
235
  - !ruby/object:Gem::Version
236
- version: 7.0.0
236
+ version: 7.1.0
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: sinatra-contrib
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -391,7 +391,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
391
391
  - !ruby/object:Gem::Version
392
392
  version: '0'
393
393
  requirements: []
394
- rubygems_version: 3.2.22
394
+ rubygems_version: 3.2.32
395
395
  signing_key:
396
396
  specification_version: 4
397
397
  summary: Create servers with pitaya