author | unc0rr |
Wed, 25 Feb 2009 17:12:32 +0000 | |
changeset 1841 | fba7210b438b |
parent 1834 | 71cb978dc85f |
child 1844 | 81abed9d4c11 |
permissions | -rw-r--r-- |
1804 | 1 |
module HWProtoNEState where |
2 |
||
3 |
import qualified Data.IntMap as IntMap |
|
4 |
import Maybe |
|
5 |
import Data.List |
|
6 |
import Data.Word |
|
7 |
-------------------------------------- |
|
8 |
import CoreTypes |
|
9 |
import Actions |
|
10 |
import Utils |
|
11 |
||
12 |
handleCmd_NotEntered :: CmdHandler |
|
13 |
||
14 |
handleCmd_NotEntered clID clients _ ["NICK", newNick] = |
|
15 |
if not . null $ nick client then |
|
16 |
[ProtocolError "Nick already chosen"] |
|
17 |
else if haveSameNick then |
|
18 |
[AnswerThisClient ["WARNING", "Nick collision"]] |
|
19 |
++ [ByeClient ""] |
|
20 |
else |
|
21 |
[ModifyClient (\c -> c{nick = newNick}), |
|
22 |
AnswerThisClient ["NICK", newNick]] |
|
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
23 |
++ checkPassword |
1804 | 24 |
where |
25 |
client = clients IntMap.! clID |
|
26 |
haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
|
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
27 |
checkPassword = if clientProto client /= 0 then [CheckRegistered] else [] |
1804 | 28 |
|
29 |
||
30 |
handleCmd_NotEntered clID clients _ ["PROTO", protoNum] = |
|
31 |
if clientProto client > 0 then |
|
32 |
[ProtocolError "Protocol already known"] |
|
33 |
else if parsedProto == 0 then |
|
34 |
[ProtocolError "Bad number"] |
|
35 |
else |
|
36 |
[ModifyClient (\c -> c{clientProto = parsedProto}), |
|
37 |
AnswerThisClient ["PROTO", show parsedProto]] |
|
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
38 |
++ checkPassword |
1804 | 39 |
where |
40 |
client = clients IntMap.! clID |
|
41 |
parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
|
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
42 |
checkPassword = if (not . null) (nick client) then [CheckRegistered] else [] |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
43 |
|
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
44 |
handleCmd_NotEntered clID clients _ ["PASSWORD"] = |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
45 |
[ModifyClient (\cl -> cl{logonPassed = True}), |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
46 |
MoveToLobby] |
1804 | 47 |
|
48 |
||
49 |
handleCmd_NotEntered _ _ _ ["DUMP"] = |
|
50 |
[Dump] |
|
51 |
||
52 |
||
53 |
handleCmd_NotEntered clID _ _ _ = [ProtocolError "Incorrect command (state: not entered)"] |