Compare commits

..

No commits in common. "7d9cf97445a2a743c73f1e82d18afce9627f2d2c" and "3e3347123f0da8b4a4667d15be32ecc4bb8bd343" have entirely different histories.

8 changed files with 49 additions and 146 deletions

View File

@ -12,8 +12,13 @@ go-xmpp4steam is a XMPP/Steam gateway.
* [cfg](https://github.com/jimlawless/cfg) for the configuration file. * [cfg](https://github.com/jimlawless/cfg) for the configuration file.
Download the CA at [https://kingpenguin.tk/ressources/cacert.pem](https://kingpenguin.tk/ressources/cacert.pem), then install it on your operating system. Download the CA at [https://kingpenguin.tk/ressources/cacert.pem](https://kingpenguin.tk/ressources/cacert.pem), then edit your .gitconfig and add the following lines
Once installed, go into your $GOPATH directory and go get the source code. ```
[https "https://git.kingpenguin.tk"]
sslCAPath = /path/to/CA
```
Then go into your $GOPATH directory and go get the code.
```sh ```sh
go get git.kingpenguin.tk/chteufleur/go-xmpp4steam.git go get git.kingpenguin.tk/chteufleur/go-xmpp4steam.git
``` ```

View File

@ -49,12 +49,6 @@ func Close() {
func (newLine *DatabaseLine) AddLine() bool { func (newLine *DatabaseLine) AddLine() bool {
log.Printf("%sAdd new line %v", LogInfo, newLine) log.Printf("%sAdd new line %v", LogInfo, newLine)
isUserRegistred := getLine(newLine.Jid) != nil
if isUserRegistred {
return newLine.UpdateLine()
}
stmt, err := db.Prepare(insertDatabaseStmt) stmt, err := db.Prepare(insertDatabaseStmt)
if err != nil { if err != nil {
log.Printf("%sError on insert jid %s", LogError, newLine.Jid, err) log.Printf("%sError on insert jid %s", LogError, newLine.Jid, err)
@ -88,12 +82,7 @@ func (newLine *DatabaseLine) UpdateLine() bool {
} }
func RemoveLine(jid string) bool { func RemoveLine(jid string) bool {
line := new(DatabaseLine)
line.Jid = jid
return line.UpdateLine()
// FIXME not working // FIXME not working
/*
log.Printf("%sRemove line %s", LogInfo, jid) log.Printf("%sRemove line %s", LogInfo, jid)
stmt, err := db.Prepare(deleteDatabaseStmt) stmt, err := db.Prepare(deleteDatabaseStmt)
@ -118,21 +107,9 @@ func RemoveLine(jid string) bool {
} }
return true return true
*/
} }
func GetLine(jid string) *DatabaseLine { func GetLine(jid string) *DatabaseLine {
ret := getLine(jid)
if ret.SteamLogin == "" {
log.Printf("%sLine empty", LogDebug)
return nil
}
return ret
}
func getLine(jid string) *DatabaseLine {
log.Printf("%sGet line %s", LogInfo, jid) log.Printf("%sGet line %s", LogInfo, jid)
ret := new(DatabaseLine) ret := new(DatabaseLine)
@ -164,10 +141,8 @@ func GetAllLines() []DatabaseLine {
for rows.Next() { for rows.Next() {
user := new(DatabaseLine) user := new(DatabaseLine)
rows.Scan(&user.Jid, &user.SteamLogin, &user.SteamPwd) rows.Scan(&user.Jid, &user.SteamLogin, &user.SteamPwd)
if user.SteamLogin != "" {
ret = append(ret, *user) ret = append(ret, *user)
} }
}
return ret return ret
} }

View File

@ -6,7 +6,6 @@ import (
const ( const (
SentryDirectory = "sentries/" SentryDirectory = "sentries/"
resource = "go-xmpp4steam"
) )
type GatewayInfo struct { type GatewayInfo struct {
@ -16,9 +15,8 @@ type GatewayInfo struct {
SteamLoginInfo *steam.LogOnDetails SteamLoginInfo *steam.LogOnDetails
SteamClient *steam.Client SteamClient *steam.Client
SentryFile string SentryFile string
FriendSteamId map[string]*StatusSteamFriend FriendSteamId map[string]struct{}
SteamConnecting bool SteamConnecting bool
Deleting bool
// XMPP // XMPP
XMPP_JID_Client string XMPP_JID_Client string
@ -26,13 +24,6 @@ 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()
} }
@ -45,8 +36,3 @@ func (g *GatewayInfo) Disconnect() {
g.XMPP_Disconnect() g.XMPP_Disconnect()
go g.SteamDisconnect() go g.SteamDisconnect()
} }
func (g *GatewayInfo) Delete() {
g.Deleting = true
g.Disconnect()
}

View File

@ -30,11 +30,6 @@ const (
) )
func (g *GatewayInfo) SteamRun() { func (g *GatewayInfo) SteamRun() {
if g.Deleting {
log.Printf("%sDeleting gateway", LogSteamInfo)
return
}
log.Printf("%sRunning", LogSteamInfo) log.Printf("%sRunning", LogSteamInfo)
g.setLoginInfos() g.setLoginInfos()
g.SteamClient = steam.NewClient() g.SteamClient = steam.NewClient()
@ -111,15 +106,10 @@ 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] = &StatusSteamFriend{XMPP_Status: status, XMPP_Type: tpye} g.FriendSteamId[steamId] = struct{}{}
} 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
@ -146,14 +136,7 @@ func (g *GatewayInfo) setLoginInfos() {
} }
func (g *GatewayInfo) IsSteamConnected() bool { func (g *GatewayInfo) IsSteamConnected() bool {
ret := g != nil return g.SteamClient.Connected()
if ret {
ret = g.SteamClient != nil
if ret {
ret = g.SteamClient.Connected()
}
}
return ret
} }
func (g *GatewayInfo) SteamConnect() { func (g *GatewayInfo) SteamConnect() {
@ -198,7 +181,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)
} }
} }

View File

@ -39,14 +39,13 @@ var (
) )
func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) { func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
if presence.Type == Type_error { if presence.Type == Type_probe || presence.Type == Type_error {
return return
} }
transfertPresence := false transfertPresence := false
jid := strings.SplitN(presence.From, "/", 2) jid := strings.SplitN(presence.From, "/", 2)
steamJid := strings.SplitN(strings.SplitN(presence.To, "/", 2)[0], "@", 2)
if len(jid) == 2 { if len(jid) == 2 {
// Resource exist —> client speaking // Resource exist —> client speaking
if presence.Type == Type_available { if presence.Type == Type_available {
@ -56,15 +55,9 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
} }
} }
if presence.Type == Type_probe { if presence.Type == Type_subscribe {
steamFriendStatus := g.FriendSteamId[steamJid[0]]
if steamFriendStatus != nil {
g.SendXmppPresence(steamFriendStatus.XMPP_Status, steamFriendStatus.XMPP_Type, "", steamJid[0]+"@"+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.From, presence.To, g.XMPP_JID_Client, "") g.SendXmppPresence("", Type_subscribed, 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 {
@ -117,7 +110,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.From, "", presence.Status, "") g.SendXmppPresence(presence.Show, presence.Type, "", presence.Status, "")
} }
} }
} }
@ -128,11 +121,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, to, from, message, nick string) { func (g *GatewayInfo) SendXmppPresence(status, tpye, from, message, nick string) {
p := xmpp.Presence{} p := xmpp.Presence{To: g.XMPP_JID_Client}
if status != "" { if status != "" {
p.Show = status p.Show = status
@ -146,16 +139,11 @@ func (g *GatewayInfo) SendXmppPresence(status, tpye, to, from, message, nick str
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 + "/" + resource p.From = XmppJidComponent
} else { } else {
p.From = from + "/" + resource p.From = from
} }
log.Printf("%sSend presence %v", LogXmppInfo, p) log.Printf("%sSend presence %v", LogXmppInfo, p)

View File

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

View File

@ -12,7 +12,6 @@ const (
CommandAuthcode = "steamAuthCodeCommand" CommandAuthcode = "steamAuthCodeCommand"
CommandGetIdentifiants = "steamGetIdentifiants" CommandGetIdentifiants = "steamGetIdentifiants"
CommandDisconnectSteam = "disconnectSteam" CommandDisconnectSteam = "disconnectSteam"
CommandRemoveRegistration = "removeRegistration"
) )
var ( var (
@ -31,8 +30,6 @@ func execDiscoCommand(iq *xmpp.Iq) {
discoItem.Item = append(discoItem.Item, *discoI) discoItem.Item = append(discoItem.Item, *discoI)
discoI = &xmpp.DiscoItem{JID: jid.Domain, Node: CommandDisconnectSteam, Name: "Force Steam deconnexion"} discoI = &xmpp.DiscoItem{JID: jid.Domain, Node: CommandDisconnectSteam, Name: "Force Steam deconnexion"}
discoItem.Item = append(discoItem.Item, *discoI) discoItem.Item = append(discoItem.Item, *discoI)
discoI = &xmpp.DiscoItem{JID: jid.Domain, Node: CommandRemoveRegistration, Name: "Remove registration"}
discoItem.Item = append(discoItem.Item, *discoI)
reply.PayloadEncode(discoItem) reply.PayloadEncode(discoItem)
comp.Out <- reply comp.Out <- reply
@ -82,20 +79,6 @@ func execCommandAdHoc(iq *xmpp.Iq) {
} else { } else {
note.Value = "Your are not registred." note.Value = "Your are not registred."
} }
cmd.Note = *note
} else if adHoc.Node == CommandRemoveRegistration {
cmd.Status = xmpp.StatusAdHocCompleted
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Remove registration"}
cmd.XForm = *cmdXForm
note := &xmpp.AdHocNote{Type: xmpp.TypeAdHocNoteInfo}
jidBare := strings.SplitN(iq.From, "/", 2)[0]
if RemoveUser(jidBare) {
note.Value = "Remove registration success."
} else {
note.Value = "Failed to remove your registration."
}
cmd.Note = *note cmd.Note = *note
} }
reply.PayloadEncode(cmd) reply.PayloadEncode(cmd)

View File

@ -2,7 +2,6 @@ package xmpp
import ( import (
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp" "git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
"git.kingpenguin.tk/chteufleur/go-xmpp4steam.git/database"
"git.kingpenguin.tk/chteufleur/go-xmpp4steam.git/gateway" "git.kingpenguin.tk/chteufleur/go-xmpp4steam.git/gateway"
"log" "log"
@ -173,8 +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]*gateway.StatusSteamFriend) g.FriendSteamId = make(map[string]struct{})
g.Deleting = false
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)
@ -182,18 +180,3 @@ func AddNewUser(jid, steamLogin, steamPwd string) {
MapGatewayInfo[jid] = g MapGatewayInfo[jid] = g
go g.Run() go g.Run()
} }
func RemoveUser(jidBare string) bool {
ret := database.RemoveLine(jidBare)
if ret {
g := MapGatewayInfo[jidBare]
ret = g != nil
if ret {
g.Delete()
MapGatewayInfo[jidBare] = nil
}
}
return ret
}