Skip to content

Commit

Permalink
remove old factorio mods code
Browse files Browse the repository at this point in the history
  • Loading branch information
Distortions81 committed Mar 9, 2024
1 parent cb9ebb4 commit 2ad99cd
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 316 deletions.
66 changes: 1 addition & 65 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,62 +227,6 @@ var cmds = []Command{
},
Command: admin.GConfigServer, AdminOnly: true, PrimaryOnly: true},
/* MODERATOR COMMANDS ---------------- */
{AppCmd: &discordgo.ApplicationCommand{
Name: "change-mods",
Description: "MOD ONLY: Change game mods",
Type: discordgo.ChatApplicationCommand,
Options: []*discordgo.ApplicationCommandOption{
{
Name: "add-mod",
Description: "attempt to add a mod by name",
Type: discordgo.ApplicationCommandOptionString,
Required: false,
},
{
Name: "del-mod",
Description: "delete a mod by number from list-all",
Type: discordgo.ApplicationCommandOptionString,
Required: false,
},
{
Name: "enable-mod",
Description: "enable a mod by number from list-all",
Type: discordgo.ApplicationCommandOptionString,
Required: false,
},
{
Name: "disable-mod",
Description: "disable a mod by number from list-all",
Type: discordgo.ApplicationCommandOptionString,
Required: false,
},
{
Name: "action",
Description: "List of possible actions.",
Type: discordgo.ApplicationCommandOptionString,
Required: false,
Choices: []*discordgo.ApplicationCommandOptionChoice{
{
Name: "enable-all",
Value: "enable-all",
},
{
Name: "disable-all",
Value: "disable-all",
},
{
Name: "delete-all",
Value: "delete-all",
},
{
Name: "show-list",
Value: "show-list",
},
},
},
},
},
Command: moderator.ModManager, ModeratorOnly: true},
{AppCmd: &discordgo.ApplicationCommand{
Name: "rcon",
Description: "MOD ONLY: remote console (remotely run a factorio command)",
Expand Down Expand Up @@ -392,22 +336,14 @@ var cmds = []Command{
Options: []*discordgo.ApplicationCommandOption{
{
Name: "options",
Description: "verbose shows all settings/info, list-mods shows all installed game mods.",
Description: "verbose shows all settings/info.",
Type: discordgo.ApplicationCommandOptionString,
Required: false,
Choices: []*discordgo.ApplicationCommandOptionChoice{
{
Name: "verbose",
Value: "verbose",
},
{
Name: "list-mods",
Value: "list-mods",
},
{
Name: "debug",
Value: "debug",
},
},
},
},
Expand Down
33 changes: 0 additions & 33 deletions commands/moderator/modManager.go

This file was deleted.

13 changes: 0 additions & 13 deletions commands/user/newInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ func Info(s *discordgo.Session, i *discordgo.InteractionCreate) {
str := arg.StringValue()
if strings.EqualFold(str, "verbose") {
verbose = true
} else if strings.EqualFold(str, "debug") {
if disc.CheckAdmin(i) {
debug = true
} else {
buf = buf + "Sorry, the debug option is admin-only.\n\n"
}
} else if strings.EqualFold(str, "list-mods") {
mList, err := fact.MakeModList()
if err != nil {
disc.EphemeralResponse(s, i, "Server Mods: (basic list)", strings.Join(fact.ModList, ", "))
} else {
disc.EphemeralResponse(s, i, "Server Mods:", "```\n"+mList+"\n```")
}
}
}
}
Expand Down
168 changes: 0 additions & 168 deletions fact/factUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fact

import (
"archive/zip"
"encoding/json"
"fmt"
"io"
"io/fs"
Expand All @@ -24,173 +23,6 @@ import (
"ChatWire/sclean"
)

type infoJSONData struct {
Name string
Version string
Title string
Dependencies []string
Description string
Factorio_version string
Homepage string
}

type modData struct {
Name string
Enabled bool
}

type modListData struct {
Mods []modData
}

func readInfoJson(content []byte) (*infoJSONData, bool) {

info := &infoJSONData{}
err := json.Unmarshal(content, &info)
if err != nil {
cwlog.DoLogCW("readInfoJson: Unmarshal failure")
return nil, false
}
return info, true
}

func readMod(filename string) (*infoJSONData, bool) {
read, err := zip.OpenReader(filename)
if err != nil {
cwlog.DoLogCW(err.Error())
return nil, false
}

for _, file := range read.File {
fc, err := file.Open()
if err != nil {
cwlog.DoLogCW(err.Error())
return nil, false
}
fileName := filepath.Base(file.Name)
if fileName == "info.json" {
content, err := io.ReadAll(fc)
if err != nil {
cwlog.DoLogCW(err.Error())
return nil, false
}
if len(content) > 0 {
return readInfoJson(content)
} else {
return nil, false
}
}
}

return nil, false
}

func readModList(path string) (*modListData, bool) {

content, err := os.ReadFile(path + "mod-list.json")
if err != nil {
cwlog.DoLogCW(err.Error())
return nil, false
}

modList := &modListData{}
err = json.Unmarshal(content, &modList)
if err != nil {
cwlog.DoLogCW("readModList: Unmarshal failure")
return nil, false
}

return modList, true
}

func searchModlist(modList *modListData, modName string) (bool, bool) {
if modList != nil && modList.Mods != nil && modName != "" {
for _, mod := range modList.Mods {
if mod.Name == modName {
return true, true
}
}
return false, true
}

return false, false
}

func checkModLoaded(modName string) bool {
for _, mod := range ModList {
if mod == modName {
return true
}
}
return false
}
func MakeModList() (string, error) {

path := cfg.Global.Paths.Folders.ServersRoot +
cfg.Global.Paths.ChatWirePrefix +
cfg.Local.Callsign + "/" +
cfg.Global.Paths.Folders.FactorioDir + "/" +
cfg.Global.Paths.Folders.Mods + "/"

files, err := os.ReadDir(path)
/* We can't read saves dir */
if err != nil {
cwlog.DoLogCW(err.Error())
return "Error", err
}

/* Loop all files */
var tempf []fs.DirEntry
for _, f := range files {
//Hide non-zip files, temp files
if strings.HasSuffix(f.Name(), ".zip") {
tempf = append(tempf, f)
}
}

modList, _ := readModList(path)
numFiles := len(tempf)

buf := ""
count := 1
for x := 0; x < numFiles; x++ {
file := tempf[x]

number := fmt.Sprintf("#%3v ", count)
info, found := readMod(path + file.Name())
if found {
buf = buf + number
foundMod, foundList := searchModlist(modList, info.Name)

if foundList {
if foundMod {
buf = buf + "( ON) "
} else {
buf = buf + "(OFF) "
}
} else {
buf = buf + "( ? ) "
}

if checkModLoaded(info.Name) {
buf = buf + "@"
} else {
buf = buf + " "
}
buf = buf + info.Name + " v" + info.Version

} else {
buf = buf + number + "Filename: " + strings.TrimSuffix(file.Name(), ".zip") + " (corrupt mod file?)"
}
buf = buf + "\n"
count++
}
if count == 0 {
buf = buf + "None."
}
return buf, err
}

func CheckSave(path, name string, showError bool) (good bool, folder string) {
zip, err := zip.OpenReader(path + "/" + name)
if err != nil || zip == nil {
Expand Down
33 changes: 0 additions & 33 deletions support/pipeHandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,39 +558,6 @@ func handleMapLoad(NoTC string, NoDSlist []string, NoTClist []string, NoTClistle
return false
}

func handleModLoad(NoTC string) bool {
/******************
* LOADING MOD
******************/
if strings.HasPrefix(NoTC, "Loading mod") {

if !strings.Contains(NoTC, "base") &&
!strings.Contains(NoTC, "core") &&
!strings.Contains(NoTC, "settings") {

parts := strings.Split(NoTC, " ")
numParts := len(parts) - 1
if numParts >= 4 {

modName := strings.Join(parts[2:numParts-1], " ")

found := false
for _, m := range fact.ModList {
if strings.EqualFold(m, modName) {
found = true
}
}
if !found {
fact.ModList = append(fact.ModList, modName)
cwlog.DoLogCW(NoTC)
}
}
}
}
/* Dont eat, factorio version handle uses this too */
return false
}

func handleBan(NoDS string, NoDSlist []string, NoDSlistlen int) bool {
/******************
* BAN
Expand Down
4 changes: 0 additions & 4 deletions support/pipeParse.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ func HandleChat() {
continue
}

if handleModLoad(NoTC) {
continue
}

go handleBan(NoDS, NoDSlist, NoDSlistlen)

if handleSVersion(line, lineList, lineListlen) {
Expand Down

0 comments on commit 2ad99cd

Please sign in to comment.