1
0
Fork 0

Answer to presence probe type

This commit is contained in:
Chteufleur 2016-04-23 10:04:44 +02:00
parent 3e3347123f
commit e064b71660
5 changed files with 38 additions and 14 deletions

View File

@ -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()
}

View File

@ -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)
}
}

View File

@ -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

View File

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

View File

@ -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)