teeworlds_network/lib/models/chat_message.rb

40 lines
771 B
Ruby
Raw Normal View History

2022-11-05 16:48:47 +00:00
# frozen_string_literal: true
2022-11-04 15:26:24 +00:00
class ChatMesage
attr_reader :mode, :client_id, :target_id, :message, :author
def initialize(data = {})
# @mode
# Type: Integer
@mode = data[:mode]
# @client_id
# Type: Integer
@client_id = data[:client_id]
# @target_id
# Type: Integer
@target_id = data[:target_id]
# @message
# Type: String
@message = data[:message]
# @author
# Type: Player see player.rb
@author = data[:author]
end
def to_s
# server message
return "*** #{@message}" if @client_id == -1
# player message
# should never be from an invalid id
# but lets not crash if servers send weird stuff
name = ''
name = @author.name if @author
"#{name}: #{@message}"
2022-11-04 15:26:24 +00:00
end
end