Skip to content

Commit 7b3c399

Browse files
committed
[Release] 4.9.1
1 parent 7e27222 commit 7b3c399

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [4.9.1] 7/17/2024
2+
3+
* **File Watchers** Add more resiliency to file watchers to prevent crashes
4+
* **Discord Crash Logs** Fix issue where some messages were getting truncated
5+
16
## [4.9.0] 6/16/2024
27

38
* **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.

internal/discord/webhook.go

+12-14
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,27 @@ func SendMessage(webhookUrl, header, contents string) {
4242
webhookUrl,
4343
header+fmt.Sprintf(" **Chunk** [%v]\n```\n%v\n```", chunkCount, chunk),
4444
)
45+
46+
//fmt.Println(header + fmt.Sprintf(" **Chunk** [%v]\n```\n%v\n```", chunkCount, chunk))
4547
chunkCount++
4648
}
4749
}
4850

4951
// chunkSubstr splits a string into chunks of a given size
5052
func chunkString(s string, chunkSize int) []string {
51-
if len(s) == 0 {
52-
return nil
53-
}
54-
if chunkSize >= len(s) {
53+
var chunks []string
54+
runes := []rune(s)
55+
56+
if len(runes) == 0 {
5557
return []string{s}
5658
}
57-
var chunks []string = make([]string, 0, (len(s)-1)/chunkSize+1)
58-
currentLen := 0
59-
currentStart := 0
60-
for i := range s {
61-
if currentLen == chunkSize {
62-
chunks = append(chunks, s[currentStart:i])
63-
currentLen = 0
64-
currentStart = i
59+
60+
for i := 0; i < len(runes); i += chunkSize {
61+
nn := i + chunkSize
62+
if nn > len(runes) {
63+
nn = len(runes)
6564
}
66-
currentLen++
65+
chunks = append(chunks, string(runes[i:nn]))
6766
}
68-
chunks = append(chunks, s[currentStart:])
6967
return chunks
7068
}

internal/eqemuserver/crash_log_watcher.go

+27-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type CrashLogWatcher struct {
3131
watchCrashLogs bool
3232
discordWebhook string
3333
serverLongName string
34+
closeWatcher bool
3435
}
3536

3637
func NewCrashLogWatcher(
@@ -74,6 +75,15 @@ func (l *CrashLogWatcher) Process() {
7475
Msg("Detected server config change")
7576
}
7677

78+
if l.closeWatcher {
79+
if l.watcher != nil {
80+
l.watcher.Close()
81+
l.watcher = nil
82+
}
83+
l.closeWatcher = false
84+
l.logger.Debug().Msg("Closing crash log watcher as a result of a queued error")
85+
}
86+
7787
if l.watchCrashLogs && l.watcher == nil {
7888
go l.startCrashLogWatcher()
7989
}
@@ -112,6 +122,15 @@ func (l *CrashLogWatcher) startCrashLogWatcher() {
112122
return
113123
}
114124

125+
if l.closeWatcher {
126+
if l.watcher != nil {
127+
l.watcher.Close()
128+
l.watcher = nil
129+
}
130+
l.closeWatcher = false
131+
return
132+
}
133+
115134
if l.watcher != nil {
116135
return
117136
}
@@ -141,19 +160,14 @@ func (l *CrashLogWatcher) startCrashLogWatcher() {
141160
select {
142161
case event, ok := <-l.watcher.Events:
143162
if !ok {
144-
l.logger.Info().Any("event", event).Msg("Watcher error - Closing watcher")
145-
if l.watcher != nil {
146-
l.watcher.Close()
147-
}
148-
l.watcher = nil
149163
return
150164
}
151165

152166
// if event is create or write
153167
if event.Op == fsnotify.Create {
154168
l.logger.Info().
155169
Any("event.Name", event.Name).
156-
Msg("Detected crash log change")
170+
Msg("Detected crash log creation")
157171

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

179193
case err, ok := <-l.watcher.Errors:
180194
if !ok {
181-
l.logger.Info().Msg("Closing watcher")
182-
if l.watcher != nil {
183-
l.watcher.Close()
184-
}
185-
l.watcher = nil
195+
l.logger.Info().Err(err).Msg("Closing watcher")
196+
l.closeWatcher = true
186197
return
187198
}
188199
log.Println("error:", err)
@@ -201,6 +212,11 @@ func (l *CrashLogWatcher) startCrashLogWatcher() {
201212
return // path does not exist
202213
}
203214

215+
if l.watcher == nil {
216+
l.logger.Debug().Msg("Watcher is nil")
217+
return
218+
}
219+
204220
err = l.watcher.AddRecursive(path)
205221
if err != nil {
206222
l.logger.Debug().

internal/eqemuserver/quest_hot_reload_watcher.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ func (l *QuestHotReloadWatcher) Start() {
155155
select {
156156
case event, ok := <-l.watcher.Events:
157157
if !ok {
158-
l.logger.Info().Any("watching", l.pathmgmt.GetQuestsDir()).Msg("Watcher error, closing watcher")
159-
if l.watcher != nil {
160-
l.watcher.Close()
161-
}
162-
l.watcher = nil
163158
return
164159
}
165160

@@ -246,6 +241,11 @@ func (l *QuestHotReloadWatcher) Start() {
246241
return nil
247242
})
248243

244+
if l.watcher == nil {
245+
l.logger.Debug().Any("watching", l.pathmgmt.GetQuestsDir()).Msg("Watcher is nil, returning")
246+
return
247+
}
248+
249249
// Add a path.
250250
err = l.watcher.AddRecursive(l.pathmgmt.GetQuestsDir())
251251
if err != nil {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spire",
3-
"version": "4.9.0",
3+
"version": "4.9.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/Akkadius/spire.git"

0 commit comments

Comments
 (0)