gameServer/OfficialServer/extdbinterface.hs
changeset 11320 556eafd1443a
parent 11275 13ce106c8836
child 11573 8fd1808b12ed
equal deleted inserted replaced
11319:3c4ec0742967 11320:556eafd1443a
    50     "INSERT INTO achievements (time, typeid, userid, value, filename, location, protocol) \
    50     "INSERT INTO achievements (time, typeid, userid, value, filename, location, protocol) \
    51     \ VALUES (?, (SELECT id FROM achievement_types WHERE name = ?), (SELECT uid FROM users WHERE name = ?), \
    51     \ VALUES (?, (SELECT id FROM achievement_types WHERE name = ?), (SELECT uid FROM users WHERE name = ?), \
    52     \ ?, ?, ?, ?)"
    52     \ ?, ?, ?, ?)"
    53 
    53 
    54 dbQueryGamesHistory =
    54 dbQueryGamesHistory =
    55     "INSERT INTO rating_games (script, protocol, filename, time) \
    55     "INSERT INTO rating_games (script, protocol, filename, time, vamp, ropes, infattacks) \
    56     \ VALUES (?, ?, ?, ?)"
    56     \ VALUES (?, ?, ?, ?, ?, ?, ?)"
    57 
    57 
    58 dbQueryGameId = "SELECT LAST_INSERT_ID()"
    58 dbQueryGameId = "SELECT LAST_INSERT_ID()"
    59 
    59 
    60 dbQueryGamesHistoryPlaces = "INSERT INTO rating_players (userid, gameid, place) \
    60 dbQueryGamesHistoryPlaces = "INSERT INTO rating_players (userid, gameid, place) \
    61     \ VALUES ((SELECT uid FROM users WHERE name = ?), ?, ?)"
    61     \ VALUES ((SELECT uid FROM users WHERE name = ?), ?, ?)"
    91                 print (clId, clUid, ReplayName fn)
    91                 print (clId, clUid, ReplayName fn)
    92                 hFlush stdout
    92                 hFlush stdout
    93 
    93 
    94         SendStats clients rooms ->
    94         SendStats clients rooms ->
    95                 void $ execute dbConn dbQueryStats (clients, rooms)
    95                 void $ execute dbConn dbQueryStats (clients, rooms)
    96         StoreAchievements p fileName teams script info ->
    96         StoreAchievements p fileName teams g info ->
    97             sequence_ $ parseStats dbConn p fileName teams script info
    97             sequence_ $ parseStats dbConn p fileName teams g info
    98 
    98 
    99 
    99 
   100 --readTime = read . B.unpack . B.take 19 . B.drop 8
   100 --readTime = read . B.unpack . B.take 19 . B.drop 8
   101 readTime = B.take 19 . B.drop 8
   101 readTime = B.take 19 . B.drop 8
   102 
   102 
   103 parseStats :: 
   103 parseStats :: 
   104     Connection
   104     Connection
   105     -> Word16 
   105     -> Word16 
   106     -> B.ByteString 
   106     -> B.ByteString 
   107     -> [(B.ByteString, B.ByteString)] 
   107     -> [(B.ByteString, B.ByteString)] 
   108     -> B.ByteString
   108     -> GameDetails
   109     -> [B.ByteString]
   109     -> [B.ByteString]
   110     -> [IO Int64]
   110     -> [IO Int64]
   111 parseStats dbConn p fileName teams script = ps
   111 parseStats dbConn p fileName teams (GameDetails script infRopes vamp infAttacks) = ps
   112     where
   112     where
   113     time = readTime fileName
   113     time = readTime fileName
   114     ps :: [B.ByteString] -> [IO Int64]
   114     ps :: [B.ByteString] -> [IO Int64]
   115     ps [] = []
   115     ps [] = []
   116     ps ("DRAW" : bs) = execute dbConn dbQueryGamesHistory (script, (fromIntegral p) :: Int, fileName, time)
   116     ps ("DRAW" : bs) = execute dbConn dbQueryGamesHistory (script, (fromIntegral p) :: Int, fileName, time, vamp, infRopes, infAttacks)
   117         : places (map drawParams teams)
   117         : places (map drawParams teams)
   118         : ps bs
   118         : ps bs
   119     ps ("WINNERS" : n : bs) = let winNum = readInt_ n in execute dbConn dbQueryGamesHistory (script, (fromIntegral p) :: Int, fileName, time)
   119     ps ("WINNERS" : n : bs) = let winNum = readInt_ n in execute dbConn dbQueryGamesHistory (script, (fromIntegral p) :: Int, fileName, time, vamp, infRopes, infAttacks)
   120         : places (map (placeParams (take winNum bs)) teams)
   120         : places (map (placeParams (take winNum bs)) teams)
   121         : ps (drop winNum bs)
   121         : ps (drop winNum bs)
   122     ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) = execute dbConn dbQueryAchievement
   122     ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) = execute dbConn dbQueryAchievement
   123         ( time
   123         ( time
   124         , typ
   124         , typ