class Conreality::Session
An authenticated session.
Attributes
The client connection this session belongs to.
@return [Client]
The session ID.
@return [Integer]
Public Class Methods
@param client [Client] @param id [Integer]
# File lib/conreality/session.rb, line 26 def initialize(client, id) @client, @id = client, id.to_i end
Public Instance Methods
@yield [action] @yieldparam action [Action] @yieldreturn [void] @return [void]
# File lib/conreality/session.rb, line 116 def _execute(&block) action = Action.new(self) if @client.connection.transaction_status.zero? # not yet in transaction scope @client.connection.transaction { |_| block.call(action) } else # already in transaction scope block.call(action) end end
TODO
@return [Game]
# File lib/conreality/session.rb, line 105 def game Game.new(self) end
Returns a developer-friendly representation of this session.
@return [String]
# File lib/conreality/session.rb, line 34 def inspect sprintf("#<%s:%#0x>", self.class.name, self.__id__) end
Terminates this session.
@return [void]
# File lib/conreality/session.rb, line 96 def logout! # TODO @client = nil end
Invokes the session-scoped `Ping` method on the server.
@return [void]
# File lib/conreality/session.rb, line 42 def ping @client.rpc_session.ping(RPC::PingRequest.new) end
Invokes the session-scoped `SendEvent` method on the server.
@param [String, to_s] predicate @param [Object] subject @param [Object] object @return [Event]
# File lib/conreality/session.rb, line 53 def send_event(predicate, subject, object) response = @client.rpc_session.send_event( RPC::SendEventRequest.new( session_id: @id, predicate: predicate, subject: subject, object: object, ) ) Event.new(self, response.id) end
Invokes the session-scoped `SendMessage` method on the server.
@param [String, to_s] text @return [Message]
# File lib/conreality/session.rb, line 70 def send_message(text) response = @client.rpc_session.send_message( RPC::SendMessageRequest.new( session_id: @id, text: text.to_s, ) ) Message.new(self, response.id) end
Invokes the session-scoped `UpdatePlayer` method on the server.
@return [void]
# File lib/conreality/session.rb, line 84 def update_player() @client.rpc_session.update_player( RPC::UpdatePlayerRequest.new( session_id: @id, ) ) end