Class: Conreality::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/conreality/session.rb

Overview

An authenticated session.

Instance Attribute Summary collapse

Action execution collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, id) ⇒ Session

Returns a new instance of Session.

Parameters:

  • client (Client)
  • id (Integer)


26
27
28
# File 'lib/conreality/session.rb', line 26

def initialize(client, id)
  @client, @id = client, id.to_i
end

Instance Attribute Details

#clientClient (readonly)

The client connection this session belongs to.

Returns:



15
16
17
# File 'lib/conreality/session.rb', line 15

def client
  @client
end

#idInteger (readonly)

The session ID.

Returns:

  • (Integer)


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.

Yields:

  • (action)

Yield Parameters:

Yield Returns:

  • (void)


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

#gameGame

TODO

Returns:



105
106
107
# File 'lib/conreality/session.rb', line 105

def game
  Game.new(self)
end

#inspectString

Returns a developer-friendly representation of this session.

Returns:

  • (String)


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

#pingvoid

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.

Parameters:

  • predicate (String, #to_s)
  • subject (Object)
  • object (Object)

Returns:



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.

Parameters:

  • text (String, #to_s)

Returns:



70
71
72
73
74
75
76
77
78
# 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

#update_playervoid

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