-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
160 lines (149 loc) · 4.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package main
import (
//"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"github.com/xackery/eqcleanup/defiant"
"github.com/xackery/eqcleanup/eqemuconfig"
"github.com/xackery/eqcleanup/ldon"
"github.com/xackery/eqcleanup/nexus"
"github.com/xackery/eqcleanup/priests"
"github.com/xackery/eqcleanup/rainsnow"
"github.com/xackery/eqcleanup/rodent"
"github.com/xackery/eqcleanup/soulbinder"
"github.com/xackery/eqcleanup/spells"
"github.com/xackery/eqcleanup/tribute"
"github.com/xackery/eqcleanup/trickortreat"
"os"
"strings"
)
func main() {
for {
showMenu()
}
}
func connectDB(config *eqemuconfig.Config) (db *sqlx.DB, err error) {
//Connect to DB
db, err = sqlx.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=true", config.Database.Username, config.Database.Password, config.Database.Host, config.Database.Port, config.Database.Db))
if err != nil {
fmt.Println("Error connecting to DB:", err.Error())
os.Exit(1)
}
return
}
var isDBConnected bool
var isConfigLoaded bool
func showMenu() {
var err error
var option string
fmt.Println("\n\n===EQ Cleanup===")
fmt.Println("Remember: Always back up before using this tool!")
fmt.Println("Choose an option:")
config := menuConfig()
db := menuDB(&config)
defer db.Close()
if isDBConnected && isConfigLoaded {
fmt.Println("3) Delete Soulbinders")
fmt.Println("4) Delete Rodents")
fmt.Println("5) Delete Trick or Treat Quests")
fmt.Println("6) Delete Tribute Masters")
fmt.Println("7) Delete All spells, tomes (scribable items)")
fmt.Println("8) Delete Priests of Discord")
fmt.Println("9) Delete Defiant Armor")
fmt.Println("10) Delete LDON Npcs")
fmt.Println("11) Delete Nexus portal NPCs")
fmt.Println("12) Disable Rain and Snow")
} else {
fmt.Println("-Commands are disabled until database and config is good-")
}
fmt.Println("Q) Quit")
fmt.Scan(&option)
fmt.Println("You chose option:", option)
option = strings.ToLower(option)
if option == "q" || option == "exit" {
fmt.Println("Exiting")
os.Exit(0)
}
if !isDBConnected || !isConfigLoaded {
return
}
if option == "3" { //Clean up Soulbinders
err = soulbinder.Clean(db, &config)
if err != nil {
fmt.Println("Error removing soulbinders:", err.Error())
}
} else if option == "4" {
err = rodent.Clean(db, &config)
if err != nil {
fmt.Println("Error removing rodents:", err.Error())
}
} else if option == "5" {
err = trickortreat.Clean(db, &config)
if err != nil {
fmt.Println("Error removing trick or treat:", err.Error())
}
} else if option == "6" {
err = tribute.Clean(db, &config)
if err != nil {
fmt.Println("Error removing tribute:", err.Error())
}
} else if option == "7" {
err = spells.Clean(db, &config)
if err != nil {
fmt.Println("Error removing spells:", err.Error())
}
} else if option == "8" {
err = priests.Clean(db, &config)
if err != nil {
fmt.Println("Error removing priest of discords:", err.Error())
}
} else if option == "9" {
err = defiant.Clean(db, &config)
if err != nil {
fmt.Println("Error removing defiant:", err.Error())
}
} else if option == "10" {
err = ldon.Clean(db, &config)
if err != nil {
fmt.Println("Error removing ldon:", err.Error())
}
} else if option == "11" {
err = nexus.Clean(db, &config)
if err != nil {
fmt.Println("Error removing nexus:", err.Error())
}
} else if option == "12" {
err = rainsnow.Clean(db, &config)
if err != nil {
fmt.Println("Error removing rain and snow:", err.Error())
}
}
return
}
func menuConfig() (config eqemuconfig.Config) {
config, err := eqemuconfig.LoadConfig()
status := "Good"
if err != nil {
isConfigLoaded = false
status = fmt.Sprintf("Bad (%s)", err.Error())
} else {
isConfigLoaded = true
status = fmt.Sprintf("Good (%s)", config.Longame)
}
fmt.Printf("1) Reload eqemu_config.xml (Status: %s)\n", status)
return
}
func menuDB(config *eqemuconfig.Config) (db *sqlx.DB) {
var err error
db, err = connectDB(config)
status := "Good"
if err != nil {
isDBConnected = false
status = fmt.Sprintf("Bad (%s)", err.Error())
} else {
isDBConnected = true
}
fmt.Printf("2) Test DB Connection Settings (Status: %s)\n", status)
return
}