Initial commit

This commit is contained in:
Henri Burau
2024-06-03 18:07:27 +02:00
commit ca04cc51f3
43 changed files with 4440 additions and 0 deletions

44
services/capture.go Normal file
View 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
}