Class: SocketClientBase
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- SocketClientBase
show all
- Defined in:
- lib/mrpin/core/remote/socket/base/socket_client_base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
Returns the value of attribute ip.
21
22
23
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 21
def ip
@ip
end
|
Returns the value of attribute player.
26
27
28
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 26
def player
@player
end
|
#should_disconnect_session ⇒ Object
use for disconnect_inactive_players and on_application_exit
24
25
26
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 24
def should_disconnect_session
@should_disconnect_session
end
|
#time_last_request ⇒ Object
20
21
22
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 20
def time_last_request
@time_last_request
end
|
Class Method Details
.manager_remote ⇒ Object
13
14
15
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 13
def self.manager_remote
@manager_remote
end
|
.manager_remote=(value) ⇒ Object
8
9
10
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 8
def self.manager_remote=(value)
@manager_remote = value
end
|
Instance Method Details
#get_requests ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 101
def get_requests
result = []
return result unless @is_online
@requests_locker.synchronize do
begin
unless @data_buffer.empty?
deserialize_data = AMF::Root.deserialize(@data_buffer)
result = deserialize_data[:objects]
@data_buffer = deserialize_data[:incomplete_objects] || ''
end
rescue Exception => e
on_get_requests_error(e)
end
end
result
end
|
#is_online? ⇒ Boolean
29
30
31
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 29
def is_online?
@is_online
end
|
#post_init ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 48
def post_init
@logger = AppInfo.instance.logger
@requests_locker = Mutex.new
@is_online = true
@time_last_request = Time.now.to_i
@should_disconnect_session = true
@manager_remote = self.class.manager_remote
@manager_remote.on_client_connected(self)
@data_buffer = ''
@player = nil
init_ip
nil
end
|
#receive_data(data) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 88
def receive_data(data)
@time_last_request = Time.now.to_i
@requests_locker.synchronize do
@data_buffer += data
end
@manager_remote.handle_data_from(self)
nil
end
|
#send_raw_data(raw_data) ⇒ Object
153
154
155
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 153
def send_raw_data(raw_data)
send_data(raw_data)
end
|
#send_response(response_obj) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 125
def send_response(response_obj)
return unless @is_online
report_about_sent_request(response_obj)
response = AMF::Root.serialize(response_obj)
send_data(response)
nil
end
|
#send_response_error(request_id, description = nil) ⇒ Object
165
166
167
168
169
170
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 165
def send_response_error(request_id, description = nil)
response = Api::ResponseError.new(request_id)
response.description = description
send_response(response)
end
|
#send_response_ok(request_id) ⇒ Object
158
159
160
161
162
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 158
def send_response_ok(request_id)
response = Api::ResponseOk.new(request_id)
send_response(response)
end
|
173
174
175
176
177
178
179
|
# File 'lib/mrpin/core/remote/socket/base/socket_client_base.rb', line 173
def unbind
@is_online = false
@manager_remote.on_client_disconnected(self) if @should_disconnect_session
nil
end
|