- Better ip2string implementation
authorunc0rr
Thu, 26 Mar 2009 13:54:02 +0000
changeset 1917 c94045b70142
parent 1916 9c3d0e3df6bb
child 1918 975d5061712f
- Better ip2string implementation - Update girder thing sprite
gameServer/NetRoutines.hs
gameServer/Utils.hs
share/hedgewars/Data/Graphics/Hedgehog/amGirder.png
--- a/gameServer/NetRoutines.hs	Mon Mar 23 21:09:34 2009 +0000
+++ b/gameServer/NetRoutines.hs	Thu Mar 26 13:54:02 2009 +0000
@@ -12,10 +12,7 @@
 -----------------------------
 import CoreTypes
 import ClientIO
-
-sockAddr2String :: SockAddr -> IO String
-sockAddr2String (SockAddrInet _ hostAddr) = inet_ntoa hostAddr
-sockAddr2String (SockAddrInet6 _ _ (a, b, c, d) _) = return (foldr1 (\a b -> a ++ ":" ++ b) [show a, show b, show c, show d])
+import Utils
 
 acceptLoop :: Socket -> Chan CoreMessage -> Int -> IO ()
 acceptLoop servSock coreChan clientCounter = do
--- a/gameServer/Utils.hs	Mon Mar 23 21:09:34 2009 +0000
+++ b/gameServer/Utils.hs	Thu Mar 26 13:54:02 2009 +0000
@@ -6,11 +6,22 @@
 import Data.Word
 import qualified Data.Map as Map
 import qualified Data.IntMap as IntMap
+import Numeric
+import Network.Socket
+import qualified Data.List as List
 -------------------------------------------------
 import qualified Codec.Binary.Base64 as Base64
 import qualified Codec.Binary.UTF8.String as UTF8
 import CoreTypes
 
+
+sockAddr2String :: SockAddr -> IO String
+sockAddr2String (SockAddrInet _ hostAddr) = inet_ntoa hostAddr
+sockAddr2String (SockAddrInet6 _ _ (a, b, c, d) _) =
+	return $ (foldr1 (.)
+		$ List.intersperse (\a -> ':':a)
+		$ concatMap (\n -> (\(a, b) -> [showHex a, showHex b]) $ divMod n 65536) [a, b, c, d]) []
+
 toEngineMsg :: String -> String
 toEngineMsg msg = Base64.encode (fromIntegral (length msg) : (UTF8.encode msg))
 
Binary file share/hedgewars/Data/Graphics/Hedgehog/amGirder.png has changed