Skip to content
Merged
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
4 changes: 2 additions & 2 deletions cmd/plugins/plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ plugins:
work_dir:
git:
enabled: true
persistent: false # persistent can be set to true if you don't
#persistent: true # persistent can be set to true if you don't
# want the plugin to be cloned at every startup
version: tags/v0.0.1 # can also specify commit hashes
#version: tags/v0.0.1 # can also specify commit hashes
path: https://github.com/secmc/plugin-go
27 changes: 19 additions & 8 deletions plugin/adapters/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,10 @@ func (m *Manager) handlePluginMessage(p *pluginProcess, msg *pb.PluginToHost) {
if result := msg.GetEventResult(); result != nil {
p.deliverEventResult(result)
}
if hello := msg.GetHello(); hello != nil {

switch payload := msg.GetPayload().(type) {
case *pb.PluginToHost_Hello:
hello := payload.Hello
cmdNames := mapSlice(hello.Commands, func(cmd *pb.CommandSpec) string {
if len(cmd.Aliases) > 0 {
return fmt.Sprintf("%s (aliases: %v)", cmd.Name, cmd.Aliases)
Expand All @@ -441,8 +444,8 @@ func (m *Manager) handlePluginMessage(p *pluginProcess, msg *pb.PluginToHost) {
p.setHello(hello)
m.registerCommands(p, hello.Commands)
m.registerCustomItems(p, hello.CustomItems)
}
if subscribe := msg.GetSubscribe(); subscribe != nil {
case *pb.PluginToHost_Subscribe:
subscribe := payload.Subscribe
eventNames := mapSlice(subscribe.Events, func(evt pb.EventType) string {
return evt.String()
})
Expand All @@ -452,11 +455,10 @@ func (m *Manager) handlePluginMessage(p *pluginProcess, msg *pb.PluginToHost) {
}
m.log.Info(fmt.Sprintf(" %s subscribed to %d events", pluginName, len(eventNames)), "events", eventNames)
p.updateSubscriptions(subscribe.Events)
}
if actions := msg.GetActions(); actions != nil {
m.applyActions(p, actions)
}
if logMsg := msg.GetLog(); logMsg != nil {
case *pb.PluginToHost_Actions:
m.applyActions(p, payload.Actions)
case *pb.PluginToHost_Log:
logMsg := payload.Log
level := strings.ToLower(logMsg.Level)
switch level {
case "warn", "warning":
Expand All @@ -466,6 +468,15 @@ func (m *Manager) handlePluginMessage(p *pluginProcess, msg *pb.PluginToHost) {
default:
p.log.Info(logMsg.Message)
}
case *pb.PluginToHost_ServerInfo:
var pluginNames []string

for _, pl := range m.plugins {
pluginNames = append(pluginNames, pl.cfg.Name)
}
p.sendServerInfo(pluginNames)
default:
p.log.Info(fmt.Sprintf("unhandled event: %#v", payload))
}
}

Expand Down
16 changes: 16 additions & 0 deletions plugin/adapters/plugin/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ func (p *pluginProcess) consumeOutput(r io.Reader) {
}
}

func (p *pluginProcess) sendServerInfo(plugins []string) error {
msg := &pb.HostToPlugin{
PluginId: p.id,
Payload: &pb.HostToPlugin_ServerInfo{
ServerInfo: &pb.ServerInformationResponse{
Plugins: plugins,
},
},
}
payload, err := proto.Marshal(msg)
if err != nil {
return err
}
return p.stream.Send(payload)
}

func (p *pluginProcess) sendHello() error {
msg := &pb.HostToPlugin{
PluginId: p.id,
Expand Down
910 changes: 730 additions & 180 deletions proto/generated/cpp/plugin.pb.cc

Large diffs are not rendered by default.

Loading