netserver/Miscutils.hs
changeset 894 2ca76a7f3121
parent 890 1d8c4a5ec622
child 895 6aee2f335726
--- a/netserver/Miscutils.hs	Wed Apr 30 20:48:12 2008 +0000
+++ b/netserver/Miscutils.hs	Thu May 01 14:30:12 2008 +0000
@@ -5,6 +5,8 @@
 import Control.Concurrent
 import Control.Concurrent.STM
 import Control.Exception (finally)
+import Data.Word
+import Data.Char
 
 data ClientInfo =
 	ClientInfo
@@ -12,6 +14,7 @@
 		chan :: TChan String,
 		handle :: Handle,
 		nick :: String,
+		protocol :: Word16,
 		room :: String,
 		isMaster :: Bool
 	}
@@ -56,3 +59,8 @@
 tselect :: [ClientInfo] -> STM (String, ClientInfo)
 tselect = foldl orElse retry . map (\ci -> (flip (,) ci) `fmap` readTChan (chan ci))
 
+maybeRead :: Read a => String -> Maybe a
+maybeRead s = case reads s of
+	[(x, rest)] | all isSpace rest -> Just x
+	_         -> Nothing
+