mirror of
https://github.com/indig0fox/Arma3-AttendanceTracker.git/
synced 2025-12-08 09:51:47 -06:00
1.1.0 - bump a3interface & refactor to new api
This commit is contained in:
Binary file not shown.
@@ -57,8 +57,35 @@ var (
|
||||
func init() {
|
||||
|
||||
a3interface.SetVersion(EXTENSION_VERSION)
|
||||
a3interface.RegisterRvExtensionChannels(RVExtensionChannels)
|
||||
a3interface.RegisterRvExtensionArgsChannels(RVExtensionArgsChannels)
|
||||
a3interface.NewRegistration(":START:").
|
||||
SetDefaultResponse(`["Extension beginning init process"]`).
|
||||
SetFunction(onStartCommand).
|
||||
SetRunInBackground(true).
|
||||
Register()
|
||||
|
||||
a3interface.NewRegistration(":MISSION:HASH:").
|
||||
SetDefaultResponse(`["Retrieving mission hash"]`).
|
||||
SetFunction(onMissionHashCommand).
|
||||
SetRunInBackground(true).
|
||||
Register()
|
||||
|
||||
a3interface.NewRegistration(":GET:SETTINGS:").
|
||||
SetDefaultResponse(`["Retrieving settings"]`).
|
||||
SetFunction(onGetSettingsCommand).
|
||||
SetRunInBackground(true).
|
||||
Register()
|
||||
|
||||
a3interface.NewRegistration(":LOG:MISSION:").
|
||||
SetDefaultResponse(`["Logging mission data"]`).
|
||||
SetArgsFunction(onLogMissionArgsCommand).
|
||||
SetRunInBackground(true).
|
||||
Register()
|
||||
|
||||
a3interface.NewRegistration(":LOG:PRESENCE:").
|
||||
SetDefaultResponse(`["Logging presence data"]`).
|
||||
SetArgsFunction(onLogPresenceArgsCommand).
|
||||
SetRunInBackground(true).
|
||||
Register()
|
||||
|
||||
go func() {
|
||||
var err error
|
||||
@@ -126,8 +153,6 @@ func init() {
|
||||
logger.Log.Error().Err(err).Msgf(`Error migrating database schema`)
|
||||
}
|
||||
|
||||
startA3CallHandlers()
|
||||
|
||||
initSuccess = true
|
||||
a3interface.WriteArmaCallback(
|
||||
EXTENSION_NAME,
|
||||
@@ -138,56 +163,82 @@ func init() {
|
||||
}()
|
||||
}
|
||||
|
||||
func startA3CallHandlers() error {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-RVExtensionChannels[":START:"]:
|
||||
logger.Log.Trace().Msgf(`RVExtension :START: requested`)
|
||||
if !initSuccess {
|
||||
logger.Log.Warn().Msgf(`Received another :START: command before init was complete, ignoring.`)
|
||||
continue
|
||||
} else {
|
||||
logger.RotateLogs()
|
||||
a3interface.WriteArmaCallback(
|
||||
EXTENSION_NAME,
|
||||
":READY:",
|
||||
)
|
||||
}
|
||||
case <-RVExtensionChannels[":MISSION:HASH:"]:
|
||||
logger.Log.Trace().Msgf(`RVExtension :MISSION:HASH: requested`)
|
||||
timestamp, hash := getMissionHash()
|
||||
a3interface.WriteArmaCallback(
|
||||
EXTENSION_NAME,
|
||||
":MISSION:HASH:",
|
||||
timestamp,
|
||||
hash,
|
||||
)
|
||||
case <-RVExtensionChannels[":GET:SETTINGS:"]:
|
||||
logger.Log.Trace().Msg(`Settings requested`)
|
||||
armaConfig, err := util.ConfigArmaFormat()
|
||||
if err != nil {
|
||||
logger.Log.Error().Err(err).Msg(`Error when marshaling arma config`)
|
||||
continue
|
||||
}
|
||||
logger.Log.Trace().Str("armaConfig", armaConfig).Send()
|
||||
a3interface.WriteArmaCallback(
|
||||
EXTENSION_NAME,
|
||||
":GET:SETTINGS:",
|
||||
armaConfig,
|
||||
)
|
||||
case v := <-RVExtensionArgsChannels[":LOG:MISSION:"]:
|
||||
go func(data []string) {
|
||||
writeWorldInfo(v[1])
|
||||
writeMission(v[0])
|
||||
}(v)
|
||||
case v := <-RVExtensionArgsChannels[":LOG:PRESENCE:"]:
|
||||
go writeAttendance(v[0])
|
||||
}
|
||||
}
|
||||
}()
|
||||
func onStartCommand(
|
||||
ctx a3interface.ArmaExtensionContext,
|
||||
data string,
|
||||
) (string, error) {
|
||||
logger.Log.Trace().Msgf(`RVExtension :START: requested`)
|
||||
if !initSuccess {
|
||||
logger.Log.Warn().Msgf(`Received another :START: command before init was complete, ignoring.`)
|
||||
return "Initing!", nil
|
||||
} else {
|
||||
logger.RotateLogs()
|
||||
a3interface.WriteArmaCallback(
|
||||
EXTENSION_NAME,
|
||||
":READY:",
|
||||
)
|
||||
return "Ready!", nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
func onMissionHashCommand(
|
||||
ctx a3interface.ArmaExtensionContext,
|
||||
data string,
|
||||
) (string, error) {
|
||||
logger.Log.Trace().Msgf(`RVExtension :MISSION:HASH: requested`)
|
||||
timestamp, hash := getMissionHash()
|
||||
a3interface.WriteArmaCallback(
|
||||
EXTENSION_NAME,
|
||||
":MISSION:HASH:",
|
||||
timestamp,
|
||||
hash,
|
||||
)
|
||||
return fmt.Sprintf(
|
||||
`[%q, %q]`,
|
||||
timestamp,
|
||||
hash,
|
||||
), nil
|
||||
}
|
||||
|
||||
func onGetSettingsCommand(
|
||||
ctx a3interface.ArmaExtensionContext,
|
||||
data string,
|
||||
) (string, error) {
|
||||
logger.Log.Trace().Msg(`Settings requested`)
|
||||
armaConfig, err := util.ConfigArmaFormat()
|
||||
if err != nil {
|
||||
logger.Log.Error().Err(err).Msg(`Error when marshaling arma config`)
|
||||
return "", err
|
||||
}
|
||||
logger.Log.Trace().Str("armaConfig", armaConfig).Send()
|
||||
a3interface.WriteArmaCallback(
|
||||
EXTENSION_NAME,
|
||||
":GET:SETTINGS:",
|
||||
armaConfig,
|
||||
)
|
||||
return armaConfig, nil
|
||||
}
|
||||
|
||||
func onLogMissionArgsCommand(
|
||||
ctx a3interface.ArmaExtensionContext,
|
||||
command string,
|
||||
args []string,
|
||||
) (string, error) {
|
||||
go func(data []string) {
|
||||
writeWorldInfo(data[1])
|
||||
writeMission(data[0])
|
||||
}(args)
|
||||
|
||||
return `["Logging mission data"]`, nil
|
||||
}
|
||||
|
||||
func onLogPresenceArgsCommand(
|
||||
ctx a3interface.ArmaExtensionContext,
|
||||
command string,
|
||||
args []string,
|
||||
) (string, error) {
|
||||
go writeAttendance(args[0])
|
||||
return `["Logging presence data"]`, nil
|
||||
}
|
||||
|
||||
// getMissionHash will return the current time in UTC and an md5 hash of that time
|
||||
|
||||
@@ -4,7 +4,7 @@ go 1.20
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/indig0fox/a3go v0.2.0
|
||||
github.com/indig0fox/a3go v0.3.1
|
||||
github.com/rs/zerolog v1.30.0
|
||||
github.com/spf13/viper v1.16.0
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||
|
||||
@@ -127,8 +127,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/indig0fox/a3go v0.2.0 h1:2r1fyUePCH9KLMBzVXBigkQT2zS39mpHZAm5egmIrNk=
|
||||
github.com/indig0fox/a3go v0.2.0/go.mod h1:8htVwBiIAVKpT1Jyb+5dm7GuLAAevTXgw7UKxSlOawY=
|
||||
github.com/indig0fox/a3go v0.3.1 h1:T1UxVrk7oicM5djyID+ppNuTc+0pEGbbGWS466eS29k=
|
||||
github.com/indig0fox/a3go v0.3.1/go.mod h1:8htVwBiIAVKpT1Jyb+5dm7GuLAAevTXgw7UKxSlOawY=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
|
||||
Reference in New Issue
Block a user