From 0481b15b9bb11e5929623a170a99be96092c877d Mon Sep 17 00:00:00 2001 From: rockisch Date: Thu, 23 Nov 2023 22:12:36 -0300 Subject: [PATCH] Allow signv2 response to be configured --- config.json | 5 +- config/config.go | 21 ++++ server/channelserver/sys_channel_server.go | 2 +- server/signv2server/endpoints.go | 118 ++------------------- 4 files changed, 33 insertions(+), 113 deletions(-) diff --git a/config.json b/config.json index 93ea5aec4..9fcb4ef68 100644 --- a/config.json +++ b/config.json @@ -134,7 +134,10 @@ "SignV2": { "Enabled": false, "Port": 8080, - "PatchServer": "" + "PatchServer": "", + "Banners": [], + "Messages": [], + "Links": [] }, "Channel": { "Enabled": true diff --git a/config/config.go b/config/config.go index a9103e6b7..e992d6594 100644 --- a/config/config.go +++ b/config/config.go @@ -198,6 +198,27 @@ type SignV2 struct { Enabled bool Port int PatchServer string + Banners []SignV2Banner + Messages []SignV2Message + Links []SignV2Link +} + +type SignV2Banner struct { + Src string `json:"src"` // Displayed image URL + Link string `json:"link"` // Link accessed on click +} + +type SignV2Message struct { + Message string `json:"message"` // Displayed message + Date int64 `json:"date"` // Displayed date + Kind int `json:"kind"` // 0 for 'Default', 1 for 'New' + Link string `json:"link"` // Link accessed on click +} + +type SignV2Link struct { + Name string `json:"name"` // Displayed name + Icon string `json:"icon"` // Displayed icon. It will be cast as a monochrome color as long as it is transparent. + Link string `json:"link"` // Link accessed on click } type Channel struct { diff --git a/server/channelserver/sys_channel_server.go b/server/channelserver/sys_channel_server.go index d12d713f5..70f52e461 100644 --- a/server/channelserver/sys_channel_server.go +++ b/server/channelserver/sys_channel_server.go @@ -9,7 +9,7 @@ import ( "erupe-ce/common/byteframe" ps "erupe-ce/common/pascalstring" - "erupe-ce/config" + _config "erupe-ce/config" "erupe-ce/network/binpacket" "erupe-ce/network/mhfpacket" "erupe-ce/server/discordbot" diff --git a/server/signv2server/endpoints.go b/server/signv2server/endpoints.go index a2ab3b151..cde28591c 100644 --- a/server/signv2server/endpoints.go +++ b/server/signv2server/endpoints.go @@ -4,10 +4,10 @@ import ( "database/sql" "encoding/json" "errors" + _config "erupe-ce/config" "erupe-ce/server/channelserver" "net/http" "strings" - "time" "github.com/lib/pq" "go.uber.org/zap" @@ -19,28 +19,10 @@ const ( NotificationNew ) -type LauncherBanner struct { - Src string `json:"src"` - Link string `json:"link"` -} - -type LauncherMessage struct { - Message string `json:"message"` - Date int64 `json:"date"` - Link string `json:"link"` - Kind int `json:"kind"` -} - -type LauncherLink struct { - Name string `json:"name"` - Link string `json:"link"` - Icon string `json:"icon"` -} - type LauncherResponse struct { - Banners []LauncherBanner `json:"banners"` - Messages []LauncherMessage `json:"messages"` - Links []LauncherLink `json:"links"` + Banners []_config.SignV2Banner `json:"banners"` + Messages []_config.SignV2Message `json:"messages"` + Links []_config.SignV2Link `json:"links"` } type User struct { @@ -122,95 +104,9 @@ func (s *Server) newAuthData(userID uint32, userRights uint32, userToken string, func (s *Server) Launcher(w http.ResponseWriter, r *http.Request) { var respData LauncherResponse - respData.Banners = []LauncherBanner{ - { - Src: "http://zerulight.cc/launcher/en/images/bnr/1030_0.jpg", - Link: "http://localhost", - }, - { - Src: "http://zerulight.cc/launcher/en/images/bnr/0801_3.jpg", - Link: "http://localhost", - }, - { - Src: "http://zerulight.cc/launcher/en/images/bnr/0705_3.jpg", - Link: "http://localhost", - }, - { - Src: "http://zerulight.cc/launcher/en/images/bnr/1211_11.jpg", - Link: "http://localhost", - }, - { - Src: "http://zerulight.cc/launcher/en/images/bnr/reg_mezefes.jpg", - Link: "http://localhost", - }, - } - respData.Messages = []LauncherMessage{ - { - Message: "Server Update 9.2 — Quest fixes,\nGacha support and tons of bug fixes!", - Date: time.Date(2023, 4, 1, 0, 0, 0, 0, time.UTC).Unix(), - Link: "https://discord.com/channels/368424389416583169/929509970624532511/1003985850255818762", - Kind: NotificationNew, - }, - { - Message: "English Patch 4.1 — Fix \"Unknown\" weapons, NPC changes & Diva Support.", - Date: time.Date(2023, 2, 27, 0, 0, 0, 0, time.UTC).Unix(), - Link: "https://discord.com/channels/368424389416583169/929509970624532511/969305400795078656", - Kind: NotificationNew, - }, - { - Message: "Server Update 9.1! Hunter Festival, Return worlds and NetCafe are back!", - Date: time.Date(2022, 11, 4, 0, 0, 0, 0, time.UTC).Unix(), - Link: "https://discord.com/channels/368424389416583169/929509970624532511/969286397301248050", - Kind: NotificationDefault, - }, - { - Message: "Deerby & Supream have been updating Ferias! You can find any and all MHF info/data there!", - Date: time.Date(2022, 7, 7, 0, 0, 0, 0, time.UTC).Unix(), - Link: "https://discord.gg/CFnzbhQ", - Kind: NotificationDefault, - }, - { - Message: "Server hosts, get Chakratos' Save Manager! Use it to enhance your Erupe server!", - Date: time.Date(2022, 7, 7, 0, 0, 0, 0, time.UTC).Unix(), - Link: "https://discord.gg/CFnzbhQ", - Kind: NotificationDefault, - }, - { - Message: "Server Update 9.0 is out! Enjoy MezFes and all the other new content!", - Date: time.Date(2022, 8, 2, 0, 0, 0, 0, time.UTC).Unix(), - Link: "https://discord.gg/CFnzbhQ", - Kind: NotificationDefault, - }, - { - Message: "English Community Translation 2 is here! Get the latest translation patch!", - Date: time.Date(2022, 5, 4, 0, 0, 0, 0, time.UTC).Unix(), - Link: "https://discord.gg/CFnzbhQ", - Kind: NotificationDefault, - }, - { - Message: "Join the community Discord for future updates!", - Date: time.Date(2022, 5, 4, 0, 0, 0, 0, time.UTC).Unix(), - Link: "https://discord.gg/CFnzbhQ", - Kind: NotificationDefault, - }, - } - respData.Links = []LauncherLink{ - { - Name: "GitHub", - Link: "https://github.com/ZeruLight/Erupe", - Icon: "https://cdn-icons-png.flaticon.com/512/25/25231.png", - }, - { - Name: "Discord", - Link: "https://discord.gg/DnwcpXM488", - Icon: "https://assets-global.website-files.com/6257adef93867e50d84d30e2/636e0a6a49cf127bf92de1e2_icon_clyde_blurple_RGB.png", - }, - { - Name: "Equal Dragon Weapon Info", - Link: "https://discord.gg/DnwcpXM488", - Icon: "", - }, - } + respData.Banners = s.erupeConfig.SignV2.Banners + respData.Messages = s.erupeConfig.SignV2.Messages + respData.Links = s.erupeConfig.SignV2.Links w.Header().Add("Content-Type", "application/json") json.NewEncoder(w).Encode(respData) }