Przeglądaj źródła

use ping to make sure we're connected

James Seward 20 lat temu
rodzic
commit
309e5246a7
1 zmienionych plików z 44 dodań i 0 usunięć
  1. 44 0
      QuoteEngine/QuoteEngine.tcl

+ 44 - 0
QuoteEngine/QuoteEngine.tcl

@@ -58,6 +58,20 @@ setudef flag quoteengine
 
 ### procedures start here
 
+################################################################################
+# quote_ping
+# Check we're still connected to mysql
+################################################################################
+proc quote_ping { } {
+	global db_handle
+
+	if [::mysql::ping $dbhandle] {
+		return 0
+	} else {
+		return 1
+	}
+}
+
 ################################################################################
 # quote_add
 # !addquote <text>
@@ -76,6 +90,11 @@ proc quote_add { nick host handle channel text } {
     set handle $nick
   }
 
+	if {![quote_ping]} {
+		putquick "PRIVMSG $channel :Sorry, lost database connection :("
+		return 0
+	}
+
   set sql "INSERT INTO quotes VALUES(null, "
   append sql "'$handle', "
   append sql "'$nick!$host', "
@@ -113,6 +132,11 @@ proc quote_rand { nick host handle channel text } {
 
   if [matchattr $handle $quote_noflags] { return 0 }
 
+	if {![quote_ping]} {
+		putquick "PRIVMSG $channel :Sorry, lost database connection :("
+		return 0
+	}
+
   set where_clause "WHERE channel='$channel'"
   if [regexp -- "--?all" $text] {
     set where_clause ""
@@ -160,6 +184,11 @@ proc quote_fetch { nick host handle channel text } {
     return 0
   }
 
+	if {![quote_ping]} {
+		putquick "PRIVMSG $channel :Sorry, lost database connection :("
+		return 0
+	}
+
 	set text [mysqlescape $text]
   set sql "SELECT * FROM quotes WHERE id='$text'"
   putloglev d * "QuoteEngine: executing $sql"
@@ -215,6 +244,11 @@ proc quote_search { nick host handle channel text } {
     return 0
   }
 
+	if {![quote_ping]} {
+		putquick "PRIVMSG $channel :Sorry, lost database connection :("
+		return 0
+	}
+
   set where_clause "AND channel='[mysqlescape $channel]'"
   if [regexp -- "--?all " $text matches skip1] {
     set where_clause ""
@@ -319,6 +353,11 @@ proc quote_stats { nick host handle channel text } {
 
   if [matchattr $handle $quote_noflags] { return 0 }
 
+	if {![quote_ping]} {
+		putquick "PRIVMSG $channel :Sorry, lost database connection :("
+		return 0
+	}
+
   set sql "SELECT COUNT(*) AS total FROM quotes WHERE channel='$channel'"
   putloglev d * "QuoteEngine: executing $sql"
 
@@ -373,6 +412,11 @@ proc quote_delete  { nick host handle channel text } {
 
   if [matchattr $handle $quote_noflags] { return 0 }
 
+	if {![quote_ping]} {
+		putquick "PRIVMSG $channel :Sorry, lost database connection :("
+		return 0
+	}
+
   set text [mysqlescape $text]
   if {![matchattr $handle m|m $channel]} {
     set sql "SELECT nick FROM quotes WHERE id='$text'"