author | nemo |
Sun, 19 Dec 2010 13:31:55 -0500 | |
changeset 4568 | f85243bf890e |
parent 4337 | 85e02b1a8e8f |
child 4862 | 899b4e3d350a |
permissions | -rw-r--r-- |
1804 | 1 |
module HWProtoNEState where |
2 |
||
3 |
import qualified Data.IntMap as IntMap |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
4 |
import Data.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 |
||
4568 | 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 |
4568 | 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 |
|
4568 | 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 |
|
4568 | 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 [] |
|
4568 | 52 |
|
1804 | 53 |
|
4568 | 54 |
handleCmd_NotEntered clID _ _ _ = [ProtocolError "Incorrect command (state: not entered)"] |