Skip to content

Commit

Permalink
[Release] 4.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Jul 17, 2024
1 parent 7e27222 commit 7b3c399
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [4.9.1] 7/17/2024

* **File Watchers** Add more resiliency to file watchers to prevent crashes
* **Discord Crash Logs** Fix issue where some messages were getting truncated

## [4.9.0] 6/16/2024

* **Local Users** Fix issue where a locally created user may not get associated to the default database connection synchronized from the `eqemu_config.json` file. This would cause the user to not be able to log in to Spire Admin.
Expand Down
26 changes: 12 additions & 14 deletions internal/discord/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,27 @@ func SendMessage(webhookUrl, header, contents string) {
webhookUrl,
header+fmt.Sprintf(" **Chunk** [%v]\n```\n%v\n```", chunkCount, chunk),
)

//fmt.Println(header + fmt.Sprintf(" **Chunk** [%v]\n```\n%v\n```", chunkCount, chunk))
chunkCount++
}
}

// chunkSubstr splits a string into chunks of a given size
func chunkString(s string, chunkSize int) []string {
if len(s) == 0 {
return nil
}
if chunkSize >= len(s) {
var chunks []string
runes := []rune(s)

if len(runes) == 0 {
return []string{s}
}
var chunks []string = make([]string, 0, (len(s)-1)/chunkSize+1)
currentLen := 0
currentStart := 0
for i := range s {
if currentLen == chunkSize {
chunks = append(chunks, s[currentStart:i])
currentLen = 0
currentStart = i

for i := 0; i < len(runes); i += chunkSize {
nn := i + chunkSize
if nn > len(runes) {
nn = len(runes)
}
currentLen++
chunks = append(chunks, string(runes[i:nn]))
}
chunks = append(chunks, s[currentStart:])
return chunks
}
38 changes: 27 additions & 11 deletions internal/eqemuserver/crash_log_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type CrashLogWatcher struct {
watchCrashLogs bool
discordWebhook string
serverLongName string
closeWatcher bool
}

func NewCrashLogWatcher(
Expand Down Expand Up @@ -74,6 +75,15 @@ func (l *CrashLogWatcher) Process() {
Msg("Detected server config change")
}

if l.closeWatcher {
if l.watcher != nil {
l.watcher.Close()
l.watcher = nil
}
l.closeWatcher = false
l.logger.Debug().Msg("Closing crash log watcher as a result of a queued error")
}

if l.watchCrashLogs && l.watcher == nil {
go l.startCrashLogWatcher()
}
Expand Down Expand Up @@ -112,6 +122,15 @@ func (l *CrashLogWatcher) startCrashLogWatcher() {
return
}

if l.closeWatcher {
if l.watcher != nil {
l.watcher.Close()
l.watcher = nil
}
l.closeWatcher = false
return
}

if l.watcher != nil {
return
}
Expand Down Expand Up @@ -141,19 +160,14 @@ func (l *CrashLogWatcher) startCrashLogWatcher() {
select {
case event, ok := <-l.watcher.Events:
if !ok {
l.logger.Info().Any("event", event).Msg("Watcher error - Closing watcher")
if l.watcher != nil {
l.watcher.Close()
}
l.watcher = nil
return
}

// if event is create or write
if event.Op == fsnotify.Create {
l.logger.Info().
Any("event.Name", event.Name).
Msg("Detected crash log change")
Msg("Detected crash log creation")

// ship to discord
filename := filepath.Base(event.Name)
Expand All @@ -178,11 +192,8 @@ func (l *CrashLogWatcher) startCrashLogWatcher() {

case err, ok := <-l.watcher.Errors:
if !ok {
l.logger.Info().Msg("Closing watcher")
if l.watcher != nil {
l.watcher.Close()
}
l.watcher = nil
l.logger.Info().Err(err).Msg("Closing watcher")
l.closeWatcher = true
return
}
log.Println("error:", err)
Expand All @@ -201,6 +212,11 @@ func (l *CrashLogWatcher) startCrashLogWatcher() {
return // path does not exist
}

if l.watcher == nil {
l.logger.Debug().Msg("Watcher is nil")
return
}

err = l.watcher.AddRecursive(path)
if err != nil {
l.logger.Debug().
Expand Down
10 changes: 5 additions & 5 deletions internal/eqemuserver/quest_hot_reload_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ func (l *QuestHotReloadWatcher) Start() {
select {
case event, ok := <-l.watcher.Events:
if !ok {
l.logger.Info().Any("watching", l.pathmgmt.GetQuestsDir()).Msg("Watcher error, closing watcher")
if l.watcher != nil {
l.watcher.Close()
}
l.watcher = nil
return
}

Expand Down Expand Up @@ -246,6 +241,11 @@ func (l *QuestHotReloadWatcher) Start() {
return nil
})

if l.watcher == nil {
l.logger.Debug().Any("watching", l.pathmgmt.GetQuestsDir()).Msg("Watcher is nil, returning")
return
}

// Add a path.
err = l.watcher.AddRecursive(l.pathmgmt.GetQuestsDir())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spire",
"version": "4.9.0",
"version": "4.9.1",
"repository": {
"type": "git",
"url": "https://github.com/Akkadius/spire.git"
Expand Down

0 comments on commit 7b3c399

Please sign in to comment.