Class: Conreality::Session
- Inherits:
-
Object
- Object
- Conreality::Session
- Defined in:
- lib/conreality/session.rb
Overview
An authenticated session.
Instance Attribute Summary collapse
-
#client ⇒ Client
readonly
The client connection this session belongs to.
-
#id ⇒ Integer
readonly
The session ID.
Action execution collapse
Instance Method Summary collapse
-
#game ⇒ Game
TODO.
-
#initialize(client, id) ⇒ Session
constructor
A new instance of Session.
-
#inspect ⇒ String
Returns a developer-friendly representation of this session.
-
#logout! ⇒ void
Terminates this session.
-
#ping ⇒ void
Invokes the session-scoped ‘Ping` method on the server.
-
#send_event(predicate, subject, object) ⇒ Event
Invokes the session-scoped ‘SendEvent` method on the server.
-
#send_message(text) ⇒ Message
Invokes the session-scoped ‘SendMessage` method on the server.
-
#update_player ⇒ void
Invokes the session-scoped ‘UpdatePlayer` method on the server.
Constructor Details
#initialize(client, id) ⇒ Session
Returns a new instance of Session.
26 27 28 |
# File 'lib/conreality/session.rb', line 26 def initialize(client, id) @client, @id = client, id.to_i end |
Instance Attribute Details
#client ⇒ Client (readonly)
The client connection this session belongs to.
15 16 17 |
# File 'lib/conreality/session.rb', line 15 def client @client end |
#id ⇒ Integer (readonly)
The session ID.
21 22 23 |
# File 'lib/conreality/session.rb', line 21 def id @id end |
Instance Method Details
#_execute {|action| ... } ⇒ void
This method returns an undefined value.
116 117 118 119 120 121 122 123 124 125 |
# 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 |
#game ⇒ Game
TODO
105 106 107 |
# File 'lib/conreality/session.rb', line 105 def game Game.new(self) end |
#inspect ⇒ String
Returns a developer-friendly representation of this session.
34 35 36 |
# File 'lib/conreality/session.rb', line 34 def inspect sprintf("#<%s:%#0x>", self.class.name, self.__id__) end |
#logout! ⇒ void
This method returns an undefined value.
Terminates this session.
96 97 98 99 |
# File 'lib/conreality/session.rb', line 96 def logout! # TODO @client = nil end |
#ping ⇒ void
This method returns an undefined value.
Invokes the session-scoped ‘Ping` method on the server.
42 43 44 |
# File 'lib/conreality/session.rb', line 42 def ping @client.rpc_session.ping(RPC::PingRequest.new) end |
#send_event(predicate, subject, object) ⇒ Event
Invokes the session-scoped ‘SendEvent` method on the server.
53 54 55 56 57 58 59 60 61 62 63 |
# 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 |
#send_message(text) ⇒ Message
Invokes the session-scoped ‘SendMessage` method on the server.
70 71 72 73 74 75 76 77 78 |
# File 'lib/conreality/session.rb', line 70 def (text) response = @client.rpc_session.( RPC::SendMessageRequest.new( session_id: @id, text: text.to_s, ) ) Message.new(self, response.id) end |
#update_player ⇒ void
This method returns an undefined value.
Invokes the session-scoped ‘UpdatePlayer` method on the server.
84 85 86 87 88 89 90 |
# File 'lib/conreality/session.rb', line 84 def update_player() @client.rpc_session.update_player( RPC::UpdatePlayerRequest.new( session_id: @id, ) ) end |