Class: GameMachine::Endpoints::UdpOutgoing

Inherits:
Actor::Base
  • Object
show all
Defined in:
lib/game_machine/endpoints/udp_outgoing.rb

Constant Summary

Constants inherited from Actor::Base

Actor::Base::ON_RECEIVE_HOOKS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Actor::Base

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 5

def client
  @client
end

#client_connectionObject (readonly)

Returns the value of attribute client_connection.



5
6
7
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 5

def client_connection
  @client_connection
end

#player_idObject (readonly)

Returns the value of attribute player_id.



5
6
7
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 5

def player_id
  @player_id
end

#protocolObject (readonly)

Returns the value of attribute protocol.



5
6
7
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 5

def protocol
  @protocol
end

#serverObject (readonly)

Returns the value of attribute server.



5
6
7
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 5

def server
  @server
end

Instance Method Details

#create_client_messageObject



22
23
24
25
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 22

def create_client_message
  client_message = MessageLib::ClientMessage.new
  client_message.set_client_connection(client_connection)
end

#on_receive(message) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 43

def on_receive(message)
  #GameMachine.logger.info "Sending message to player"
  client_message = create_client_message
  message.set_send_to_player(false)
  client_message.add_entity(message)
  send_to_client(client_message)
end

#post_init(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 6

def post_init(*args)
  @client_connection = args[0]
  @client = args[1]
  @server = args[2]
  @player_id = args[3]
  @protocol = args[4]
  send_connected_message
  GameMachine.logger.info "Player gateway created #{player_id}"
end

#send_connected_messageObject



16
17
18
19
20
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 16

def send_connected_message
  client_message = create_client_message
  client_message.set_player_connected(MessageLib::PlayerConnected.new)
  send_to_client(client_message)
end

#send_to_client(message) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/game_machine/endpoints/udp_outgoing.rb', line 27

def send_to_client(message)
  #GameMachine.logger.info("Sending #{message} out via #{protocol}")
  if protocol == 0
    bytes = message.to_byte_array
    server.sendToClient(
      client[:address],
      bytes,
      client[:ctx]
    )
  else
    client[:ctx].write(message)
    client[:ctx].flush
    JavaLib::UdpServerHandler.countOut.incrementAndGet
  end
end