MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / MainWorker

Method MainWorker

world.go:322–462  ·  view source on GitHub ↗
(shutdown chan bool, wg *sync.WaitGroup)

Source from the content-addressed store, hash-verified

320)
321
322func (w *World) MainWorker(shutdown chan bool, wg *sync.WaitGroup) {
323
324 wg.Add(1)
325
326 mudlog.Info("MainWorker", "state", "Started")
327 defer func() {
328 mudlog.Warn("MainWorker", "state", "Stopped")
329 wg.Done()
330 }()
331
332 c := configs.GetConfig()
333
334 roomUpdateTimer := time.NewTimer(roomMaintenancePeriod)
335 ansiAliasTimer := time.NewTimer(ansiAliasReloadPeriod)
336 eventLoopTimer := time.NewTimer(time.Millisecond)
337 turnTimer := time.NewTimer(time.Duration(c.Timing.TurnMs) * time.Millisecond)
338 statsTimer := time.NewTimer(time.Duration(10) * time.Second)
339
340loop:
341 for {
342
343 // The reason for
344 // util.LockGame() / util.UnlockGame()
345 // In each of these cases is to lock down the
346 // logic for when other processes need to query data
347 // such as the webserver
348
349 select {
350 case <-shutdown:
351
352 mudlog.Warn(`MainWorker`, `action`, `shutdown received`)
353
354 util.LockMud()
355 if err := rooms.SaveAllRooms(); err != nil {
356 mudlog.Error("rooms.SaveAllRooms()", "error", err.Error())
357 }
358 users.SaveAllUsers() // Save all user data too.
359 util.UnlockMud()
360
361 break loop
362 case <-statsTimer.C:
363
364 // TODO: Move this to events
365 util.LockMud()
366
367 w.UpdateStats()
368 // save the round counter.
369 util.SaveRoundCount(c.FilePaths.DataFiles.String() + `/` + util.RoundCountFilename)
370
371 util.UnlockMud()
372
373 statsTimer.Reset(time.Duration(10) * time.Second)
374
375 case <-roomUpdateTimer.C:
376
377 // TODO: Move this to events
378 util.LockMud()
379 scripting.PruneRoomVMs(rooms.RoomMaintenance()...)

Callers 1

mainFunction · 0.80

Calls 15

UpdateStatsMethod · 0.95
EventLoopMethod · 0.95
enterWorldMethod · 0.95
InfoFunction · 0.92
WarnFunction · 0.92
GetConfigFunction · 0.92
LockMudFunction · 0.92
SaveAllRoomsFunction · 0.92
ErrorFunction · 0.92
SaveAllUsersFunction · 0.92
UnlockMudFunction · 0.92

Tested by

no test coverage detected