Module: RuneRb::Game::World::Gateway

Included in:
Instance
Defined in:
app/game/world/helpers/gateway.rb

Overview

Since:

  • 0.9.3

Instance Method Summary collapse

Instance Method Details

#receive(session) ⇒ Object

Receives a session and attempts to authorize the login attempt. If the session is valid, a Context entity is created and added to the <@entities> collection. If the session is invalid, an appropriate response is dispatched to the session before the connection is closed by the session.

Parameters:

Since:

  • 0.9.3


5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/game/world/helpers/gateway.rb', line 5

def receive(session)
  post(id: :RECEIVE_SESSION, priority: :HIGH, assets: [session, @entities[:players], self]) do |sess, players, world|
    if authorized?(sess) && players.values.none? { |player| player.session == sess }
      ctx = RuneRb::Game::Entity::Context.new(sess, RuneRb::Database::PlayerProfile.fetch_profile(sess.[:Credentials]), world)
      ctx.index = players.empty? ? 1 : players.keys.last + 1
      players[ctx.index] = ctx
      ctx.
      log RuneRb::GLOBAL[:COLOR].green("Registered new Context for #{RuneRb::GLOBAL[:COLOR].yellow(ctx.profile[:name].capitalize)}") if RuneRb::GLOBAL[:DEBUG]
      log RuneRb::GLOBAL[:COLOR].green("Welcome, #{RuneRb::GLOBAL[:COLOR].yellow.bold(ctx.profile[:name].capitalize)}!")
    end
  end
end

#release(context) ⇒ Object

Removes a context mob from the Instance#entities hash, then calls Context#logout on the specified mob to ensure a logout is performed.

Parameters:

Since:

  • 0.9.3


20
21
22
23
24
25
26
27
28
29
30
# File 'app/game/world/helpers/gateway.rb', line 20

def release(context)
  post(id: :RELEASE_CONTEXT, priority: :HIGH, assets: [@entities[:players], context]) do |players, ctx|
    # Remove the context from the entity list
    players.delete_if { |_idx, entity| ctx.session.id == entity.session.id }

    # Logout the context.
    ctx.logout if ctx.session.status[:auth] == :LOGGED_IN
    log RuneRb::GLOBAL[:COLOR].green.bold("Released Context for #{RuneRb::GLOBAL[:COLOR].yellow(context.profile[:name].capitalize)}") if RuneRb::GLOBAL[:DEBUG]
    log RuneRb::GLOBAL[:COLOR].magenta("See ya, #{RuneRb::GLOBAL[:COLOR].yellow(context.profile[:name].capitalize)}!")
  end
end