author | unc0rr |
Sun, 14 Nov 2010 21:36:47 +0300 | |
branch | 0.9.14.1 |
changeset 4333 | ae71dff40ecc |
parent 4242 | 5e3c5fe2cb14 |
child 4295 | 1f5604cd99be |
child 4334 | 82cfbbab73da |
permissions | -rw-r--r-- |
1804 | 1 |
module HWProtoNEState where |
2 |
||
3 |
import qualified Data.IntMap as IntMap |
|
4242 | 4 |
import Maybe |
1804 | 5 |
import Data.List |
6 |
import Data.Word |
|
7 |
-------------------------------------- |
|
8 |
import CoreTypes |
|
9 |
import Actions |
|
10 |
import Utils |
|
11 |
||
12 |
handleCmd_NotEntered :: CmdHandler |
|
13 |
||
4242 | 14 |
handleCmd_NotEntered clID clients _ ["NICK", newNick] |
15 |
| not . null $ nick client = [ProtocolError "Nickname already chosen"] |
|
16 |
| haveSameNick = [AnswerThisClient ["WARNING", "Nickname already in use"], ByeClient ""] |
|
17 |
| illegalName newNick = [ByeClient "Illegal nickname"] |
|
18 |
| otherwise = |
|
19 |
ModifyClient (\c -> c{nick = newNick}) : |
|
20 |
AnswerThisClient ["NICK", newNick] : |
|
21 |
[CheckRegistered | clientProto client /= 0] |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
22 |
where |
4242 | 23 |
client = clients IntMap.! clID |
24 |
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
|
25 |
|
3536 | 26 |
|
4242 | 27 |
handleCmd_NotEntered clID clients _ ["PROTO", protoNum] |
28 |
| clientProto client > 0 = [ProtocolError "Protocol already known"] |
|
29 |
| parsedProto == 0 = [ProtocolError "Bad number"] |
|
30 |
| otherwise = |
|
31 |
ModifyClient (\c -> c{clientProto = parsedProto}) : |
|
32 |
AnswerThisClient ["PROTO", show parsedProto] : |
|
33 |
[CheckRegistered | (not . null) (nick client)] |
|
34 |
where |
|
35 |
client = clients IntMap.! clID |
|
36 |
parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
|
1879 | 37 |
|
1804 | 38 |
|
4242 | 39 |
handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
40 |
if passwd == webPassword client then |
|
41 |
[ModifyClient (\cl -> cl{logonPassed = True}), |
|
42 |
MoveToLobby] ++ adminNotice |
|
43 |
else |
|
44 |
[ByeClient "Authentication failed"] |
|
45 |
where |
|
46 |
client = clients IntMap.! clID |
|
47 |
adminNotice = [AnswerThisClient ["ADMIN_ACCESS"] | isAdministrator client] |
|
48 |
||
1804 | 49 |
|
2868 | 50 |
handleCmd_NotEntered clID clients _ ["DUMP"] = |
51 |
if isAdministrator (clients IntMap.! clID) then [Dump] else [] |
|
4242 | 52 |
|
1804 | 53 |
|
4242 | 54 |
handleCmd_NotEntered clID _ _ _ = [ProtocolError "Incorrect command (state: not entered)"] |