author | unc0rr |
Sun, 12 Apr 2009 15:33:59 +0000 | |
changeset 1969 | 3b04393b1291 |
parent 1879 | bb114339eb4e |
child 2150 | 45b695f3a7b9 |
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 |
|
1879 | 44 |
|
1844 | 45 |
handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
46 |
if passwd == webPassword client then |
|
47 |
[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
|
48 |
MoveToLobby] ++ adminNotice |
1844 | 49 |
else |
50 |
[ByeClient "Authentication failed"] |
|
51 |
where |
|
52 |
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
|
53 |
adminNotice = if isAdministrator client then [AnswerThisClient ["ADMIN_ACCESS"]] else [] |
1804 | 54 |
|
55 |
||
56 |
handleCmd_NotEntered _ _ _ ["DUMP"] = |
|
57 |
[Dump] |
|
58 |
||
59 |
||
60 |
handleCmd_NotEntered clID _ _ _ = [ProtocolError "Incorrect command (state: not entered)"] |