Skip to content
Permalink
Browse files

Merge pull request #438 from cj123/live-timing-join-link

Live timing join link
  • Loading branch information...
Hecrer committed Jul 26, 2019
2 parents 59c5b2c + 8448f06 commit 76fe58ef2747cb76c2502863b92c5b1f3bc69373
@@ -96,6 +96,10 @@ func (dummyServerProcess) Done() <-chan struct{} {
return nil
}

func (dummyServerProcess) GetServerConfig() ServerConfig {
return ConfigIniDefault
}

var championshipEventFixtures = []string{
"barbagello.db",
"red-bull-ring.db",
@@ -32,6 +32,7 @@
{{ end }}
{{ define "content" }}
{{ $CMJoinLink := .CMJoinLink }}
{{ with .RaceDetails }}
<div class="race-control-event-info">
{{ range $sessionName, $session := .RaceConfig.Sessions }}
@@ -41,6 +42,10 @@
<br>
<small class="mr-1" data-toggle="tooltip" title="{{ .EntryList.Entrants }}" >{{ len .EntryList }} <i class="fa fa-user"></i></small>
<br>
{{ with $CMJoinLink }} <a id="cm-join-link" href="{{ . }}" class="btn btn-success btn-sm mt-1">Join</a> {{ end }}
</div>
<div class="race-control-weather-info">
@@ -163,6 +163,7 @@ type GlobalServerConfig struct {
UseShortenedDriverNames int `ini:"-" input:"checkbox" help:"When on, this option will make Server Manager hide driver's last names, for example 'John Smith' becomes 'John S.'"`
EnableContentManagerWrapper int `ini:"-" input:"checkbox" help:"When on, this option makes Server Manager provide extra information to Content Manager. This includes more detail about connected clients, event descriptions and download links. A side-effect of this is that your server name will contain a new piece of information (an 'i' character followed by a port - which Content Manager requires). Also - if enabled - this wrapper uses a GeoIP functionality provided by <a href='https://freegeoip.app''>freegeoip.app</a>."`
ContentManagerWrapperPort int `ini:"-" min:"0" max:"65535" help:"The port on which to serve Content Manager with the above information. Please make sure this port is open on your firewall."`
ShowContentManagerJoinLink int `ini:"-" input:"checkbox" help:"When on, this option will make Server Manager display Content Manager join links on the Live Timing page."`
}

type CurrentRaceConfig struct {
@@ -3,25 +3,26 @@ package servermanager
// ConfigIniDefault is the default server config (ish) as supplied via the assetto corsa server.
var ConfigIniDefault = ServerConfig{
GlobalServerConfig: GlobalServerConfig{
Name: "Assetto Corsa Server",
Password: "",
AdminPassword: "",
UDPPort: 9600,
TCPPort: 9600,
HTTPPort: 8081,
ClientSendIntervalInHertz: 18,
SendBufferSize: 0,
ReceiveBufferSize: 0,
KickQuorum: 85,
VotingQuorum: 80,
VoteDuration: 20,
BlacklistMode: 1,
RegisterToLobby: 1,
UDPPluginLocalPort: 0,
UDPPluginAddress: "",
AuthPluginAddress: "",
NumberOfThreads: 2,
ShowRaceNameInServerLobby: 1,
Name: "Assetto Corsa Server",
Password: "",
AdminPassword: "",
UDPPort: 9600,
TCPPort: 9600,
HTTPPort: 8081,
ClientSendIntervalInHertz: 18,
SendBufferSize: 0,
ReceiveBufferSize: 0,
KickQuorum: 85,
VotingQuorum: 80,
VoteDuration: 20,
BlacklistMode: 1,
RegisterToLobby: 1,
UDPPluginLocalPort: 0,
UDPPluginAddress: "",
AuthPluginAddress: "",
NumberOfThreads: 2,
ShowRaceNameInServerLobby: 1,
ShowContentManagerJoinLink: 1,
},

CurrentRaceConfig: CurrentRaceConfig{
@@ -2,6 +2,8 @@ package servermanager

import (
"net/http"
"net/url"
"strconv"
"strings"
"time"

@@ -14,6 +16,8 @@ import (
const (
// Time allowed to write a message to the peer.
writeWait = 10 * time.Second

CMJoinLinkBase string = "https://acstuff.ru/s/q:race/online/join"
)

type Broadcaster interface {
@@ -126,20 +130,22 @@ func (c *raceControlClient) writePump() {

type RaceControlHandler struct {
*BaseHandler
serverProcess ServerProcess

store Store
raceManager *RaceManager
raceControl *RaceControl
raceControlHub *RaceControlHub
}

func NewRaceControlHandler(baseHandler *BaseHandler, store Store, raceManager *RaceManager, raceControl *RaceControl, raceControlHub *RaceControlHub) *RaceControlHandler {
func NewRaceControlHandler(baseHandler *BaseHandler, store Store, raceManager *RaceManager, raceControl *RaceControl, raceControlHub *RaceControlHub, serverProcess ServerProcess) *RaceControlHandler {
return &RaceControlHandler{
BaseHandler: baseHandler,
store: store,
raceManager: raceManager,
raceControl: raceControl,
raceControlHub: raceControlHub,
serverProcess: serverProcess,
}
}

@@ -159,14 +165,50 @@ func (rch *RaceControlHandler) liveTiming(w http.ResponseWriter, r *http.Request
return
}

linkString := ""

if rch.serverProcess.GetServerConfig().GlobalServerConfig.ShowContentManagerJoinLink == 1 {
link, err := rch.getCMJoinLink()

if err != nil {
logrus.Errorf("could not get CM join link, err: %s", err)
}

linkString = link.String()
}

rch.viewRenderer.MustLoadTemplate(w, r, "live-timing.html", map[string]interface{}{
"RaceDetails": customRace,
"FrameLinks": frameLinks,
"CSSDotSmoothing": udp.RealtimePosIntervalMs,
"WideContainer": true,
"CMJoinLink": linkString,
})
}

func (rch *RaceControlHandler) getCMJoinLink() (*url.URL, error) {
// get the join link for the current session
geoIP, err := geoIP()

if err != nil {
return nil, err
}

cmUrl, err := url.Parse(CMJoinLinkBase)

if err != nil {
return nil, err
}

queryString := cmUrl.Query()
queryString.Set("ip", geoIP.IP)
queryString.Set("httpPort", strconv.Itoa(rch.serverProcess.GetServerConfig().GlobalServerConfig.HTTPPort))

cmUrl.RawQuery = queryString.Encode()

return cmUrl, nil
}

func deleteEmpty(s []string) []string {
var r []string
for _, str := range s {
@@ -326,6 +326,7 @@ func (r *Resolver) resolveRaceControlHandler() *RaceControlHandler {
r.resolveRaceManager(),
r.resolveRaceControl(),
r.resolveRaceControlHub(),
r.resolveServerProcess(),
)

return r.raceControlHandler
@@ -37,6 +37,7 @@ type ServerProcess interface {
Event() RaceEvent
UDPCallback(message udp.Message)
SendUDPMessage(message udp.Message) error
GetServerConfig() ServerConfig

Done() <-chan struct{}
}
@@ -369,6 +370,10 @@ func (as *AssettoServerProcess) Stop() error {
return nil
}

func (as *AssettoServerProcess) GetServerConfig() ServerConfig {
return as.serverConfig
}

func FreeUDPPort() (int, error) {
addr, err := net.ResolveUDPAddr("udp", "localhost:0")

0 comments on commit 76fe58e

Please sign in to comment.
You can’t perform that action at this time.