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
|
2022-11-20 09:13:07 +00:00
|
|
|
# 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
|