21 |
21 |
22 dbQueryStats = |
22 dbQueryStats = |
23 "INSERT INTO gameserver_stats (players, rooms, last_update) VALUES (?, ?, UNIX_TIMESTAMP())" |
23 "INSERT INTO gameserver_stats (players, rooms, last_update) VALUES (?, ?, UNIX_TIMESTAMP())" |
24 |
24 |
25 dbQueryAchievement = |
25 dbQueryAchievement = |
26 "INSERT INTO achievements (typeid, userid, value, filename, location) \ |
26 "INSERT INTO achievements (time, typeid, userid, value, filename, location) \ |
27 \ VALUES ((SELECT id FROM achievement_types WHERE name = ?), (SELECT uid FROM users WHERE name = ?), \ |
27 \ VALUES ((SELECT id FROM achievement_types WHERE name = ?), (SELECT uid FROM users WHERE name = ?), \ |
28 \ ?, ?, ?)" |
28 \ ?, ?, ?)" |
29 |
29 |
30 dbInteractionLoop dbConn = forever $ do |
30 dbInteractionLoop dbConn = forever $ do |
31 q <- liftM read getLine |
31 q <- liftM read getLine |
55 run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return () |
55 run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return () |
56 --StoreAchievements (B.pack fileName) (map toPair teams) info |
56 --StoreAchievements (B.pack fileName) (map toPair teams) info |
57 StoreAchievements fileName teams info -> |
57 StoreAchievements fileName teams info -> |
58 mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info |
58 mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info |
59 |
59 |
|
60 readTime = read . B.unpack . B.take 19 . B.drop 8 |
|
61 |
60 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]] |
62 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]] |
61 parseStats fileName teams = ps |
63 parseStats fileName teams = ps |
62 where |
64 where |
|
65 time = readTime fileName |
63 ps [] = [] |
66 ps [] = [] |
64 ps ("DRAW" : bs) = ps bs |
67 ps ("DRAW" : bs) = ps bs |
65 ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs |
68 ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs |
66 ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) = |
69 ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) = |
67 [SqlByteString typ |
70 [ SqlUTCTime time |
|
71 , SqlByteString typ |
68 , SqlByteString $ fromMaybe "" (lookup teamname teams) |
72 , SqlByteString $ fromMaybe "" (lookup teamname teams) |
69 , SqlInt32 (readInt_ value) |
73 , SqlInt32 (readInt_ value) |
70 , SqlByteString fileName |
74 , SqlByteString fileName |
71 , SqlByteString location |
75 , SqlByteString location |
72 ] : ps bs |
76 ] : ps bs |