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

Function handleTelnetConnection

main.go:591–966  ·  view source on GitHub ↗
(connDetails *connections.ConnectionDetails, wg *sync.WaitGroup)

Source from the content-addressed store, hash-verified

589}
590
591func handleTelnetConnection(connDetails *connections.ConnectionDetails, wg *sync.WaitGroup) {
592 defer func() {
593 wg.Done()
594 }()
595
596 mudlog.Info("New Connection", "connectionID", connDetails.ConnectionId(), "remoteAddr", connDetails.RemoteAddr().String())
597
598 // Setup shared state map for this connection's handlers
599 // Needs to be created BEFORE the first handler call
600 var sharedState map[string]any = make(map[string]any)
601
602 // Add starting handlers
603
604 // Special escape handlers
605 connDetails.AddInputHandler("TelnetIACHandler", inputhandlers.TelnetIACHandler)
606 connDetails.AddInputHandler("AnsiHandler", inputhandlers.AnsiHandler)
607 // Consider a macro handler at this point?
608 // Text Processing
609 connDetails.AddInputHandler("CleanserInputHandler", inputhandlers.CleanserInputHandler)
610 connDetails.AddInputHandler("TextPrefixHandler", inputhandlers.TextPrefixHandler)
611
612 loginHandler := inputhandlers.GetLoginPromptHandler() // Get the configured handler func
613 connDetails.AddInputHandler("LoginPromptHandler", loginHandler) // Add it with a unique name
614
615 // Turn off "line at a time", send chars as typed
616 connections.SendTo(
617 term.TelnetWILL(term.TELNET_OPT_SUP_GO_AHD),
618 connDetails.ConnectionId(),
619 )
620 // Tell the client we expect chars as they are typed
621 connections.SendTo(
622 term.TelnetWONT(term.TELNET_OPT_LINE_MODE),
623 connDetails.ConnectionId(),
624 )
625
626 // Tell the client we intend to echo back what they type
627 // So they shouldn't locally echo it
628
629 connections.SendTo(
630 term.TelnetWILL(term.TELNET_OPT_ECHO),
631 connDetails.ConnectionId(),
632 )
633 // Request that the client report window size changes as they happen
634 connections.SendTo(
635 term.TelnetDO(term.TELNET_OPT_NAWS),
636 connDetails.ConnectionId(),
637 )
638
639 // Send request to change charset
640 connections.SendTo(
641 term.TelnetRequestChangeCharset.BytesWithPayload(nil),
642 connDetails.ConnectionId(),
643 )
644
645 // Send request to enable MSP
646 connections.SendTo(
647 term.MspEnable.BytesWithPayload(nil),
648 connDetails.ConnectionId(),

Callers 1

TelnetListenOnPortFunction · 0.85

Calls 15

GetUnsentTextMethod · 0.95
CountMethod · 0.95
SetMethod · 0.95
NextMethod · 0.95
SetUnsentTextMethod · 0.95
ClearMethod · 0.95
GetCommandPromptMethod · 0.95
ResetMethod · 0.95
InfoFunction · 0.92
GetLoginPromptHandlerFunction · 0.92
SendToFunction · 0.92
TelnetWILLFunction · 0.92

Tested by

no test coverage detected