Merge pull request #7 from Apfel/master

yet another fix
This commit is contained in:
CornierKhan1 2019-06-20 12:31:47 +10:00 committed by GitHub
commit 257a177992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 33 deletions

View File

@ -7,6 +7,12 @@ This is the SOAP Server Software. The other repository only has the communicatio
# Changelog # Changelog
Versions on this software are based on goals. (e.g 0.2 works towards SQL support. 0.3 works towards NUS support, etc.) Versions on this software are based on goals. (e.g 0.2 works towards SQL support. 0.3 works towards NUS support, etc.)
## 0.2.x Kawauso ## 0.2.x Kawauso
### 0.2.6
*This version of WiiSOAP Server was brought to you by Apfel. Thank you for your contribution.*
- Fixed error handling.
- Moved configuration example.
- Added `go.mod` for an easier installation.
- Changed `SQLPort` to `SQLAddress` in the `config.xml` file.
### 0.2.5 ### 0.2.5
*This version of WiiSOAP Server was brought to you by Apfel. Thank you for your contribution.* *This version of WiiSOAP Server was brought to you by Apfel. Thank you for your contribution.*
- Fixed lint errors. - Fixed lint errors.

View File

@ -1,8 +1,8 @@
<Config> <Config>
<Address>127.0.0.1:8080</Address> <Address>127.0.0.1:8080</Address>
<SQLAddress>127.0.0.1:3306</SQLAddress>
<SQLUser>uwu</SQLUser> <SQLUser>uwu</SQLUser>
<SQLPass>owo</SQLPass> <SQLPass>owo</SQLPass>
<SQLDB>wiisoap</SQLDB> <SQLDB>wiisoap</SQLDB>
<SQLPort>127.0.0.1:3306</SQLPort>
</Config> </Config>

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module github.com/Apfel/WiiSOAP
go 1.12
require github.com/go-sql-driver/mysql v1.4.1

7
go.sum Normal file
View File

@ -0,0 +1,7 @@
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=

56
main.go
View File

