Skip to content

Commit

Permalink
Merge branch 'master' into show-dlc-mod
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecrer authored Oct 25, 2019
2 parents fa7bb65 + c3e3dbe commit e62ad98
Show file tree
Hide file tree
Showing 16 changed files with 519 additions and 185 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ v1.5.2
Added:

* Added information about whether a car/track is part of a DLC or a Mod when creating an event.
* Discord Enhancements (Thanks @cheesegrits!):
- Splits the '!schedule' command into '!sessions' (full "wall of text" individual session calendar, restricted to one week ahead) and '!schedule' (abbreviated, one per race calendar). This still needs work, as can easily exceed Discord's max msg length.

- Added role mentioning. If the optional DiscordRoleID is set, that role will be mentioned in all Discord notifications (meaning anyone with that role will get pinged). Additionally, if the optional 'DiscordRoleCommand' is also set, we will attempt to add/remove that role for users, when they issue the "!whatever" command verb - this requires that the bot has "Manage Roles" permission.

- Changed NotificationReminderTimer to NotificationReminderTimers (plural), to support comma separated multiple timers (like "90,15" for two reminders at 90 and 15 minutes).

- Added option to disable notifications when a race is scheduled.

- Added notification for scheduled races being cancelled.

- Improved formatting of Discord messages, everything is now an embed (except the role mention, which has to be part of the basic message).

Fixes:

* Fixes track pages for users running Server Manager on Windows
* Fixes an issue where Championships with 'Any Car Model' specified would fail to find a class for a car.
* Fixes an issue where cars with no skins might prevent a race from starting.
* Fixes an issue where Scheduled Championship Race Weekend sessions caused the calendar to error on load.
* Fixes the Race Weekend "Start after previous session" checkbox not displaying correctly.
* Fixes an issue where all drivers were incorrectly disconnected from the Live Timings page when an event with multiple sessions looped

---

Expand Down
44 changes: 19 additions & 25 deletions championship_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,6 @@ func (cm *ChampionshipManager) ScheduleEvent(championshipID string, eventID stri
return err
}

serverOpts, err := cm.store.LoadServerOptions()

if err != nil {
return err
}

event.Scheduled = date

// if there is an existing schedule timer for this event stop it
Expand Down Expand Up @@ -648,12 +642,15 @@ func (cm *ChampionshipManager) ScheduleEvent(championshipID string, eventID stri
}
})

if serverOpts.NotificationReminderTimer > 0 {
duration = time.Until(date.Add(time.Duration(0-serverOpts.NotificationReminderTimer) * time.Minute))
if cm.notificationManager.HasNotificationReminders() {
for _, timer := range cm.notificationManager.GetNotificationReminders() {
duration = time.Until(date.Add(time.Duration(0-timer) * time.Minute))
thisTimer := timer

cm.championshipEventReminderTimers[event.ID.String()] = time.AfterFunc(duration, func() {
cm.notificationManager.SendChampionshipReminderMessage(championship, event)
})
cm.championshipEventReminderTimers[event.ID.String()] = time.AfterFunc(duration, func() {
cm.notificationManager.SendChampionshipReminderMessage(championship, event, thisTimer)
})
}
}
} else {
event.ClearRecurrenceRule()
Expand Down Expand Up @@ -1472,12 +1469,6 @@ func (cm *ChampionshipManager) InitScheduledChampionships() error {
return err
}

serverOpts, err := cm.store.LoadServerOptions()

if err != nil {
return err
}

for _, championship := range championships {
championship := championship

Expand All @@ -1496,14 +1487,17 @@ func (cm *ChampionshipManager) InitScheduledChampionships() error {
}
})

