author | unc0rr |
Thu, 01 May 2008 14:30:12 +0000 | |
changeset 894 | 2ca76a7f3121 |
parent 893 | 149244d86bf1 |
child 895 | 6aee2f335726 |
permissions | -rw-r--r-- |
890 | 1 |
module HWProto where |
2 |
||
3 |
import IO |
|
894 | 4 |
import Data.Word |
890 | 5 |
import Miscutils |
894 | 6 |
import Maybe (fromMaybe) |
890 | 7 |
|
893 | 8 |
handleCmd :: ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientInfo, [RoomInfo], [ClientInfo], [String]) |
894 | 9 |
handleCmd_noInfo :: ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientInfo, [RoomInfo], [ClientInfo], [String]) |
10 |
handleCmd_noRoom :: 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
|
11 |
|
894 | 12 |
-- 'noInfo' clients state command handlers |
13 |
handleCmd_noInfo client clients rooms ("NICK":newNick:[]) = |
|
14 |
if not . null $ nick client then |
|
15 |
(client, rooms, [client], ["ERROR", "The nick already chosen"]) |
|
16 |
else if haveSameNick then |
|
17 |
(client, rooms, [client], ["WARNING", "Choose another nick"]) |
|
18 |
else |
|
19 |
(client{nick = newNick}, rooms, [client], ["NICK", newNick]) |
|
20 |
where |
|
21 |
haveSameNick = not . null $ filter (\cl -> newNick == nick cl) clients |
|
22 |
||
23 |
handleCmd_noInfo client clients rooms ("PROTO":protoNum:[]) = |
|
24 |
if protocol client > 0 then |
|
25 |
(client, rooms, [client], ["ERROR", "Protocol number already known"]) |
|
26 |
else if parsedProto == 0 then |
|
27 |
(client, rooms, [client], ["ERROR", "Bad input"]) |
|
28 |
else |
|
29 |
(client{protocol = parsedProto}, rooms, [], []) |
|
30 |
where |
|
31 |
parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
|
32 |
||
33 |
||
34 |
handleCmd_noInfo client _ rooms _ = (client, rooms, [client], ["ERROR", "Bad command or incorrect parameter"]) |
|
35 |
||
36 |
||
37 |
-- 'noRoom' clients state command handlers |
|
38 |
--handleCmd_noRoom client clients rooms ("CREATE":newRoom:[]) = |
|
39 |
||
40 |
handleCmd_noRoom client _ rooms _ = (client, rooms, [client], ["ERROR", "Bad command or incorrect parameter"]) |
|
41 |
||
893 | 42 |
|
43 |
handleCmd client clients rooms ("QUIT":xs) = |
|
891
701f86df9b4c
Properly handle QUIT command. Now, we can concentrate on protocol implementation
unc0rr
parents:
890
diff
changeset
|
44 |
if null (room client) then |
893 | 45 |
(client, rooms, [client], ["QUIT"]) |
891
701f86df9b4c
Properly handle QUIT command. Now, we can concentrate on protocol implementation
unc0rr
parents:
890
diff
changeset
|
46 |
else |
893 | 47 |
(client, rooms, clients, ["QUIT", nick client]) |
48 |
||
891
701f86df9b4c
Properly handle QUIT command. Now, we can concentrate on protocol implementation
unc0rr
parents:
890
diff
changeset
|
49 |
|
894 | 50 |
handleCmd client clients rooms cmd = |
51 |
if null (nick client) || protocol client == 0 then |
|
52 |
handleCmd_noInfo client clients rooms cmd |
|
893 | 53 |
else |
894 | 54 |
handleCmd_noRoom client clients rooms cmd |