Initial commit
This commit is contained in:
44
services/capture.go
Normal file
44
services/capture.go
Normal file
@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user