author | unc0rr |
Sun, 18 Oct 2009 13:04:41 +0000 | |
changeset 2542 | 4f2d6e18616d |
parent 2352 | 7eaf82cf0890 |
child 2747 | 7889a3a9724f |
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 |
||
2352 | 14 |
handleCmd_NotEntered clID clients _ ["NICK", newNick] |
15 |
| not . null $ nick client = [ProtocolError "Nickname already chosen"] |
|
16 |
| haveSameNick = [AnswerThisClient ["WARNING", "Nickname collision"], ByeClient ""] |
|
17 |
| illegalName newNick = [ByeClient "Illegal nickname"] |
|
18 |
| otherwise = |
|
19 |
ModifyClient (\c -> c{nick = newNick}) : |
|
20 |
AnswerThisClient ["NICK", newNick] : |
|
21 |
[CheckRegistered | clientProto client /= 0] |
|
1804 | 22 |
where |
23 |
client = clients IntMap.! clID |
|
24 |
haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
|
25 |
||
26 |
||
2349 | 27 |
handleCmd_NotEntered clID clients _ ["PROTO", protoNum] |
28 |
| clientProto client > 0 = [ProtocolError "Protocol already known"] |
|
29 |
| parsedProto == 0 = [ProtocolError "Bad number"] |
|
30 |
| otherwise = |
|
2352 | 31 |
ModifyClient (\c -> c{clientProto = parsedProto}) : |
32 |
AnswerThisClient ["PROTO", show parsedProto] : |
|
33 |
[CheckRegistered | (not . null) (nick client)] |
|
1804 | 34 |
where |
35 |
client = clients IntMap.! clID |
|
36 |
parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
|
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
37 |
|
1879 | 38 |
|
1844 | 39 |
handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
40 |
if passwd == webPassword client then |
|
41 |
[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
|
42 |
MoveToLobby] ++ adminNotice |
1844 | 43 |
else |
44 |
[ByeClient "Authentication failed"] |
|
45 |
where |
|
46 |
client = clients IntMap.! clID |
|
2349 | 47 |
adminNotice = [AnswerThisClient ["ADMIN_ACCESS"] | isAdministrator client] |
1804 | 48 |
|
49 |
||
2155
d897222d3339
Implement ability for server admin to clear accounts cache
unc0rr
parents:
2150
diff
changeset
|
50 |
--handleCmd_NotEntered _ _ _ ["DUMP"] = |
d897222d3339
Implement ability for server admin to clear accounts cache
unc0rr
parents:
2150
diff
changeset
|
51 |
-- [Dump] |
1804 | 52 |
|
53 |
||
54 |
handleCmd_NotEntered clID _ _ _ = [ProtocolError "Incorrect command (state: not entered)"] |