79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
package services
|
|
|
|
import (
|
|
"api/globals"
|
|
"api/models"
|
|
"api/utils"
|
|
"time"
|
|
)
|
|
|
|
func VerifyTransmissionsLimits() {
|
|
// log.Println("Verificando")
|
|
for channelname, currentTransmission := range globals.Transmissions {
|
|
// If the channel has no daily transmission limit, skip the verification (Channels with 24 hours daily limit)
|
|
if time.Duration(currentTransmission.LimiteDiario) == 1440 {
|
|
continue
|
|
}
|
|
|
|
// AddTransmissionlog(channelname, "Verificando expiração de transmissão")
|
|
|
|
// TODO: Implementar verificação de limite de transmissão diária (ou seja, quanto já foi transmitido HOJE)
|
|
if time.Now().After(currentTransmission.Limite) {
|
|
// AddTransmissionlog(channelname, "Limite de transmissão diária atingido")
|
|
utils.KickSession(channelname, currentTransmission.SessionID)
|
|
}
|
|
}
|
|
}
|
|
|
|
func VerifyTransmissionAuthorization(channelname, sessionid, transmissionkey, playerKey string) (bool, models.CurrentTransmission) {
|
|
var (
|
|
channel models.Canal
|
|
|
|
currentTransmission models.CurrentTransmission
|
|
)
|
|
|
|
globals.DB.Where("nome = ?", channelname).First(&channel)
|
|
|
|
currentTransmission.Canal = channel.Nome
|
|
currentTransmission.SessionID = sessionid
|
|
currentTransmission.Chave = transmissionkey
|
|
currentTransmission.LimiteDiario = channel.LimiteDiario
|
|
currentTransmission.Inicio = time.Now()
|
|
|
|
currentTransmission.Limite = currentTransmission.Inicio.Add(time.Duration(channel.LimiteDiario) * time.Hour)
|
|
|
|
// If the channel is not found, kick the session
|
|
if channel.ID == 0 {
|
|
// AddTransmissionlog(channelname, "Canal inexistente")
|
|
utils.KickSession(channelname, sessionid)
|
|
return false, currentTransmission
|
|
}
|
|
|
|
// If the channel expiration date is reached, kick the session
|
|
if time.Now().After(channel.Validade) {
|
|
// AddTransmissionlog(channelname, "Canal com data de expiração vencida")
|
|
utils.KickSession(channelname, sessionid)
|
|
return false, currentTransmission
|
|
}
|
|
|
|
// // If the channel is not active, kick the session
|
|
// if channel.Status != "A" {
|
|
// AddTransmissionlog(channelname, "Canal não está ativo")
|
|
// utils.KickSession(channelname, sessionid)
|
|
// return false, currentTransmission
|
|
// }
|
|
|
|
// If the transmission key does not match, kick the session
|
|
if transmissionkey != channel.Chave {
|
|
// AddTransmissionlog(channelname, "Transmissão com chave de transmissão errada")
|
|
utils.KickSession(channelname, sessionid)
|
|
return false, currentTransmission
|
|
}
|
|
|
|
// TODO: Save the transmission on database for future calculation of remaining daily time
|
|
|
|
globals.Transmissions[channelname] = ¤tTransmission
|
|
|
|
return true, currentTransmission
|
|
}
|