author | nemo |
Fri, 14 May 2010 23:42:56 +0000 | |
changeset 3461 | 0781275649e9 |
parent 3458 | 11cd56019f00 |
child 3500 | af8390d807d6 |
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 |
|
3458 | 7 |
import Control.Monad.Reader |
1804 | 8 |
-------------------------------------- |
9 |
import CoreTypes |
|
10 |
import Actions |
|
11 |
import Utils |
|
3458 | 12 |
import RoomsAndClients |
1804 | 13 |
|
14 |
handleCmd_NotEntered :: CmdHandler |
|
15 |
||
3458 | 16 |
handleCmd_NotEntered ["NICK", newNick] = do |
17 |
(ci, irnc) <- ask |
|
18 |
let cl = irnc `client` ci |
|
19 |
if not . null $ nick cl then return [ProtocolError "Nickname already chosen"] |
|
20 |
else |
|
21 |
if haveSameNick irnc then return [AnswerClients [sendChan cl] ["WARNING", "Nickname already in use"], ByeClient ""] |
|
22 |
else |
|
23 |
if illegalName newNick then return [ByeClient "Illegal nickname"] |
|
24 |
else |
|
25 |
return $ |
|
26 |
ModifyClient (\c -> c{nick = newNick}) : |
|
27 |
AnswerClients [sendChan cl] ["NICK", newNick] : |
|
28 |
[CheckRegistered | clientProto cl /= 0] |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
29 |
where |
3458 | 30 |
haveSameNick irnc = False --isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
1804 | 31 |
|
3458 | 32 |
handleCmd_NotEntered ["PROTO", protoNum] = do |
33 |
(ci, irnc) <- ask |
|
34 |
let cl = irnc `client` ci |
|
35 |
if clientProto cl > 0 then return [ProtocolError "Protocol already known"] |
|
36 |
else |
|
37 |
if parsedProto == 0 then return [ProtocolError "Bad number"] |
|
38 |
else |
|
39 |
return $ |
|
40 |
ModifyClient (\c -> c{clientProto = parsedProto}) : |
|
41 |
AnswerClients [sendChan cl] ["PROTO", show parsedProto] : |
|
42 |
[CheckRegistered | (not . null) (nick cl)] |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
43 |
where |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
44 |
parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1834
diff
changeset
|
45 |
|
3458 | 46 |
{- |
1879 | 47 |
|
1844 | 48 |
handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
49 |
if passwd == webPassword client then |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
50 |
[ModifyClient (\cl -> cl{logonPassed = True}), |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
51 |
MoveToLobby] ++ adminNotice |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
52 |
else |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
53 |
[ByeClient "Authentication failed"] |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
54 |
where |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
55 |
client = clients IntMap.! clID |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
56 |
adminNotice = [AnswerThisClient ["ADMIN_ACCESS"] | isAdministrator client] |
1804 | 57 |
|
58 |
||
2868 | 59 |
handleCmd_NotEntered clID clients _ ["DUMP"] = |
60 |
if isAdministrator (clients IntMap.! clID) then [Dump] else [] |
|
3435 | 61 |
-} |
1804 | 62 |
|
3435 | 63 |
handleCmd_NotEntered _ = return [ProtocolError "Incorrect command (state: not entered)"] |