Permit remove registration. Working but can be improve
This commit is contained in:
parent
8692512b22
commit
7d9cf97445
|
|
@ -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,34 +88,51 @@ 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)
|
||||
/*
|
||||
log.Printf("%sRemove line %s", LogInfo, jid)
|
||||
|
||||
stmt, err := db.Prepare(deleteDatabaseStmt)
|
||||
if err != nil {
|
||||
log.Printf("%sError on delete jid %s", LogError, jid, err)
|
||||
return false
|
||||
}
|
||||
defer stmt.Close()
|
||||
res, err := stmt.Exec(jid)
|
||||
if err != nil {
|
||||
log.Printf("%sError on delete SQL statement", LogError, err)
|
||||
return false
|
||||
}
|
||||
stmt, err := db.Prepare(deleteDatabaseStmt)
|
||||
if err != nil {
|
||||
log.Printf("%sError on delete jid %s", LogError, jid, err)
|
||||
return false
|
||||
}
|
||||
defer stmt.Close()
|
||||
res, err := stmt.Exec(jid)
|
||||
if err != nil {
|
||||
log.Printf("%sError on delete SQL statement", LogError, err)
|
||||
return false
|
||||
}
|
||||
|
||||
affect, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
log.Printf("%sError on delete SQL statement", LogError, err)
|
||||
return false
|
||||
}
|
||||
if affect == 0 {
|
||||
return false
|
||||
}
|
||||
affect, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
log.Printf("%sError on delete SQL statement", LogError, err)
|
||||
return false
|
||||
}
|
||||
if affect == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
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,7 +164,9 @@ func GetAllLines() []DatabaseLine {
|
|||
for rows.Next() {
|
||||
user := new(DatabaseLine)
|
||||
rows.Scan(&user.Jid, &user.SteamLogin, &user.SteamPwd)
|
||||
ret = append(ret, *user)
|
||||
if user.SteamLogin != "" {
|
||||
ret = append(ret, *user)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type GatewayInfo struct {
|
|||
SentryFile string
|
||||
FriendSteamId map[string]*StatusSteamFriend
|
||||
SteamConnecting bool
|
||||
Deleting bool
|
||||
|
||||
// XMPP
|
||||
XMPP_JID_Client string
|
||||
|
|
@ -44,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()
|
||||
|
|
@ -141,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() {
|
||||
|
|
|
|||
2
main.go
2
main.go
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
Version = "v0.3.7"
|
||||
Version = "v0.3.8"
|
||||
configurationFilePath = "xmpp4steam.cfg"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
CommandAuthcode = "steamAuthCodeCommand"
|
||||
CommandGetIdentifiants = "steamGetIdentifiants"
|
||||
CommandDisconnectSteam = "disconnectSteam"
|
||||
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)
|
||||
|
|
|
|||
17
xmpp/xmpp.go
17
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"
|
||||
|
|
@ -173,6 +174,7 @@ func AddNewUser(jid, steamLogin, steamPwd string) {
|
|||
g.XMPP_JID_Client = jid
|
||||
g.SentryFile = gateway.SentryDirectory + jid
|
||||
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