forked from CFC-Servers/cfc_chat_transit
Add player counting logic
This commit is contained in:
parent
a01fd1cbc8
commit
2c7b85120f
@ -6,7 +6,7 @@ include "cfc_chat_transit/server/avatar_service.lua"
|
||||
|
||||
import Read from file
|
||||
import GetColor from team
|
||||
import TableToJSON from util
|
||||
import JSONToTable, TableToJSON from util
|
||||
|
||||
logger = ChatTransit.Logger
|
||||
relayPort = CreateConVar "cfc_relay_port", "", FCVAR_NONE
|
||||
@ -67,6 +67,17 @@ ChatTransit.guard = (f) -> (...) ->
|
||||
|
||||
return nil
|
||||
|
||||
ChatTransit.getPlayerCount = (cb) ->
|
||||
fail = -> cb player\GetCount!
|
||||
|
||||
success = (body) ->
|
||||
count = JSONToTable body
|
||||
return fail! unless count
|
||||
|
||||
cb count.player_count
|
||||
|
||||
http.Fetch "https://nanny.cfcservers.org/cfc3-status", success, fail
|
||||
|
||||
logger\info "Loading modules..."
|
||||
for f in *file.Find "cfc_chat_transit/server/modules/*.lua", "LUA"
|
||||
logger\info "Loading modules/#{f}"
|
||||
|
@ -1,4 +1,4 @@
|
||||
import guard from ChatTransit
|
||||
import getPlayerCount, guard from ChatTransit
|
||||
import SteamIDTo64 from util
|
||||
-- TODO: Send a preliminary avatarservice link that will be backfilled when they fully connect
|
||||
|
||||
@ -8,13 +8,14 @@ ChatTransit.PlayerConnect = (data) =>
|
||||
bot = tobool bot
|
||||
steamId = nil if bot
|
||||
|
||||
@Send
|
||||
Type: "connect"
|
||||
Data:
|
||||
SteamName: name
|
||||
SteamId: steamId and SteamIDTo64 steamId
|
||||
PlayerCountCurrent: player\GetCount! + 1
|
||||
PlayerCountMax: game\MaxPlayers!
|
||||
getPlayerCount (count) ->
|
||||
@Send
|
||||
Type: "connect"
|
||||
Data:
|
||||
SteamName: name
|
||||
SteamId: steamId and SteamIDTo64 steamId
|
||||
PlayerCountCurrent: count
|
||||
PlayerCountMax: game\MaxPlayers!
|
||||
|
||||
ChatTransit.PlayerInitialSpawn = (ply) =>
|
||||
@Send
|
||||
|
@ -1,4 +1,4 @@
|
||||
import guard from ChatTransit
|
||||
import getPlayerCount, guard from ChatTransit
|
||||
import GetBySteamID from player
|
||||
import SteamIDTo64 from util
|
||||
|
||||
@ -7,14 +7,15 @@ ChatTransit.PlayerDisconnected = (data) =>
|
||||
|
||||
ply = GetBySteamID steamId
|
||||
|
||||
@Send
|
||||
Type: "disconnect"
|
||||
Data:
|
||||
SteamName: ply and ply\Nick! or name
|
||||
SteamId: ply and ply\SteamID64! or SteamIDTo64 steamId
|
||||
PlayerCountCurrent: player\GetCount! - 1
|
||||
PlayerCountMax: game\MaxPlayers!
|
||||
Content: reason
|
||||
getPlayerCount (count) ->
|
||||
@Send
|
||||
Type: "disconnect"
|
||||
Data:
|
||||
SteamName: ply and ply\Nick! or name
|
||||
SteamId: ply and ply\SteamID64! or SteamIDTo64 steamId
|
||||
PlayerCountCurrent: count
|
||||
PlayerCountMax: game\MaxPlayers!
|
||||
Content: reason
|
||||
|
||||
gameevent.Listen "player_disconnect"
|
||||
hook.Add "player_disconnect", "CFC_ChatTransit_DisconnectListener", guard ChatTransit\PlayerDisconnected
|
||||
|
Loading…
Reference in New Issue
Block a user