-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ggst | ||
|
||
type StatReqHeader struct { | ||
_msgpack struct{} `msgpack:",as_array"` | ||
UserID string // 18 digit User ID | ||
Hash string // 13 character response hash from /api/user/login | ||
Unk3 int // Always 2 | ||
Version string // Some version string. Same as ResponseHeader.Version | ||
Unk4 int // Always 3 | ||
} | ||
|
||
type StatGetReqPayload struct { | ||
_msgpack struct{} `msgpack:",as_array"` | ||
OtherUserID string // 18 digit User ID of other player. Empty string if self. | ||
Type int // Request type. 1: Vs stats (tension use, RC usage, perfects, etc). 2: Battle Record/Battle Chart. 6: Single player stats (eg mission, story). 7: Levels, Floor, Name, etc. 8: Unknown. 9: News. | ||
Unk2 int // Set to -1 normally. Sometimes set to 1 on Type 1 requests. | ||
Page int // Seems to be page number or character ID. -1 if N/A. 0 for first page. Only used by Type 6 and 8. | ||
Unk3 int // Set to -1 normally. Sometimes set to -2 on Type 1 requests. | ||
Unk4 int // -1 | ||
} | ||
|
||
type StatGetRequest struct { | ||
_msgpack struct{} `msgpack:",as_array"` | ||
Header StatReqHeader | ||
Payload StatGetReqPayload | ||
} | ||
|
||
type StatGetRespHeader struct { | ||
_msgpack struct{} `msgpack:",as_array"` | ||
Hash string // Some sort of incrementing 13 char hash | ||
Unk1 int // Unknown, always 0 | ||
Timestamp string // Current time in "YYYY/MM/DD HH:MM:SS" in UTC | ||
Version1 string // Some version string. "0.1.1" in v1.16. "0.0.7" in v1.10. "0.0.6" in v1.07. "0.0.5" in v1.06, was "0.0.4" in v1.05 | ||
Version2 string // Another version string. Always 0.0.2 | ||
Version3 string // Another version string. Always 0.0.2 | ||
Unk2 string // Unknown, empty string | ||
Unk3 string // Unknown, empty string | ||
} | ||
|
||
type Payload struct { | ||
_msgpack struct{} `msgpack:",as_array"` | ||
Unk1 int // Unknown, always 0. | ||
Payload map[string]interface{} | ||
} | ||
|
||
type StatGetRespPayload struct { | ||
_msgpack struct{} `msgpack:",as_array"` | ||
Unk1 int // Unknown, always 0. | ||
JSON RawJSON | ||
} | ||
|
||
type RawJSON map[string]interface{} | ||
|
||
type StatGetResponse struct { | ||
_msgpack struct{} `msgpack:",as_array"` | ||
Header StatGetRespHeader | ||
Payload StatGetRespPayload | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package ggst | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
|
||
"github.com/vmihailenco/msgpack/v5" | ||
) | ||
|
||
type Decoder struct { | ||
d *msgpack.Decoder | ||
} | ||
|
||
func NewDecoder(r io.Reader) *Decoder { | ||
return &Decoder{d: msgpack.NewDecoder(r)} | ||
} | ||
|
||
func (dec *Decoder) Decode(v interface{}) error { | ||
return dec.d.Decode(v) | ||
} | ||
|
||
type Encoder struct { | ||
e *msgpack.Encoder | ||
} | ||
|
||
func NewEncoder(w io.Writer) *Encoder { | ||
return &Encoder{e: msgpack.NewEncoder(w)} | ||
} | ||
|
||
func (dec *Encoder) Encode(v interface{}) error { | ||
return dec.e.Encode(v) | ||
} | ||
|
||
func Unmarshal(data []byte, v interface{}) error { | ||
return msgpack.Unmarshal(data, v) | ||
} | ||
|
||
func Marshal(v interface{}) ([]byte, error) { | ||
return msgpack.Marshal(v) | ||
} | ||
|
||
func UnmarshalStatResp(data []byte) (*StatGetResponse, error) { | ||
parsedResp := &StatGetResponse{} | ||
err := Unmarshal(data, parsedResp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return parsedResp, err | ||
} | ||
|
||
func (J *RawJSON) DecodeMsgpack(dec *msgpack.Decoder) error { | ||
s, err := dec.DecodeString() | ||
if err != nil { | ||
return err | ||
} | ||
jDecoder := json.NewDecoder(bytes.NewBufferString(s)) | ||
jDecoder.UseNumber() // Things like AccountID are very long numbers | ||
jDecoder.Decode(J) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (J *RawJSON) EncodeMsgpack(enc *msgpack.Encoder) error { | ||
b, err := json.Marshal(J) | ||
if err != nil { | ||
return err | ||
} | ||
return enc.EncodeString(string(b)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ggst | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/vmihailenco/msgpack/v5" | ||
) | ||
|
||
func ParseReq(r *http.Request, v interface{}) error { | ||
req, err := hex.DecodeString(strings.TrimRight(r.FormValue("data"), "\x00")) // Clean up input | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
err = msgpack.Unmarshal(req, &v) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// BufferedResponseWriter is a wrapper around http.ResponseWriter that buffers the response for later use. | ||
type BufferedResponseWriter struct { | ||
HttpHeader http.Header | ||
StatusCode int | ||
Body bytes.Buffer | ||
} | ||
|
||
func (b *BufferedResponseWriter) Header() http.Header { | ||
return b.HttpHeader | ||
} | ||
|
||
func (b *BufferedResponseWriter) WriteHeader(code int) { | ||
b.StatusCode = code | ||
} | ||
|
||
func (b *BufferedResponseWriter) Write(data []byte) (int, error) { | ||
return b.Body.Write(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.