move some UserInfo properties into separate adc/nmdc sub structs

--HG--
branch : adc
This commit is contained in:
mappu 2017-11-26 13:29:09 +13:00
parent 95cd5c85f0
commit aabaa128c4
2 changed files with 44 additions and 14 deletions

View File

@ -24,23 +24,27 @@ func TestMyINFOParse(t *testing.T) {
ClientVersion: "1.4.3", ClientVersion: "1.4.3",
Email: "xyz@example.com", Email: "xyz@example.com",
ShareSize: 53054999578, ShareSize: 53054999578,
ConnectionMode: CONNECTIONMODE_PASSIVE,
Flag: FLAG_NORMAL, Flag: FLAG_NORMAL,
Slots: 1, Slots: 1,
Speed: "0.0",
HubsUnregistered: 9, HubsUnregistered: 9,
HubsRegistered: 0, HubsRegistered: 0,
HubsOperator: 2, HubsOperator: 2,
UserInfo_NMDCOnly: UserInfo_NMDCOnly{
ConnectionMode: CONNECTIONMODE_PASSIVE,
Speed: "0.0",
},
}, },
}, },
myInfoTestPair{ myInfoTestPair{
in: "$ALL ixxxxxxx0 $P$10A$$0$", in: "$ALL ixxxxxxx0 $P$10A$$0$",
expect: UserInfo{ expect: UserInfo{
Nick: "ixxxxxxx0", Nick: "ixxxxxxx0",
ClientVersion: "0", // Auto-inserted by the parser for short-format MyINFO strings ClientVersion: "0", // Auto-inserted by the parser for short-format MyINFO strings
ConnectionMode: CONNECTIONMODE_PASSIVE, Flag: UserFlag(rune('A')),
Flag: UserFlag(rune('A')), UserInfo_NMDCOnly: UserInfo_NMDCOnly{
Speed: "1", ConnectionMode: CONNECTIONMODE_PASSIVE,
Speed: "1",
},
}, },
}, },
myInfoTestPair{ myInfoTestPair{
@ -49,11 +53,13 @@ func TestMyINFOParse(t *testing.T) {
Nick: "SXXXX_XXXXXXR", Nick: "SXXXX_XXXXXXR",
ClientTag: "ncdc", ClientTag: "ncdc",
ClientVersion: "1.19.1-12-g5561", ClientVersion: "1.19.1-12-g5561",
ConnectionMode: CONNECTIONMODE_PASSIVE,
Flag: UserFlag(rune('Q')), Flag: UserFlag(rune('Q')),
Slots: 10, Slots: 10,
Speed: "0.00",
HubsUnregistered: 1, HubsUnregistered: 1,
UserInfo_NMDCOnly: UserInfo_NMDCOnly{
ConnectionMode: CONNECTIONMODE_PASSIVE,
Speed: "0.00",
},
}, },
}, },
myInfoTestPair{ myInfoTestPair{
@ -63,10 +69,12 @@ func TestMyINFOParse(t *testing.T) {
Description: "desccccc", Description: "desccccc",
ClientTag: "HexChat", ClientTag: "HexChat",
ClientVersion: "2.12.1", ClientVersion: "2.12.1",
ConnectionMode: CONNECTIONMODE_PASSIVE,
Flag: UserFlag(rune('p')), Flag: UserFlag(rune('p')),
HubsUnregistered: 1, HubsUnregistered: 1,
Slots: 0, Slots: 0,
UserInfo_NMDCOnly: UserInfo_NMDCOnly{
ConnectionMode: CONNECTIONMODE_PASSIVE,
},
}, },
}, },
} }

View File

@ -8,21 +8,43 @@ type UserInfo struct {
ClientVersion string ClientVersion string
Email string Email string
ShareSize uint64 ShareSize uint64
ConnectionMode ConnectionMode
Flag UserFlag Flag UserFlag
Slots uint64 Slots uint64
Speed string
HubsUnregistered uint64 HubsUnregistered uint64
HubsRegistered uint64 HubsRegistered uint64
HubsOperator uint64 HubsOperator uint64
IsOperator bool IsOperator bool
IPAddress string
UserInfo_NMDCOnly
UserInfo_ADCOnly
}
type UserInfo_NMDCOnly struct {
Speed string
IPAddress string
ConnectionMode ConnectionMode
}
type UserInfo_ADCOnly struct {
SharedFiles uint64
UploadSpeedBps uint64
DownloadSpeedBps uint64
IsBot bool
IsRegistered bool
IsSuperUser bool
IsHubOwner bool
IPv4Address string // Passive <==> these fields are not set
IPv6Address string
IPv4UDPPort uint
IPv6UDPPort uint
} }
func NewUserInfo(username string) *UserInfo { func NewUserInfo(username string) *UserInfo {
return &UserInfo{ return &UserInfo{
Nick: username, Nick: username,
ConnectionMode: CONNECTIONMODE_PASSIVE,
HubsUnregistered: 1, HubsUnregistered: 1,
UserInfo_NMDCOnly: UserInfo_NMDCOnly{
ConnectionMode: CONNECTIONMODE_PASSIVE,
},
} }
} }