forked from chteufleur/go-xmpp4steam
Add multi connected client support for one account
This commit is contained in:
parent
dc5027d36d
commit
ade4020625
|
|
@ -14,17 +14,18 @@ var (
|
||||||
|
|
||||||
type GatewayInfo struct {
|
type GatewayInfo struct {
|
||||||
// Steam
|
// Steam
|
||||||
SteamLogin string
|
SteamLogin string
|
||||||
SteamPassword string
|
SteamPassword string
|
||||||
SteamLoginInfo *steam.LogOnDetails
|
SteamLoginInfo *steam.LogOnDetails
|
||||||
SteamClient *steam.Client
|
SteamClient *steam.Client
|
||||||
SentryFile string
|
SentryFile string
|
||||||
FriendSteamId map[string]struct{}
|
FriendSteamId map[string]struct{}
|
||||||
SteamConnecting bool
|
SteamConnecting bool
|
||||||
|
|
||||||
// XMPP
|
// XMPP
|
||||||
XMPP_JID_Client string
|
XMPP_JID_Client string
|
||||||
XMPP_Out chan interface{}
|
XMPP_Out chan interface{}
|
||||||
|
XMPP_Connected_Client map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GatewayInfo) Run() {
|
func (g *GatewayInfo) Run() {
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,16 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||||
|
|
||||||
transfertPresence := false
|
transfertPresence := false
|
||||||
|
|
||||||
|
jid := strings.SplitN(presence.From, "/", 2)
|
||||||
|
if len(jid) == 2 {
|
||||||
|
// Resource exist —> client speaking
|
||||||
|
if presence.Type == Type_available {
|
||||||
|
g.XMPP_Connected_Client[presence.From] = true
|
||||||
|
} else if presence.Type == Type_unavailable {
|
||||||
|
delete(g.XMPP_Connected_Client, presence.From)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if presence.Type == Type_subscribe {
|
if presence.Type == Type_subscribe {
|
||||||
// Send presence to tell that the JID has been added to roster
|
// Send presence to tell that the JID has been added to roster
|
||||||
g.SendXmppPresence("", Type_subscribed, presence.To, g.XMPP_JID_Client, "")
|
g.SendXmppPresence("", Type_subscribed, presence.To, g.XMPP_JID_Client, "")
|
||||||
|
|
@ -56,11 +66,12 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||||
// Destination is gateway itself
|
// Destination is gateway itself
|
||||||
if presence.Type == Type_unavailable {
|
if presence.Type == Type_unavailable {
|
||||||
// Disconnect
|
// Disconnect
|
||||||
// TODO multi client connected management
|
if len(g.XMPP_Connected_Client) <= 0 {
|
||||||
g.XMPP_Disconnect()
|
g.XMPP_Disconnect()
|
||||||
go g.SteamDisconnect()
|
go g.SteamDisconnect()
|
||||||
|
}
|
||||||
} else if presence.Type == Type_available {
|
} else if presence.Type == Type_available {
|
||||||
// TODO multi client connected management
|
g.XMPP_Connect()
|
||||||
go g.SteamConnect()
|
go g.SteamConnect()
|
||||||
transfertPresence = true
|
transfertPresence = true
|
||||||
}
|
}
|
||||||
|
|
@ -69,11 +80,12 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||||
// Destination is Steam user
|
// Destination is Steam user
|
||||||
if presence.Type == Type_unavailable {
|
if presence.Type == Type_unavailable {
|
||||||
// Disconnect
|
// Disconnect
|
||||||
// TODO multi client connected management
|
if len(g.XMPP_Connected_Client) <= 0 {
|
||||||
g.XMPP_Disconnect()
|
g.XMPP_Disconnect()
|
||||||
go g.SteamDisconnect()
|
go g.SteamDisconnect()
|
||||||
|
}
|
||||||
} else if presence.Type == Type_available {
|
} else if presence.Type == Type_available {
|
||||||
// TODO multi client connected management
|
g.XMPP_Connect()
|
||||||
go g.SteamConnect()
|
go g.SteamConnect()
|
||||||
transfertPresence = true
|
transfertPresence = true
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +124,12 @@ func (g *GatewayInfo) ReceivedXMPP_Message(message *xmpp.Message) {
|
||||||
g.SendSteamMessage(steamID, message.Subject+"\n"+message.Body)
|
g.SendSteamMessage(steamID, message.Subject+"\n"+message.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GatewayInfo) XMPP_Connect() {
|
||||||
|
// TODO multi client connected management
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GatewayInfo) XMPP_Disconnect() {
|
func (g *GatewayInfo) XMPP_Disconnect() {
|
||||||
|
// TODO multi client connected management
|
||||||
g.SendXmppPresence(Status_offline, Type_unavailable, "", "", "")
|
g.SendXmppPresence(Status_offline, Type_unavailable, "", "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue