Compare commits
5 Commits
3e3347123f
...
7d9cf97445
| Author | SHA1 | Date |
|---|---|---|
|
|
7d9cf97445 | |
|
|
8692512b22 | |
|
|
844eddae4f | |
|
|
7368dce789 | |
|
|
e064b71660 |
|
|
@ -12,13 +12,8 @@ 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 edit your .gitconfig and add the following lines
|
Download the CA at [https://kingpenguin.tk/ressources/cacert.pem](https://kingpenguin.tk/ressources/cacert.pem), then install it on your operating system.
|
||||||
```
|
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
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,12 @@ 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)
|
||||||
|
|
@ -82,34 +88,51 @@ 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)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%sError on delete jid %s", LogError, jid, err)
|
log.Printf("%sError on delete jid %s", LogError, jid, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
res, err := stmt.Exec(jid)
|
res, err := stmt.Exec(jid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%sError on delete SQL statement", LogError, err)
|
log.Printf("%sError on delete SQL statement", LogError, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
affect, err := res.RowsAffected()
|
affect, err := res.RowsAffected()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%sError on delete SQL statement", LogError, err)
|
log.Printf("%sError on delete SQL statement", LogError, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if affect == 0 {
|
if affect == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
@ -141,7 +164,9 @@ 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)
|
||||||
ret = append(ret, *user)
|
if user.SteamLogin != "" {
|
||||||
|
ret = append(ret, *user)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SentryDirectory = "sentries/"
|
SentryDirectory = "sentries/"
|
||||||
|
resource = "go-xmpp4steam"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GatewayInfo struct {
|
type GatewayInfo struct {
|
||||||
|
|
@ -15,8 +16,9 @@ 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
|
||||||
|
Deleting bool
|
||||||
|
|
||||||
// XMPP
|
// XMPP
|
||||||
XMPP_JID_Client string
|
XMPP_JID_Client string
|
||||||
|
|
@ -24,6 +26,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()
|
||||||
}
|
}
|
||||||
|
|
@ -36,3 +45,8 @@ 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()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,11 @@ 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()
|
||||||
|
|
@ -106,10 +111,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
|
||||||
|
|
@ -136,7 +146,14 @@ func (g *GatewayInfo) setLoginInfos() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GatewayInfo) IsSteamConnected() bool {
|
func (g *GatewayInfo) IsSteamConnected() bool {
|
||||||
return g.SteamClient.Connected()
|
ret := g != nil
|
||||||
|
if ret {
|
||||||
|
ret = g.SteamClient != nil
|
||||||
|
if ret {
|
||||||
|
ret = g.SteamClient.Connected()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GatewayInfo) SteamConnect() {
|
func (g *GatewayInfo) SteamConnect() {
|
||||||
|
|
@ -181,7 +198,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,13 +39,14 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
|
@ -55,9 +56,15 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if presence.Type == Type_subscribe {
|
if presence.Type == Type_probe {
|
||||||
|
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.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,11 +146,16 @@ 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 + "/" + resource
|
||||||
} else {
|
} else {
|
||||||
p.From = from
|
p.From = from + "/" + resource
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%sSend presence %v", LogXmppInfo, p)
|
log.Printf("%sSend presence %v", LogXmppInfo, p)
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "v0.3.6"
|
Version = "v0.3.8"
|
||||||
configurationFilePath = "xmpp4steam.cfg"
|
configurationFilePath = "xmpp4steam.cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CommandAuthcode = "steamAuthCodeCommand"
|
CommandAuthcode = "steamAuthCodeCommand"
|
||||||
CommandGetIdentifiants = "steamGetIdentifiants"
|
CommandGetIdentifiants = "steamGetIdentifiants"
|
||||||
CommandDisconnectSteam = "disconnectSteam"
|
CommandDisconnectSteam = "disconnectSteam"
|
||||||
|
CommandRemoveRegistration = "removeRegistration"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -30,6 +31,8 @@ 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
|
||||||
|
|
@ -79,6 +82,20 @@ 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)
|
||||||
|
|
|
||||||
19
xmpp/xmpp.go
19
xmpp/xmpp.go
|
|
@ -2,6 +2,7 @@ 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"
|
||||||
|
|
@ -172,7 +173,8 @@ 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.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)
|
||||||
|
|
@ -180,3 +182,18 @@ 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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue