Set admin flag and send admin notification to users with rid equal to 3
authorunc0rr
Fri, 27 Feb 2009 19:51:22 +0000
changeset 1847 2178c0fc838c
parent 1846 24d0074d4eed
child 1848 1eb88d41ccc6
Set admin flag and send admin notification to users with rid equal to 3
gameServer/Actions.hs
gameServer/CoreTypes.hs
gameServer/HWProtoNEState.hs
gameServer/NetRoutines.hs
gameServer/OfficialServer/DBInteraction.hs
--- a/gameServer/Actions.hs	Thu Feb 26 15:00:48 2009 +0000
+++ b/gameServer/Actions.hs	Fri Feb 27 19:51:22 2009 +0000
@@ -259,10 +259,10 @@
 
 processAction (clID, serverInfo, clients, rooms) (ProcessAccountInfo info) = do
 	case info of
-		HasAccount passwd -> do
+		HasAccount passwd isAdmin -> do
 			infoM "Clients" $ show clID ++ " has account"
 			writeChan (sendChan $ clients ! clID) ["ASKPASSWORD"]
-			return (clID, serverInfo, adjust (\cl -> cl{webPassword = passwd}) clID clients, rooms)
+			return (clID, serverInfo, adjust (\cl -> cl{webPassword = passwd, isAdministrator = isAdmin}) clID clients, rooms)
 		Guest -> do
 			infoM "Clients" $ show clID ++ " is guest"
 			processAction (clID, serverInfo, adjust (\cl -> cl{logonPassed = True}) clID clients, rooms) MoveToLobby
--- a/gameServer/CoreTypes.hs	Thu Feb 26 15:00:48 2009 +0000
+++ b/gameServer/CoreTypes.hs	Fri Feb 27 19:51:22 2009 +0000
@@ -25,6 +25,7 @@
 		roomID :: Int,
 		isMaster :: Bool,
 		isReady :: Bool,
+		isAdministrator :: Bool,
 		forceQuit :: Bool,
 		partRoom :: Bool
 	}
@@ -139,7 +140,7 @@
 	)
 
 data AccountInfo =
-	HasAccount String
+	HasAccount String Bool
 	| Guest
 
 data CoreMessage =
@@ -151,7 +152,6 @@
 
 data DBQuery =
 	CheckAccount Int String
-	| CheckPassword String
 
 
 type Clients = IntMap.IntMap ClientInfo
--- a/gameServer/HWProtoNEState.hs	Thu Feb 26 15:00:48 2009 +0000
+++ b/gameServer/HWProtoNEState.hs	Fri Feb 27 19:51:22 2009 +0000
@@ -44,11 +44,12 @@
 handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] =
 	if passwd == webPassword client then
 		[ModifyClient (\cl -> cl{logonPassed = True}),
-		MoveToLobby]
+		MoveToLobby] ++ adminNotice
 	else
 		[ByeClient "Authentication failed"]
 	where
 		client = clients IntMap.! clID
+		adminNotice = if isAdministrator client then [AnswerThisClient ["ADMIN_ACCESS"]] else []
 
 
 handleCmd_NotEntered _ _ _ ["DUMP"] =
--- a/gameServer/NetRoutines.hs	Thu Feb 26 15:00:48 2009 +0000
+++ b/gameServer/NetRoutines.hs	Fri Feb 27 19:51:22 2009 +0000
@@ -48,7 +48,9 @@
 					False
 					False
 					False
-					False)
+					False
+					False
+					)
 
 		writeChan coreChan $ Accept newClient
 
--- a/gameServer/OfficialServer/DBInteraction.hs	Thu Feb 26 15:00:48 2009 +0000
+++ b/gameServer/OfficialServer/DBInteraction.hs	Fri Feb 27 19:51:22 2009 +0000
@@ -24,23 +24,28 @@
 -- to be deleted --------------------------------------------------
 -------------------------------------------------------------------
 
+dbQueryString =
+	"SELECT users.pass, users_roles.rid FROM `users`, users_roles "
+	++ "WHERE users.name = ? AND users_roles.uid = users.uid"
 
 dbInteractionLoop queries coreChan dbConn = do
 	q <- readChan queries
 	case q of
 		CheckAccount clID name -> do
-				statement <- prepare dbConn "SELECT pass FROM users WHERE name=?"
+				statement <- prepare dbConn dbQueryString
 				execute statement [SqlString name]
-				pass <- fetchRow statement
+				passAndRole <- fetchRow statement
 				finish statement
-				if isJust pass then
-					writeChan coreChan $ ClientAccountInfo clID (HasAccount $ fromSql $ head $ fromJust $ pass)
+				if isJust passAndRole then
+					writeChan coreChan $
+							ClientAccountInfo clID $
+								HasAccount
+									(fromSql $ head $ fromJust $ passAndRole)
+									((fromSql $ last $ fromJust $ passAndRole) == (3 :: Int))
 					else
 					writeChan coreChan $ ClientAccountInfo clID Guest
 			`onException`
 				(unGetChan queries $ CheckAccount clID name)
-		
-		CheckPassword queryStr -> putStrLn queryStr
 
 	dbInteractionLoop queries coreChan dbConn