Compare commits

...

4 Commits

5 changed files with 34 additions and 12 deletions

View File

@ -23,8 +23,9 @@ type GatewayInfo 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.2" Version = "go-xmpp4steam v0.3.4"
configurationFilePath = "xmpp4steam.cfg" configurationFilePath = "xmpp4steam.cfg"
) )

View File

@ -54,6 +54,7 @@ func execCommandAdHoc(iq *xmpp.Iq) {
// Command Auth Code // Command Auth Code
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocForm, Title: "Steam Account Info", Instructions: "Please provide your Steam login and password."} cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocForm, Title: "Steam Account Info", Instructions: "Please provide your Steam login and password."}
// TODO Warn that the given info is stored in database in clear // TODO Warn that the given info is stored in database in clear
note := &xmpp.AdHocNote{Type: xmpp.TypeAdHocNoteInfo, Value: "Please, be aware that the given Steam account information will be saved into an un-encrypted SQLite database."}
field := &xmpp.AdHocField{Var: "login", Label: "Steam Login", Type: xmpp.TypeAdHocFieldTextSingle} field := &xmpp.AdHocField{Var: "login", Label: "Steam Login", Type: xmpp.TypeAdHocFieldTextSingle}
cmdXForm.Fields = append(cmdXForm.Fields, *field) cmdXForm.Fields = append(cmdXForm.Fields, *field)
@ -61,6 +62,7 @@ func execCommandAdHoc(iq *xmpp.Iq) {
cmdXForm.Fields = append(cmdXForm.Fields, *field) cmdXForm.Fields = append(cmdXForm.Fields, *field)
cmd.XForm = *cmdXForm cmd.XForm = *cmdXForm
cmd.Note = *note
} }
reply.PayloadEncode(cmd) reply.PayloadEncode(cmd)
comp.Out <- reply comp.Out <- reply

View File

@ -42,7 +42,8 @@ func Run() {
comp = must(xmpp.NewComponentXMPP(stream, jid, Secret)).(*xmpp.XMPP) comp = must(xmpp.NewComponentXMPP(stream, jid, Secret)).(*xmpp.XMPP)
mainXMPP() mainXMPP()
ChanAction <- ActionMainMethodEnded log.Printf("%sReach main method's end", LogInfo)
go Run()
} }
func mainXMPP() { func mainXMPP() {
@ -157,6 +158,7 @@ func AddNewUser(jid, steamLogin, steamPwd string) {
g.FriendSteamId = make(map[string]struct{}) g.FriendSteamId = make(map[string]struct{})
g.XMPP_Out = comp.Out g.XMPP_Out = comp.Out
g.XMPP_Connected_Client = make(map[string]bool)
MapGatewayInfo[jid] = g MapGatewayInfo[jid] = g
go g.Run() go g.Run()