diff --git a/gateway/gateway.go b/gateway/gateway.go index 5faf1ca..306111e 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -15,7 +15,7 @@ type GatewayInfo struct { SteamLoginInfo *steam.LogOnDetails SteamClient *steam.Client SentryFile string - FriendSteamId map[string]struct{} + FriendSteamId map[string]*StatusSteamFriend SteamConnecting bool // XMPP @@ -24,6 +24,13 @@ type GatewayInfo struct { XMPP_Connected_Client map[string]bool } +type StatusSteamFriend struct { + XMPP_Status string + XMPP_Type string + SteamGameName string + SteamName string +} + func (g *GatewayInfo) Run() { go g.SteamRun() } diff --git a/gateway/steam.go b/gateway/steam.go index fbe8b88..c17ccbd 100644 --- a/gateway/steam.go +++ b/gateway/steam.go @@ -106,10 +106,15 @@ func (g *GatewayInfo) mainSteam() { } if _, ok := g.FriendSteamId[steamId]; !ok { // Send subscribsion - g.SendXmppPresence(status, Type_subscribe, steamId+"@"+XmppJidComponent, gameName, name) - g.FriendSteamId[steamId] = struct{}{} + g.SendXmppPresence(status, Type_subscribe, "", steamId+"@"+XmppJidComponent, gameName, name) + g.FriendSteamId[steamId] = &StatusSteamFriend{XMPP_Status: status, XMPP_Type: tpye} + } else { + g.FriendSteamId[steamId].XMPP_Status = status + g.FriendSteamId[steamId].XMPP_Type = tpye + g.FriendSteamId[steamId].SteamGameName = gameName + g.FriendSteamId[steamId].SteamName = name } - g.SendXmppPresence(status, tpye, steamId+"@"+XmppJidComponent, gameName, name) + g.SendXmppPresence(status, tpye, "", steamId+"@"+XmppJidComponent, gameName, name) case *steam.ChatMsgEvent: // Message received @@ -181,7 +186,7 @@ func (g *GatewayInfo) SteamDisconnect() { func (g *GatewayInfo) DisconnectAllSteamFriend() { for sid, _ := range g.FriendSteamId { - g.SendXmppPresence(Status_offline, Type_unavailable, sid+"@"+XmppJidComponent, "", "") + g.SendXmppPresence(Status_offline, Type_unavailable, "", sid+"@"+XmppJidComponent, "", "") delete(g.FriendSteamId, sid) } } diff --git a/gateway/xmpp.go b/gateway/xmpp.go index fbbb2ca..5f375ae 100644 --- a/gateway/xmpp.go +++ b/gateway/xmpp.go @@ -39,7 +39,7 @@ var ( ) func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) { - if presence.Type == Type_probe || presence.Type == Type_error { + if presence.Type == Type_error { return } @@ -55,9 +55,16 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) { } } - if presence.Type == Type_subscribe { + if presence.Type == Type_probe { + steamId := strings.SplitN(strings.SplitN(presence.To, "/", 2)[0], "@", 2)[0] + steamFriendStatus := g.FriendSteamId[steamId] + if steamFriendStatus != nil { + g.SendXmppPresence(steamFriendStatus.XMPP_Status, steamFriendStatus.XMPP_Type, "", steamId+"@"+XmppJidComponent, steamFriendStatus.SteamGameName, steamFriendStatus.SteamName) + } + + } else 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, "") + g.SendXmppPresence("", Type_subscribed, presence.From, presence.To, g.XMPP_JID_Client, "") } else if presence.Type == Type_subscribed { } else if presence.Type == Type_unsubscribe { @@ -110,7 +117,7 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) { if g.IsSteamConnected() { g.SendSteamPresence(steamStatus) - g.SendXmppPresence(presence.Show, presence.Type, "", presence.Status, "") + g.SendXmppPresence(presence.Show, presence.Type, presence.From, "", presence.Status, "") } } } @@ -121,11 +128,11 @@ func (g *GatewayInfo) ReceivedXMPP_Message(message *xmpp.Message) { } func (g *GatewayInfo) XMPP_Disconnect() { - g.SendXmppPresence(Status_offline, Type_unavailable, "", "", "") + g.SendXmppPresence(Status_offline, Type_unavailable, "", "", "", "") } -func (g *GatewayInfo) SendXmppPresence(status, tpye, from, message, nick string) { - p := xmpp.Presence{To: g.XMPP_JID_Client} +func (g *GatewayInfo) SendXmppPresence(status, tpye, to, from, message, nick string) { + p := xmpp.Presence{} if status != "" { p.Show = status @@ -139,6 +146,11 @@ func (g *GatewayInfo) SendXmppPresence(status, tpye, from, message, nick string) if nick != "" { p.Nick = nick } + if to == "" { + p.To = g.XMPP_JID_Client + } else { + p.To = to + } if from == "" { // TODO add an option to allow message comming directly from the gateway p.From = XmppJidComponent diff --git a/main.go b/main.go index 6ec8201..188bf12 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( ) const ( - Version = "v0.3.6" + Version = "v0.3.7d" configurationFilePath = "xmpp4steam.cfg" ) diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go index e9b6db6..3bfa727 100644 --- a/xmpp/xmpp.go +++ b/xmpp/xmpp.go @@ -172,7 +172,7 @@ func AddNewUser(jid, steamLogin, steamPwd string) { g.SteamPassword = steamPwd g.XMPP_JID_Client = jid g.SentryFile = gateway.SentryDirectory + jid - g.FriendSteamId = make(map[string]struct{}) + g.FriendSteamId = make(map[string]*gateway.StatusSteamFriend) g.XMPP_Out = comp.Out g.XMPP_Connected_Client = make(map[string]bool)