45 lines
1004 B
Go
45 lines
1004 B
Go
package services
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitea.henriburau.de/haw-lan/cod4watcher/models"
|
|
)
|
|
|
|
type CaptureService struct {
|
|
}
|
|
|
|
var captures = []models.Capture{
|
|
{Id: 1, Host: "80.57.28.137", Port: "28960", Active: true, Name: "Gungame HAW-LAN 11", Start: time.Now().Add(-1 * time.Hour)},
|
|
{Id: 1, Host: "80.57.28.137", Port: "28960", Active: true, Name: "Gungame HAW-LAN 12", Start: time.Now().Add(-5 * time.Minute)},
|
|
}
|
|
|
|
func (cs *CaptureService) GetActiveCapures() ([]models.Capture, error) {
|
|
|
|
return captures, nil
|
|
}
|
|
|
|
func (cs *CaptureService) GetCaptureById(id int) (*models.Capture, error) {
|
|
capture := captures[0]
|
|
server, err := models.NewCOD4ServerStatus(capture.Host, capture.Port, time.Second)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
status, err := server.GetServerStatus()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
capture.MapScores = []models.MapScore{
|
|
{
|
|
Id: 0,
|
|
StartTime: status.MapStartTime,
|
|
Map: status.MapName,
|
|
ScoreList: status.Score,
|
|
},
|
|
}
|
|
|
|
return &capture, nil
|
|
}
|