aboutsummaryrefslogtreecommitdiff
path: root/internal/net
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-19 18:20:26 -0400
committerhistoria <[not public]>2026-06-19 18:20:26 -0400
commit0ea4eec5dd2122c6704216971eb1249276297867 (patch)
tree430fbbef04e837820f1d031c190f52ecd6112e25 /internal/net
parent3a58125d14bb307f861b38c6c5b0a63babde7e08 (diff)
downloadthehouseoficarus-0ea4eec5dd2122c6704216971eb1249276297867.tar.gz
shop fixes, 'toggle' completely removed, movement speed increased
Diffstat (limited to 'internal/net')
-rw-r--r--internal/net/server.go95
-rw-r--r--internal/net/welcome.go82
2 files changed, 89 insertions, 88 deletions
diff --git a/internal/net/server.go b/internal/net/server.go
index 7c7a18c..f82f82b 100644
--- a/internal/net/server.go
+++ b/internal/net/server.go
@@ -6,10 +6,10 @@ import (
"log"
"net"
"net/http"
- "strings"
- "thehouseoficarus/internal/color"
+ "thehouseoficarus/internal/action"
"thehouseoficarus/internal/config"
+ "thehouseoficarus/internal/player"
)
type SessionState int
@@ -46,8 +46,8 @@ const (
type Session struct {
Conn Conn
State SessionState
- Account *AccountEntry
- Player interface{}
+ Account *player.Account
+ Player *player.Player
PendingChar string
PendingPass string
PendingMenu []map[string]string
@@ -57,17 +57,10 @@ type Session struct {
PendingBackground bool
Disconnecting bool
DisconnectTicks int
- Shop interface{}
+ Shop *action.ShopConfig
}
-type AccountEntry struct {
- Name string
- PasswordHash string
- Characters []string
- Aliases map[string]string
- Colors map[string]string
- Options map[string]any
-}
+
type Server struct {
config *config.Config
@@ -281,53 +274,6 @@ func (s *Server) serveHTTPS() {
}
}
-func artColor(r rune) string {
- switch r {
- case '@':
- return color.FgCode("ansi", 4)
- case '!', ':', '.':
- return color.StyleCode("dim") + color.FgCode("ansi", 4)
- case ',':
- return color.FgCode("ansi", 5)
- case '*':
- return color.FgCode("ansi", 5)
- case '+', '|', '-':
- return color.FgCode("ansi", 3)
- }
- return ""
-}
-
-func colorizeRunes(s string) string {
- var sb strings.Builder
- current := ""
- for _, r := range s {
- want := artColor(r)
- if want != current {
- if current != "" {
- sb.WriteString(color.Reset)
- }
- if want != "" {
- sb.WriteString(want)
- }
- current = want
- }
- sb.WriteRune(r)
- }
- if current != "" {
- sb.WriteString(color.Reset)
- }
- return sb.String()
-}
-
-func colorizeArt(art string) string {
- welcomeText := "welcome to the house of icarus"
- before, after, found := strings.Cut(art, welcomeText)
- if found {
- return colorizeRunes(before) + color.FgCode("ansi", 7) + welcomeText + color.Reset + colorizeRunes(after)
- }
- return colorizeRunes(art)
-}
-
func (s *Server) handleSession(sess *Session, handler func(*Session, string)) {
defer func() {
if r := recover(); r != nil {
@@ -339,34 +285,7 @@ func (s *Server) handleSession(sess *Session, handler func(*Session, string)) {
sess.Conn.Write([]byte("\033[2J\033[H"))
- welcomeart := colorizeArt(`
- | *
- * + -+-
- . , |
-. , . ,
- *
- @@@@@@@ @@@ @@@ @@@@@@@@ @@@ @@@ @@@@@@ @@@ @@@ @@@@@@ @@@@@@@@ +
- @@! @@! @@@ @@! + @@! @@@ @@! @@@ @@! @@@ !@@ @@!
- @!! @!@!@!@! @!!!:! @!@!@!@! @!@ !@! @!@ !@! !@@!! @!!!:! *
- !!: !!: !!! !!: . !!: !!! !!: !!! !!: !!! !:! !!:
- : : : : : :: ::: : : : : :. : :.:: : ::.: : : :: ::: .
- . +
- * welcome to the house of icarus , ,
- , .
- @@@@@@ @@@@@@@@ @@@ @@@@@@@ @@@@@@ @@@@@@@ @@@ @@@ @@@@@@
- @@! @@@ @@! , @@! !@@ @@! @@@ @@! @@@ @@! @@@ !@@
- | @!@ !@! @!!!:! !!@ !@! @!@!@!@! @!@!!@! @!@ !@! !@@!!
- -+- !!: !!! !!: !!: :!! !!: !!! !!: :!! !!: !!! !:!
- | : :. : : . : :: :: : : : : : : : :.:: : ::.: :
- ,
- . + , .
- . ,
- * . , *
- +
-`)
-
-
- sess.Write(welcomeart)
+ sess.Write(WelcomeBanner())
sess.Write("What's your account name? ")
for {
diff --git a/internal/net/welcome.go b/internal/net/welcome.go
new file mode 100644
index 0000000..e17c82e
--- /dev/null
+++ b/internal/net/welcome.go
@@ -0,0 +1,82 @@
+package net
+
+import (
+ "strings"
+
+ "thehouseoficarus/internal/color"
+)
+
+func artColor(r rune) string {
+ switch r {
+ case '@':
+ return color.FgCode("ansi", 4)
+ case '!', ':', '.':
+ return color.StyleCode("dim") + color.FgCode("ansi", 4)
+ case ',':
+ return color.FgCode("ansi", 5)
+ case '*':
+ return color.FgCode("ansi", 5)
+ case '+', '|', '-':
+ return color.FgCode("ansi", 3)
+ }
+ return ""
+}
+
+func colorizeRunes(s string) string {
+ var sb strings.Builder
+ current := ""
+ for _, r := range s {
+ want := artColor(r)
+ if want != current {
+ if current != "" {
+ sb.WriteString(color.Reset)
+ }
+ if want != "" {
+ sb.WriteString(want)
+ }
+ current = want
+ }
+ sb.WriteRune(r)
+ }
+ if current != "" {
+ sb.WriteString(color.Reset)
+ }
+ return sb.String()
+}
+
+func colorizeArt(art string) string {
+ welcomeText := "welcome to the house of icarus"
+ before, after, found := strings.Cut(art, welcomeText)
+ if found {
+ return colorizeRunes(before) + color.FgCode("ansi", 7) + welcomeText + color.Reset + colorizeRunes(after)
+ }
+ return colorizeRunes(art)
+}
+
+func WelcomeBanner() string {
+ return colorizeArt(`
+ | *
+ * + -+-
+ . , |
+. , . ,
+ *
+ @@@@@@@ @@@ @@@ @@@@@@@@ @@@ @@@ @@@@@@ @@@ @@@ @@@@@@ @@@@@@@@ +
+ @@! @@! @@@ @@! + @@! @@@ @@! @@@ @@! @@@ !@@ @@!
+ @!! @!@!@!@! @!!!:! @!@!@!@! @!@ !@! @!@ !@! !@@!! @!!!:! *
+ !!: !!: !!! !!: . !!: !!! !!: !!! !!: !!! :!; !!:
+ : : : : : :: ::: : : : : :. : :.:: : ::.: : : :: ::: .
+ . +
+ * welcome to the house of icarus , ,
+ , .
+ @@@@@@ @@@@@@@@ @@@ @@@@@@@ @@@@@@ @@@@@@@ @@@ @@@ @@@@@@
+ @@! @@@ @@! , @@! !@@ @@! @@@ @@! @@@ @@! @@@ !@@
+ | @!@ !@! @!!!:! !!@ @!@ @!@!@!@! @!@!!@! @!@ !@! !@@!!
+ -+- !!: !!! !!: !!: :!! !!: !!! !!: :!! !!: !!! :!;
+ | : :. : : . : :: :: : : : : : : : :.:: : ::.: :
+ ,
+ . + , .
+ . ,
+ * . , *
+ +
+`)
+}