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.
|
||||
|
||||
|
||||
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
|
||||
```
|
||||
[https "https://git.kingpenguin.tk"]
|
||||
sslCAPath = /path/to/CA
|
||||
```
|
||||
|
||||
Then go into your $GOPATH directory and go get the code.
|
||||
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.
|
||||
```sh
|
||||
go get git.kingpenguin.tk/chteufleur/go-xmpp4steam.git
|
||||
```
|
||||
|
|
|
|||
|
|
@ -49,6 +49,12 @@ func Close() {
|
|||
|
||||
func (newLine *DatabaseLine) AddLine() bool {
|
||||
log.Printf("%sAdd new line %v", LogInfo, newLine)
|
||||
|
||||
isUserRegistred := getLine(newLine.Jid) != nil
|
||||
if isUserRegistred {
|
||||
return newLine.UpdateLine()
|
||||
}
|
||||
|
||||
stmt, err := db.Prepare(insertDatabaseStmt)
|
||||
if err != nil {
|
||||
log.Printf("%sError on insert jid %s", LogError, newLine.Jid, err)
|
||||
|
|
@ -82,7 +88,12 @@ func (newLine *DatabaseLine) UpdateLine() bool {
|
|||
}
|
||||
|
||||
func RemoveLine(jid string) bool {
|
||||
line := new(DatabaseLine)
|
||||
line.Jid = jid
|
||||
return line.UpdateLine()
|
||||
|
||||
// FIXME not working
|
||||
/*
|
||||
log.Printf("%sRemove line %s", LogInfo, jid)
|
||||
|
||||
stmt, err := db.Prepare(deleteDatabaseStmt)
|
||||
|
|
@ -107,9 +118,21 @@ func RemoveLine(jid string) bool {
|
|||
}
|
||||
|
||||
return true
|
||||
*/
|
||||
}
|
||||
|
||||
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)
|
||||
ret := new(DatabaseLine)
|
||||
|
||||
|
|
@ -141,8 +164,10 @@ func GetAllLines() []DatabaseLine {
|
|||
for rows.Next() {
|
||||
user := new(DatabaseLine)
|
||||
rows.Scan(&user.Jid, &user.SteamLogin, &user.SteamPwd)
|
||||
if user.SteamLogin != "" {
|
||||
ret = append(ret, *user)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
const (
|
||||
SentryDirectory = "sentries/"
|
||||
resource = "go-xmpp4steam"
|
||||
)
|
||||
|
||||
type GatewayInfo struct {
|
||||
|
|
@ -15,8 +16,9 @@ type GatewayInfo struct {
|
|||
SteamLoginInfo *steam.LogOnDetails
|
||||
SteamClient *steam.Client
|
||||
SentryFile string
|
||||
FriendSteamId map[string]struct{}
|
||||
FriendSteamId map[string]*StatusSteamFriend
|
||||
SteamConnecting bool
|
||||
Deleting bool
|
||||
|
||||
// XMPP
|
||||
XMPP_JID_Client string
|
||||
|
|
@ -24,6 +26,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()
|
||||
}
|
||||
|
|
@ -36,3 +45,8 @@ func (g *GatewayInfo) Disconnect() {
|
|||
g.XMPP_Disconnect()
|
||||
go g.SteamDisconnect()
|
||||
}
|
||||
|
||||
func (g *GatewayInfo) Delete() {
|
||||
g.Deleting = true
|
||||
g.Disconnect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ const (
|
|||
)
|
||||
|
||||
func (g *GatewayInfo) SteamRun() {
|
||||
if g.Deleting {
|
||||
log.Printf("%sDeleting gateway", LogSteamInfo)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("%sRunning", LogSteamInfo)
|
||||
g.setLoginInfos()
|
||||
g.SteamClient = steam.NewClient()
|
||||
|
|
@ -106,10 +111,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
|
||||
|
|
@ -136,7 +146,14 @@ func (g *GatewayInfo) setLoginInfos() {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
@ -181,7 +198,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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,13 +39,14 @@ var (
|
|||
)
|
||||
|
||||
func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||
if presence.Type == Type_probe || presence.Type == Type_error {
|
||||
if presence.Type == Type_error {
|
||||
return
|
||||
}
|
||||
|
||||
transfertPresence := false
|
||||
|
||||
jid := strings.SplitN(presence.From, "/", 2)
|
||||
steamJid := strings.SplitN(strings.SplitN(presence.To, "/", 2)[0], "@", 2)
|
||||
if len(jid) == 2 {
|
||||
// Resource exist —> client speaking
|
||||
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
|
||||
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,11 +146,16 @@ 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
|
||||
p.From = XmppJidComponent + "/" + resource
|
||||
} else {
|
||||
p.From = from
|
||||
p.From = from + "/" + resource
|
||||
}
|
||||
|
||||
log.Printf("%sSend presence %v", LogXmppInfo, p)
|
||||
|
|
|
|||
2
main.go
2
main.go
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
Version = "v0.3.6"
|
||||
Version = "v0.3.8"
|
||||
configurationFilePath = "xmpp4steam.cfg"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ const (
|
|||
CommandAuthcode = "steamAuthCodeCommand"
|
||||
CommandGetIdentifiants = "steamGetIdentifiants"
|
||||
CommandDisconnectSteam = "disconnectSteam"
|
||||
CommandRemoveRegistration = "removeRegistration"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -30,6 +31,8 @@ func execDiscoCommand(iq *xmpp.Iq) {
|
|||
discoItem.Item = append(discoItem.Item, *discoI)
|
||||
discoI = &xmpp.DiscoItem{JID: jid.Domain, Node: CommandDisconnectSteam, Name: "Force Steam deconnexion"}
|
||||
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)
|
||||
comp.Out <- reply
|
||||
|
|
@ -79,6 +82,20 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
|||
} else {
|
||||
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
|
||||
}
|
||||
reply.PayloadEncode(cmd)
|
||||
|
|
|
|||
19
xmpp/xmpp.go
19
xmpp/xmpp.go
|
|
@ -2,6 +2,7 @@ package xmpp
|
|||
|
||||
import (
|
||||
"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"
|
||||
|
||||
"log"
|
||||
|
|
@ -172,7 +173,8 @@ 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.Deleting = false
|
||||
|
||||
g.XMPP_Out = comp.Out
|
||||
g.XMPP_Connected_Client = make(map[string]bool)
|
||||
|
|
@ -180,3 +182,18 @@ func AddNewUser(jid, steamLogin, steamPwd string) {
|
|||
MapGatewayInfo[jid] = g
|
||||
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