# HG changeset patch # User unc0rr # Date 1377288795 -14400 # Node ID 9e94a9bc8c7eb380cbe97451f304dc9bb2dede99 # Parent 151c8e553de22d2e530d170499a320474dacb8ec Store TrophyRace records in database diff -r 151c8e553de2 -r 9e94a9bc8c7e gameServer/OfficialServer/extdbinterface.hs --- a/gameServer/OfficialServer/extdbinterface.hs Tue Aug 06 00:26:07 2013 +0400 +++ b/gameServer/OfficialServer/extdbinterface.hs Sat Aug 24 00:13:15 2013 +0400 @@ -9,8 +9,11 @@ import Data.Maybe import Database.HDBC import Database.HDBC.MySQL +import Data.List (lookup) +import qualified Data.ByteString.Char8 as B -------------------------- import CoreTypes +import Utils dbQueryAccount = @@ -19,6 +22,11 @@ dbQueryStats = "INSERT INTO gameserver_stats (players, rooms, last_update) VALUES (?, ?, UNIX_TIMESTAMP())" +dbQueryAchievement = + "INSERT INTO achievements (typeid, userid, value, filename, location) \ + \ VALUES ((SELECT id FROM achievement_types WHERE name = ?), (SELECT uid FROM users WHERE name = ?), \ + \ ?, ?, ?)" + dbInteractionLoop dbConn = forever $ do q <- liftM read getLine hPutStrLn stderr $ show q @@ -45,7 +53,27 @@ SendStats clients rooms -> run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return () +--StoreAchievements (B.pack fileName) (map toPair teams) info + StoreAchievements fileName teams info -> + mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info +<<<<<<< local + StoreAchievements {} -> return () + +======= +parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]] +parseStats fileName teams = ps + where + ps ("DRAW" : bs) = ps bs + ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs + ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) = + [SqlByteString typ + , SqlByteString $ fromMaybe "" (lookup teamname teams) + , SqlInt32 (readInt_ value) + , SqlByteString fileName + , SqlByteString location + ] : ps bs +>>>>>>> other dbConnectionLoop mySQLConnectionInfo = Control.Exception.handle (\(e :: IOException) -> hPutStrLn stderr $ show e) $ handleSqlError $ diff -r 151c8e553de2 -r 9e94a9bc8c7e hedgewars/uScript.pas --- a/hedgewars/uScript.pas Tue Aug 06 00:26:07 2013 +0400 +++ b/hedgewars/uScript.pas Sat Aug 24 00:13:15 2013 +0400 @@ -1840,10 +1840,10 @@ function lc_declareachievement(L : Plua_State) : LongInt; Cdecl; var gear: PGear; begin - if lua_gettop(L) <> 3 then + if lua_gettop(L) <> 4 then LuaError('Lua: Wrong number of parameters passed to DeclareAchievement!') else - declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tointeger(L, 3)); + declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4)); lc_declareachievement:= 0 end; /////////////////// diff -r 151c8e553de2 -r 9e94a9bc8c7e hedgewars/uStats.pas --- a/hedgewars/uStats.pas Tue Aug 06 00:26:07 2013 +0400 +++ b/hedgewars/uStats.pas Sat Aug 24 00:13:15 2013 +0400 @@ -34,7 +34,7 @@ procedure TurnReaction; procedure SendStats; procedure hedgehogFlight(Gear: PGear; time: Longword); -procedure declareAchievement(id, teamname: shortstring; value: LongInt); +procedure declareAchievement(id, teamname, location: shortstring; value: LongInt); implementation uses uSound, uLocale, uVariables, uUtils, uIO, uCaptions, uDebug, uMisc, uConsole, uScript; @@ -311,12 +311,13 @@ WriteLnToConsole(''); end; -procedure declareAchievement(id, teamname: shortstring; value: LongInt); +procedure declareAchievement(id, teamname, location: shortstring; value: LongInt); begin if (length(id) = 0) or (length(teamname) = 0) then exit; WriteLnToConsole('ACHIEVEMENT'); WriteLnToConsole(id); WriteLnToConsole(teamname); + WriteLnToConsole(location); WriteLnToConsole(inttostr(value)); end; diff -r 151c8e553de2 -r 9e94a9bc8c7e share/hedgewars/Data/Maps/TrophyRace/map.lua --- a/share/hedgewars/Data/Maps/TrophyRace/map.lua Tue Aug 06 00:26:07 2013 +0400 +++ b/share/hedgewars/Data/Maps/TrophyRace/map.lua Sat Aug 24 00:13:15 2013 +0400 @@ -165,6 +165,6 @@ function onAchievementsDeclaration() if besthog ~= nil then - DeclareAchievement("rope race", GetHogTeamName(besthog), besttime) + DeclareAchievement("rope race", GetHogTeamName(besthog), "TrophyRace", besttime) end end