Merge pull request #6 from Apfel/master

Minor changes
This commit is contained in:
CornierKhan1 2019-02-12 21:25:03 +11:00 committed by GitHub
commit e1d549158d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 185 additions and 201 deletions

View File

@ -7,6 +7,11 @@ 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.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 ### 0.2.4
- Added SQL skeleton. - Added SQL skeleton.
- Edited config template. - Edited config template.

View File

@ -1,8 +1,8 @@
<Config> <Config>
<Address>127.0.0.1:8080</Address>
<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> <SQLPort>127.0.0.1:3306</SQLPort>
<Port>127.0.0.1:8080</Port>
<!-- Please use an address for the port. Failing to do so will cause oddities to occur with WiiSOAP. -->
</Config> </Config>

308
main.go
View File

@ -21,13 +21,14 @@ import (
"database/sql" "database/sql"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
_ "github.com/go-sql-driver/mysql"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"time" "time"
_ "github.com/go-sql-driver/mysql"
) )
const ( const (
@ -40,15 +41,13 @@ const (
// CheckError makes error handling not as ugly and inefficient. // CheckError makes error handling not as ugly and inefficient.
func CheckError(e error) { func CheckError(e error) {
if e != nil { 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() { func main() {
// Initial Start. // Initial Start.
fmt.Println("WiiSOAP 0.2.4 Kawauso") fmt.Println("WiiSOAP 0.2.5 Kawauso\nReading the Config...")
fmt.Println("Reading the Config...")
// Check the Config. // Check the Config.
configfile, err := os.Open("./config.xml") configfile, err := os.Open("./config.xml")
@ -63,25 +62,23 @@ func main() {
fmt.Println("Initializing core...") fmt.Println("Initializing core...")
// Start SQL. // Start SQL.
db, err := sql.Open("mysql", db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s)", CON.SQLUser, CON.SQLPass, CON.SQLPort, CON.SQLDB))
CON.SQLUser+":"+CON.SQLPass+"@tcp("+CON.SQLPort+")/"+CON.SQLDB)
CheckError(err) CheckError(err)
// 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.Println("Starting HTTP connection (" + CON.Port + ")...") 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.Println("Not using the usual port for HTTP? Be sure to use a proxy, otherwise the Wii can't connect!")
http.HandleFunc("/", handler) // each request calls handler 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. // From here on out, all special cool things should go into the handler function.
} }
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
// Get a sexy new timestamp to use. // Get a sexy new timestamp to use.
timestampnano := strconv.FormatInt(time.Now().UTC().Unix(), 10) timestampnano := strconv.FormatInt(time.Now().UTC().Unix(), 10)
timestamp := timestampnano + "000" timestamp := timestampnano + "000"
@ -89,8 +86,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("-=Incoming request!=-") fmt.Println("-=Incoming request!=-")
body, err := ioutil.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
http.Error(w, "Error reading request body...", http.Error(w, "Error reading request body...", http.StatusInternalServerError)
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. // 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). // TODO: Update the responses so that they query the SQL Database for the proper information (e.g. Device Code, Token, etc).
case "CheckDeviceStatus": case "CheckDeviceStatus":
fmt.Println("CDS.") fmt.Println("CDS.")
CDS := CDS{} CDS := CDS{}
err = xml.Unmarshal([]byte(body), &CDS) if err = xml.Unmarshal(body, &CDS); os.IsExist(err) {
if 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. ;)")
return return
} }
fmt.Println(CDS) fmt.Println(CDS)
fmt.Println("The request is valid! Responding...") fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, ` fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <soapenv:Body>
<CheckDeviceStatusResponse xmlns="urn:ecs.wsapi.broadon.com"> <CheckDeviceStatusResponse xmlns="urn:ecs.wsapi.broadon.com">
<Version>`+CDS.Version+`</Version> <Version>%s</Version>
<DeviceId>`+CDS.DeviceId+`</DeviceId> <DeviceId>%s</DeviceId>
<MessageId>`+CDS.MessageId+`</MessageId> <MessageId>%s</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp> <TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode> <ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode> <ServiceStandbyMode>false</ServiceStandbyMode>
<Balance> <Balance>
<Amount>2018</Amount> <Amount>2018</Amount>
<Currency>POINTS</Currency> <Currency>POINTS</Currency>
</Balance> </Balance>
<ForceSyncTime>0</ForceSyncTime> <ForceSyncTime>0</ForceSyncTime>
<ExtTicketTime>`+timestamp+`</ExtTicketTime> <ExtTicketTime>%s</ExtTicketTime>
<SyncTime>`+timestamp+`</SyncTime> <SyncTime>%s</SyncTime>
</CheckDeviceStatusResponse> </CheckDeviceStatusResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`, CDS.Version, CDS.DeviceID, CDS.MessageID, timestamp, timestamp, timestamp)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
case "NotifiedETicketsSynced": case "NotifiedETicketsSynced":
fmt.Println("NETS") fmt.Println("NETS")
NETS := NETS{} NETS := NETS{}
err = xml.Unmarshal([]byte(body), &NETS) if err = xml.Unmarshal(body, &NETS); os.IsExist(err) {
if 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. ;)")
fmt.Printf("error: %v", err) 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.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?> fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <soapenv:Body>
<NotifyETicketsSyncedResponse xmlns="urn:ecs.wsapi.broadon.com"> <NotifyETicketsSyncedResponse xmlns="urn:ecs.wsapi.broadon.com">
<Version>`+NETS.Version+`</Version> <Version>%s</Version>
<DeviceId>`+NETS.DeviceId+`</DeviceId> <DeviceId>%s</DeviceId>
<MessageId>`+NETS.MessageId+`</MessageId> <MessageId>%s</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp> <TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode> <ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode> <ServiceStandbyMode>false</ServiceStandbyMode>
</NotifyETicketsSyncedResponse> </NotifyETicketsSyncedResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`, NETS.Version, NETS.DeviceID, NETS.MessageID, timestamp)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
case "ListETickets": case "ListETickets":
fmt.Println("LET") fmt.Println("LET")
LET := LET{} LET := LET{}
err = xml.Unmarshal([]byte(body), &LET) if err = xml.Unmarshal(body, &LET); os.IsExist(err) {
if 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. ;)")
fmt.Printf("error: %v", err) fmt.Printf("error: %v", err)
@ -179,183 +168,173 @@ func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println(LET) fmt.Println(LET)
fmt.Println("The request is valid! Responding...") fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?> fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <soapenv:Body>
<ListETicketsResponse xmlns="urn:ecs.wsapi.broadon.com"> <ListETicketsResponse xmlns="urn:ecs.wsapi.broadon.com">
<Version>`+LET.Version+`</Version> <Version>%s</Version>
<DeviceId>`+LET.DeviceId+`</DeviceId> <DeviceId>%s</DeviceId>
<MessageId>`+LET.MessageId+`</MessageId> <MessageId>%s</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp> <TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode> <ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode> <ServiceStandbyMode>false</ServiceStandbyMode>
<ForceSyncTime>0</ForceSyncTime> <ForceSyncTime>0</ForceSyncTime>
<ExtTicketTime>`+timestamp+`</ExtTicketTime> <ExtTicketTime>%s</ExtTicketTime>
<SyncTime>`+timestamp+`</SyncTime> <SyncTime>%s</SyncTime>
</ListETicketsResponse> </ListETicketsResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`, LET.Version, LET.DeviceID, LET.MessageID, timestamp, timestamp, timestamp)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
case "PurchaseTitle": case "PurchaseTitle":
fmt.Println("PT") fmt.Println("PT")
PT := PT{} PT := PT{}
err = xml.Unmarshal([]byte(body), &PT) if err = xml.Unmarshal(body, &PT); os.IsExist(err) {
if 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. ;)")
fmt.Printf("error: %v", err) fmt.Printf("Error: %s", err.Error())
return return
} }
fmt.Println(PT) fmt.Println(PT)
fmt.Println("The request is valid! Responding...") fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?> fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <soapenv:Body>
<PurchaseTitleResponse xmlns="urn:ecs.wsapi.broadon.com"> <PurchaseTitleResponse xmlns="urn:ecs.wsapi.broadon.com">
<Version>`+PT.Version+`</Version> <Version>%s</Version>
<DeviceId>`+PT.DeviceId+`</DeviceId> <DeviceId>%s</DeviceId>
<MessageId>`+PT.MessageId+`</MessageId> <MessageId>%s</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp> <TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode> <ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode> <ServiceStandbyMode>false</ServiceStandbyMode>
<Balance> <Balance>
<Amount>2018</Amount> <Amount>2018</Amount>
<Currency>POINTS</Currency> <Currency>POINTS</Currency>
</Balance> </Balance>
<Transactions> <Transactions>
<TransactionId>00000000</TransactionId> <TransactionId>00000000</TransactionId>
<Date>`+timestamp+`</Date> <Date>%s</Date>
<Type>PURCHGAME</Type> <Type>PURCHGAME</Type>
</Transactions> </Transactions>
<SyncTime>`+timestamp+`</SyncTime> <SyncTime>%s</SyncTime>
<ETickets>00000000</ETickets> <ETickets>00000000</ETickets>
<Certs>00000000</Certs> <Certs>00000000</Certs>
<Certs>00000000</Certs> <Certs>00000000</Certs>
<TitleId>00000000</TitleId> <TitleId>00000000</TitleId>
</PurchaseTitleResponse> </PurchaseTitleResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`, PT.Version, PT.DeviceID, PT.MessageID, timestamp, timestamp, timestamp)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
case "CheckRegistration": case "CheckRegistration":
fmt.Println("CR.") fmt.Println("CR.")
CR := CR{} CR := CR{}
err = xml.Unmarshal([]byte(body), &CR) if err = xml.Unmarshal(body, &CR); os.IsExist(err) {
if 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. ;)")
fmt.Printf("error: %v", err) fmt.Printf("Error: %s", err.Error())
return return
} }
fmt.Println(CR) fmt.Println(CR)
fmt.Println("The request is valid! Responding...") fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?> fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <soapenv:Body>
<CheckRegistrationResponse xmlns="urn:ias.wsapi.broadon.com"> <CheckRegistrationResponse xmlns="urn:ias.wsapi.broadon.com">
<Version>`+CR.Version+`</Version> <Version>%s</Version>
<DeviceId>`+CR.DeviceId+`</DeviceId> <DeviceId>%s</DeviceId>
<MessageId>`+CR.DeviceId+`</MessageId> <MessageId>%s</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp> <TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode> <ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode> <ServiceStandbyMode>false</ServiceStandbyMode>
<OriginalSerialNumber>`+CR.SerialNo+`</OriginalSerialNumber> <OriginalSerialNumber>%s</OriginalSerialNumber>
<DeviceStatus>R</DeviceStatus> <DeviceStatus>R</DeviceStatus>
</CheckRegistrationResponse> </CheckRegistrationResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`, CR.Version, CR.DeviceID, CR.DeviceID, timestamp, CR.SerialNo)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
case "GetRegistrationInfo": case "GetRegistrationInfo":
fmt.Println("GRI.") fmt.Println("GRI.")
GRI := GRI{} GRI := GRI{}
err = xml.Unmarshal([]byte(body), &GRI) if err = xml.Unmarshal(body, &GRI); os.IsExist(err) {
if 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. ;)")
fmt.Printf("error: %v", err) fmt.Printf("Error: %s", err.Error())
return return
} }
fmt.Println(GRI) fmt.Println(GRI)
fmt.Println("The request is valid! Responding...") fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?> fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <soapenv:Body>
<GetRegistrationInfoResponse xmlns="urn:ias.wsapi.broadon.com"> <GetRegistrationInfoResponse xmlns="urn:ias.wsapi.broadon.com">
<Version>`+GRI.Version+`</Version> <Version>%s</Version>
<DeviceId>`+GRI.DeviceId+`</DeviceId> <DeviceId>%s</DeviceId>
<MessageId>`+GRI.MessageId+`</MessageId> <MessageId>%s</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp> <TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode> <ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode> <ServiceStandbyMode>false</ServiceStandbyMode>
<AccountId>`+GRI.AccountId+`</AccountId> <AccountId>%s</AccountId>
<DeviceToken>00000000</DeviceToken> <DeviceToken>00000000</DeviceToken>
<DeviceTokenExpired>false</DeviceTokenExpired> <DeviceTokenExpired>false</DeviceTokenExpired>
<Country>`+GRI.Country+`</Country> <Country>%s</Country>
<ExtAccountId></ExtAccountId> <ExtAccountId></ExtAccountId>
<DeviceCode>0000000000000000</DeviceCode> <DeviceCode>0000000000000000</DeviceCode>
<DeviceStatus>R</DeviceStatus> <DeviceStatus>R</DeviceStatus>
<Currency>POINTS</Currency> <Currency>POINTS</Currency>
</GetRegistrationInfoResponse> </GetRegistrationInfoResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`, GRI.Version, GRI.DeviceID, GRI.MessageID, timestamp, GRI.AccountID, GRI.Country)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
case "Register": case "Register":
fmt.Println("REG.") fmt.Println("REG.")
REG := REG{} REG := REG{}
err = xml.Unmarshal([]byte(body), &REG) if err = xml.Unmarshal(body, &REG); os.IsExist(err) {
if 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. ;)")
fmt.Printf("error: %v", err) fmt.Printf("Error: %s", err.Error())
return return
} }
fmt.Println(REG) fmt.Println(REG)
fmt.Println("The request is valid! Responding...") fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?> fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <soapenv:Body>
<RegisterResponse xmlns="urn:ias.wsapi.broadon.com"> <RegisterResponse xmlns="urn:ias.wsapi.broadon.com">
<Version>`+REG.Version+`</Version> <Version>%s</Version>
<DeviceId>`+REG.DeviceId+`</DeviceId> <DeviceId>%s</DeviceId>
<MessageId>`+REG.MessageId+`</MessageId> <MessageId>%s</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp> <TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode> <ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode> <ServiceStandbyMode>false</ServiceStandbyMode>
<AccountId>`+REG.AccountId+`</AccountId> <AccountId>%s</AccountId>
<DeviceToken>00000000</DeviceToken> <DeviceToken>00000000</DeviceToken>
<Country>`+REG.Country+`</Country> <Country>%s</Country>
<ExtAccountId></ExtAccountId> <ExtAccountId></ExtAccountId>
<DeviceCode>00000000</DeviceCode> <DeviceCode>00000000</DeviceCode>
</RegisterResponse> </RegisterResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`, REG.Version, REG.DeviceID, REG.MessageID, timestamp, REG.AccountID, REG.Country)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
case "Unregister": case "Unregister":
fmt.Println("UNR.") fmt.Println("UNR.")
UNR := UNR{} UNR := UNR{}
err = xml.Unmarshal([]byte(body), &UNR) if err = xml.Unmarshal(body, &UNR); os.IsExist(err) {
if 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... ;)")
fmt.Printf("error: %v", err) fmt.Printf("Error: %s", err.Error())
return return
} }
fmt.Println(UNR) fmt.Println(UNR)
@ -364,20 +343,19 @@ func handler(w http.ResponseWriter, r *http.Request) {
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <soapenv:Body>
<UnregisterResponse xmlns="urn:ias.wsapi.broadon.com"> <UnregisterResponse xmlns="urn:ias.wsapi.broadon.com">
<Version>`+UNR.Version+`</Version> <Version>%s</Version>
<DeviceId>`+UNR.DeviceId+`</DeviceId> <DeviceId>%s</DeviceId>
<MessageId>`+UNR.MessageId+`</MessageId> <MessageId>%s</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp> <TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode> <ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode> <ServiceStandbyMode>false</ServiceStandbyMode>
</UnregisterResponse> </UnregisterResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`, UNR.Version, UNR.DeviceID, UNR.MessageID, timestamp)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
default: default:
fmt.Fprintf(w, "WiiSOAP can't handle this. Try again later or actually use a Wii instead of a computer.") 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. // TODO: Add NUS and CAS SOAP to the case list.

View File

@ -1,8 +1,6 @@
package main package main
import ( import "encoding/xml"
"encoding/xml"
)
// Copyright (C) 2018-2019 CornierKhan1 // Copyright (C) 2018-2019 CornierKhan1
// //
@ -26,80 +24,83 @@ import (
///////////////////// /////////////////////
// The structures may seem repetitive and redundant, but blame WSC's inconsistent SOAP requests. // The structures may seem repetitive and redundant, but blame WSC's inconsistent SOAP requests.
// Config - WiiSOAP Configuration data.
type Config struct { type Config struct {
XMLName xml.Name `xml:"Config"` XMLName xml.Name `xml:"Config"`
SQLUser string `xml:"SQLUser"`
SQLPass string `xml:"SQLPass"` Address string `xml:"Address"`
SQLPort string `xml:"SQLPort"`
Port string `xml:"Port"` SQLUser string `xml:"SQLUser"`
SQLDB string `xml:"SQLDB"` SQLPass string `xml:"SQLPass"`
SQLPort string `xml:"SQLPort"`
SQLDB string `xml:"SQLDB"`
} }
// CheckDeviceStatus // CDS - CheckDeviceStatus
type CDS struct { type CDS struct {
XMLName xml.Name `xml:"Envelope"` XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>CheckDeviceStatus>Version"` Version string `xml:"Body>CheckDeviceStatus>Version"`
DeviceId string `xml:"Body>CheckDeviceStatus>DeviceId"` DeviceID string `xml:"Body>CheckDeviceStatus>DeviceId"`
MessageId string `xml:"Body>CheckDeviceStatus>MessageId"` MessageID string `xml:"Body>CheckDeviceStatus>MessageId"`
} }
// NotifiedETicketsSynced // NETS - NotifiedETicketsSynced
type NETS struct { type NETS struct {
XMLName xml.Name `xml:"Envelope"` XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>NotifiedETicketsSynced>Version"` Version string `xml:"Body>NotifiedETicketsSynced>Version"`
DeviceId string `xml:"Body>NotifiedETicketsSynced>DeviceId"` DeviceID string `xml:"Body>NotifiedETicketsSynced>DeviceId"`
MessageId string `xml:"Body>NotifiedETicketsSynced>MessageId"` MessageID string `xml:"Body>NotifiedETicketsSynced>MessageId"`
} }
// ListETickets // LET - ListETickets
type LET struct { type LET struct {
XMLName xml.Name `xml:"Envelope"` XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>ListETickets>Version"` Version string `xml:"Body>ListETickets>Version"`
DeviceId string `xml:"Body>ListETickets>DeviceId"` DeviceID string `xml:"Body>ListETickets>DeviceId"`
MessageId string `xml:"Body>ListETickets>MessageId"` MessageID string `xml:"Body>ListETickets>MessageId"`
} }
// PurchaseTitle // PT - PurchaseTitle
type PT struct { type PT struct {
XMLName xml.Name `xml:"Envelope"` XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>PurchaseTitle>Version"` Version string `xml:"Body>PurchaseTitle>Version"`
DeviceId string `xml:"Body>PurchaseTitle>DeviceId"` DeviceID string `xml:"Body>PurchaseTitle>DeviceId"`
MessageId string `xml:"Body>PurchaseTitle>MessageId"` MessageID string `xml:"Body>PurchaseTitle>MessageId"`
} }
// CheckRegistration // CR - CheckRegistration
type CR struct { type CR struct {
XMLName xml.Name `xml:"Envelope"` XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>CheckRegistration>Version"` Version string `xml:"Body>CheckRegistration>Version"`
DeviceId string `xml:"Body>CheckRegistration>DeviceId"` DeviceID string `xml:"Body>CheckRegistration>DeviceId"`
MessageId string `xml:"Body>CheckRegistration>MessageId"` MessageID string `xml:"Body>CheckRegistration>MessageId"`
SerialNo string `xml:"Body>CheckRegistration>SerialNumber"` SerialNo string `xml:"Body>CheckRegistration>SerialNumber"`
} }
// GetRegistrationInfo // GRI - GetRegistrationInfo
type GRI struct { type GRI struct {
XMLName xml.Name `xml:"Envelope"` XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>GetRegistrationInfo>Version"` Version string `xml:"Body>GetRegistrationInfo>Version"`
DeviceId string `xml:"Body>GetRegistrationInfo>DeviceId"` DeviceID string `xml:"Body>GetRegistrationInfo>DeviceId"`
MessageId string `xml:"Body>GetRegistrationInfo>MessageId"` MessageID string `xml:"Body>GetRegistrationInfo>MessageId"`
AccountId string `xml:"Body>GetRegistrationInfo>AccountId"` AccountID string `xml:"Body>GetRegistrationInfo>AccountId"`
Country string `xml:"Body>GetRegistrationInfo>Country"` Country string `xml:"Body>GetRegistrationInfo>Country"`
} }
// Register // REG - Register
type REG struct { type REG struct {
XMLName xml.Name `xml:"Envelope"` XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>Register>Version"` Version string `xml:"Body>Register>Version"`
DeviceId string `xml:"Body>Register>DeviceId"` DeviceID string `xml:"Body>Register>DeviceId"`
MessageId string `xml:"Body>Register>MessageId"` MessageID string `xml:"Body>Register>MessageId"`
AccountId string `xml:"Body>Register>AccountId"` AccountID string `xml:"Body>Register>AccountId"`
Country string `xml:"Body>Register>Country"` Country string `xml:"Body>Register>Country"`
} }
// Unregister // UNR - Unregister
type UNR struct { type UNR struct {
XMLName xml.Name `xml:"Envelope"` XMLName xml.Name `xml:"Envelope"`
Version string `xml:"Body>Unregister>Version"` Version string `xml:"Body>Unregister>Version"`
DeviceId string `xml:"Body>Unregister>DeviceId"` DeviceID string `xml:"Body>Unregister>DeviceId"`
MessageId string `xml:"Body>Unregister>MessageId"` MessageID string `xml:"Body>Unregister>MessageId"`
} }