# HG changeset patch # User unc0rr # Date 1209910046 0 # Node ID 3cc10f0aae37a187df73b00f9e1a882cceaffe86 # Parent 2f5ce9a584f9063c070df40c8551d389af50bf6d Finish conversion diff -r 2f5ce9a584f9 -r 3cc10f0aae37 netserver/HWProto.hs --- a/netserver/HWProto.hs Sun May 04 13:49:55 2008 +0000 +++ b/netserver/HWProto.hs Sun May 04 14:07:26 2008 +0000 @@ -37,30 +37,31 @@ -- 'noRoom' clients state command handlers handleCmd_noRoom :: Handle -> [ClientInfo] -> [RoomInfo] -> [String] -> ([ClientInfo], [RoomInfo], [Handle], [String]) -{--handleCmd_noRoom clhandle clients rooms ("CREATE":newRoom:roomPassword:[]) = +handleCmd_noRoom clhandle clients rooms ("CREATE":newRoom:roomPassword:[]) = if haveSameRoom then - (client, rooms, [clhandle], ["WARNING", "There's already a room with that name"]) + (clients, rooms, [clhandle], ["WARNING", "There's already a room with that name"]) else - (client{room = newRoom, isMaster = True}, (RoomInfo newRoom roomPassword):rooms, [client], ["JOINS", nick client]) + (modifyClient clhandle clients (\cl -> cl{room = newRoom, isMaster = True}), (RoomInfo newRoom roomPassword):rooms, [clhandle], ["JOINS", nick client]) where haveSameRoom = not . null $ filter (\room -> newRoom == name room) rooms + client = clientByHandle clhandle clients handleCmd_noRoom clhandle clients rooms ("CREATE":newRoom:[]) = - handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""] + handleCmd_noRoom clhandle clients rooms ["CREATE", newRoom, ""] handleCmd_noRoom clhandle clients rooms ("JOIN":roomName:roomPassword:[]) = - if noRoom then - (client, rooms, [clhandle], ["WARNING", "There's no room with that name"]) - else if roomPassword /= password (getRoom roomName) then - (client, rooms, [clhandle], ["WARNING", "Wrong password"]) + if noSuchRoom then + (clients, rooms, [clhandle], ["WARNING", "There's no room with that name"]) + else if roomPassword /= password (roomByName roomName rooms) then + (clients, rooms, [clhandle], ["WARNING", "Wrong password"]) else - (client{room = roomName}, rooms, client : fromRoom roomName clients, ["JOINS", nick client]) + (modifyClient clhandle clients (\cl -> cl{room = roomName}), rooms, clhandle : (fromRoomHandles roomName clients), ["JOINS", nick client]) where - noRoom = null $ filter (\room -> roomName == name room) rooms - getRoom roomName = fromJust $ find (\room -> roomName == name room) rooms + noSuchRoom = null $ filter (\room -> roomName == name room) rooms + client = clientByHandle clhandle clients handleCmd_noRoom clhandle clients rooms ("JOIN":roomName:[]) = - handleCmd_noRoom client clients rooms ["JOIN", ""]--} + handleCmd_noRoom clhandle clients rooms ["JOIN", roomName, ""] handleCmd_noRoom clhandle clients rooms _ = (clients, rooms, [clhandle], ["ERROR", "Bad command or incorrect parameter"]) diff -r 2f5ce9a584f9 -r 3cc10f0aae37 netserver/Miscutils.hs --- a/netserver/Miscutils.hs Sun May 04 13:49:55 2008 +0000 +++ b/netserver/Miscutils.hs Sun May 04 14:07:26 2008 +0000 @@ -29,6 +29,9 @@ clientByHandle :: Handle -> [ClientInfo] -> ClientInfo clientByHandle clhandle clients = fromJust $ find (\ci -> handle ci == clhandle) clients +roomByName :: String -> [RoomInfo] -> RoomInfo +roomByName roomName rooms = fromJust $ find (\room -> roomName == name room) rooms + fromRoomHandles :: String -> [ClientInfo] -> [Handle] fromRoomHandles roomName clients = map (\ci -> handle ci) $ filter (\ci -> room ci == roomName) clients