@ -38,40 +38,40 @@ const (
Header = `<?xml version="1.0" encoding="UTF-8"?>` + "\n" Header = `<?xml version="1.0" encoding="UTF-8"?>` + "\n"
) )
// CheckError makes error handling not as ugly and inefficient. // checkError makes error handling not as ugly and inefficient.
func CheckError(e error) { func checkError(err error) {
if e != nil { if err != nil {
log.Fatal("WiiSOAP forgot how to drive and suddenly crashed! Reason: ", e) log.Fatalf("WiiSOAP forgot how to drive and suddenly crashed! Reason: %s\n", err.Error())
} }
} }
func main() { func main() {
// Initial Start. // Initial Start.
fmt.Println("WiiSOAP 0.2.5 Kawauso\nReading the Config...") fmt.Println("WiiSOAP 0.2.6 Kawauso\nReading the Config...")
// Check the Config. // Check the Config.
configfile, err := os.Open("./config.xml") configfile, err := os.Open("./config.xml")
CheckError(err) checkError(err)
ioconfig, err := ioutil.ReadAll(configfile) ioconfig, err := ioutil.ReadAll(configfile)
CheckError(err) checkError(err)
CON := Config{} CON := Config{}
err = xml.Unmarshal([]byte(ioconfig), &CON) err = xml.Unmarshal([]byte(ioconfig), &CON)
fmt.Println(CON) fmt.Println(CON)
CheckError(err) checkError(err)
fmt.Println("Initializing core...") fmt.Println("Initializing core...")
// Start SQL. // Start SQL.
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s)", CON.SQLUser, CON.SQLPass, CON.SQLPort, CON.SQLDB)) db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s)", CON.SQLUser, CON.SQLPass, CON.SQLAddress, CON.SQLDB))
CheckError(err) checkError(err)
// Close SQL after everything else is done. // Close SQL after everything else is done.
defer db.Close() defer db.Close()
err = db.Ping() err = db.Ping()
CheckError(err) checkError(err)
// Start the HTTP server. // Start the HTTP server.
fmt.Printf("Starting HTTP connection (%s)...\nNot using the usual port for HTTP? Be sure to use a proxy, otherwise the Wii can't connect!", CON.Address) fmt.Printf("Starting HTTP connection (%s)...\nNot using the usual port for HTTP?\nBe sure to use a proxy, otherwise the Wii can't connect!\n", CON.Address)
http.HandleFunc("/", handler) // each request calls handler http.HandleFunc("/", handler) // each request calls handler
log.Fatal(http.ListenAndServe(CON.Address, nil)) log.Fatal(http.ListenAndServe(CON.Address, nil))
@ -97,9 +97,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "CheckDeviceStatus": case "CheckDeviceStatus":
fmt.Println("CDS.") fmt.Println("CDS.")
CDS := CDS{} CDS := CDS{}
if err = xml.Unmarshal(body, &CDS); os.IsExist(err) { if err = xml.Unmarshal(body, &CDS); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "You need to POST some SOAP from WSC if you wanna get some, honey. ;)") fmt.Fprint(w, "You need to POST some SOAP from WSC if you wanna get some, honey. ;3")
return return
} }
fmt.Println(CDS) fmt.Println(CDS)
@ -131,9 +131,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "NotifiedETicketsSynced": case "NotifiedETicketsSynced":
fmt.Println("NETS") fmt.Println("NETS")
NETS := NETS{} NETS := NETS{}
if err = xml.Unmarshal(body, &NETS); os.IsExist(err) { if err = xml.Unmarshal(body, &NETS); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;)") fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;3")
fmt.Printf("error: %v", err) fmt.Printf("error: %v", err)
return return
} }
@ -159,9 +159,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "ListETickets": case "ListETickets":
fmt.Println("LET") fmt.Println("LET")
LET := LET{} LET := LET{}
if err = xml.Unmarshal(body, &LET); os.IsExist(err) { if err = xml.Unmarshal(body, &LET); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;)") fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;3")
fmt.Printf("error: %v", err) fmt.Printf("error: %v", err)
return return
} }
@ -190,9 +190,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "PurchaseTitle": case "PurchaseTitle":
fmt.Println("PT") fmt.Println("PT")
PT := PT{} PT := PT{}
if err = xml.Unmarshal(body, &PT); os.IsExist(err) { if err = xml.Unmarshal(body, &PT); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "if you wanna fun time, its gonna cost ya extra sweetie. ;)") fmt.Fprint(w, "if you wanna fun time, its gonna cost ya extra sweetie. ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }
@ -232,9 +232,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "CheckRegistration": case "CheckRegistration":
fmt.Println("CR.") fmt.Println("CR.")
CR := CR{} CR := CR{}
if err = xml.Unmarshal(body, &CR); os.IsExist(err) { if err = xml.Unmarshal(body, &CR); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "not good enough for me. ;)") fmt.Fprint(w, "not good enough for me. ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }
@ -262,9 +262,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "GetRegistrationInfo": case "GetRegistrationInfo":
fmt.Println("GRI.") fmt.Println("GRI.")
GRI := GRI{} GRI := GRI{}
if err = xml.Unmarshal(body, &GRI); os.IsExist(err) { if err = xml.Unmarshal(body, &GRI); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "how dirty. ;)") fmt.Fprint(w, "how dirty. ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }
@ -298,9 +298,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "Register": case "Register":
fmt.Println("REG.") fmt.Println("REG.")
REG := REG{} REG := REG{}
if err = xml.Unmarshal(body, &REG); os.IsExist(err) { if err = xml.Unmarshal(body, &REG); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "disgustingly invalid. ;)") fmt.Fprint(w, "disgustingly invalid. ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }
@ -331,9 +331,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "Unregister": case "Unregister":
fmt.Println("UNR.") fmt.Println("UNR.")
UNR := UNR{} UNR := UNR{}
if err = xml.Unmarshal(body, &UNR); os.IsExist(err) { if err = xml.Unmarshal(body, &UNR); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "how abnormal... ;)") fmt.Fprint(w, "how abnormal... ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }

View File

@ -30,9 +30,9 @@ type Config struct {
Address string `xml:"Address"` Address string `xml:"Address"`
SQLAddress string `xml:"SQLAddress"`
SQLUser string `xml:"SQLUser"` SQLUser string `xml:"SQLUser"`
SQLPass string `xml:"SQLPass"` SQLPass string `xml:"SQLPass"`
SQLPort string `xml:"SQLPort"`
SQLDB string `xml:"SQLDB"` SQLDB string `xml:"SQLDB"`
} }