Extract time from file name, assuming it is stored in 'replay' folder
authorunc0rr
Sun, 25 Aug 2013 21:43:47 +0400
changeset 9425 49eb707b9367
parent 9423 43798a77f1d1
child 9427 c6c7e68de2a4
Extract time from file name, assuming it is stored in 'replay' folder
gameServer/OfficialServer/extdbinterface.hs
--- a/gameServer/OfficialServer/extdbinterface.hs	Sun Aug 25 00:03:00 2013 +0400
+++ b/gameServer/OfficialServer/extdbinterface.hs	Sun Aug 25 21:43:47 2013 +0400
@@ -23,7 +23,7 @@
     "INSERT INTO gameserver_stats (players, rooms, last_update) VALUES (?, ?, UNIX_TIMESTAMP())"
 
 dbQueryAchievement =
-    "INSERT INTO achievements (typeid, userid, value, filename, location) \
+    "INSERT INTO achievements (time, typeid, userid, value, filename, location) \
     \ VALUES ((SELECT id FROM achievement_types WHERE name = ?), (SELECT uid FROM users WHERE name = ?), \
     \ ?, ?, ?)"
 
@@ -57,14 +57,18 @@
         StoreAchievements fileName teams info -> 
             mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info
 
+readTime = read . B.unpack . B.take 19 . B.drop 8
+
 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]]
 parseStats fileName teams = ps
     where
+    time = readTime fileName
     ps [] = []
     ps ("DRAW" : bs) = ps bs
     ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs
     ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) =
-        [SqlByteString typ
+        [ SqlUTCTime time
+        , SqlByteString typ
         , SqlByteString $ fromMaybe "" (lookup teamname teams)
         , SqlInt32 (readInt_ value)
         , SqlByteString fileName