1
0
Fork 0

Add multi connected client support for one account

This commit is contained in:
Chteufleur 2016-04-19 17:12:36 +02:00
parent dc5027d36d
commit ade4020625
3 changed files with 36 additions and 18 deletions

View File

@ -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() {

View File

@ -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, "", "", "")
} }

View File

@ -15,7 +15,7 @@ import (
) )
const ( const (
Version = "go-xmpp4steam v0.3.3" Version = "go-xmpp4steam v0.3.4"
configurationFilePath = "xmpp4steam.cfg" configurationFilePath = "xmpp4steam.cfg"
) )