diff --git a/gateway/gateway.go b/gateway/gateway.go index a8b6976..5faf1ca 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -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() +} diff --git a/gateway/xmpp.go b/gateway/xmpp.go index 5d167cb..fbbb2ca 100644 --- a/gateway/xmpp.go +++ b/gateway/xmpp.go @@ -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, "", "", "") } diff --git a/main.go b/main.go index 115071e..6ec8201 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( ) const ( - Version = "v0.3.5" + Version = "v0.3.6" configurationFilePath = "xmpp4steam.cfg" ) diff --git a/xmpp/commands.go b/xmpp/commands.go index 2c744b2..e0da871 100644 --- a/xmpp/commands.go +++ b/xmpp/commands.go @@ -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 diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go index 931158a..e9b6db6 100644 --- a/xmpp/xmpp.go +++ b/xmpp/xmpp.go @@ -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