From 28ded1fc9bcd7df772ec9f1bbf3d719078c821c9 Mon Sep 17 00:00:00 2001
From: Thor77 <xXThor77Xx@gmail.com>
Date: Mon, 22 Jun 2015 16:20:20 +0200
Subject: [PATCH] add support for multiple connects with one identity

---
 tsstats.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/tsstats.py b/tsstats.py
index bcf9a8a..3b44b14 100755
--- a/tsstats.py
+++ b/tsstats.py
@@ -65,7 +65,7 @@ class Client:
         # public
         self.identifier = identifier
         self.nick = None
-        self.connected = False
+        self.connected = 0
         self.onlinetime = datetime.timedelta()
         self.kicks = 0
         self.pkicks = 0
@@ -79,7 +79,7 @@ class Client:
         client connects at "timestamp"
         '''
         logging.debug('CONNECT {}'.format(str(self)))
-        self.connected = True
+        self.connected += 1
         self._last_connect = timestamp
 
     def disconnect(self, timestamp):
@@ -88,8 +88,9 @@ class Client:
         '''
         logging.debug('DISCONNECT {}'.format(str(self)))
         if not self.connected:
-            raise Exception('WTF did just happen?! A client disconnected before connecting!')
-        self.connected = False
+            logging.debug('^ disconnect before connect')
+            raise Exception('disconnect before connect!')
+        self.connected -= 1
         session_time = timestamp - self._last_connect
         self.onlinetime += session_time
 
@@ -163,7 +164,7 @@ for log_file in log_files:
 for line in log_lines:
     parts = line.split('|')
     logdatetime = datetime.datetime.strptime(parts[0], '%Y-%m-%d %H:%M:%S.%f')
-    data = parts[4].strip()
+    data = '|'.join(parts[4:]).strip()
     if data.startswith('client'):
         nick, clid = re_dis_connect.findall(data)[0]
         if clid in id_map: