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

Method onCLIRequest

modules/clibridge/clibridge.go:237–315  ·  view source on GitHub ↗
(e events.Event)

Source from the content-addressed store, hash-verified

235}
236
237func (m *CLIBridgeModule) onCLIRequest(e events.Event) events.ListenerReturn {
238 evt, ok := e.(events.CLIRequest)
239 if !ok {
240 return events.Continue
241 }
242
243 user := users.GetByUserId(evt.UserId)
244 if user == nil {
245 return events.Continue
246 }
247
248 connId := evt.ConnectionId
249 connDetails := connections.Get(connId)
250 if connDetails == nil {
251 return events.Continue
252 }
253
254 binaryPath, err := exec.LookPath(evt.Command)
255 if err != nil {
256 user.SendText(fmt.Sprintf("Tool %q not found on system: %s", evt.Command, err.Error()))
257 return events.Continue
258 }
259
260 resolvedArgs, err := m.resolveArgs(evt.Args)
261 if err != nil {
262 user.SendText(fmt.Sprintf("Path error: %s", err.Error()))
263 return events.Continue
264 }
265
266 cs := connections.GetClientSettings(connId)
267 cols := uint16(cs.Display.ScreenWidth)
268 rows := uint16(cs.Display.ScreenHeight)
269 if cols == 0 {
270 cols = 80
271 }
272 if rows == 0 {
273 rows = 24
274 }
275
276 cmd := exec.Command(binaryPath, resolvedArgs...)
277 cmd.Dir = configs.GetFilePathsConfig().DataFiles.String()
278 cmd.Env = append(os.Environ(),
279 "TERM=xterm-256color",
280 fmt.Sprintf("COLUMNS=%d", cols),
281 fmt.Sprintf("LINES=%d", rows),
282 )
283
284 winSize := &pty.Winsize{Cols: cols, Rows: rows}
285 ptmx, err := pty.StartWithSize(cmd, winSize)
286 if err != nil {
287 user.SendText(fmt.Sprintf("Failed to start CLI tool: %s", err.Error()))
288 return events.Continue
289 }
290
291 sess := &Session{
292 ConnectionId: connId,
293 UserId: evt.UserId,
294 Cmd: cmd,

Callers

nothing calls this directly

Calls 15

resolveArgsMethod · 0.95
setSessionMethod · 0.95
makeInputHandlerMethod · 0.95
ptyToClientMethod · 0.95
waitForExitMethod · 0.95
GetByUserIdFunction · 0.92
GetFunction · 0.92
GetClientSettingsFunction · 0.92
GetFilePathsConfigFunction · 0.92
IsSSHMethod · 0.80
PrependInputHandlerMethod · 0.80
AddInputHandlerMethod · 0.80

Tested by

no test coverage detected