forked from chteufleur/go-xmpp4steam
Add debug command to allow/diallow debug messages
This commit is contained in:
parent
659fcba63d
commit
ec8ff5ee92
|
|
@ -9,11 +9,11 @@ import (
|
|||
const (
|
||||
databaseFile = "go_xmpp4steam.db"
|
||||
|
||||
createDatabaseStmt = "create table if not exists users (jid text not null primary key, steamLogin text, steamPwd text);"
|
||||
insertDatabaseStmt = "insert into users (jid, steamLogin, steamPwd) values(?, ?, ?)"
|
||||
createDatabaseStmt = "create table if not exists users (jid text not null primary key, steamLogin text, steamPwd text, debug int);"
|
||||
insertDatabaseStmt = "insert into users (jid, steamLogin, steamPwd, debug) values(?, ?, ?, ?)"
|
||||
deleteDatabaseStmt = "delete from users where jid=?"
|
||||
selectDatabaseStmt = "select jid, steamLogin, steamPwd from users where jid=?"
|
||||
updateDatabaseStmt = "update users set steamLogin=?, steamPwd=? where jid=?"
|
||||
selectDatabaseStmt = "select jid, steamLogin, steamPwd, debug from users where jid=?"
|
||||
updateDatabaseStmt = "update users set steamLogin=?, steamPwd=?, debug=? where jid=?"
|
||||
|
||||
LogInfo = "\t[SQLITE INFO]\t"
|
||||
LogError = "\t[SQLITE ERROR]\t"
|
||||
|
|
@ -24,6 +24,7 @@ type DatabaseLine struct {
|
|||
Jid string
|
||||
SteamLogin string
|
||||
SteamPwd string
|
||||
Debug bool
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -61,7 +62,11 @@ func (newLine *DatabaseLine) AddLine() bool {
|
|||
return false
|
||||
}
|
||||
defer stmt.Close()
|
||||
_, err = stmt.Exec(newLine.Jid, newLine.SteamLogin, newLine.SteamPwd)
|
||||
debug := 0
|
||||
if newLine.Debug {
|
||||
debug = 1
|
||||
}
|
||||
_, err = stmt.Exec(newLine.Jid, newLine.SteamLogin, newLine.SteamPwd, debug)
|
||||
if err != nil {
|
||||
log.Printf("%sError on creating SQL statement", LogError, err)
|
||||
return false
|
||||
|
|
@ -78,7 +83,11 @@ func (newLine *DatabaseLine) UpdateLine() bool {
|
|||
return false
|
||||
}
|
||||
defer stmt.Close()
|
||||
_, err = stmt.Exec(newLine.SteamLogin, newLine.SteamPwd, newLine.Jid)
|
||||
debug := 0
|
||||
if newLine.Debug {
|
||||
debug = 1
|
||||
}
|
||||
_, err = stmt.Exec(newLine.SteamLogin, newLine.SteamPwd, debug, newLine.Jid)
|
||||
if err != nil {
|
||||
log.Printf("%sError on updating SQL statement", LogError, err)
|
||||
return false
|
||||
|
|
@ -141,12 +150,17 @@ func getLine(jid string) *DatabaseLine {
|
|||
return nil
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
err = stmt.QueryRow(jid).Scan(&ret.Jid, &ret.SteamLogin, &ret.SteamPwd)
|
||||
debug := 0
|
||||
err = stmt.QueryRow(jid).Scan(&ret.Jid, &ret.SteamLogin, &ret.SteamPwd, &debug)
|
||||
if err != nil {
|
||||
log.Printf("%sError on select scan", LogError, err)
|
||||
return nil
|
||||
}
|
||||
if debug == 1 {
|
||||
ret.Debug = true
|
||||
} else {
|
||||
ret.Debug = false
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ type GatewayInfo struct {
|
|||
XMPP_JID_Client string
|
||||
XMPP_Out chan interface{}
|
||||
XMPP_Connected_Client map[string]bool
|
||||
DebugMessage bool
|
||||
}
|
||||
|
||||
type StatusSteamFriend struct {
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ func (g *GatewayInfo) SendXmppPresence(status, tpye, to, from, message, nick str
|
|||
}
|
||||
|
||||
func (g *GatewayInfo) SendXmppMessage(from, subject, message string) {
|
||||
if from != XmppJidComponent || from == XmppJidComponent && g.DebugMessage {
|
||||
m := xmpp.Message{To: g.XMPP_JID_Client, From: from, Body: message, Type: "chat"}
|
||||
|
||||
if subject != "" {
|
||||
|
|
@ -172,3 +173,4 @@ func (g *GatewayInfo) SendXmppMessage(from, subject, message string) {
|
|||
log.Printf("%sSend message %v", LogXmppInfo, m)
|
||||
g.XMPP_Out <- m
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
main.go
2
main.go
|
|
@ -41,7 +41,7 @@ func init() {
|
|||
func main() {
|
||||
allDbUsers := database.GetAllLines()
|
||||
for _, dbUser := range allDbUsers {
|
||||
xmpp.AddNewUser(dbUser.Jid, dbUser.SteamLogin, dbUser.SteamPwd)
|
||||
xmpp.AddNewUser(dbUser.Jid, dbUser.SteamLogin, dbUser.SteamPwd, dbUser.Debug)
|
||||
}
|
||||
go xmpp.Run()
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"Addresses":[{"IP":"146.66.152.11","Port":27020},{"IP":"162.254.197.41","Port":27020},{"IP":"162.254.197.40","Port":27019},{"IP":"162.254.197.41","Port":27017},{"IP":"146.66.152.10","Port":27020},{"IP":"146.66.152.11","Port":27017},{"IP":"146.66.152.11","Port":27019},{"IP":"146.66.152.10","Port":27018},{"IP":"162.254.197.42","Port":27021},{"IP":"162.254.197.42","Port":27020},{"IP":"162.254.197.42","Port":27018},{"IP":"162.254.197.41","Port":27019},{"IP":"162.254.197.40","Port":27020},{"IP":"146.66.152.10","Port":27017},{"IP":"162.254.197.42","Port":27017},{"IP":"162.254.197.41","Port":27021},{"IP":"162.254.197.40","Port":27021},{"IP":"162.254.197.41","Port":27018},{"IP":"146.66.152.11","Port":27018},{"IP":"146.66.152.10","Port":27019},{"IP":"162.254.197.40","Port":27018},{"IP":"162.254.197.40","Port":27017},{"IP":"162.254.197.42","Port":27019},{"IP":"162.254.196.42","Port":27021},{"IP":"162.254.196.42","Port":27019},{"IP":"162.254.196.43","Port":27018},{"IP":"162.254.196.41","Port":27018},{"IP":"162.254.196.43","Port":27020},{"IP":"162.254.196.42","Port":27020},{"IP":"162.254.196.41","Port":27017},{"IP":"162.254.196.42","Port":27018},{"IP":"162.254.196.41","Port":27019},{"IP":"162.254.196.41","Port":27020},{"IP":"162.254.196.42","Port":27017},{"IP":"162.254.196.40","Port":27021},{"IP":"162.254.196.43","Port":27021},{"IP":"162.254.196.40","Port":27020},{"IP":"162.254.196.40","Port":27017},{"IP":"162.254.196.41","Port":27021},{"IP":"162.254.196.40","Port":27018},{"IP":"162.254.196.40","Port":27019},{"IP":"162.254.196.43","Port":27019},{"IP":"162.254.196.43","Port":27017},{"IP":"146.66.155.8","Port":27019},{"IP":"155.133.242.9","Port":27019},{"IP":"185.25.180.14","Port":27020},{"IP":"185.25.182.10","Port":27020},{"IP":"185.25.180.14","Port":27019},{"IP":"146.66.155.8","Port":27020},{"IP":"146.66.155.8","Port":27018},{"IP":"185.25.180.15","Port":27020},{"IP":"155.133.242.9","Port":27018},{"IP":"155.133.242.9","Port":27020},{"IP":"146.66.155.8","Port":27017},{"IP":"185.25.182.10","Port":27017},{"IP":"185.25.182.10","Port":27018},{"IP":"185.25.180.14","Port":27018},{"IP":"185.25.180.14","Port":27017},{"IP":"155.133.242.9","Port":27017},{"IP":"155.133.242.8","Port":27017},{"IP":"185.25.180.15","Port":27018},{"IP":"185.25.182.10","Port":27019},{"IP":"185.25.180.15","Port":27017},{"IP":"155.133.242.8","Port":27019},{"IP":"185.25.180.15","Port":27019},{"IP":"155.133.242.8","Port":27018},{"IP":"155.133.242.8","Port":27020},{"IP":"208.78.164.12","Port":27018},{"IP":"208.78.164.9","Port":27017},{"IP":"208.78.164.9","Port":27019},{"IP":"208.78.164.13","Port":27019},{"IP":"208.78.164.12","Port":27019},{"IP":"208.78.164.10","Port":27018},{"IP":"208.78.164.14","Port":27017},{"IP":"208.78.164.11","Port":27019},{"IP":"208.78.164.13","Port":27018},{"IP":"208.78.164.12","Port":27017},{"IP":"208.78.164.11","Port":27018},{"IP":"208.78.164.10","Port":27017},{"IP":"208.78.164.9","Port":27018}]}
|
||||
{"Addresses":[{"IP":"146.66.152.10","Port":27019},{"IP":"146.66.152.11","Port":27017},{"IP":"146.66.152.10","Port":27017},{"IP":"146.66.152.11","Port":27020},{"IP":"146.66.152.10","Port":27018},{"IP":"146.66.152.10","Port":27020},{"IP":"162.254.197.42","Port":27020},{"IP":"162.254.197.40","Port":27018},{"IP":"162.254.197.42","Port":27021},{"IP":"146.66.152.11","Port":27018},{"IP":"162.254.197.42","Port":27018},{"IP":"162.254.197.41","Port":27018},{"IP":"162.254.197.41","Port":27017},{"IP":"162.254.197.42","Port":27019},{"IP":"162.254.197.40","Port":27019},{"IP":"162.254.197.40","Port":27017},{"IP":"162.254.197.41","Port":27021},{"IP":"162.254.197.40","Port":27020},{"IP":"162.254.197.40","Port":27021},{"IP":"162.254.197.42","Port":27017},{"IP":"146.66.152.11","Port":27019},{"IP":"162.254.197.41","Port":27020},{"IP":"162.254.196.42","Port":27018},{"IP":"162.254.196.41","Port":27017},{"IP":"162.254.196.43","Port":27020},{"IP":"162.254.197.41","Port":27019},{"IP":"162.254.196.42","Port":27017},{"IP":"162.254.196.40","Port":27017},{"IP":"162.254.196.43","Port":27018},{"IP":"162.254.196.42","Port":27019},{"IP":"162.254.196.40","Port":27018},{"IP":"162.254.196.40","Port":27019},{"IP":"162.254.196.41","Port":27019},{"IP":"162.254.196.42","Port":27020},{"IP":"162.254.196.41","Port":27021},{"IP":"162.254.196.40","Port":27020},{"IP":"162.254.196.43","Port":27019},{"IP":"162.254.196.42","Port":27021},{"IP":"162.254.196.41","Port":27018},{"IP":"162.254.196.41","Port":27020},{"IP":"162.254.196.43","Port":27017},{"IP":"162.254.196.40","Port":27021},{"IP":"162.254.196.43","Port":27021},{"IP":"185.25.182.10","Port":27018},{"IP":"146.66.155.8","Port":27019},{"IP":"185.25.182.10","Port":27017},{"IP":"146.66.155.8","Port":27018},{"IP":"146.66.155.8","Port":27017},{"IP":"185.25.182.10","Port":27019},{"IP":"146.66.155.8","Port":27020},{"IP":"185.25.180.15","Port":27019},{"IP":"185.25.180.15","Port":27020},{"IP":"185.25.180.15","Port":27018},{"IP":"155.133.242.9","Port":27020},{"IP":"185.25.180.15","Port":27017},{"IP":"155.133.242.8","Port":27018},{"IP":"155.133.242.8","Port":27019},{"IP":"185.25.180.14","Port":27017},{"IP":"185.25.180.14","Port":27019},{"IP":"185.25.180.14","Port":27018},{"IP":"185.25.180.14","Port":27020},{"IP":"185.25.182.10","Port":27020},{"IP":"155.133.242.8","Port":27017},{"IP":"155.133.242.8","Port":27020},{"IP":"155.133.242.9","Port":27018},{"IP":"155.133.242.9","Port":27019},{"IP":"155.133.242.9","Port":27017},{"IP":"208.78.164.9","Port":27018},{"IP":"208.78.164.11","Port":27019},{"IP":"208.78.164.10","Port":27019},{"IP":"208.78.164.10","Port":27018},{"IP":"208.78.164.12","Port":27017},{"IP":"208.78.164.11","Port":27018},{"IP":"208.78.164.9","Port":27019},{"IP":"208.78.164.14","Port":27018},{"IP":"208.78.164.11","Port":27017},{"IP":"208.78.164.13","Port":27019},{"IP":"208.78.164.10","Port":27017},{"IP":"208.78.164.14","Port":27019},{"IP":"208.78.164.12","Port":27019}]}
|
||||
|
|
@ -13,6 +13,7 @@ const (
|
|||
CommandGetIdentifiants = "steamGetIdentifiants"
|
||||
CommandDisconnectSteam = "disconnectSteam"
|
||||
CommandRemoveRegistration = "removeRegistration"
|
||||
CommandToggleDebugMode = "toggleDebugMode"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -33,6 +34,8 @@ func execDiscoCommand(iq *xmpp.Iq) {
|
|||
discoItem.Item = append(discoItem.Item, *discoI)
|
||||
discoI = &xmpp.DiscoItem{JID: jid.Domain, Node: CommandRemoveRegistration, Name: "Remove registration"}
|
||||
discoItem.Item = append(discoItem.Item, *discoI)
|
||||
discoI = &xmpp.DiscoItem{JID: jid.Domain, Node: CommandToggleDebugMode, Name: "Toggle debug mode"}
|
||||
discoItem.Item = append(discoItem.Item, *discoI)
|
||||
|
||||
reply.PayloadEncode(discoItem)
|
||||
comp.Out <- reply
|
||||
|
|
@ -96,6 +99,29 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
|||
note.Value = "Failed to remove your registration."
|
||||
}
|
||||
|
||||
cmd.Note = *note
|
||||
} else if adHoc.Node == CommandToggleDebugMode {
|
||||
cmd.Status = xmpp.StatusAdHocCompleted
|
||||
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Toggle debug mode"}
|
||||
cmd.XForm = *cmdXForm
|
||||
note := &xmpp.AdHocNote{Type: xmpp.TypeAdHocNoteInfo}
|
||||
|
||||
jidBare := strings.SplitN(iq.From, "/", 2)[0]
|
||||
dbUser := database.GetLine(jidBare)
|
||||
dbUser.Debug = !dbUser.Debug
|
||||
g := MapGatewayInfo[jidBare]
|
||||
ok := dbUser.UpdateLine()
|
||||
if ok && g != nil {
|
||||
g.DebugMessage = dbUser.Debug
|
||||
if dbUser.Debug {
|
||||
note.Value = "Debug activated."
|
||||
} else {
|
||||
note.Value = "Debug desactivated."
|
||||
}
|
||||
} else {
|
||||
note.Value = "Failed to update your profile. :("
|
||||
}
|
||||
|
||||
cmd.Note = *note
|
||||
}
|
||||
reply.PayloadEncode(cmd)
|
||||
|
|
@ -159,6 +185,7 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
|||
dbUser.Jid = jidBare
|
||||
dbUser.SteamLogin = steamLogin
|
||||
dbUser.SteamPwd = steamPwd
|
||||
dbUser.Debug = false
|
||||
|
||||
isUserRegistred := database.GetLine(dbUser.Jid) != nil
|
||||
var isSqlSuccess bool
|
||||
|
|
@ -168,7 +195,7 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
|||
isSqlSuccess = dbUser.AddLine()
|
||||
}
|
||||
if isSqlSuccess {
|
||||
AddNewUser(dbUser.Jid, dbUser.SteamLogin, dbUser.SteamPwd)
|
||||
AddNewUser(dbUser.Jid, dbUser.SteamLogin, dbUser.SteamPwd, dbUser.Debug)
|
||||
note.Value = "Command succeded !"
|
||||
} else {
|
||||
note.Value = "Error append while executing command"
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ func SendMessage(to, subject, message string) {
|
|||
comp.Out <- m
|
||||
}
|
||||
|
||||
func AddNewUser(jid, steamLogin, steamPwd string) {
|
||||
func AddNewUser(jid, steamLogin, steamPwd string, debugMessage bool) {
|
||||
log.Printf("%sAdd user %s to the map", LogInfo, jid)
|
||||
|
||||
g := new(gateway.GatewayInfo)
|
||||
|
|
@ -200,6 +200,7 @@ func AddNewUser(jid, steamLogin, steamPwd string) {
|
|||
|
||||
g.XMPP_Out = comp.Out
|
||||
g.XMPP_Connected_Client = make(map[string]bool)
|
||||
g.DebugMessage = debugMessage
|
||||
|
||||
MapGatewayInfo[jid] = g
|
||||
go g.Run()
|
||||
|
|
|
|||
Loading…
Reference in New Issue