110 lines
2.1 KiB
Go
110 lines
2.1 KiB
Go
package gateway
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/Philipp15b/go-steam"
|
|
)
|
|
|
|
const (
|
|
resource = "go-xmpp4steam"
|
|
)
|
|
|
|
var (
|
|
SentryDirectory = "sentries/"
|
|
XmppGroupUser = "Steam"
|
|
|
|
RemoteRosterRequestPermission = "remote-roster-request-permission"
|
|
RemoteRosterRequestRoster = "remote-roster-request-roster"
|
|
)
|
|
|
|
type GatewayInfo struct {
|
|
// Steam
|
|
SteamLogin string
|
|
SteamPassword string
|
|
SteamLoginInfo *steam.LogOnDetails
|
|
SteamClient *steam.Client
|
|
SentryFile string
|
|
friendSteamId map[string]*StatusSteamFriend
|
|
SteamConnecting bool
|
|
Deleting bool
|
|
|
|
// XMPP
|
|
XMPP_JID_Client string
|
|
XMPP_Out chan interface{}
|
|
XMPP_Connected_Client map[string]bool
|
|
DebugMessage bool
|
|
XMPP_IQ_RemoteRoster_Request map[string]string
|
|
AllowEditRoster bool
|
|
ChatstateNotificationData chan string
|
|
|
|
sync.RWMutex
|
|
}
|
|
|
|
type StatusSteamFriend struct {
|
|
XMPP_Status string
|
|
XMPP_Type string
|
|
SteamGameName string
|
|
SteamName string
|
|
}
|
|
|
|
func (g *GatewayInfo) Run() {
|
|
go g.SteamRun()
|
|
go g.chatstatesNotification()
|
|
}
|
|
|
|
func (g *GatewayInfo) SetSteamAuthCode(authCode string) {
|
|
g.SteamLoginInfo.AuthCode = authCode
|
|
}
|
|
|
|
func (g *GatewayInfo) Disconnect() {
|
|
go g.XMPP_Disconnect()
|
|
go g.SteamDisconnect()
|
|
g.SteamConnecting = false
|
|
}
|
|
|
|
func (g *GatewayInfo) Delete() {
|
|
g.Deleting = true
|
|
|
|
if g.AllowEditRoster {
|
|
g.removeAllUserFromRoster()
|
|
}
|
|
|
|
g.Disconnect()
|
|
}
|
|
|
|
func (s *GatewayInfo) CreateSteamIds() {
|
|
s.friendSteamId = make(map[string]*StatusSteamFriend)
|
|
}
|
|
|
|
func (s *GatewayInfo) GetFriendSteamId(steamId string) *StatusSteamFriend {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
return s.friendSteamId[steamId]
|
|
}
|
|
|
|
func (s *GatewayInfo) GetAllFriendSteamId() []string {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
allSteamIds := make([]string, len(s.friendSteamId))
|
|
|
|
i := 0
|
|
for steamId := range s.friendSteamId {
|
|
allSteamIds[i] = steamId
|
|
i++
|
|
}
|
|
return allSteamIds
|
|
}
|
|
|
|
func (s *GatewayInfo) SetFriendSteamId(steamId string, status *StatusSteamFriend) {
|
|
s.Lock()
|
|
s.friendSteamId[steamId] = status
|
|
s.Unlock()
|
|
}
|
|
|
|
func (s *GatewayInfo) RemoveFriendSteamId(steamId string) {
|
|
s.Lock()
|
|
delete(s.friendSteamId, steamId)
|
|
s.Unlock()
|
|
}
|