some defers in case jabber server disappears
[svn42.git] / r3-netstatus / r3xmppbot / r3xmppbot.go
index fc2b239..f795afc 100644 (file)
@@ -157,6 +157,12 @@ func init() {
 func (botdata *XmppBot) handleEventsforXMPP(xmppout chan <- xmpp.Stanza, presence_events <- chan interface{}, jabber_events <- chan JabberEvent) {
     var last_status_msg *string
 
+    defer func() {
+        if x := recover(); x != nil {
+            log.Printf("handleEventsforXMPP: run time panic: %v", x)
+        }
+    }()
+
        for {
                select {
                case pe := <-presence_events:
@@ -219,7 +225,7 @@ func (botdata *XmppBot) isAuthenticated(jid string) bool {
 }
 
 const help_text_ string = "\n*auth*<password>* ...Enables you to use more commands.\n*time* ...Returns bot time."
-const help_text_auth string = "You are authorized to use the following commands:\n*off* ...You will no longer receive notifications.\n*on* ...You will be notified of r3 status changes.\n*on_with_recap* ...Like *on* but additionally you will receive the current r3 status when you come online.\n*on_while_offline* ...You will receive all r3 status changes, wether your are online or offline.\n*status* ...Use it to query the current status.\n*time* ...Returns bot time.\n*bye* ...Logout."
+const help_text_auth string = "You are authorized to use the following commands:\n*off* ...You will no longer receive notifications.\n*on* ...You will be notified of r3 status changes while you are online.\n*on_with_recap* ...Like *on* but additionally you will receive the current status when you come online.\n*on_while_offline* ...You will receive all r3 status changes, wether you are online or offline.\n*status* ...Use it to query the current status.\n*time* ...Returns bot time.\n*bye* ...Logout."
 
 //~ var re_msg_auth_    *regexp.Regexp     = regexp.MustCompile("auth\s+(\S+)")
 
@@ -278,6 +284,14 @@ func (botdata *XmppBot) handleIncomingMessageDialog(inmsg xmpp.Message, xmppout
 }
 
 func (botdata *XmppBot) handleIncomingXMPPStanzas(xmppin <- chan xmpp.Stanza, xmppout chan<- xmpp.Stanza, jabber_events chan JabberEvent) {
+
+    defer func() {
+        if x := recover(); x != nil {
+            log.Printf("handleIncomingXMPPStanzas: run time panic: %v", x)
+            close(jabber_events)
+        }
+    }()
+
     var incoming_stanza interface{}
     for incoming_stanza = range xmppin {
         switch stanza := incoming_stanza.(type) {