Fix shutdown bug
This commit is contained in:
parent
c7d1d71c95
commit
e11f5d3f98
41
main.go
41
main.go
|
|
@ -7,15 +7,15 @@ import (
|
|||
"github.com/Philipp15b/go-steam/internal/steamlang"
|
||||
"github.com/jimlawless/cfg"
|
||||
|
||||
"bufio"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
Version = "go-xmpp4steam v0.1.3"
|
||||
Version = "go-xmpp4steam v0.1.4.0"
|
||||
configurationFilePath = "xmpp4steam.cfg"
|
||||
)
|
||||
|
||||
|
|
@ -54,13 +54,19 @@ func main() {
|
|||
go gatewaySteamXmppPresence()
|
||||
|
||||
go steam.Run()
|
||||
xmpp.Run()
|
||||
go xmpp.Run()
|
||||
|
||||
// inputStop()
|
||||
sigchan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigchan, os.Interrupt)
|
||||
signal.Notify(sigchan, syscall.SIGTERM)
|
||||
signal.Notify(sigchan, os.Kill)
|
||||
<-sigchan
|
||||
|
||||
steam.Disconnect()
|
||||
xmpp.Disconnect()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
log.Println("Exit main()")
|
||||
}
|
||||
|
||||
// XMPP -> Steam gateways
|
||||
|
|
@ -78,6 +84,9 @@ func gatewayXmppSteamAction() {
|
|||
if steam.IsConnected() {
|
||||
steam.Disconnect()
|
||||
}
|
||||
|
||||
case xmpp.ActionMainMethodEnded:
|
||||
go xmpp.Run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -134,6 +143,9 @@ func gatewaySteamXmppAction() {
|
|||
disconnectAllSteamUser()
|
||||
time.Sleep(2 * time.Second)
|
||||
go steam.Run()
|
||||
|
||||
case steam.ActionMainMethodEnded:
|
||||
go steam.Run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -149,7 +161,7 @@ func gatewaySteamXmppMessage() {
|
|||
func gatewaySteamXmppPresence() {
|
||||
for {
|
||||
steamId := <-steam.ChanPresence
|
||||
name := <- steam.ChanPresence
|
||||
name := <-steam.ChanPresence
|
||||
stat := <-steam.ChanPresenceSteam
|
||||
gameName := <-steam.ChanPresence
|
||||
|
||||
|
|
@ -185,26 +197,11 @@ func gatewaySteamXmppPresence() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func disconnectAllSteamUser() {
|
||||
for sid, _ := range SetSteamId {
|
||||
xmpp.SendPresenceFrom(xmpp.Status_offline, xmpp.Type_unavailable, sid+"@"+xmpp.JidStr, "", "")
|
||||
delete(SetSteamId, sid)
|
||||
}
|
||||
}
|
||||
|
||||
// /Steam -> XMPP gateways
|
||||
|
||||
func inputStop() {
|
||||
for {
|
||||
in := bufio.NewReader(os.Stdin)
|
||||
line, err := in.ReadString('\n')
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
line = strings.TrimRight(line, "\n")
|
||||
|
||||
if line == "stop" {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,10 @@ const (
|
|||
State_LookingToPlay = steamlang.EPersonaState_LookingToPlay
|
||||
State_Max = steamlang.EPersonaState_Max
|
||||
|
||||
ActionConnected = "steam_connected"
|
||||
ActionDisconnected = "steam_disconnected"
|
||||
ActionFatalError = "steam_fatal_error"
|
||||
ActionConnected = "steam_connected"
|
||||
ActionDisconnected = "steam_disconnected"
|
||||
ActionFatalError = "steam_fatal_error"
|
||||
ActionMainMethodEnded = "action_steam_main_method_ended"
|
||||
|
||||
LogInfo = "\t[STEAM INFO]\t"
|
||||
LogError = "\t[STEAM ERROR]\t"
|
||||
|
|
@ -55,6 +56,7 @@ func Run() {
|
|||
client.ConnectionTimeout = 10 * time.Second
|
||||
|
||||
mainSteam()
|
||||
ChanAction <- ActionMainMethodEnded
|
||||
}
|
||||
|
||||
func mainSteam() {
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ const (
|
|||
Type_probe = "probe"
|
||||
Type_error = "error"
|
||||
|
||||
ActionConnexion = "action_xmpp_connexion"
|
||||
ActionDeconnexion = "action_xmpp_deconnexion"
|
||||
ActionConnexion = "action_xmpp_connexion"
|
||||
ActionDeconnexion = "action_xmpp_deconnexion"
|
||||
ActionMainMethodEnded = "action_xmpp_main_method_ended"
|
||||
|
||||
LogInfo = "\t[XMPP INFO]\t"
|
||||
LogError = "\t[XMPP ERROR]\t"
|
||||
|
|
@ -60,6 +61,7 @@ func Run() {
|
|||
comp = must(xmpp.NewComponentXMPP(stream, jid, Secret)).(*xmpp.XMPP)
|
||||
|
||||
mainXMPP()
|
||||
ChanAction <- ActionMainMethodEnded
|
||||
}
|
||||
|
||||
func mainXMPP() {
|
||||
|
|
@ -102,6 +104,7 @@ func must(v interface{}, err error) interface{} {
|
|||
}
|
||||
|
||||
func Disconnect() {
|
||||
log.Printf("%sXMPP disconnect", LogInfo)
|
||||
SendPresence(Status_offline, Type_unavailable, "")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue