8000 Companion Mode + New MenuFlow by artosimonyan · Pull Request #716 · hectorgimenez/koolo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Companion Mode + New MenuFlow #716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions internal/bot/companion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package bot

import (
"context"
"log/slog"

"github.com/hectorgimenez/koolo/internal/config"
"github.com/hectorgimenez/koolo/internal/event"
)

// CompanionEventHandler handles events related to companion functionality
type CompanionEventHandler struct {
supervisor string
log *slog.Logger
cfg *config.CharacterCfg
}

// NewCompanionEventHandler creates a new instance of CompanionEventHandler
func NewCompanionEventHandler(supervisor string, log *slog.Logger, cfg *config.CharacterCfg) *CompanionEventHandler {
return &CompanionEventHandler{
supervisor: supervisor,
log: log,
cfg: cfg,
}
}

// Handle processes companion-related events
func (h *CompanionEventHandler) Handle(ctx context.Context, e event.Event) error {

switch evt := e.(type) {

case event.RequestCompanionJoinGameEvent:

if h.cfg.Companion.Enabled && !h.cfg.Companion.Leader {

// Check if the leader matches the one in our config or no leader set
if h.cfg.Companion.LeaderName == "" || evt.Leader == h.cfg.Companion.LeaderName {
h.log.Info("Companion join game event received", slog.String("supervisor", h.supervisor), slog.String("leader", evt.Leader), slog.String("name", evt.Name), slog.String("password", evt.Password))
h.cfg.Companion.CompanionGameName = evt.Name
h.cfg.Companion.CompanionGamePassword = evt.Password
}
}

case event.ResetCompanionGameInfoEvent:

// If this character is a companion (not a leader), clear game info
if h.cfg.Companion.Enabled && !h.cfg.Companion.Leader {

// Check if the leader matches the one in our config or no leader set.
// Additional check for if LeaderName is the same as the character name for Manual join triggers
if h.cfg.Companion.LeaderName == "" || evt.Leader == h.cfg.Companion.LeaderName || h.cfg.CharacterName == evt.Leader {
h.log.Info("Companion reset game info event received", slog.String("supervisor", h.supervisor), slog.String("leader", evt.Leader))
h.cfg.Companion.CompanionGameName = ""
h.cfg.Companion.CompanionGamePassword = ""
}
}
}

return nil
}
122 changes: 0 additions & 122 deletions internal/bot/companion_supervisor.go

This file was deleted.

7 changes: 6 additions & 1 deletion internal/bot/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type SupervisorManager struct {
}

func NewSupervisorManager(logger *slog.Logger, eventListener *event.Listener) *SupervisorManager {

return &SupervisorManager{
logger: logger,
supervisors: make(map[string]Supervisor),
Expand Down Expand Up @@ -262,15 +263,19 @@ func (mng *SupervisorManager) buildSupervisor(supervisorName string, logger *slo
bot := NewBot(ctx.Context)

statsHandler := NewStatsHandler(supervisorName, logger)
companionHandler := NewCompanionEventHandler(supervisorName, logger, cfg)

// Register event handler for stats
mng.eventListener.Register(statsHandler.Handle)
mng.eventListener.Register(companionHandler.Handle)

// Create the supervisor
var supervisor Supervisor

supervisor, err = NewSinglePlayerSupervisor(supervisorName, bot, statsHandler)

if err != nil {
return nil, nil, err

}

// This function will be used to restart the client - passed to the crashDetector
Expand Down
Loading
0