Compare commits
4 Commits
6d1fcc1333
...
0b04382ca0
| Author | SHA1 | Date |
|---|---|---|
|
|
0b04382ca0 | |
|
|
ade4020625 | |
|
|
dc5027d36d | |
|
|
5109d91e35 |
|
|
@ -25,6 +25,7 @@ type GatewayInfo struct {
|
|||
// XMPP
|
||||
XMPP_JID_Client string
|
||||
XMPP_Out chan interface{}
|
||||
XMPP_Connected_Client map[string]bool
|
||||
}
|
||||
|
||||
func (g *GatewayInfo) Run() {
|
||||
|
|
|
|||
|
|
@ -45,6 +45,16 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
|||
|
||||
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 {
|
||||
// Send presence to tell that the JID has been added to roster
|
||||
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
|
||||
if presence.Type == Type_unavailable {
|
||||
// Disconnect
|
||||
// TODO multi client connected management
|
||||
if len(g.XMPP_Connected_Client) <= 0 {
|
||||
g.XMPP_Disconnect()
|
||||
go g.SteamDisconnect()
|
||||
}
|
||||
} else if presence.Type == Type_available {
|
||||
// TODO multi client connected management
|
||||
g.XMPP_Connect()
|
||||
go g.SteamConnect()
|
||||
transfertPresence = true
|
||||
}
|
||||
|
|
@ -69,11 +80,12 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
|||
// Destination is Steam user
|
||||
if presence.Type == Type_unavailable {
|
||||
// Disconnect
|
||||
// TODO multi client connected management
|
||||
if len(g.XMPP_Connected_Client) <= 0 {
|
||||
g.XMPP_Disconnect()
|
||||
go g.SteamDisconnect()
|
||||
}
|
||||
} else if presence.Type == Type_available {
|
||||
// TODO multi client connected management
|
||||
g.XMPP_Connect()
|
||||
go g.SteamConnect()
|
||||
transfertPresence = true
|
||||
}
|
||||
|
|
@ -112,7 +124,12 @@ func (g *GatewayInfo) ReceivedXMPP_Message(message *xmpp.Message) {
|
|||
g.SendSteamMessage(steamID, message.Subject+"\n"+message.Body)
|
||||
}
|
||||
|
||||
func (g *GatewayInfo) XMPP_Connect() {
|
||||
// TODO multi client connected management
|
||||
}
|
||||
|
||||
func (g *GatewayInfo) XMPP_Disconnect() {
|
||||
// TODO multi client connected management
|
||||
g.SendXmppPresence(Status_offline, Type_unavailable, "", "", "")
|
||||
}
|
||||
|
||||
|
|
|
|||
2
main.go
2
main.go
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
Version = "go-xmpp4steam v0.3.2"
|
||||
Version = "go-xmpp4steam v0.3.4"
|
||||
configurationFilePath = "xmpp4steam.cfg"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
|||
// Command Auth Code
|
||||
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
|
||||
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}
|
||||
cmdXForm.Fields = append(cmdXForm.Fields, *field)
|
||||
|
|
@ -61,6 +62,7 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
|||
cmdXForm.Fields = append(cmdXForm.Fields, *field)
|
||||
|
||||
cmd.XForm = *cmdXForm
|
||||
cmd.Note = *note
|
||||
}
|
||||
reply.PayloadEncode(cmd)
|
||||
comp.Out <- reply
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ func Run() {
|
|||
comp = must(xmpp.NewComponentXMPP(stream, jid, Secret)).(*xmpp.XMPP)
|
||||
|
||||
mainXMPP()
|
||||
ChanAction <- ActionMainMethodEnded
|
||||
log.Printf("%sReach main method's end", LogInfo)
|
||||
go Run()
|
||||
}
|
||||
|
||||
func mainXMPP() {
|
||||
|
|
@ -157,6 +158,7 @@ func AddNewUser(jid, steamLogin, steamPwd string) {
|
|||
g.FriendSteamId = make(map[string]struct{})
|
||||
|
||||
g.XMPP_Out = comp.Out
|
||||
g.XMPP_Connected_Client = make(map[string]bool)
|
||||
|
||||
MapGatewayInfo[jid] = g
|
||||
go g.Run()
|
||||
|
|
|
|||
Loading…
Reference in New Issue