gameServer/OfficialServer/extdbinterface.hs
changeset 4921 2efad3acbb74
parent 4906 22cc9c2b5ae5
child 4932 f11d80bac7ed
equal deleted inserted replaced
4920:bc3c077e15a2 4921:2efad3acbb74
    20     "UPDATE gameserver_stats SET players = ?, rooms = ?, last_update = UNIX_TIMESTAMP()"
    20     "UPDATE gameserver_stats SET players = ?, rooms = ?, last_update = UNIX_TIMESTAMP()"
    21 
    21 
    22 dbInteractionLoop dbConn = forever $ do
    22 dbInteractionLoop dbConn = forever $ do
    23     q <- (getLine >>= return . read)
    23     q <- (getLine >>= return . read)
    24     hPutStrLn stderr $ show q
    24     hPutStrLn stderr $ show q
    25     
    25 
    26     case q of
    26     case q of
    27         CheckAccount clUid clNick _ -> do
    27         CheckAccount clId clUid clNick _ -> do
    28                 statement <- prepare dbConn dbQueryAccount
    28                 statement <- prepare dbConn dbQueryAccount
    29                 execute statement [SqlByteString $ clNick]
    29                 execute statement [SqlByteString $ clNick]
    30                 passAndRole <- fetchRow statement
    30                 passAndRole <- fetchRow statement
    31                 finish statement
    31                 finish statement
    32                 let response = 
    32                 let response = 
    33                         if isJust passAndRole then
    33                         if isJust passAndRole then
    34                         (
    34                         (
       
    35                             clId,
    35                             clUid,
    36                             clUid,
    36                             HasAccount
    37                             HasAccount
    37                                 (fromSql $ head $ fromJust $ passAndRole)
    38                                 (fromSql $ head $ fromJust $ passAndRole)
    38                                 ((fromSql $ last $ fromJust $ passAndRole) == (Just (3 :: Int)))
    39                                 ((fromSql $ last $ fromJust $ passAndRole) == (Just (3 :: Int)))
    39                         )
    40                         )
    40                         else
    41                         else
    41                         (clUid, Guest)
    42                         (clId, clUid, Guest)
    42                 putStrLn (show response)
    43                 putStrLn (show response)
    43                 hFlush stdout
    44                 hFlush stdout
    44 
    45 
    45         SendStats clients rooms ->
    46         SendStats clients rooms ->
    46                 run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return ()
    47                 run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return ()
    52             (connectMySQL mySQLConnectionInfo)
    53             (connectMySQL mySQLConnectionInfo)
    53             (disconnect)
    54             (disconnect)
    54             (dbInteractionLoop)
    55             (dbInteractionLoop)
    55 
    56 
    56 
    57 
    57 processRequest :: DBQuery -> IO String
    58 --processRequest :: DBQuery -> IO String
    58 processRequest (CheckAccount clUid clNick clHost) = return $ show (clUid, Guest)
    59 --processRequest (CheckAccount clId clUid clNick clHost) = return $ show (clclId, clUid, Guest)
    59 
    60 
    60 main = do
    61 main = do
    61         dbHost <- getLine
    62         dbHost <- getLine
    62         dbLogin <- getLine
    63         dbLogin <- getLine
    63         dbPassword <- getLine
    64         dbPassword <- getLine