Skip to content

Commit e205bdb

Browse files
authored
Telnet GO AHEAD (#226)
# Changes * Negotiates whether to send IAC GO AHEAD with client. * If enabled, sends GO AHEAD at end of in-game prompts. * Note: Does not send anywhere else. * A little bit of code and comment cleanup
1 parent 7b00819 commit e205bdb

File tree

6 files changed

+45
-28
lines changed

6 files changed

+45
-28
lines changed

internal/connections/clientsettings.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package connections
33
type ClientSettings struct {
44
Display DisplaySettings
55
Discord DiscordSettings
6-
Client ClientType
6+
Client ClientType // Client data provided by `Core.Hello` GMCP command
77
// Enabled GMCP Modules
8-
GMCPModules map[string]int
8+
GMCPModules map[string]int // Enabled GMCP Modules (if any)
99
// Is MSP enabled?
10-
MSPEnabled bool
10+
MSPEnabled bool // Do they accept sound in their client?
11+
SendTelnetGoAhead bool // Defaults false, should we send a IAC GA after prompts?
1112
}
1213

1314
type DisplaySettings struct {

internal/events/eventtypes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ type Message struct {
5858

5959
func (m Message) Type() string { return `Message` }
6060

61-
// Messages that are intended to reach all users on the system
61+
// Special commands that only the webclient is equipped to handle
6262
type WebClientCommand struct {
6363
ConnectionId uint64
6464
Text string
6565
}
6666

6767
func (b WebClientCommand) Type() string { return `WebClientCommand` }
6868

69-
// Messages that are intended to reach all users on the system
69+
// GMCP Commands from clients to server
7070
type GMCPIn struct {
7171
ConnectionId uint64
7272
Command string
@@ -75,7 +75,7 @@ type GMCPIn struct {
7575

7676
func (b GMCPIn) Type() string { return `GMCP` }
7777

78-
// Messages that are intended to reach all users on the system
78+
// GMCP Commands from server to client
7979
type GMCPOut struct {
8080
ConnectionId uint64
8181
UserId int
@@ -91,7 +91,7 @@ type System struct {
9191

9292
func (s System) Type() string { return `System` }
9393

94-
// Messages that are intended to reach all users on the system
94+
// Payloads describing sound/music to play
9595
type MSP struct {
9696
UserId int
9797
SoundType string // SOUND or MUSIC

internal/inputhandlers/term_iac.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ func TelnetIACHandler(clientInput *connections.ClientInput, sharedState map[stri
187187
continue
188188
}
189189

190+
if ok, _ := term.Matches(iacCmd, term.TelnetDontSuppressGoAhead); ok {
191+
slog.Info("Received", "type", "IAC (TelnetDontSuppressGoAhead)")
192+
193+
cs := connections.GetClientSettings(clientInput.ConnectionId)
194+
cs.SendTelnetGoAhead = true
195+
connections.OverwriteClientSettings(clientInput.ConnectionId, cs)
196+
197+
continue
198+
}
199+
190200
// Is it a screen size report?
191201
if ok, payload := term.Matches(iacCmd, term.TelnetScreenSizeResponse); ok {
192202

internal/term/term.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ var (
4848
//
4949
// GENERAL SETUP
5050
//
51-
// // Suppress Go Ahead
52-
TelnetSuppressGoAhead = TerminalCommand{[]byte{TELNET_IAC, TELNET_WILL, TELNET_OPT_SUP_GO_AHD}, []byte{}}
51+
// // Do/Don't Suppress Go Ahead
52+
TelnetSuppressGoAhead = TerminalCommand{[]byte{TELNET_IAC, TELNET_WILL, TELNET_OPT_SUP_GO_AHD}, []byte{}}
53+
TelnetDontSuppressGoAhead = TerminalCommand{[]byte{TELNET_IAC, TELNET_DONT, TELNET_OPT_SUP_GO_AHD}, []byte{}}
5354
// // Echo On
5455
TelnetEchoOn = TerminalCommand{[]byte{TELNET_IAC, TELNET_WILL, TELNET_OPT_ECHO}, []byte{}}
5556
// // Echo Off
@@ -76,6 +77,8 @@ var (
7677
TelnetAcceptedChangeCharset = TerminalCommand{[]byte{TELNET_IAC, TELNET_SB, 2}, []byte{TELNET_IAC, TELNET_SE}}
7778
// Client rejectected change
7879
TelnetRejectedChangeCharset = TerminalCommand{[]byte{TELNET_IAC, TELNET_SB, 3, TELNET_IAC, TELNET_SE}, []byte{}}
80+
// Go Ahead
81+
TelnetGoAhead = TerminalCommand{[]byte{TELNET_IAC, TELNET_GA}, []byte{}}
7982

8083
///////////////////////////
8184
// ANSI COMMANDS

internal/users/userrecord.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -290,36 +290,34 @@ func (u *UserRecord) GetConnectTime() time.Time {
290290
return u.connectionTime
291291
}
292292

293-
func (u *UserRecord) GetCommandPrompt(fullRedraw bool, forcePromptType ...string) string {
293+
func (u *UserRecord) GetCommandPrompt(fullRedraw bool) string {
294294

295295
promptOut := ``
296296

297-
if len(forcePromptType) == 0 || forcePromptType[0] != `mprompt` {
298-
if u.activePrompt != nil {
297+
if u.activePrompt != nil {
299298

300-
if activeQuestion := u.activePrompt.GetNextQuestion(); activeQuestion != nil {
301-
promptOut = activeQuestion.String()
302-
}
299+
if activeQuestion := u.activePrompt.GetNextQuestion(); activeQuestion != nil {
300+
promptOut = activeQuestion.String()
303301
}
304302
}
305303

304+
goAhead := ``
305+
if connections.GetClientSettings(u.ConnectionId()).SendTelnetGoAhead {
306+
goAhead = term.TelnetGoAhead.String()
307+
}
308+
306309
if len(promptOut) == 0 {
307310

308311
var customPrompt any = nil
309312
var inCombat bool = u.Character.Aggro != nil
310313

311-
if len(forcePromptType) > 0 {
312-
customPrompt = u.GetConfigOption(forcePromptType[0] + `-compiled`)
313-
} else {
314-
315-
if inCombat {
316-
customPrompt = u.GetConfigOption(`fprompt-compiled`)
317-
}
314+
if inCombat {
315+
customPrompt = u.GetConfigOption(`fprompt-compiled`)
316+
}
318317

319-
// No other custom prompts? try the default setting
320-
if customPrompt == nil {
321-
customPrompt = u.GetConfigOption(`prompt-compiled`)
322-
}
318+
// No other custom prompts? try the default setting
319+
if customPrompt == nil {
320+
customPrompt = u.GetConfigOption(`prompt-compiled`)
323321
}
324322

325323
var ok bool
@@ -339,10 +337,10 @@ func (u *UserRecord) GetCommandPrompt(fullRedraw bool, forcePromptType ...string
339337
if len(suggested) > 0 {
340338
suggested = `<ansi fg="suggested-text">` + suggested + `</ansi>`
341339
}
342-
return term.AnsiMoveCursorColumn.String() + term.AnsiEraseLine.String() + promptOut + unsent + suggested
340+
return term.AnsiMoveCursorColumn.String() + term.AnsiEraseLine.String() + promptOut + unsent + suggested + goAhead
343341
}
344342

345-
return promptOut
343+
return promptOut + goAhead
346344
}
347345

348346
func (u *UserRecord) ProcessPromptString(promptStr string) string {

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ func handleTelnetConnection(connDetails *connections.ConnectionDetails, wg *sync
297297
connDetails.ConnectionId(),
298298
)
299299

300+
connections.SendTo(
301+
term.TelnetSuppressGoAhead.BytesWithPayload(nil),
302+
connDetails.ConnectionId(),
303+
)
304+
300305
clientSetupCommands := "" + //term.AnsiAltModeStart.String() + // alternative mode (No scrollback)
301306
//term.AnsiCursorHide.String() + // Hide Cursor (Because we will manually echo back)
302307
//term.AnsiCharSetUTF8.String() + // UTF8 mode

0 commit comments

Comments
 (0)