gameServer/OfficialServer/extdbinterface.hs
changeset 9446 4fd5df03deb8
parent 9437 8d1e9a9dda8e
child 9450 2084b1b7839c
equal deleted inserted replaced
9444:30748b1d9ec7 9446:4fd5df03deb8
    28 dbQueryAchievement =
    28 dbQueryAchievement =
    29     "INSERT INTO achievements (time, typeid, userid, value, filename, location) \
    29     "INSERT INTO achievements (time, typeid, userid, value, filename, location) \
    30     \ VALUES (?, (SELECT id FROM achievement_types WHERE name = ?), (SELECT uid FROM users WHERE name = ?), \
    30     \ VALUES (?, (SELECT id FROM achievement_types WHERE name = ?), (SELECT uid FROM users WHERE name = ?), \
    31     \ ?, ?, ?)"
    31     \ ?, ?, ?)"
    32 
    32 
       
    33 dbQueryReplayFilename = "SELECT filename FROM achievements WHERE id = ?"
       
    34 
       
    35 
    33 dbInteractionLoop dbConn = forever $ do
    36 dbInteractionLoop dbConn = forever $ do
    34     q <- liftM read getLine
    37     q <- liftM read getLine
    35     hPutStrLn stderr $ show q
    38     hPutStrLn stderr $ show q
    36 
    39 
    37     case q of
    40     case q of
    53                         else
    56                         else
    54                         (clId, clUid, Guest)
    57                         (clId, clUid, Guest)
    55                 print response
    58                 print response
    56                 hFlush stdout
    59                 hFlush stdout
    57 
    60 
       
    61         GetReplayName clId clUid fileId -> do
       
    62                 statement <- prepare dbConn dbQueryReplayFilename
       
    63                 execute statement [SqlByteString fileId]
       
    64                 result <- fetchRow statement
       
    65                 finish statement
       
    66                 let fn = if (isJust result) then fromJust . fromSql . head $ result else ""
       
    67                 print (clId, clUid, ReplayName fn)
       
    68                 hFlush stdout
       
    69 
    58         SendStats clients rooms ->
    70         SendStats clients rooms ->
    59                 run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return ()
    71                 run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return ()
    60 --StoreAchievements (B.pack fileName) (map toPair teams) info
    72 --StoreAchievements (B.pack fileName) (map toPair teams) info
    61         StoreAchievements fileName teams info -> 
    73         StoreAchievements fileName teams info -> 
    62             mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info
    74             mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info
    63 
    75 
       
    76 
    64 readTime = read . B.unpack . B.take 19 . B.drop 8
    77 readTime = read . B.unpack . B.take 19 . B.drop 8
       
    78 
    65 
    79 
    66 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]]
    80 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]]
    67 parseStats fileName teams = ps
    81 parseStats fileName teams = ps
    68     where
    82     where
    69     time = readTime fileName
    83     time = readTime fileName