From c1117bb859053a2edace051a95506a0509869c0f Mon Sep 17 00:00:00 2001 From: EladNLG Date: Wed, 29 Mar 2023 13:17:28 +0300 Subject: pkg/atlas, pkg/api/api0: lol --- pkg/api/api0/serverlist.go | 39 ++++++++++++++++++++++++++++++++++++--- pkg/atlas/config.go | 3 +++ pkg/atlas/server.go | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/pkg/api/api0/serverlist.go b/pkg/api/api0/serverlist.go index 3a11c21..89b2e05 100644 --- a/pkg/api/api0/serverlist.go +++ b/pkg/api/api0/serverlist.go @@ -11,6 +11,7 @@ import ( "net/netip" "sort" "strconv" + "strings" "sync" "sync/atomic" "time" @@ -70,6 +71,8 @@ type ServerListConfig struct { // restarting the masterserver) or server restart. Notable, if a server // changes their name or description, the ID will not be the same anymore. ExperimentalDeterministicServerIDSecret string + + AllowUwuify bool } type Server struct { @@ -272,14 +275,14 @@ func (s *ServerList) csGetJSON() []byte { // generate the json and cache it // // note: we write it manually to avoid copying the entire list and to avoid the perf overhead of reflection - buf, est := csJSON(ss, int(s.csEst.Load())) + buf, est := csJSON(ss, int(s.csEst.Load()), s.cfg) s.csBytes.Store(&buf) s.csEst.Store(uint64(est)) return buf } -func csJSON(ss []*Server, est int) ([]byte, int) { +func csJSON(ss []*Server, est int, cfg ServerListConfig) ([]byte, int) { if len(ss) == 0 { return []byte(`[]`), est } @@ -316,7 +319,13 @@ func csJSON(ss []*Server, est int) ([]byte, int) { b = append(b, `,"id":"`...) b = append(b, srv.ID...) b = append(b, `","name":`...) - b = appendJSONString(b, srv.Name) + name := srv.Name + if cfg.AllowUwuify { + if _, m, d := time.Now().UTC().Date(); m == time.April && d == 1 { + name = uwuify(name) + } + } + b = appendJSONString(b, name) if srv.Region != "" && srv.Password == "" { b = append(b, `,"region":`...) b = appendJSONString(b, srv.Region) @@ -1295,3 +1304,27 @@ func appendJSONString(e []byte, s string) []byte { e = append(e, '"') return e } + +// uwuifier contains replacements to convert a string to uwu. +// +// Source: gitlab.com/lamados/uwuify, MIT license, Copyright (c) 2020 lamados. +// P.S. since repo is now gone see rehosted at https://github.com/1lann/uwuify +var replacer = strings.NewReplacer( + "r", "w", "R", "W", + "l", "w", "L", "W", + "f", "fw", "F", "FW", + "ck", "cc", "cK", "cC", "Ck", "Cc", "CC", "CC", + "ff", "ffw", "fF", "fFW", "Ff", "Ffw", "FF", "FFW", + // "ing", "in", "inG", "iN", "iNg", "iN", "iNG", "iN", "Ing", "In", "InG", "IN", "INg", "IN", "ING", "IN", + "tha", "da", "thA", "dA", "tHa", "Da", "tHA", "DA", "Tha", "Da", "ThA", "DA", "THa", "Da", "THA", "DA", + "the", "de", "thE", "dE", "tHe", "De", "tHE", "DE", "The", "De", "ThE", "DE", "THe", "De", "THE", "DE", + "...", ",,,", "..", ",,", "…", ",,,", + ".", "!!!", "?", "?!!!", "!", "!!!", + "Northstar", "SouwthSuwn", + "northstar", "souwthsuwn", +) + +// converts s to UwU. +func uwuify(s string) string { + return replacer.Replace(s) +} diff --git a/pkg/atlas/config.go b/pkg/atlas/config.go index a7cc8c2..2855489 100644 --- a/pkg/atlas/config.go +++ b/pkg/atlas/config.go @@ -220,6 +220,9 @@ type Config struct { // {status}.html. Web string `env:"ATLAS_WEB"` + // For the Funny:tm: + AllowJokes bool `env:"ATLAS_JOKES"` + // The path to the IP2Location database, which should contain at least the // country and region fields. The database must not be modified while atlas // is running, but it can be replaced (and a reload can be triggered with diff --git a/pkg/atlas/server.go b/pkg/atlas/server.go index 043fa2c..c8f39f4 100644 --- a/pkg/atlas/server.go +++ b/pkg/atlas/server.go @@ -272,6 +272,7 @@ func NewServer(c *Config) (*Server, error) { s.API0 = &api0.Handler{ ServerList: api0.NewServerList(c.API0_ServerList_DeadTime, c.API0_ServerList_GhostTime, c.API0_ServerList_VerifyTime, api0.ServerListConfig{ ExperimentalDeterministicServerIDSecret: c.API0_ServerList_ExperimentalDeterministicServerIDSecret, + AllowUwuify: c.AllowJokes, }), MaxServers: c.API0_MaxServers, MaxServersPerIP: c.API0_MaxServersPerIP, -- cgit v1.2.3