Class: GameMachine::GameSystems::ChatManager

Inherits:
Actor::Base
  • Object
show all
Includes:
Commands
Defined in:
server/lib/game_machine/game_systems/chat_manager.rb

Overview

Note:

All chat system requests go through the ChatManager Chat can be topic based or private player to player messages Topics are automatically created by the first player to send a join request to a topic that does not already exist.

Chat topic channels are distributed across the cluster, and guaranteed to be delivered.

Constant Summary

Constants inherited from Actor::Base

Actor::Base::ON_RECEIVE_HOOKS

Instance Method Summary collapse

Methods included from Commands

#commands

Methods inherited from Actor::Base

aspect, aspects, find, find_by_address, find_distributed, find_distributed_local, find_remote, hashring, local_path, logger, model_filter, #onReceive, player_controller, #receive_message, #schedule_message, #schedule_message_once, #sender, set_player_controller

Instance Method Details

#define_update_procsObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'server/lib/game_machine/game_systems/chat_manager.rb', line 24

def define_update_procs
  commands.datastore.define_dbproc(:chat_remove_subscriber) do |id,current_entity,update_entity|
    if current_entity.nil?
      current_entity = MessageLib::Entity.new.set_id(id)
    end

    if current_entity.subscribers
      if subscriber_id_list = current_entity.subscribers.get_subscriber_id_list.to_a
        current_entity.subscribers.set_subscriber_id_list(nil)
        subscriber_id_list.each do |name|
          unless name == update_entity.id
            current_entity.subscribers.add_subscriber_id(name)
          end
        end
      end
    end
    current_entity
  end

  commands.datastore.define_dbproc(:chat_add_subscriber) do |id,current_entity,update_entity|
    if current_entity.nil?
      current_entity = MessageLib::Entity.new.set_id(id)
    end

    unless current_entity.subscribers
      current_entity.set_subscribers(MessageLib::Subscribers.new)
    end

    subscriber_id_list = current_entity.subscribers.get_subscriber_id_list.to_a
    unless subscriber_id_list.include?(update_entity.id)
      current_entity.subscribers.add_subscriber_id(update_entity.id)
    end
    current_entity
  end
end

#on_receive(message) ⇒ Object


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'server/lib/game_machine/game_systems/chat_manager.rb', line 65

def on_receive(message)
  if message.is_a?(MessageLib::ChatDestroy)
    if @chat_actors.has_key?(message.player_id)
      ask_child(message.player_id,message)
      destroy_child(message.player_id)
    end
    return
  end

  if message.chat_invite
    send_invite(message.chat_invite)
  elsif message.chat_register
    unless @chat_actors.has_key?(message.chat_register.chat_id)
      create_child(message.chat_register.chat_id,message.chat_register.register_as)
    end
  else
    unless @chat_actors.has_key?(message.player.id)
      create_child(message.player.id)

      # Give it a second or the message will be lost
      sleep 1
    end
    forward_chat_request(message.player.id,message)
  end
end

#post_init(*args) ⇒ Object


60
61
62
63
# File 'server/lib/game_machine/game_systems/chat_manager.rb', line 60

def post_init(*args)
  @chat_actors = {}
  define_update_procs
end