gameServer/OfficialServer/extdbinterface.hs
changeset 9421 90fe753b3654
parent 9409 6564baf7dedf
child 9425 49eb707b9367
equal deleted inserted replaced
9419:fa8324ed4702 9421:90fe753b3654
    58             mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info
    58             mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info
    59 
    59 
    60 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]]
    60 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]]
    61 parseStats fileName teams = ps
    61 parseStats fileName teams = ps
    62     where
    62     where
       
    63     ps [] = []
    63     ps ("DRAW" : bs) = ps bs
    64     ps ("DRAW" : bs) = ps bs
    64     ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs
    65     ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs
    65     ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) =
    66     ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) =
    66         [SqlByteString typ
    67         [SqlByteString typ
    67         , SqlByteString $ fromMaybe "" (lookup teamname teams)
    68         , SqlByteString $ fromMaybe "" (lookup teamname teams)
    68         , SqlInt32 (readInt_ value)
    69         , SqlInt32 (readInt_ value)
    69         , SqlByteString fileName
    70         , SqlByteString fileName
    70         , SqlByteString location
    71         , SqlByteString location
    71         ] : ps bs
    72         ] : ps bs
       
    73     ps (b:bs) = ps bs
       
    74 
    72 
    75 
    73 dbConnectionLoop mySQLConnectionInfo =
    76 dbConnectionLoop mySQLConnectionInfo =
    74     Control.Exception.handle (\(e :: IOException) -> hPutStrLn stderr $ show e) $ handleSqlError $
    77     Control.Exception.handle (\(e :: IOException) -> hPutStrLn stderr $ show e) $ handleSqlError $
    75         bracket
    78         bracket
    76             (connectMySQL mySQLConnectionInfo)
    79             (connectMySQL mySQLConnectionInfo)