if serverOpts.NotificationReminderTimer > 0 {
if event.Scheduled.Add(time.Duration(0-serverOpts.NotificationReminderTimer) * time.Minute).After(time.Now()) {
// add reminder
duration = time.Until(event.Scheduled.Add(time.Duration(0-serverOpts.NotificationReminderTimer) * time.Minute))

cm.championshipEventReminderTimers[event.ID.String()] = time.AfterFunc(duration, func() {
cm.notificationManager.SendChampionshipReminderMessage(championship, event)
})
if cm.notificationManager.HasNotificationReminders() {
for _, timer := range cm.notificationManager.GetNotificationReminders() {
if event.Scheduled.Add(time.Duration(0-timer) * time.Minute).After(time.Now()) {
// add reminder
duration = time.Until(event.Scheduled.Add(time.Duration(0-timer) * time.Minute))
thisTimer := timer

cm.championshipEventReminderTimers[event.ID.String()] = time.AfterFunc(duration, func() {
cm.notificationManager.SendChampionshipReminderMessage(championship, event, thisTimer)
})
}
}
}

Expand Down
33 changes: 26 additions & 7 deletions championship_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ var TestEntryList = EntryList{
},
}

type dummyServerProcess struct{}
type dummyServerProcess struct {
doneCh chan struct{}
}

func (dummyServerProcess) Logs() string {
return ""
Expand All @@ -69,7 +71,10 @@ func (dummyServerProcess) Start(cfg ServerConfig, entryList EntryList, forwardin
return nil
}

func (dummyServerProcess) Stop() error {
func (d dummyServerProcess) Stop() error {
if d.doneCh != nil {
d.doneCh <- struct{}{}
}
return nil
}

Expand All @@ -92,8 +97,8 @@ func (dummyServerProcess) SendUDPMessage(message udp.Message) error {
return nil
}

func (dummyServerProcess) Done() <-chan struct{} {
return nil
func (d dummyServerProcess) Done() <-chan struct{} {
return d.doneCh
}

func (dummyServerProcess) GetServerConfig() ServerConfig {
Expand All @@ -111,7 +116,17 @@ var championshipManager *ChampionshipManager

type dummyNotificationManager struct{}

func (d dummyNotificationManager) SendRaceWeekendReminderMessage(raceWeekend *RaceWeekend, session *RaceWeekendSession) error {
func (d *dummyNotificationManager) HasNotificationReminders() bool {
return false
}

func (d *dummyNotificationManager) GetNotificationReminders() []int {
var reminders []int

return reminders
}

func (d dummyNotificationManager) SendRaceWeekendReminderMessage(raceWeekend *RaceWeekend, session *RaceWeekendSession, timer int) error {
return nil
}

Expand All @@ -131,11 +146,15 @@ func (d dummyNotificationManager) SendRaceScheduledMessage(event *CustomRace, da
return nil
}

func (d dummyNotificationManager) SendRaceReminderMessage(event *CustomRace) error {
func (d dummyNotificationManager) SendRaceCancelledMessage(event *CustomRace, date time.Time) error {
return nil
}

func (d dummyNotificationManager) SendRaceReminderMessage(event *CustomRace, timer int) error {
return nil
}

func (d dummyNotificationManager) SendChampionshipReminderMessage(championship *Championship, event *ChampionshipEvent) error {
func (d dummyNotificationManager) SendChampionshipReminderMessage(championship *Championship, event *ChampionshipEvent, timer int) error {
return nil
}

Expand Down
20 changes: 20 additions & 0 deletions championships.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"html/template"
"math/rand"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -402,6 +403,25 @@ func (c *Championship) FindClassForCarModel(model string) (*ChampionshipClass, e
}
}

if model == AnyCarModel {
// randomly assign a class based from whatever classes we have with AnyCarModel in their entrylist.
classes := make([]*ChampionshipClass, len(c.Classes))

copy(classes, c.Classes)

rand.Shuffle(len(classes), func(i, j int) {
classes[i], classes[j] = classes[j], classes[i]
})

for _, class := range classes {
for _, entrant := range class.Entrants {
if entrant.Model == AnyCarModel {
return class, nil
}
}
}
}

return nil, ErrClassNotFound
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/server-manager/typescript/src/javascript/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $(document).ready(function () {
$.fn.bootstrapSwitch.defaults.size = 'small';
$.fn.bootstrapSwitch.defaults.animate = false;
$.fn.bootstrapSwitch.defaults.onColor = "success";
$document.find("input[type='checkbox']:not(input[name='EntryList.OverwriteAllEvents']:hidden)").bootstrapSwitch();
$document.find("input[type='checkbox']:not(input[name='EntryList.OverwriteAllEvents']:hidden):not(input[name='session-start-after-parent']:hidden)").bootstrapSwitch();

championships.init();
$document.find(".race-setup").each(function (index, elem) {
Expand Down
15 changes: 10 additions & 5 deletions config_ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,16 @@ type GlobalServerConfig struct {
UseMPH int `ini:"-" input:"checkbox" help:"When on, this option will make Server Manager use MPH instead of Km/h for all speed values."`

// Discord Integration
DiscordIntegration FormHeading `ini:"-" input:"heading"`
DiscordAPIToken string `ini:"-" help:"If set, will enable race start and scheduled reminder messages to the Discord channel ID specified below. Use your bot's user token, not the OAuth token."`
DiscordChannelID string `ini:"-" help:"If Discord is enabled, this is the channel ID it will send messages to"`
NotificationReminderTimer int `ini:"-" min:"0" max:"65535" help:"If Discord is enabled, a reminder will be sent this many minutes prior to race start. If 0, only race start messages will be sent."`
ShowPasswordInNotifications int `ini:"-" show:"open" input:"checkbox" help:"Show the server password in race start notifications"`
DiscordIntegration FormHeading `ini:"-" input:"heading"`
DiscordAPIToken string `ini:"-" help:"If set, will enable race start and scheduled reminder messages to the Discord channel ID specified below. Use your bot's user token, not the OAuth token."`
DiscordChannelID string `ini:"-" help:"If Discord is enabled, this is the channel ID it will send messages to. To find the channel ID, enable Developer mode in Discord (user settings, Appearance), then Server Settings, Roles, and right click on the channel and Copy ID."`
DiscordRoleID string `ini:"-" help:"If set, this role will be mentioned in all Discord notifications. Any users with this role and access to the channel will be pinged. To find the role ID, enable Developer mode (see above)), then Server Settings, Roles, right click on the role and Copy ID."`
DiscordRoleCommand string `ini:"-" help:"If the Discord Role ID is set, you can optionally specify a command string here, like \"notify\" (no ! prefix), which if run as a ! command by a user (on a line by itself) in Discord will cause this server to attempt to add the configured role to the user. If you run multiple servers with Discord enabled, only set this on one of them. In order for this to work your bot must have the \"Manage Roles\" permission."`

NotificationReminderTimer int `ini:"-" show:"-" min:"0" max:"65535" help:"This setting has been deprecated and will be removed in the next release. Use Notification Reminder Timers instead."`
NotificationReminderTimers string `ini:"-" help:"If Discord is enabled, a reminder will be sent this many minutes prior to race start. If 0 or empty, only race start messages will be sent. You may schedule multiple reminders by using a comma separated list like 120,15."`
ShowPasswordInNotifications int `ini:"-" input:"checkbox" help:"Show the server password in race start notifications."`
NotifyWhenScheduled int `ini:"-" input:"checkbox" help:"Send a notification when a race is scheduled (or cancelled)."`

// Messages
ContentManagerWelcomeMessage string `ini:"-" show:"-"`
Expand Down
Loading

0 comments on commit e62ad98

Please sign in to comment.