diff --git a/README.md b/README.md
index 9b3d7c2..164427c 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,11 @@ This is the SOAP Server Software. The other repository only has the communicatio
# Changelog
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.5
+- Fixed lint errors.
+- Uses Fprintf properly now.
+- Uses `if err = action(); os.IsExist(err) {}` now. This makes error checks a little bit shorter.
+- Changed `Port` to `Address` in the `config.xml` file.
### 0.2.4
- Added SQL skeleton.
- Edited config template.
diff --git a/config.xml.example b/config.xml.example
index 68ab120..a49dfe9 100644
--- a/config.xml.example
+++ b/config.xml.example
@@ -1,8 +1,8 @@
+ 127.0.0.1:8080
+
uwu
owo
wiisoap
127.0.0.1:3306
- 127.0.0.1:8080
-
diff --git a/main.go b/main.go
index 3528069..a567a07 100644
--- a/main.go
+++ b/main.go
@@ -21,13 +21,14 @@ import (
"database/sql"
"encoding/xml"
"fmt"
- _ "github.com/go-sql-driver/mysql"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"time"
+
+ _ "github.com/go-sql-driver/mysql"
)
const (
@@ -40,15 +41,13 @@ const (
// CheckError makes error handling not as ugly and inefficient.
func CheckError(e error) {
if e != nil {
- log.Fatal("WiiSOAP forgot how to drive and crashed! Reason: ", e)
+ log.Fatal("WiiSOAP forgot how to drive and suddenly crashed! Reason: ", e)
}
}
func main() {
-
// Initial Start.
- fmt.Println("WiiSOAP 0.2.4 Kawauso")
- fmt.Println("Reading the Config...")
+ fmt.Println("WiiSOAP 0.2.5 Kawauso\nReading the Config...")
// Check the Config.
configfile, err := os.Open("./config.xml")
@@ -63,25 +62,23 @@ func main() {
fmt.Println("Initializing core...")
// Start SQL.
- db, err := sql.Open("mysql",
- CON.SQLUser+":"+CON.SQLPass+"@tcp("+CON.SQLPort+")/"+CON.SQLDB)
+ db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s)", CON.SQLUser, CON.SQLPass, CON.SQLPort, CON.SQLDB))
CheckError(err)
+ // Close SQL after everything else is done.
defer db.Close()
err = db.Ping()
CheckError(err)
// Start the HTTP server.
- fmt.Println("Starting HTTP connection (" + CON.Port + ")...")
- fmt.Println("Not using the usual port for HTTP? Be sure to use a proxy, otherwise the Wii can't connect!")
+ 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)
http.HandleFunc("/", handler) // each request calls handler
- log.Fatal(http.ListenAndServe(CON.Port, nil))
+ log.Fatal(http.ListenAndServe(CON.Address, nil))
// From here on out, all special cool things should go into the handler function.
}
func handler(w http.ResponseWriter, r *http.Request) {
-
// Get a sexy new timestamp to use.
timestampnano := strconv.FormatInt(time.Now().UTC().Unix(), 10)
timestamp := timestampnano + "000"
@@ -89,8 +86,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("-=Incoming request!=-")
body, err := ioutil.ReadAll(r.Body)
if err != nil {
- http.Error(w, "Error reading request body...",
- http.StatusInternalServerError)
+ http.Error(w, "Error reading request body...", http.StatusInternalServerError)
}
// The switch converts the HTTP Body of the request into a string. There is no need to convert the cases to byte format.
@@ -99,48 +95,43 @@ func handler(w http.ResponseWriter, r *http.Request) {
// TODO: Update the responses so that they query the SQL Database for the proper information (e.g. Device Code, Token, etc).
case "CheckDeviceStatus":
-
fmt.Println("CDS.")
CDS := CDS{}
- err = xml.Unmarshal([]byte(body), &CDS)
- if err != nil {
+ if err = xml.Unmarshal(body, &CDS); os.IsExist(err) {
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. ;)")
return
}
fmt.Println(CDS)
fmt.Println("The request is valid! Responding...")
- fmt.Fprintf(w, `
-
+ fmt.Fprintf(w, `
-
-
- `+CDS.Version+`
- `+CDS.DeviceId+`
- `+CDS.MessageId+`
- `+timestamp+`
- 0
- false
-
- 2018
- POINTS
-
- 0
- `+timestamp+`
- `+timestamp+`
-
-
-`)
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+
+ %s
+ %s
+ %s
+ %s
+ 0
+ false
+
+ 2018
+ POINTS
+
+ 0
+ %s
+ %s
+
+
+`, CDS.Version, CDS.DeviceID, CDS.MessageID, timestamp, timestamp, timestamp)
fmt.Println("Delivered response!")
case "NotifiedETicketsSynced":
-
fmt.Println("NETS")
NETS := NETS{}
- err = xml.Unmarshal([]byte(body), &NETS)
- if err != nil {
+ if err = xml.Unmarshal(body, &NETS); os.IsExist(err) {
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.Printf("error: %v", err)
@@ -150,27 +141,25 @@ func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `
-
-
- `+NETS.Version+`
- `+NETS.DeviceId+`
- `+NETS.MessageId+`
- `+timestamp+`
- 0
- false
-
-
-`)
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+
+ %s
+ %s
+ %s
+ %s
+ 0
+ false
+
+
+`, NETS.Version, NETS.DeviceID, NETS.MessageID, timestamp)
fmt.Println("Delivered response!")
case "ListETickets":
-
fmt.Println("LET")
LET := LET{}
- err = xml.Unmarshal([]byte(body), &LET)
- if err != nil {
+ if err = xml.Unmarshal(body, &LET); os.IsExist(err) {
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.Printf("error: %v", err)
@@ -179,183 +168,173 @@ func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println(LET)
fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `
-
-
-
- `+LET.Version+`
- `+LET.DeviceId+`
- `+LET.MessageId+`
- `+timestamp+`
- 0
- false
- 0
- `+timestamp+`
- `+timestamp+`
-
-
-`)
+
+
+
+ %s
+ %s
+ %s
+ %s
+ 0
+ false
+ 0
+ %s
+ %s
+
+
+`, LET.Version, LET.DeviceID, LET.MessageID, timestamp, timestamp, timestamp)
fmt.Println("Delivered response!")
case "PurchaseTitle":
-
fmt.Println("PT")
PT := PT{}
- err = xml.Unmarshal([]byte(body), &PT)
- if err != nil {
+ if err = xml.Unmarshal(body, &PT); os.IsExist(err) {
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.Printf("error: %v", err)
+ fmt.Printf("Error: %s", err.Error())
return
}
fmt.Println(PT)
fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `
-
-
- `+PT.Version+`
- `+PT.DeviceId+`
- `+PT.MessageId+`
- `+timestamp+`
- 0
- false
-
- 2018
- POINTS
-
-
- 00000000
- `+timestamp+`
- PURCHGAME
-
- `+timestamp+`
- 00000000
- 00000000
- 00000000
- 00000000
-
-
-`)
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+
+ %s
+ %s
+ %s
+ %s
+ 0
+ false
+
+ 2018
+ POINTS
+
+
+ 00000000
+ %s
+ PURCHGAME
+
+ %s
+ 00000000
+ 00000000
+ 00000000
+ 00000000
+
+
+`, PT.Version, PT.DeviceID, PT.MessageID, timestamp, timestamp, timestamp)
fmt.Println("Delivered response!")
case "CheckRegistration":
-
fmt.Println("CR.")
CR := CR{}
- err = xml.Unmarshal([]byte(body), &CR)
- if err != nil {
+ if err = xml.Unmarshal(body, &CR); os.IsExist(err) {
fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "not good enough for me. ;)")
- fmt.Printf("error: %v", err)
+ fmt.Printf("Error: %s", err.Error())
return
}
fmt.Println(CR)
fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- `+CR.Version+`
- `+CR.DeviceId+`
- `+CR.DeviceId+`
- `+timestamp+`
+ %s
+ %s
+ %s
+ %s
0
false
- `+CR.SerialNo+`
+ %s
R
-`)
+`, CR.Version, CR.DeviceID, CR.DeviceID, timestamp, CR.SerialNo)
fmt.Println("Delivered response!")
case "GetRegistrationInfo":
-
fmt.Println("GRI.")
GRI := GRI{}
- err = xml.Unmarshal([]byte(body), &GRI)
- if err != nil {
+ if err = xml.Unmarshal(body, &GRI); os.IsExist(err) {
fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "how dirty. ;)")
- fmt.Printf("error: %v", err)
+ fmt.Printf("Error: %s", err.Error())
return
}
fmt.Println(GRI)
fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `
-
-
- `+GRI.Version+`
- `+GRI.DeviceId+`
- `+GRI.MessageId+`
- `+timestamp+`
- 0
- false
- `+GRI.AccountId+`
- 00000000
- false
- `+GRI.Country+`
-
- 0000000000000000
- R
- POINTS
-
-
-`)
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+
+ %s
+ %s
+ %s
+ %s
+ 0
+ false
+ %s
+ 00000000
+ false
+ %s
+
+ 0000000000000000
+ R
+ POINTS
+
+
+`, GRI.Version, GRI.DeviceID, GRI.MessageID, timestamp, GRI.AccountID, GRI.Country)
fmt.Println("Delivered response!")
case "Register":
-
fmt.Println("REG.")
REG := REG{}
- err = xml.Unmarshal([]byte(body), ®)
- if err != nil {
+ if err = xml.Unmarshal(body, ®); os.IsExist(err) {
fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "disgustingly invalid. ;)")
- fmt.Printf("error: %v", err)
+ fmt.Printf("Error: %s", err.Error())
return
}
fmt.Println(REG)
fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- `+REG.Version+`
- `+REG.DeviceId+`
- `+REG.MessageId+`
- `+timestamp+`
+ %s
+ %s
+ %s
+ %s
0
false
- `+REG.AccountId+`
+ %s
00000000
- `+REG.Country+`
+ %s
00000000
-`)
+`, REG.Version, REG.DeviceID, REG.MessageID, timestamp, REG.AccountID, REG.Country)
fmt.Println("Delivered response!")
case "Unregister":
-
fmt.Println("UNR.")
UNR := UNR{}
- err = xml.Unmarshal([]byte(body), &UNR)
- if err != nil {
+ if err = xml.Unmarshal(body, &UNR); os.IsExist(err) {
fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "how abnormal... ;)")
- fmt.Printf("error: %v", err)
+ fmt.Printf("Error: %s", err.Error())
return
}
fmt.Println(UNR)
@@ -364,20 +343,19 @@ func handler(w http.ResponseWriter, r *http.Request) {
- `+UNR.Version+`
- `+UNR.DeviceId+`
- `+UNR.MessageId+`
- `+timestamp+`
+ %s
+ %s
+ %s
+ %s
0
false
-`)
+`, UNR.Version, UNR.DeviceID, UNR.MessageID, timestamp)
fmt.Println("Delivered response!")
default:
fmt.Fprintf(w, "WiiSOAP can't handle this. Try again later or actually use a Wii instead of a computer.")
-
}
// TODO: Add NUS and CAS SOAP to the case list.
diff --git a/structure.go b/structure.go
index e5138a2..f4ffd20 100644
--- a/structure.go
+++ b/structure.go
@@ -1,8 +1,6 @@
package main
-import (
- "encoding/xml"
-)
+import "encoding/xml"
// Copyright (C) 2018-2019 CornierKhan1
//
@@ -26,80 +24,83 @@ import (
/////////////////////
// The structures may seem repetitive and redundant, but blame WSC's inconsistent SOAP requests.
+// Config - WiiSOAP Configuration data.
type Config struct {
XMLName xml.Name `xml:"Config"`
- SQLUser string `xml:"SQLUser"`
- SQLPass string `xml:"SQLPass"`
- SQLPort string `xml:"SQLPort"`
- Port string `xml:"Port"`
- SQLDB string `xml:"SQLDB"`
+
+ Address string `xml:"Address"`
+
+ SQLUser string `xml:"SQLUser"`
+ SQLPass string `xml:"SQLPass"`
+ SQLPort string `xml:"SQLPort"`
+ SQLDB string `xml:"SQLDB"`
}
-// CheckDeviceStatus
+// CDS - CheckDeviceStatus
type CDS struct {
XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>CheckDeviceStatus>Version"`
- DeviceId string `xml:"Body>CheckDeviceStatus>DeviceId"`
- MessageId string `xml:"Body>CheckDeviceStatus>MessageId"`
+ DeviceID string `xml:"Body>CheckDeviceStatus>DeviceId"`
+ MessageID string `xml:"Body>CheckDeviceStatus>MessageId"`
}
-// NotifiedETicketsSynced
+// NETS - NotifiedETicketsSynced
type NETS struct {
XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>NotifiedETicketsSynced>Version"`
- DeviceId string `xml:"Body>NotifiedETicketsSynced>DeviceId"`
- MessageId string `xml:"Body>NotifiedETicketsSynced>MessageId"`
+ DeviceID string `xml:"Body>NotifiedETicketsSynced>DeviceId"`
+ MessageID string `xml:"Body>NotifiedETicketsSynced>MessageId"`
}
-// ListETickets
+// LET - ListETickets
type LET struct {
XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>ListETickets>Version"`
- DeviceId string `xml:"Body>ListETickets>DeviceId"`
- MessageId string `xml:"Body>ListETickets>MessageId"`
+ DeviceID string `xml:"Body>ListETickets>DeviceId"`
+ MessageID string `xml:"Body>ListETickets>MessageId"`
}
-// PurchaseTitle
+// PT - PurchaseTitle
type PT struct {
XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>PurchaseTitle>Version"`
- DeviceId string `xml:"Body>PurchaseTitle>DeviceId"`
- MessageId string `xml:"Body>PurchaseTitle>MessageId"`
+ DeviceID string `xml:"Body>PurchaseTitle>DeviceId"`
+ MessageID string `xml:"Body>PurchaseTitle>MessageId"`
}
-// CheckRegistration
+// CR - CheckRegistration
type CR struct {
XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>CheckRegistration>Version"`
- DeviceId string `xml:"Body>CheckRegistration>DeviceId"`
- MessageId string `xml:"Body>CheckRegistration>MessageId"`
+ DeviceID string `xml:"Body>CheckRegistration>DeviceId"`
+ MessageID string `xml:"Body>CheckRegistration>MessageId"`
SerialNo string `xml:"Body>CheckRegistration>SerialNumber"`
}
-// GetRegistrationInfo
+// GRI - GetRegistrationInfo
type GRI struct {
XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>GetRegistrationInfo>Version"`
- DeviceId string `xml:"Body>GetRegistrationInfo>DeviceId"`
- MessageId string `xml:"Body>GetRegistrationInfo>MessageId"`
- AccountId string `xml:"Body>GetRegistrationInfo>AccountId"`
+ DeviceID string `xml:"Body>GetRegistrationInfo>DeviceId"`
+ MessageID string `xml:"Body>GetRegistrationInfo>MessageId"`
+ AccountID string `xml:"Body>GetRegistrationInfo>AccountId"`
Country string `xml:"Body>GetRegistrationInfo>Country"`
}
-// Register
+// REG - Register
type REG struct {
XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>Register>Version"`
- DeviceId string `xml:"Body>Register>DeviceId"`
- MessageId string `xml:"Body>Register>MessageId"`
- AccountId string `xml:"Body>Register>AccountId"`
+ DeviceID string `xml:"Body>Register>DeviceId"`
+ MessageID string `xml:"Body>Register>MessageId"`
+ AccountID string `xml:"Body>Register>AccountId"`
Country string `xml:"Body>Register>Country"`
}
-// Unregister
+// UNR - Unregister
type UNR struct {
XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>Unregister>Version"`
- DeviceId string `xml:"Body>Unregister>DeviceId"`
- MessageId string `xml:"Body>Unregister>MessageId"`
+ DeviceID string `xml:"Body>Unregister>DeviceId"`
+ MessageID string `xml:"Body>Unregister>MessageId"`
}