update server network
authorJens Petersen
Wed, 08 Jul 2020 17:02:45 +0300
changeset 15699 27eb5abd5058
parent 15698 f681c3f2eeba
child 15700 a3d2f69f3ac1
update server network
gameServer/Actions.hs
gameServer/CMakeLists.txt
gameServer/ClientIO.hs
gameServer/CoreTypes.hs
gameServer/OfficialServer/checker.hs
gameServer/Utils.hs
gameServer/hedgewars-server.cabal
gameServer/hedgewars-server.hs
--- a/gameServer/Actions.hs	Tue Jul 07 00:17:05 2020 +0200
+++ b/gameServer/Actions.hs	Wed Jul 08 17:02:45 2020 +0300
@@ -709,7 +709,7 @@
         args <- gets (runArgs . serverInfo)
         io $ do
             noticeM "Core" "Closing listening socket"
-            sClose sock
+            close sock
             noticeM "Core" "Spawning new server"
             _ <- createProcess (proc "./hedgewars-server" args)
             return ()
--- a/gameServer/CMakeLists.txt	Tue Jul 07 00:17:05 2020 +0200
+++ b/gameServer/CMakeLists.txt	Wed Jul 08 17:02:45 2020 +0300
@@ -9,7 +9,8 @@
 check_haskell_package_exists(containers "Data.Map" size 1)
 check_haskell_package_exists(vector "Data.Vector" length 1)
 check_haskell_package_exists(bytestring "Data.ByteString" pack 1)
-check_haskell_package_exists(network "Network.BSD" getHostName 0)
+check_haskell_package_exists(network "Network.Socket" defaultHints 0)
+check_haskell_package_exists(network-bsd "Network.BSD" getHostName 0)
 check_haskell_package_exists(time "Data.Time" getCurrentTime 0)
 check_haskell_package_exists(mtl "Control.Monad.State" fix 1)
 check_haskell_package_exists(sandi "Codec.Binary.Base64" encode 1)
--- a/gameServer/ClientIO.hs	Tue Jul 07 00:17:05 2020 +0200
+++ b/gameServer/ClientIO.hs	Wed Jul 08 17:02:45 2020 +0300
@@ -23,7 +23,7 @@
 import Control.Monad.State
 import Control.Concurrent.Chan
 import Control.Concurrent
-import Network
+import Network.Socket hiding (recv)
 import Network.Socket.ByteString
 import qualified Data.ByteString.Char8 as B
 ----------------
@@ -90,7 +90,7 @@
             sendAll s $ B.unlines answer `B.snoc` '\n'
 
     if isQuit answer then
-        sClose s
+        close s
         else
         clientSendLoop s tId chan ci
 
--- a/gameServer/CoreTypes.hs	Tue Jul 07 00:17:05 2020 +0200
+++ b/gameServer/CoreTypes.hs	Wed Jul 08 17:02:45 2020 +0300
@@ -23,7 +23,7 @@
 import Data.Word
 import qualified Data.Map as Map
 import Data.Time
-import Network
+import Network.Socket
 import Data.Function
 import Data.ByteString.Char8 as B
 import Data.Unique
--- a/gameServer/OfficialServer/checker.hs	Tue Jul 07 00:17:05 2020 +0200
+++ b/gameServer/OfficialServer/checker.hs	Wed Jul 08 17:02:45 2020 +0300
@@ -28,8 +28,7 @@
 import Control.Monad.State
 import Control.Concurrent.Chan
 import Control.Concurrent
-import Network
-import Network.BSD
+import Network.BSD hiding (recv)
 import Network.Socket hiding (recv, sClose)
 import Network.Socket.ByteString
 import qualified Data.ByteString.Char8 as B
@@ -207,7 +206,7 @@
 
     Exception.bracket
         setupConnection
-        (\s -> noticeM "Core" "Shutting down" >> sClose s)
+        (\s -> noticeM "Core" "Shutting down" >> close s)
         (session login password (d ++ "/.hedgewars") exeFullname dataPrefix)
     where
         setupConnection = do
--- a/gameServer/Utils.hs	Tue Jul 07 00:17:05 2020 +0200
+++ b/gameServer/Utils.hs	Wed Jul 08 17:02:45 2020 +0300
@@ -41,11 +41,7 @@
 
 
 sockAddr2String :: SockAddr -> IO B.ByteString
-sockAddr2String (SockAddrInet _ hostAddr) = liftM B.pack $ inet_ntoa hostAddr
-sockAddr2String (SockAddrInet6 _ _ (a, b, c, d) _) =
-    return $ B.pack $ (foldr1 (.)
-        $ List.intersperse (':':)
-        $ concatMap (\n -> (\(a0, a1) -> [showHex a0, showHex a1]) $ divMod n 65536) [a, b, c, d]) []
+sockAddr2String = liftM (B.pack . fromJust . fst) . getNameInfo [] True False
 
 maybeRead :: Read a => String -> Maybe a
 maybeRead s = case reads s of
--- a/gameServer/hedgewars-server.cabal	Tue Jul 07 00:17:05 2020 +0200
+++ b/gameServer/hedgewars-server.cabal	Wed Jul 08 17:02:45 2020 +0300
@@ -57,7 +57,8 @@
     containers,
     vector,
     bytestring,
-    network >= 2.3 && < 3.0,
+    network >= 2.3,
+    network-bsd,
     mtl >= 2,
     sandi,
     hslogger,
--- a/gameServer/hedgewars-server.hs	Tue Jul 07 00:17:05 2020 +0200
+++ b/gameServer/hedgewars-server.hs	Wed Jul 08 17:02:45 2020 +0300
@@ -50,10 +50,11 @@
     proto <- getProtocolNumber "tcp"
     E.bracket
         (socket AF_INET Stream proto)
-        sClose
+        close
         (\sock -> do
             setSocketOption sock ReuseAddr 1
-            bindSocket sock (SockAddrInet (listenPort si) iNADDR_ANY)
+            iNADDR_ANY <- addrAddress . head <$> getAddrInfo Nothing (Just "0") (Just (show (listenPort si)))
+            bind sock iNADDR_ANY
             listen sock maxListenQueue
             startServer si{serverSocket = Just sock}
         )