Handle password parameter on JOIN
authorunc0rr
Thu, 01 May 2008 15:24:13 +0000
changeset 896 93df8ac94382
parent 895 6aee2f335726
child 897 35d91fa3753b
Handle password parameter on JOIN
netserver/HWProto.hs
--- a/netserver/HWProto.hs	Thu May 01 15:14:32 2008 +0000
+++ b/netserver/HWProto.hs	Thu May 01 15:24:13 2008 +0000
@@ -1,9 +1,10 @@
 module HWProto where
 
 import IO
+import Data.List
 import Data.Word
 import Miscutils
-import Maybe (fromMaybe)
+import Maybe (fromMaybe, fromJust)
 
 fromRoom :: String -> [ClientInfo] -> [ClientInfo]
 fromRoom roomName clients = filter (\cl -> roomName == room cl) clients
@@ -52,10 +53,13 @@
 handleCmd_noRoom client clients rooms ("JOIN":roomName:roomPassword:[]) =
 	if noRoom then
 		(client, rooms, [client], ["WARNING", "There's no room with that name"])
+	else if roomPassword /= password (getRoom roomName) then
+		(client, rooms, [client], ["WARNING", "Wrong password"])
 	else
 		(client{room = roomName}, rooms, client : fromRoom roomName clients, ["JOIN", roomName, nick client])
 	where
 		noRoom = null $ filter (\room -> roomName == name room) rooms
+		getRoom roomName = fromJust $ find (\room -> roomName == name room) rooms
 
 handleCmd_noRoom client clients rooms ("JOIN":roomName:[]) =
 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]