Implement ability for server admin to clear accounts cache
authorunc0rr
Fri, 12 Jun 2009 08:47:05 +0000
changeset 2155 d897222d3339
parent 2154 3d2917be12c3
child 2156 3f1a19802d10
Implement ability for server admin to clear accounts cache
QTfrontend/hwform.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
QTfrontend/pages.cpp
QTfrontend/pages.h
gameServer/Actions.hs
gameServer/CoreTypes.hs
gameServer/HWProtoLobbyState.hs
gameServer/HWProtoNEState.hs
gameServer/OfficialServer/DBInteraction.hs
--- a/QTfrontend/hwform.cpp	Fri Jun 12 00:39:36 2009 +0000
+++ b/QTfrontend/hwform.cpp	Fri Jun 12 08:47:05 2009 +0000
@@ -632,6 +632,7 @@
 // admin stuff
 	connect(hwnet, SIGNAL(serverMessage(const QString&)), ui.pageAdmin, SLOT(serverMessage(const QString &)));
 	connect(ui.pageAdmin, SIGNAL(setServerMessage(const QString&)), hwnet, SLOT(newServerMessage(const QString &)));
+	connect(ui.pageAdmin->pbClearAccountsCache, SIGNAL(clicked()), hwnet, SLOT(clearAccountsCache()));
 
 // disconnect
 	connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection);
--- a/QTfrontend/newnetclient.cpp	Fri Jun 12 00:39:36 2009 +0000
+++ b/QTfrontend/newnetclient.cpp	Fri Jun 12 08:47:05 2009 +0000
@@ -660,6 +660,11 @@
 	RawSendNet(QString("TOGGLE_RESTRICT_TEAMS"));
 }
 
+void HWNewNet::clearAccountsCache()
+{
+	RawSendNet(QString("CLEAR_ACCOUNTS_CACHE"));
+}
+
 void HWNewNet::partRoom()
 {
 	netClientState = 2;
--- a/QTfrontend/newnetclient.h	Fri Jun 12 00:39:36 2009 +0000
+++ b/QTfrontend/newnetclient.h	Fri Jun 12 08:47:05 2009 +0000
@@ -145,6 +145,7 @@
   void toggleRestrictJoins();
   void toggleRestrictTeamAdds();
   void partRoom();
+  void clearAccountsCache();
 
  private slots:
   void ClientRead();
--- a/QTfrontend/pages.cpp	Fri Jun 12 00:39:36 2009 +0000
+++ b/QTfrontend/pages.cpp	Fri Jun 12 08:47:05 2009 +0000
@@ -1141,7 +1141,9 @@
 	pageLayout->addWidget(leServerMessage, 0, 1);
 
 	pbSetSM = addButton(tr("Set message"), pageLayout, 0, 2);
-	BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
+	pbClearAccountsCache = addButton(tr("Clear Accounts Cache"), pageLayout, 1, 0);
+
+	BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true);
 
 	connect(pbSetSM, SIGNAL(clicked()), this, SLOT(smChanged()));
 }
--- a/QTfrontend/pages.h	Fri Jun 12 00:39:36 2009 +0000
+++ b/QTfrontend/pages.h	Fri Jun 12 08:47:05 2009 +0000
@@ -456,6 +456,7 @@
 	PageAdmin(QWidget* parent = 0);
 
 	QPushButton * BtnBack;
+	QPushButton * pbClearAccountsCache;
 
 private:
 	QLineEdit * leServerMessage;
--- a/gameServer/Actions.hs	Fri Jun 12 00:39:36 2009 +0000
+++ b/gameServer/Actions.hs	Fri Jun 12 08:47:05 2009 +0000
@@ -39,6 +39,7 @@
 	| ModifyServerInfo (ServerInfo -> ServerInfo)
 	| AddRoom String String
 	| CheckRegistered
+	| ClearAccountsCache
 	| ProcessAccountInfo AccountInfo
 	| Dump
 	| AddClient ClientInfo
@@ -295,6 +296,13 @@
 		client = clients ! clID
 
 
+processAction (clID, serverInfo, clients, rooms) (ClearAccountsCache) = do
+	writeChan (dbQueries serverInfo) $ ClearCache
+	return (clID, serverInfo, clients, rooms)
+	where
+		client = clients ! clID
+
+
 processAction (clID, serverInfo, clients, rooms) (Dump) = do
 	writeChan (sendChan $ clients ! clID) ["DUMP", show serverInfo, showTree clients, showTree rooms]
 	return (clID, serverInfo, clients, rooms)
--- a/gameServer/CoreTypes.hs	Fri Jun 12 00:39:36 2009 +0000
+++ b/gameServer/CoreTypes.hs	Fri Jun 12 08:47:05 2009 +0000
@@ -152,6 +152,7 @@
 
 data DBQuery =
 	CheckAccount Int String String
+	| ClearCache
 	deriving (Show, Read)
 
 data CoreMessage =
--- a/gameServer/HWProtoLobbyState.hs	Fri Jun 12 00:39:36 2009 +0000
+++ b/gameServer/HWProtoLobbyState.hs	Fri Jun 12 08:47:05 2009 +0000
@@ -111,6 +111,8 @@
 handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName] =
 	handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName, ""]
 
+	---------------------------
+	-- Administrator's stuff --
 
 handleCmd_lobby clID clients rooms ["KICK", kickNick] =
 	if not $ isAdministrator client then
@@ -148,4 +150,13 @@
 		client = clients IntMap.! clID
 
 
+handleCmd_lobby clID clients rooms ["CLEAR_ACCOUNTS_CACHE"] =
+	if not $ isAdministrator client then
+		[]
+	else
+		[ClearAccountsCache]
+	where
+		client = clients IntMap.! clID
+
+
 handleCmd_lobby clID _ _ _ = [ProtocolError "Incorrect command (state: in lobby)"]
--- a/gameServer/HWProtoNEState.hs	Fri Jun 12 00:39:36 2009 +0000
+++ b/gameServer/HWProtoNEState.hs	Fri Jun 12 08:47:05 2009 +0000
@@ -55,8 +55,8 @@
 		adminNotice = if isAdministrator client then [AnswerThisClient ["ADMIN_ACCESS"]] else []
 
 
-handleCmd_NotEntered _ _ _ ["DUMP"] =
-	[Dump]
+--handleCmd_NotEntered _ _ _ ["DUMP"] =
+--	[Dump]
 
 
 handleCmd_NotEntered clID _ _ _ = [ProtocolError "Incorrect command (state: not entered)"]
--- a/gameServer/OfficialServer/DBInteraction.hs	Fri Jun 12 00:39:36 2009 +0000
+++ b/gameServer/OfficialServer/DBInteraction.hs	Fri Jun 12 08:47:05 2009 +0000
@@ -27,6 +27,7 @@
 		CheckAccount clUid _ clHost -> do
 			writeChan (coreChan serverInfo) $ ClientAccountInfo (clUid,
 				if clHost `elem` localAddressList then Admin else Guest)
+		ClearCache -> return ()
 
 	fakeDbConnection serverInfo
 
@@ -63,6 +64,8 @@
 				do
 					writeChan coreChan $ ClientAccountInfo (clUid, snd $ fromJust cacheEntry)
 					return accountsCache
+
+		ClearCache -> return Map.empty
 	
 	return updatedCache
 	where