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
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.

View File

@ -1,8 +1,8 @@
<Config>
<Address>127.0.0.1:8080</Address>
<SQLUser>uwu</SQLUser>
<SQLPass>owo</SQLPass>
<SQLDB>wiisoap</SQLDB>
<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>

170
main.go
View File

@ -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,28 +95,25 @@ 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, `
<?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/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<CheckDeviceStatusResponse xmlns="urn:ecs.wsapi.broadon.com">
<Version>`+CDS.Version+`</Version>
<DeviceId>`+CDS.DeviceId+`</DeviceId>
<MessageId>`+CDS.MessageId+`</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp>
<Version>%s</Version>
<DeviceId>%s</DeviceId>
<MessageId>%s</MessageId>
<TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode>
<Balance>
@ -128,19 +121,17 @@ func handler(w http.ResponseWriter, r *http.Request) {
<Currency>POINTS</Currency>
</Balance>
<ForceSyncTime>0</ForceSyncTime>
<ExtTicketTime>`+timestamp+`</ExtTicketTime>
<SyncTime>`+timestamp+`</SyncTime>
<ExtTicketTime>%s</ExtTicketTime>
<SyncTime>%s</SyncTime>
</CheckDeviceStatusResponse>
</soapenv:Body>
</soapenv:Envelope>`)
</soapenv:Envelope>`, 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)
@ -154,23 +145,21 @@ func handler(w http.ResponseWriter, r *http.Request) {
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<NotifyETicketsSyncedResponse xmlns="urn:ecs.wsapi.broadon.com">
<Version>`+NETS.Version+`</Version>
<DeviceId>`+NETS.DeviceId+`</DeviceId>
<MessageId>`+NETS.MessageId+`</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp>
<Version>%s</Version>
<DeviceId>%s</DeviceId>
<MessageId>%s</MessageId>
<TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode>
</NotifyETicketsSyncedResponse>
</soapenv:Body>
</soapenv:Envelope>`)
</soapenv:Envelope>`, 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)
@ -184,29 +173,27 @@ func handler(w http.ResponseWriter, r *http.Request) {
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ListETicketsResponse xmlns="urn:ecs.wsapi.broadon.com">
<Version>`+LET.Version+`</Version>
<DeviceId>`+LET.DeviceId+`</DeviceId>
<MessageId>`+LET.MessageId+`</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp>
<Version>%s</Version>
<DeviceId>%s</DeviceId>
<MessageId>%s</MessageId>
<TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode>
<ForceSyncTime>0</ForceSyncTime>
<ExtTicketTime>`+timestamp+`</ExtTicketTime>
<SyncTime>`+timestamp+`</SyncTime>
<ExtTicketTime>%s</ExtTicketTime>
<SyncTime>%s</SyncTime>
</ListETicketsResponse>
</soapenv:Body>
</soapenv:Envelope>`)
</soapenv:Envelope>`, 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)
@ -217,10 +204,10 @@ func handler(w http.ResponseWriter, r *http.Request) {
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<PurchaseTitleResponse xmlns="urn:ecs.wsapi.broadon.com">
<Version>`+PT.Version+`</Version>
<DeviceId>`+PT.DeviceId+`</DeviceId>
<MessageId>`+PT.MessageId+`</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp>
<Version>%s</Version>
<DeviceId>%s</DeviceId>
<MessageId>%s</MessageId>
<TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode>
<Balance>
@ -229,28 +216,26 @@ func handler(w http.ResponseWriter, r *http.Request) {
</Balance>
<Transactions>
<TransactionId>00000000</TransactionId>
<Date>`+timestamp+`</Date>
<Date>%s</Date>
<Type>PURCHGAME</Type>
</Transactions>
<SyncTime>`+timestamp+`</SyncTime>
<SyncTime>%s</SyncTime>
<ETickets>00000000</ETickets>
<Certs>00000000</Certs>
<Certs>00000000</Certs>
<TitleId>00000000</TitleId>
</PurchaseTitleResponse>
</soapenv:Body>
</soapenv:Envelope>`)
</soapenv:Envelope>`, 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)
@ -261,28 +246,26 @@ func handler(w http.ResponseWriter, r *http.Request) {
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<CheckRegistrationResponse xmlns="urn:ias.wsapi.broadon.com">
<Version>`+CR.Version+`</Version>
<DeviceId>`+CR.DeviceId+`</DeviceId>
<MessageId>`+CR.DeviceId+`</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp>
<Version>%s</Version>
<DeviceId>%s</DeviceId>
<MessageId>%s</MessageId>
<TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode>
<OriginalSerialNumber>`+CR.SerialNo+`</OriginalSerialNumber>
<OriginalSerialNumber>%s</OriginalSerialNumber>
<DeviceStatus>R</DeviceStatus>
</CheckRegistrationResponse>
</soapenv:Body>
</soapenv:Envelope>`)
</soapenv:Envelope>`, 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)
@ -293,34 +276,32 @@ func handler(w http.ResponseWriter, r *http.Request) {
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<GetRegistrationInfoResponse xmlns="urn:ias.wsapi.broadon.com">
<Version>`+GRI.Version+`</Version>
<DeviceId>`+GRI.DeviceId+`</DeviceId>
<MessageId>`+GRI.MessageId+`</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp>
<Version>%s</Version>
<DeviceId>%s</DeviceId>
<MessageId>%s</MessageId>
<TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode>
<AccountId>`+GRI.AccountId+`</AccountId>
<AccountId>%s</AccountId>
<DeviceToken>00000000</DeviceToken>
<DeviceTokenExpired>false</DeviceTokenExpired>
<Country>`+GRI.Country+`</Country>
<Country>%s</Country>
<ExtAccountId></ExtAccountId>
<DeviceCode>0000000000000000</DeviceCode>
<DeviceStatus>R</DeviceStatus>
<Currency>POINTS</Currency>
</GetRegistrationInfoResponse>
</soapenv:Body>
</soapenv:Envelope>`)
</soapenv:Envelope>`, 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), &REG)
if err != nil {
if err = xml.Unmarshal(body, &REG); 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)
@ -331,31 +312,29 @@ func handler(w http.ResponseWriter, r *http.Request) {
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<RegisterResponse xmlns="urn:ias.wsapi.broadon.com">
<Version>`+REG.Version+`</Version>
<DeviceId>`+REG.DeviceId+`</DeviceId>
<MessageId>`+REG.MessageId+`</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp>
<Version>%s</Version>
<DeviceId>%s</DeviceId>
<MessageId>%s</MessageId>
<TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode>
<AccountId>`+REG.AccountId+`</AccountId>
<AccountId>%s</AccountId>
<DeviceToken>00000000</DeviceToken>
<Country>`+REG.Country+`</Country>
<Country>%s</Country>
<ExtAccountId></ExtAccountId>
<DeviceCode>00000000</DeviceCode>
</RegisterResponse>
</soapenv:Body>
</soapenv:Envelope>`)
</soapenv:Envelope>`, 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) {
<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>
<UnregisterResponse xmlns="urn:ias.wsapi.broadon.com">
<Version>`+UNR.Version+`</Version>
<DeviceId>`+UNR.DeviceId+`</DeviceId>
<MessageId>`+UNR.MessageId+`</MessageId>
<TimeStamp>`+timestamp+`</TimeStamp>
<Version>%s</Version>
<DeviceId>%s</DeviceId>
<MessageId>%s</MessageId>
<TimeStamp>%s</TimeStamp>
<ErrorCode>0</ErrorCode>
<ServiceStandbyMode>false</ServiceStandbyMode>
</UnregisterResponse>
</soapenv:Body>
</soapenv:Envelope>`)
</soapenv:Envelope>`, 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.

View File

@ -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"`
Address string `xml:"Address"`
SQLUser string `xml:"SQLUser"`
SQLPass string `xml:"SQLPass"`
SQLPort string `xml:"SQLPort"`
Port string `xml:"Port"`
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"`
}