Only writing to IRCd socket if it exists
authorDarren <darren@darrenwhitlen.com>
Tue, 23 Sep 2014 23:31:00 +0000 (00:31 +0100)
committerDarren <darren@darrenwhitlen.com>
Tue, 23 Sep 2014 23:31:00 +0000 (00:31 +0100)
server/irc/connection.js

index 0c6f70c0f7a42272302900d60c8e3e18ed1adb6a..9584ffa45b2fa420ae0603771253bac1765ae4ed 100644 (file)
@@ -374,7 +374,7 @@ IrcConnection.prototype.write = function (data, force, force_complete_fn) {
     var encoded_buffer = iconv.encode(data + '\r\n', this.encoding);
 
     if (force) {
-        this.socket.write(encoded_buffer, force_complete_fn);
+        this.socket && this.socket.write(encoded_buffer, force_complete_fn);
         return;
     }
 
@@ -405,7 +405,7 @@ IrcConnection.prototype.flushWriteBuffer = function () {
     // Disabled write buffer? Send everything we have
     if (!this.write_buffer_lines_second) {
         this.write_buffer.forEach(function(buffer) {
-            this.socket.write(buffer);
+            this.socket && this.socket.write(buffer);
             this.write_buffer = null;
         });
 
@@ -421,7 +421,7 @@ IrcConnection.prototype.flushWriteBuffer = function () {
         return;
     }
 
-    this.socket.write(this.write_buffer[0]);
+    this.socket && this.socket.write(this.write_buffer[0]);
     this.write_buffer = this.write_buffer.slice(1);
 
     // Call this function again at some point if we still have data to write