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

Method processInput

world.go:493–602  ·  view source on GitHub ↗
(userId int, inputText string, flags events.EventFlag)

Source from the content-addressed store, hash-verified

491}
492
493func (w *World) processInput(userId int, inputText string, flags events.EventFlag) {
494
495 user := users.GetByUserId(userId)
496 if user == nil { // Something went wrong. User not found.
497 mudlog.Error("User not found", "userId", userId)
498 return
499 }
500
501 var activeQuestion *prompt.Question = nil
502 hadPrompt := false
503 if cmdPrompt := user.GetPrompt(); cmdPrompt != nil {
504 hadPrompt = true
505 if activeQuestion = cmdPrompt.GetNextQuestion(); activeQuestion != nil {
506
507 activeQuestion.Answer(string(inputText))
508 inputText = ``
509
510 // set the input buffer to invoke the command prompt it was relevant to
511 if cmdPrompt.Command != `` {
512 inputText = cmdPrompt.Command + " " + cmdPrompt.Rest
513 }
514 } else {
515 // If a prompt was found, but no pending questions, clear it.
516 user.ClearPrompt()
517 }
518
519 }
520
521 command := ``
522 remains := ``
523
524 var err error
525 handled := false
526
527 inputText = strings.TrimSpace(inputText)
528
529 if len(inputText) > 0 {
530
531 // Update their last input
532 // Must be actual text, blank space doesn't count.
533 user.SetLastInputRound(util.GetRoundCount())
534
535 // Check for macros
536 if user.Macros != nil && len(inputText) == 2 {
537 if macro, ok := user.Macros[inputText]; ok {
538 handled = true
539 readyTurn := util.GetTurnCount()
540 for _, newCmd := range strings.Split(macro, `;`) {
541 if newCmd == `` {
542 continue
543 }
544
545 events.AddToQueue(events.Input{
546 UserId: userId,
547 InputText: newCmd,
548 ReadyTurn: readyTurn,
549 })
550

Callers 1

HandleInputEventsMethod · 0.95

Calls 15

AnswerMethod · 0.95
GetByUserIdFunction · 0.92
ErrorFunction · 0.92
GetRoundCountFunction · 0.92
GetTurnCountFunction · 0.92
AddToQueueFunction · 0.92
TryCommandFunction · 0.92
WarnFunction · 0.92
SendToFunction · 0.92
AnsiParseFunction · 0.92
TrackBadCommandFunction · 0.92
GetPromptMethod · 0.80

Tested by

no test coverage detected