netserver/HWProto.hs
changeset 893 149244d86bf1
parent 892 dfe97199f17e
child 894 2ca76a7f3121
equal deleted inserted replaced
892:dfe97199f17e 893:149244d86bf1
     1 module HWProto where
     1 module HWProto where
     2 
     2 
     3 import IO
     3 import IO
     4 import Miscutils
     4 import Miscutils
     5 
     5 
     6 handleCmd :: ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> ([ClientInfo], [String])
     6 handleCmd :: ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientInfo, [RoomInfo], [ClientInfo], [String])
     7 
     7 
     8 handleCmd client clients _ ("QUIT":xs) =
     8 
       
     9 handleCmd client clients rooms ("QUIT":xs) =
     9 	if null (room client) then
    10 	if null (room client) then
    10 		([client], ["QUIT"])
    11 		(client, rooms, [client], ["QUIT"])
    11 	else
    12 	else
    12 		(clients, ["QUIT", nick client])
    13 		(client, rooms, clients, ["QUIT", nick client])
    13 
    14 
    14 handleCmd client _ _ _ = ([client], ["Bad command"])
    15 
       
    16 handleCmd client clients rooms ("NICK":newNick:[]) =
       
    17 	if not . null $ nick client then
       
    18 		(client, rooms, [client], ["ERROR", "The nick already chosen"])
       
    19 	else if haveSameNick then
       
    20 		(client, rooms, [client], ["ERROR", "Choose another nick"])
       
    21 	else
       
    22 		(client{nick = newNick}, rooms, [client], ["NICK", newNick])
       
    23 	where
       
    24 		haveSameNick = not . null $ filter (\cl -> newNick == nick cl) clients
       
    25 
       
    26 
       
    27 handleCmd client _ rooms _ = (client, rooms, [client], ["ERROR", "Bad command"])