netserver/HWProto.hs
author unc0rr
Wed, 30 Apr 2008 20:48:12 +0000
changeset 893 149244d86bf1
parent 892 dfe97199f17e
child 894 2ca76a7f3121
permissions -rw-r--r--
- Some improvements in core - Handle 'NICK' command
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
890
1d8c4a5ec622 - Improve server core
unc0rr
parents:
diff changeset
     1
module HWProto where
1d8c4a5ec622 - Improve server core
unc0rr
parents:
diff changeset
     2
1d8c4a5ec622 - Improve server core
unc0rr
parents:
diff changeset
     3
import IO
1d8c4a5ec622 - Improve server core
unc0rr
parents:
diff changeset
     4
import Miscutils
1d8c4a5ec622 - Improve server core
unc0rr
parents:
diff changeset
     5
893
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
     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
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
     8
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
     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
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    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
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    13
		(client, rooms, clients, ["QUIT", nick client])
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    14
891
701f86df9b4c Properly handle QUIT command. Now, we can concentrate on protocol implementation
unc0rr
parents: 890
diff changeset
    15
893
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    16
handleCmd client clients rooms ("NICK":newNick:[]) =
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    17
	if not . null $ nick client then
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    18
		(client, rooms, [client], ["ERROR", "The nick already chosen"])
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    19
	else if haveSameNick then
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    20
		(client, rooms, [client], ["ERROR", "Choose another nick"])
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    21
	else
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    22
		(client{nick = newNick}, rooms, [client], ["NICK", newNick])
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    23
	where
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    24
		haveSameNick = not . null $ filter (\cl -> newNick == nick cl) clients
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    25
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    26
149244d86bf1 - Some improvements in core
unc0rr
parents: 892
diff changeset
    27
handleCmd client _ rooms _ = (client, rooms, [client], ["ERROR", "Bad command"])