author | unc0rr |
Wed, 30 Apr 2008 20:48:12 +0000 | |
changeset 893 | 149244d86bf1 |
parent 892 | dfe97199f17e |
child 894 | 2ca76a7f3121 |
permissions | -rw-r--r-- |
890 | 1 |
module HWProto where |
2 |
||
3 |
import IO |
|
4 |
import Miscutils |
|
5 |
||
893 | 6 |
handleCmd :: ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientInfo, [RoomInfo], [ClientInfo], [String]) |
891
701f86df9b4c
Properly handle QUIT command. Now, we can concentrate on protocol implementation
unc0rr
parents:
890
diff
changeset
|
7 |
|
893 | 8 |
|
9 |
handleCmd client clients rooms ("QUIT":xs) = |
|
891
701f86df9b4c
Properly handle QUIT command. Now, we can concentrate on protocol implementation
unc0rr
parents:
890
diff
changeset
|
10 |
if null (room client) then |
893 | 11 |
(client, rooms, [client], ["QUIT"]) |
891
701f86df9b4c
Properly handle QUIT command. Now, we can concentrate on protocol implementation
unc0rr
parents:
890
diff
changeset
|
12 |
else |
893 | 13 |
(client, rooms, clients, ["QUIT", nick client]) |
14 |
||
891
701f86df9b4c
Properly handle QUIT command. Now, we can concentrate on protocol implementation
unc0rr
parents:
890
diff
changeset
|
15 |
|
893 | 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"]) |