forked from chteufleur/go-xmpp4steam
Answer to presence probe type
This commit is contained in:
parent
3e3347123f
commit
e064b71660
|
|
@ -15,7 +15,7 @@ type GatewayInfo struct {
|
||||||
SteamLoginInfo *steam.LogOnDetails
|
SteamLoginInfo *steam.LogOnDetails
|
||||||
SteamClient *steam.Client
|
SteamClient *steam.Client
|
||||||
SentryFile string
|
SentryFile string
|
||||||
FriendSteamId map[string]struct{}
|
FriendSteamId map[string]*StatusSteamFriend
|
||||||
SteamConnecting bool
|
SteamConnecting bool
|
||||||
|
|
||||||
// XMPP
|
// XMPP
|
||||||
|
|
@ -24,6 +24,13 @@ type GatewayInfo struct {
|
||||||
XMPP_Connected_Client map[string]bool
|
XMPP_Connected_Client map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StatusSteamFriend struct {
|
||||||
|
XMPP_Status string
|
||||||
|
XMPP_Type string
|
||||||
|
SteamGameName string
|
||||||
|
SteamName string
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GatewayInfo) Run() {
|
func (g *GatewayInfo) Run() {
|
||||||
go g.SteamRun()
|
go g.SteamRun()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,10 +106,15 @@ func (g *GatewayInfo) mainSteam() {
|
||||||
}
|
}
|
||||||
if _, ok := g.FriendSteamId[steamId]; !ok {
|
if _, ok := g.FriendSteamId[steamId]; !ok {
|
||||||
// Send subscribsion
|
// Send subscribsion
|
||||||
g.SendXmppPresence(status, Type_subscribe, steamId+"@"+XmppJidComponent, gameName, name)
|
g.SendXmppPresence(status, Type_subscribe, "", steamId+"@"+XmppJidComponent, gameName, name)
|
||||||
g.FriendSteamId[steamId] = struct{}{}
|
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:
|
case *steam.ChatMsgEvent:
|
||||||
// Message received
|
// Message received
|
||||||
|
|
@ -181,7 +186,7 @@ func (g *GatewayInfo) SteamDisconnect() {
|
||||||
|
|
||||||
func (g *GatewayInfo) DisconnectAllSteamFriend() {
|
func (g *GatewayInfo) DisconnectAllSteamFriend() {
|
||||||
for sid, _ := range g.FriendSteamId {
|
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)
|
delete(g.FriendSteamId, sid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||||
if presence.Type == Type_probe || presence.Type == Type_error {
|
if presence.Type == Type_error {
|
||||||
return
|
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
|
// 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_subscribed {
|
||||||
} else if presence.Type == Type_unsubscribe {
|
} else if presence.Type == Type_unsubscribe {
|
||||||
|
|
@ -110,7 +117,7 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||||
|
|
||||||
if g.IsSteamConnected() {
|
if g.IsSteamConnected() {
|
||||||
g.SendSteamPresence(steamStatus)
|
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() {
|
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) {
|
func (g *GatewayInfo) SendXmppPresence(status, tpye, to, from, message, nick string) {
|
||||||
p := xmpp.Presence{To: g.XMPP_JID_Client}
|
p := xmpp.Presence{}
|
||||||
|
|
||||||
if status != "" {
|
if status != "" {
|
||||||
p.Show = status
|
p.Show = status
|
||||||
|
|
@ -139,6 +146,11 @@ func (g *GatewayInfo) SendXmppPresence(status, tpye, from, message, nick string)
|
||||||
if nick != "" {
|
if nick != "" {
|
||||||
p.Nick = nick
|
p.Nick = nick
|
||||||
}
|
}
|
||||||
|
if to == "" {
|
||||||
|
p.To = g.XMPP_JID_Client
|
||||||
|
} else {
|
||||||
|
p.To = to
|
||||||
|
}
|
||||||
if from == "" {
|
if from == "" {
|
||||||
// TODO add an option to allow message comming directly from the gateway
|
// TODO add an option to allow message comming directly from the gateway
|
||||||
p.From = XmppJidComponent
|
p.From = XmppJidComponent
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "v0.3.6"
|
Version = "v0.3.7d"
|
||||||
configurationFilePath = "xmpp4steam.cfg"
|
configurationFilePath = "xmpp4steam.cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ func AddNewUser(jid, steamLogin, steamPwd string) {
|
||||||
g.SteamPassword = steamPwd
|
g.SteamPassword = steamPwd
|
||||||
g.XMPP_JID_Client = jid
|
g.XMPP_JID_Client = jid
|
||||||
g.SentryFile = gateway.SentryDirectory + 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_Out = comp.Out
|
||||||
g.XMPP_Connected_Client = make(map[string]bool)
|
g.XMPP_Connected_Client = make(map[string]bool)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue