1
0
Fork 0

Add an Ad-Hoc command to force Steam deconnexion

This commit is contained in:
Chteufleur 2016-04-21 23:33:59 +02:00
parent 43d9c6c5c6
commit 3e3347123f
5 changed files with 26 additions and 13 deletions

View File

@ -31,3 +31,8 @@ func (g *GatewayInfo) Run() {
func (g *GatewayInfo) SetSteamAuthCode(authCode string) {
g.SteamLoginInfo.AuthCode = authCode
}
func (g *GatewayInfo) Disconnect() {
g.XMPP_Disconnect()
go g.SteamDisconnect()
}

View File

@ -67,11 +67,9 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
if presence.Type == Type_unavailable {
// Disconnect
if len(g.XMPP_Connected_Client) <= 0 {
g.XMPP_Disconnect()
go g.SteamDisconnect()
g.Disconnect()
}
} else if presence.Type == Type_available {
g.XMPP_Connect()
go g.SteamConnect()
transfertPresence = true
}
@ -81,11 +79,9 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
if presence.Type == Type_unavailable {
// Disconnect
if len(g.XMPP_Connected_Client) <= 0 {
g.XMPP_Disconnect()
go g.SteamDisconnect()
g.Disconnect()
}
} else if presence.Type == Type_available {
g.XMPP_Connect()
go g.SteamConnect()
transfertPresence = true
}
@ -124,12 +120,7 @@ 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, "", "", "")
}

View File

@ -15,7 +15,7 @@ import (
)
const (
Version = "v0.3.5"
Version = "v0.3.6"
configurationFilePath = "xmpp4steam.cfg"
)

View File

@ -11,6 +11,7 @@ import (
const (
CommandAuthcode = "steamAuthCodeCommand"
CommandGetIdentifiants = "steamGetIdentifiants"
CommandDisconnectSteam = "disconnectSteam"
)
var (
@ -27,6 +28,8 @@ func execDiscoCommand(iq *xmpp.Iq) {
discoItem.Item = append(discoItem.Item, *discoI)
discoI = &xmpp.DiscoItem{JID: jid.Domain, Node: CommandGetIdentifiants, Name: "Steam registration"}
discoItem.Item = append(discoItem.Item, *discoI)
discoI = &xmpp.DiscoItem{JID: jid.Domain, Node: CommandDisconnectSteam, Name: "Force Steam deconnexion"}
discoItem.Item = append(discoItem.Item, *discoI)
reply.PayloadEncode(discoItem)
comp.Out <- reply
@ -62,6 +65,21 @@ func execCommandAdHoc(iq *xmpp.Iq) {
cmd.XForm = *cmdXForm
cmd.Note = *note
} else if adHoc.Node == CommandDisconnectSteam {
cmd.Status = xmpp.StatusAdHocCompleted
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Force Steam deconnexion"}
cmd.XForm = *cmdXForm
note := &xmpp.AdHocNote{Type: xmpp.TypeAdHocNoteInfo}
jidBare := strings.SplitN(iq.From, "/", 2)[0]
g := MapGatewayInfo[jidBare]
if g != nil {
g.Disconnect()
note.Value = "Send deconnexion on Steam network"
} else {
note.Value = "Your are not registred."
}
cmd.Note = *note
}
reply.PayloadEncode(cmd)
comp.Out <- reply

View File

@ -167,7 +167,6 @@ func SendMessage(to, subject, message string) {
func AddNewUser(jid, steamLogin, steamPwd string) {
log.Printf("%sAdd user %s to the map", LogInfo, jid)
// TODO Move Gateway creation into right package
g := new(gateway.GatewayInfo)
g.SteamLogin = steamLogin
g.SteamPassword = steamPwd