Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ A simple and customizable chat box that can format text, display images and emoj
- [OverrideCustomChatPlayerColor](#overridecustomchatplayercolor)
- [CustomChatBlockInput](#customchatblockinput)
- [CustomChatHideJoinMessage](#customchathidejoinmessage)
- [CustomChatPlayerInitialSpawn](#customchatplayerinitialspawn)
- [Contributing](#contributing)

## Features
Expand Down Expand Up @@ -77,6 +78,7 @@ By default, the chat box will only load pictures from trusted websites. You can
- [OverrideCustomChatPlayerColor](#overridecustomchatplayercolor)
- [CustomChatBlockInput](#customchatblockinput)
- [CustomChatHideJoinMessage](#customchathidejoinmessage)
- [CustomChatPlayerInitialSpawn](#customchatplayerinitialspawn)
- [PostPlayerSay](#postplayersay)

### CanEmbedCustomChat
Expand Down Expand Up @@ -176,6 +178,30 @@ You can return `true` on this hook to block the "open chat" button(s). It runs o

You can return `true` on this hook to dynamically prevent join/leave messages from showing up. It runs on the **client side**, and gives a `data` table as a argument, that contains the same keys given by the [player_connect_client](https://wiki.facepunch.com/gmod/gameevent/player_connect_client#members) hook.

### CustomChatPlayerInitialSpawn

Runs on the **server side** after a player's initial spawn data has been gathered and broadcast to clients. Useful for reacting to join events with full absence/load-time context.

Arguments:
- `ply` — the player entity
- `steamId` — the player's SteamID string
- `color` — the team `Color` assigned to the player at spawn time
- `absenceLength` — seconds since the player was last seen on this server (`0` for first-timers)
- `timeToSpawn` — seconds the player took to load into the server

```lua
hook.Add( "CustomChatPlayerInitialSpawn", "example", function( ply, steamId, color, absenceLength, timeToSpawn )
-- Example: print load time and absence to server console
print( ply:Nick() .. " took " .. math.Round( timeToSpawn ) .. "s to load" )

if absenceLength > 0 then
print( ply:Nick() .. " was last seen " .. math.Round( absenceLength ) .. "s ago" )
else
print( ply:Nick() .. " joined for the first time" )
end
end )
```

### PostPlayerSay

For getting the final contents of a chat message. Doesn't get ran if a message is blocked/edited away by PlayerSay
Expand Down
19 changes: 14 additions & 5 deletions lua/custom_chat/client/join_leave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ hook.Add( "player_disconnect", "CustomChat.ShowDisconnectMessages", function( da
chat.AddText( unpack( parts ) )
end, HOOK_LOW )

local function OnPlayerActivated( ply, steamId, name, color, absenceLength )
local function OnPlayerActivated( ply, steamId, name, color, absenceLength, timeToSpawn )
if ply:IsBot() and not JoinLeave.botConnectDisconnect then return end

-- Only use a player block if Custom Chat is enabled
Expand All @@ -115,6 +115,8 @@ local function OnPlayerActivated( ply, steamId, name, color, absenceLength )
}
end

local niceTimeToSpawn = CustomChat.NiceTime( math.Round( timeToSpawn ) )

-- Show a message if this player is a friend
if
CustomChat.GetConVarInt( "enable_friend_messages", 0 ) > 0 and
Expand All @@ -124,7 +126,8 @@ local function OnPlayerActivated( ply, steamId, name, color, absenceLength )
chat.AddText(
Color( 255, 255, 255 ), ":small_blue_diamond: " .. CustomChat.GetLanguageText( "friend_spawned1" ) .. " ",
color, name,
Color( 255, 255, 255 ), " " .. CustomChat.GetLanguageText( "friend_spawned2" )
Color( 255, 255, 255 ), " " .. CustomChat.GetLanguageText( "friend_spawned2" ),
Color( 150, 150, 150 ), " (" .. niceTimeToSpawn .. ")"
)
end

Expand All @@ -135,6 +138,8 @@ local function OnPlayerActivated( ply, steamId, name, color, absenceLength )
if absenceLength < 1 then
chat.AddText(
color, name,
Color( 150, 150, 150 ), " " .. CustomChat.GetLanguageText( "took" ),
Color( 200, 200, 200 ), " " .. niceTimeToSpawn,
Color( 150, 150, 150 ), " " .. CustomChat.GetLanguageText( "first_seen" )
)
return
Expand All @@ -148,6 +153,8 @@ local function OnPlayerActivated( ply, steamId, name, color, absenceLength )

chat.AddText(
color, name,
Color( 150, 150, 150 ), " " .. CustomChat.GetLanguageText( "took" ),
Color( 200, 200, 200 ), " " .. niceTimeToSpawn,
Color( 150, 150, 150 ), " " .. CustomChat.GetLanguageText( "last_seen1" ),
Color( 200, 200, 200 ), " " .. lastSeenTime,
Color( 150, 150, 150 ), " " .. CustomChat.GetLanguageText( "last_seen2" )
Expand All @@ -163,24 +170,26 @@ hook.Add( "NetworkEntityCreated", "CustomChat.HandlePlayerInitialSpawn", functio
if not data then return end

CustomChat.PlayerInitialSpawnWaiting[steamId] = nil
OnPlayerActivated( ent, steamId, data.name, data.color, data.absenceLength )
OnPlayerActivated( ent, steamId, data.name, data.color, data.absenceLength, data.timeToSpawn )
end )

net.Receive( "customchat.player_spawned", function()
local steamId = net.ReadString()
local name = net.ReadString()
local color = net.ReadColor( false )
local absenceLength = net.ReadFloat()
local timeToSpawn = net.ReadFloat()

local ply = player.GetBySteamID( steamId )
if IsValid( ply ) then
OnPlayerActivated( ply, steamId, name, color, absenceLength )
OnPlayerActivated( ply, steamId, name, color, absenceLength, timeToSpawn )
return
end

CustomChat.PlayerInitialSpawnWaiting[steamId] = {
name = name,
color = color,
absenceLength = absenceLength
absenceLength = absenceLength,
timeToSpawn = timeToSpawn
}
end )
22 changes: 22 additions & 0 deletions lua/custom_chat/server/player_spawn.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
util.AddNetworkString( "customchat.player_spawned" )

local connectingSteamIDs = {}
gameevent.Listen( "player_connect" )
hook.Add( "player_connect", "CustomChat.TrackConnectingPlayers", function( data )
local steamId = data.networkid
connectingSteamIDs[steamId] = SysTime()
end )

gameevent.Listen( "player_disconnect" )
hook.Add( "player_disconnect", "CustomChat.TrackDisconnectingPlayers", function( data )
local steamId = data.networkid
connectingSteamIDs[steamId] = nil
end )

hook.Add( "PlayerInitialSpawn", "CustomChat.BroadcastInitialSpawn", function( ply )
-- Give some time for other addons to assign the team
timer.Simple( 3, function()
Expand All @@ -18,12 +31,21 @@ hook.Add( "PlayerInitialSpawn", "CustomChat.BroadcastInitialSpawn", function( pl

CustomChat:SetLastSeen( steamId, time )

local timeToSpawn = 0
if connectingSteamIDs[steamId] then
local connectTime = connectingSteamIDs[steamId]
timeToSpawn = SysTime() - connectTime
end

net.Start( "customchat.player_spawned", false )
net.WriteString( steamId )
net.WriteString( ply:Nick() )
net.WriteColor( color, false )
net.WriteFloat( absenceLength )
net.WriteFloat( timeToSpawn )
net.Broadcast()

hook.Run( "CustomChatPlayerInitialSpawn", ply, steamId, color, absenceLength, timeToSpawn )
end )
end, HOOK_LOW )

Expand Down
5 changes: 3 additions & 2 deletions resource/localization/en/custom_chat.properties
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ custom_chat.server_theme.remove=Remove
custom_chat.server_theme.tip=This action will force all players (including those who join later) to use this theme. Are you sure?
custom_chat.friend_spawned1=Your friend
custom_chat.friend_spawned2=has spawned in.
custom_chat.last_seen1=spawned in, last played
custom_chat.first_seen=joined for the first time.
custom_chat.took=took
custom_chat.last_seen1=to load, last played
custom_chat.first_seen=to load, joined for the first time.
custom_chat.time.years=years
custom_chat.time.months=months
custom_chat.time.weeks=weeks
Expand Down
5 changes: 3 additions & 2 deletions resource/localization/pt-br/custom_chat.properties
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ custom_chat.server_theme.remove=Remover
custom_chat.server_theme.tip=Esta ação forçará todos os jogadores (incluindo aqueles que entrarem depois) a usar este tema. Tem certeza?
custom_chat.friend_spawned1=Seu amigo
custom_chat.friend_spawned2=acabou de aparecer aqui.
custom_chat.last_seen1=apareceu, jogou pela última vez há
custom_chat.first_seen=entrou pela primeira vez.
custom_chat.took=levou
custom_chat.last_seen1=para carregar, jogou pela última vez há
custom_chat.first_seen=para carregar, entrou pela primeira vez.
custom_chat.time.years=anos
custom_chat.time.months=meses
custom_chat.time.weeks=semanas
Expand Down
5 changes: 3 additions & 2 deletions resource/localization/ru/custom_chat.properties
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ custom_chat.server_theme.remove=Удалить
custom_chat.server_theme.tip=Это действие заставит всех игроков (включая тех, кто зайдёт позже) использовать эту тему. Вы уверены?
custom_chat.friend_spawned1=Ваш друг
custom_chat.friend_spawned2=загрузился.
custom_chat.last_seen1=загрузился, заходил последний раз
custom_chat.first_seen=зашёл в первый раз.
custom_chat.took=загружался
custom_chat.last_seen1=, заходил последний раз
custom_chat.first_seen=, зашёл в первый раз.
custom_chat.time.years=г.
custom_chat.time.months=мес.
custom_chat.time.weeks=нед.
Expand Down
5 changes: 3 additions & 2 deletions resource/localization/tr/custom_chat.properties
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ custom_chat.server_theme.remove=Kaldır
custom_chat.server_theme.tip=Bu işlem, tüm oyuncuları (daha sonra katılanlar dahil) bu temayı kullanmaya zorlayacaktır. Emin misiniz?
custom_chat.friend_spawned1=Arkadaşın
custom_chat.friend_spawned2=burada.
custom_chat.last_seen1=doğdu, en son
custom_chat.first_seen=ilk kez katıldı.
custom_chat.took=yüklendi
custom_chat.last_seen1=sürede, en son
custom_chat.first_seen=sürede, ilk kez katıldı.
custom_chat.time.years=yıl
custom_chat.time.months=aylar
custom_chat.time.weeks=hafta
Expand Down
Loading