 ; login version 1
 (defmethod process-packet ["login" "1"] [packet channel]
   (do
-    (let [login (:data packet)]
+    (let [login (:data packet) id (- @max-id 20)]
       (swap! clients         assoc channel login)
-      (swap! clients-last-id assoc channel (- max-id 20)
+      (swap! clients-last-id assoc channel id)
       (println packet @clients-last-id)
-      (send! channel (json-str {:status "ok"})))))
+      (send! channel (json-str {:status "ok"}))
+      (dosync (ref-set all-msgs (conj @all-msgs {:id (next-id) :time (now) :msg (format "Пришел: %s" (@clients channel)) :author "system"}))))))
 ; logout version 1
 (defn logout [channel]
   (do
+    (dosync (ref-set all-msgs (conj @all-msgs {:id (next-id) :time (now) :msg (format "Ушел: %s" (@clients channel)) :author "system"})))
     (swap! clients dissoc channel)
     (swap! clients-last-id dissoc channel)
     (println @clients-last-id)

(defmethod process-packet ["logout" "1"] [packet channel]
  (do
    (logout channel)
    (println packet)
    (send! channel (json-str {:status "ok"}))))
; send version 1
(defmethod process-packet ["send" "1"] [packet channel]

      (.write wrtr line)))
    (reset! log-msgs [])))
; messages
(defonce all-msgs (ref [{:id (next-id) :time (now) :msg "Добро пожаловать в чат!" :author "system"}]))
(defn add-msg-to-storage [msg]
  (dosync (let [all-msgs* (conj @all-msgs msg)] (ref-set all-msgs all-msgs*))))
(defn min-msg-id []
