Skip to content

Commit 1a691a9

Browse files
authored
Web Adjustments
# Changes * Added `MudName` config - should be name of mud. * Injecting `MudName` various web places (webclient connect button, page titles, page header nav) * Using defined webport in config for webclient (was hard coded) Example: ![Screenshot 2025-03-01 at 2 14 23 PM](https://github.com/user-attachments/assets/e40579c4-4fac-41bf-a911-1715c222fed0) ![Screenshot 2025-03-01 at 2 14 05 PM](https://github.com/user-attachments/assets/bee2a736-1030-4042-af68-a087c6324e02)
1 parent 35c16f2 commit 1a691a9

File tree

7 files changed

+27
-9
lines changed

7 files changed

+27
-9
lines changed

_datafiles/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
# overwrite your changes.
2424
#
2525
################################################################################
26+
# - MudName -
27+
# Display name of the MUD.
28+
# This will be used a few places by default (such as the web pages).
29+
MudName: "GoMud"
2630
# - Version -
2731
# Latest semantic version of the datafiles (MAJOR.MINOR.PATCH)
2832
# Do not change this value, it will be handled by the server when updated

_datafiles/html/public/_header.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<head>
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>GoMud: The Open-source MUD server, written in Go</title>
7+
<title>Welcome to {{ mudname }}</title>
88
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" />
99
<link rel="stylesheet" href="/static/public/css/gomud.css">
1010
</head>
1111
<body>
1212
<header>
1313
<div>
14-
<a class="gomud-btn" href="/">GoMud</a>
14+
<a class="gomud-btn" href="/">{{ mudname }}</a>
1515
</div>
1616
<div class="nav-toggle" onclick="toggleMenu()">
1717
<div></div>
@@ -22,7 +22,7 @@
2222

2323
<nav>
2424
<div class="nav-container">
25-
<a href="/">Home</a>
25+
<a href="/">Go Home</a>
2626
<a href="/online">Who's Online</a>
2727
<a href="/webclient">Web Client</a>
2828
<a href="/viewconfig">See Configuration</a>

_datafiles/html/public/webclient.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>GoMud Web Terminal</title>
4+
<title>{{ mudname }} Web Terminal</title>
55
<style>
66
* {
77
box-sizing: border-box;
@@ -190,7 +190,7 @@ <h3>Volume Controls</h3>
190190
</div>
191191

192192
<!-- CONNECT BUTTON FLOATED IN CENTER -->
193-
<button id="connect-button">Connect</button>
193+
<button id="connect-button">Connect to {{ .MudName }}</button>
194194

195195
<div id="input-area">
196196
<input type="text" id="command-input" placeholder="Enter command...">
@@ -298,8 +298,8 @@ <h3>Volume Controls</h3>
298298
socket.close();
299299
return;
300300
}
301-
debugLog("Connecting to: " + 'ws://'+location.host +':80/ws');
302-
socket = new WebSocket('ws://'+location.host +':80/ws');
301+
debugLog("Connecting to: " + 'ws://'+location.host +':{{ .WebPort }}/ws');
302+
socket = new WebSocket('ws://'+location.host +':{{ .WebPort }}/ws');
303303

304304
socket.onopen = function() {
305305
term.writeln("Connected to the server!");

internal/configs/configs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const (
2323
)
2424

2525
type Config struct {
26-
Version ConfigString `yaml:"Version"` // Cuurrent version of all datafiles
26+
MudName ConfigString `yaml:"MudName"` // Name of the MUD
27+
Version ConfigString `yaml:"Version"` // Current version of all datafiles
2728
MaxCPUCores ConfigInt `yaml:"MaxCPUCores"`
2829
FolderDataFiles ConfigString `yaml:"FolderDataFiles"`
2930
FolderHtmlFiles ConfigString `yaml:"FolderHtmlFiles"`

internal/web/home.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,12 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
2121

2222
func serveClient(w http.ResponseWriter, r *http.Request) {
2323
// read contents of webclient.html and print it out
24-
http.ServeFile(w, r, configs.GetConfig().FolderHtmlFiles.String()+"/public/webclient.html")
24+
25+
tmpl, err := template.New("webclient.html").Funcs(funcMap).ParseFiles(configs.GetConfig().FolderHtmlFiles.String() + "/public/webclient.html")
26+
if err != nil {
27+
mudlog.Error("HTML ERROR", "error", err)
28+
}
29+
30+
tmpl.Execute(w, configs.GetConfig())
31+
2532
}

internal/web/template_func.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"html"
66
"strings"
77
"text/template"
8+
9+
"github.com/volte6/gomud/internal/configs"
810
)
911

1012
var (
@@ -97,5 +99,8 @@ var (
9799
"lowercase": func(str string) string {
98100
return strings.ToLower(str)
99101
},
102+
"mudname": func() string {
103+
return string(configs.GetConfig().MudName)
104+
},
100105
}
101106
)

internal/web/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func Listen(webPort int, wg *sync.WaitGroup, webSocketHandler func(*websocket.Co
3232

3333
// HTTP Server
3434
httpServer = &http.Server{Addr: fmt.Sprintf(`:%d`, webPort)}
35+
3536
// Routing
3637
// Basic homepage
3738
http.HandleFunc("/", serveHome)

0 commit comments

Comments
 (0)