1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
package tradeapi
import (
"encoding/json"
"github.com/Philipp15b/go-steam/jsont"
"github.com/Philipp15b/go-steam/steamid"
"strconv"
)
type Status struct {
Success bool
Error string
NewVersion bool `json:"newversion"`
TradeStatus TradeStatus `json:"trade_status"`
Version uint
LogPos int
Me User
Them User
Events EventList
}
type TradeStatus uint
const (
TradeStatus_Open TradeStatus = 0
TradeStatus_Complete = 1
TradeStatus_Empty = 2 // when both parties trade no items
TradeStatus_Cancelled = 3
TradeStatus_Timeout = 4 // the partner timed out
TradeStatus_Failed = 5
)
type EventList map[uint]*Event
// The EventList can either be an array or an object of id -> event
func (e *EventList) UnmarshalJSON(data []byte) error {
// initialize the map if it's nil
if *e == nil {
*e = make(EventList)
}
o := make(map[string]*Event)
err := json.Unmarshal(data, &o)
// it's an object
if err == nil {
for is, event := range o {
i, err := strconv.ParseUint(is, 10, 32)
if err != nil {
panic(err)
}
(*e)[uint(i)] = event
}
return nil
}
// it's an array
var a []*Event
err = json.Unmarshal(data, &a)
if err != nil {
return err
}
for i, event := range a {
(*e)[uint(i)] = event
}
return nil
}
type Event struct {
SteamId steamid.SteamId `json:",string"`
Action Action `json:",string"`
Timestamp uint64
AppId uint32
ContextId uint64 `json:",string"`
AssetId uint64 `json:",string"`
Text string // only used for chat messages
// The following is used for SetCurrency
CurrencyId uint64 `json:",string"`
OldAmount uint64 `json:"old_amount,string"`
NewAmount uint64 `json:"amount,string"`
}
type Action uint
const (
Action_AddItem Action = 0
Action_RemoveItem = 1
Action_Ready = 2
Action_Unready = 3
Action_Accept = 4
Action_SetCurrency = 6
Action_ChatMessage = 7
)
type User struct {
Ready jsont.UintBool
Confirmed jsont.UintBool
SecSinceTouch int `json:"sec_since_touch"`
ConnectionPending bool `json:"connection_pending"`
Assets interface{}
Currency interface{} // either []*Currency or empty string
}
type Currency struct {
AppId uint64 `json:",string"`
ContextId uint64 `json:",string"`
CurrencyId uint64 `json:",string"`
Amount uint64 `json:",string"`
}
|