author | unc0rr |
Thu, 05 Mar 2009 21:41:18 +0000 | |
changeset 1863 | 705c01571196 |
parent 1847 | 2178c0fc838c |
child 1879 | bb114339eb4e |
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 |
|
1844 | 44 |
handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
45 |
if passwd == webPassword client then |
|
46 |
[ModifyClient (\cl -> cl{logonPassed = True}), |
|
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1844
diff
changeset
|
47 |
MoveToLobby] ++ adminNotice |
1844 | 48 |
else |
49 |
[ByeClient "Authentication failed"] |
|
50 |
where |
|
51 |
client = clients IntMap.! clID |
|
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1844
diff
changeset
|
52 |
adminNotice = if isAdministrator client then [AnswerThisClient ["ADMIN_ACCESS"]] else [] |
1804 | 53 |
|
54 |
||
55 |
handleCmd_NotEntered _ _ _ ["DUMP"] = |
|
56 |
[Dump] |
|
57 |
||
58 |
||
59 |
handleCmd_NotEntered clID _ _ _ = [ProtocolError "Incorrect command (state: not entered)"] |