author | unc0rr |
Fri, 04 Sep 2009 12:48:44 +0000 | |
changeset 2349 | ba7a0813c532 |
parent 2155 | d897222d3339 |
child 2352 | 7eaf82cf0890 |
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 |
|
2150
45b695f3a7b9
Forbid room names and nicknames consisting only of space characters
unc0rr
parents:
1879
diff
changeset
|
16 |
[ProtocolError "Nickname already chosen"] |
1804 | 17 |
else if haveSameNick then |
2150
45b695f3a7b9
Forbid room names and nicknames consisting only of space characters
unc0rr
parents:
1879
diff
changeset
|
18 |
[AnswerThisClient ["WARNING", "Nickname collision"]] |
1804 | 19 |
++ [ByeClient ""] |
2150
45b695f3a7b9
Forbid room names and nicknames consisting only of space characters
unc0rr
parents:
1879
diff
changeset
|
20 |
else if illegalName newNick then |
45b695f3a7b9
Forbid room names and nicknames consisting only of space characters
unc0rr
parents:
1879
diff
changeset
|
21 |
[ByeClient "Illegal nickname"] |
1804 | 22 |
else |
23 |
[ModifyClient (\c -> c{nick = newNick}), |
|
24 |
AnswerThisClient ["NICK", newNick]] |
|
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
25 |
++ checkPassword |
1804 | 26 |
where |
27 |
client = clients IntMap.! clID |
|
28 |
haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
|
2349 | 29 |
checkPassword = [CheckRegistered | clientProto client /= 0] |
1804 | 30 |
|
31 |
||
2349 | 32 |
handleCmd_NotEntered clID clients _ ["PROTO", protoNum] |
33 |
| clientProto client > 0 = [ProtocolError "Protocol already known"] |
|
34 |
| parsedProto == 0 = [ProtocolError "Bad number"] |
|
35 |
| otherwise = |
|
36 |
[ModifyClient (\ c -> c{clientProto = parsedProto}), |
|
1804 | 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) |
|
2349 | 42 |
checkPassword = [CheckRegistered | (not . null) (nick client)] |
1841
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 |
|
2349 | 53 |
adminNotice = [AnswerThisClient ["ADMIN_ACCESS"] | isAdministrator client] |
1804 | 54 |
|
55 |
||
2155
d897222d3339
Implement ability for server admin to clear accounts cache
unc0rr
parents:
2150
diff
changeset
|
56 |
--handleCmd_NotEntered _ _ _ ["DUMP"] = |
d897222d3339
Implement ability for server admin to clear accounts cache
unc0rr
parents:
2150
diff
changeset
|
57 |
-- [Dump] |
1804 | 58 |
|
59 |
||
60 |
handleCmd_NotEntered clID _ _ _ = [ProtocolError "Incorrect command (state: not entered)"] |