author | mbait |
Mon, 10 May 2010 04:43:07 +0000 | |
changeset 3455 | f33e7ad2261c |
parent 3435 | 4e4f88a7bdf2 |
child 3458 | 11cd56019f00 |
permissions | -rw-r--r-- |
1804 | 1 |
module HWProtoCore where |
2 |
||
3 |
import qualified Data.IntMap as IntMap |
|
1862 | 4 |
import Data.Foldable |
5 |
import Maybe |
|
3435 | 6 |
import Control.Monad.Reader |
1804 | 7 |
-------------------------------------- |
8 |
import CoreTypes |
|
9 |
import Actions |
|
10 |
import Utils |
|
11 |
import HWProtoNEState |
|
12 |
import HWProtoLobbyState |
|
13 |
import HWProtoInRoomState |
|
3435 | 14 |
import HandlerUtils |
15 |
import RoomsAndClients |
|
1804 | 16 |
|
1862 | 17 |
handleCmd, handleCmd_loggedin :: CmdHandler |
1804 | 18 |
|
3435 | 19 |
|
20 |
handleCmd ["PING"] = answerClient ["PONG"] |
|
1804 | 21 |
|
3435 | 22 |
|
23 |
handleCmd ("QUIT" : xs) = return [ByeClient msg] |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
24 |
where |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
25 |
msg = if not $ null xs then head xs else "" |
1804 | 26 |
|
3435 | 27 |
{- |
1928 | 28 |
handleCmd clID clients _ ["PONG"] = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
29 |
if pingsQueue client == 0 then |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
30 |
[ProtocolError "Protocol violation"] |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
31 |
else |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
32 |
[ModifyClient (\cl -> cl{pingsQueue = pingsQueue cl - 1})] |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
33 |
where |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
34 |
client = clients IntMap.! clID |
3435 | 35 |
-} |
1928 | 36 |
|
3435 | 37 |
handleCmd cmd = do |
38 |
(ci, irnc) <- ask |
|
39 |
if logonPassed (irnc `client` ci) then |
|
40 |
handleCmd_NotEntered cmd |
|
41 |
else |
|
42 |
handleCmd_loggedin cmd |
|
1862 | 43 |
|
3435 | 44 |
{- |
1862 | 45 |
handleCmd_loggedin clID clients rooms ["INFO", asknick] = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
46 |
if noSuchClient then |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
47 |
[] |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
48 |
else |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
49 |
[AnswerThisClient |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
50 |
["INFO", |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
51 |
nick client, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
52 |
"[" ++ host client ++ "]", |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
53 |
protoNumber2ver $ clientProto client, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
54 |
"[" ++ roomInfo ++ "]" ++ roomStatus]] |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
55 |
where |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
56 |
maybeClient = find (\cl -> asknick == nick cl) clients |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
57 |
noSuchClient = isNothing maybeClient |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
58 |
client = fromJust maybeClient |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
59 |
room = rooms IntMap.! roomID client |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
60 |
roomInfo = if roomID client /= 0 then roomMasterSign ++ "room " ++ (name room) else adminSign ++ "lobby" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
61 |
roomMasterSign = if isMaster client then "@" else "" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
62 |
adminSign = if isAdministrator client then "@" else "" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
63 |
roomStatus = |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
64 |
if gameinprogress room |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
65 |
then if teamsInGame client > 0 then "(playing)" else "(spectating)" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
66 |
else "" |
1862 | 67 |
|
3435 | 68 |
-} |
1862 | 69 |
|
3435 | 70 |
|
71 |
handleCmd_loggedin cmd = do |
|
72 |
(ci, rnc) <- ask |
|
73 |
if clientRoom rnc ci == lobbyId then |
|
74 |
handleCmd_lobby cmd |
|
75 |
else |
|
76 |
handleCmd_inRoom cmd |