gameServer/OfficialServer/extdbinterface.hs
changeset 9868 53d1b92db6ce
parent 9450 2084b1b7839c
child 9884 6e09ca662fa3
equal deleted inserted replaced
9866:62ffe234127d 9868:53d1b92db6ce
    24 
    24 
    25 dbQueryStats =
    25 dbQueryStats =
    26     "INSERT INTO gameserver_stats (players, rooms, last_update) VALUES (?, ?, UNIX_TIMESTAMP())"
    26     "INSERT INTO gameserver_stats (players, rooms, last_update) VALUES (?, ?, UNIX_TIMESTAMP())"
    27 
    27 
    28 dbQueryAchievement =
    28 dbQueryAchievement =
    29     "INSERT INTO achievements (time, typeid, userid, value, filename, location) \
    29     "INSERT INTO achievements (time, typeid, userid, value, filename, location, protocol) \
    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 = ?"
    33 dbQueryReplayFilename = "SELECT filename FROM achievements WHERE id = ?"
    34 
    34 
    35 
    35 
    36 dbInteractionLoop dbConn = forever $ do
    36 dbInteractionLoop dbConn = forever $ do
    68                 hFlush stdout
    68                 hFlush stdout
    69 
    69 
    70         SendStats clients rooms ->
    70         SendStats clients rooms ->
    71                 run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return ()
    71                 run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return ()
    72 --StoreAchievements (B.pack fileName) (map toPair teams) info
    72 --StoreAchievements (B.pack fileName) (map toPair teams) info
    73         StoreAchievements fileName teams info -> 
    73         StoreAchievements p fileName teams info -> 
    74             mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info
    74             mapM_ (run dbConn dbQueryAchievement) $ (parseStats p fileName teams) info
    75 
    75 
    76 
    76 
    77 readTime = read . B.unpack . B.take 19 . B.drop 8
    77 readTime = read . B.unpack . B.take 19 . B.drop 8
    78 
    78 
    79 
    79 
    80 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]]
    80 parseStats :: Word16 -> B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]]
    81 parseStats fileName teams = ps
    81 parseStats p fileName teams = ps
    82     where
    82     where
    83     time = readTime fileName
    83     time = readTime fileName
    84     ps [] = []
    84     ps [] = []
    85     ps ("DRAW" : bs) = ps bs
    85     ps ("DRAW" : bs) = ps bs
    86     ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs
    86     ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs
    89         , SqlByteString typ
    89         , SqlByteString typ
    90         , SqlByteString $ fromMaybe "" (lookup teamname teams)
    90         , SqlByteString $ fromMaybe "" (lookup teamname teams)
    91         , SqlInt32 (readInt_ value)
    91         , SqlInt32 (readInt_ value)
    92         , SqlByteString fileName
    92         , SqlByteString fileName
    93         , SqlByteString location
    93         , SqlByteString location
       
    94         , SqlInt32 p
    94         ] : ps bs
    95         ] : ps bs
    95     ps (b:bs) = ps bs
    96     ps (b:bs) = ps bs
    96 
    97 
    97 
    98 
    98 dbConnectionLoop mySQLConnectionInfo =
    99 dbConnectionLoop mySQLConnectionInfo =