Class: Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr = {}) ⇒ Client

Returns a new instance of Client.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/teeworlds_server.rb', line 21

def initialize(attr = {})
  @id = attr[:id]
  @addr = attr[:addr]
  @vital_sent = 0
  @ack = 0
  @in_game = false
  @last_recv_time = Time.now
  @player = Player.new(
    id: @id,
    local: 0,
    team: 0,
    name: '(connecting)',
    clan: '',
    country: -1
  )
  @token = attr[:token]
  SecurityToken.validate(@token)
end

Instance Attribute Details

#ackObject (readonly)

Returns the value of attribute ack.



19
20
21
# File 'lib/teeworlds_server.rb', line 19

def ack
  @ack
end

#addrObject

Returns the value of attribute addr.



18
19
20
# File 'lib/teeworlds_server.rb', line 18

def addr
  @addr
end

#idObject

Returns the value of attribute id.



18
19
20
# File 'lib/teeworlds_server.rb', line 18

def id
  @id
end

#in_gameObject

Returns the value of attribute in_game.



18
19
20
# File 'lib/teeworlds_server.rb', line 18

def in_game
  @in_game
end

#last_recv_timeObject

Returns the value of attribute last_recv_time.



18
19
20
# File 'lib/teeworlds_server.rb', line 18

def last_recv_time
  @last_recv_time
end

#playerObject

Returns the value of attribute player.



18
19
20
# File 'lib/teeworlds_server.rb', line 18

def player
  @player
end

#tokenObject

Returns the value of attribute token.



18
19
20
# File 'lib/teeworlds_server.rb', line 18

def token
  @token
end

#vital_sentObject

Returns the value of attribute vital_sent.



18
19
20
# File 'lib/teeworlds_server.rb', line 18

def vital_sent
  @vital_sent
end

Instance Method Details

#bump_ackObject



44
45
46
# File 'lib/teeworlds_server.rb', line 44

def bump_ack
  @ack = (@ack + 1) % NET_MAX_SEQUENCE
end

#in_game?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/teeworlds_server.rb', line 40

def in_game?
  @in_game
end

#seqObject

TODO: use or remove

not sure if its cool
one can make vital_sent read only
and then the seq reader increments it
so everytime a header is created
the chunk builder just calls
seq = client.seq


55
56
57
# File 'lib/teeworlds_server.rb', line 55

def seq
  @vital_sent + 1
end