Skip to content

Commit

Permalink
Merge pull request #438 from cj123/live-timing-join-link
Browse files Browse the repository at this point in the history
Live timing join link
  • Loading branch information
Hecrer committed Jul 26, 2019
2 parents 59c5b2c + 8448f06 commit 76fe58e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 20 deletions.
4 changes: 4 additions & 0 deletions championship_manager_test.go
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions cmd/server-manager/views/pages/live-timing.html
Expand Up @@ -32,6 +32,7 @@
{{ end }}

{{ define "content" }}
{{ $CMJoinLink := .CMJoinLink }}
{{ with .RaceDetails }}
<div class="race-control-event-info">
{{ range $sessionName, $session := .RaceConfig.Sessions }}
Expand All @@ -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">
Expand Down
1 change: 1 addition & 0 deletions config_ini.go
Expand Up @@ -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 {
Expand Down
39 changes: 20 additions & 19 deletions config_ini_default.go
Expand Up @@ -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{
Expand Down
44 changes: 43 additions & 1 deletion race_control_http.go
Expand Up @@ -2,6 +2,8 @@ package servermanager

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

Expand All @@ -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 {
Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions resolver.go
Expand Up @@ -326,6 +326,7 @@ func (r *Resolver) resolveRaceControlHandler() *RaceControlHandler {
r.resolveRaceManager(),
r.resolveRaceControl(),
r.resolveRaceControlHub(),
r.resolveServerProcess(),
)

return r.raceControlHandler
Expand Down
5 changes: 5 additions & 0 deletions server_process.go
Expand Up @@ -37,6 +37,7 @@ type ServerProcess interface {
Event() RaceEvent
UDPCallback(message udp.Message)
SendUDPMessage(message udp.Message) error
GetServerConfig() ServerConfig

Done() <-chan struct{}
}
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 76fe58e

Please sign in to comment.