author | unc0rr |
Fri, 12 Nov 2010 19:48:51 +0300 | |
branch | mbait-mangen |
changeset 2566 | 4fb45d86d5e8 |
parent 2318 | f3407513dc42 |
child 2706 | 935b7d618cf0 |
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 |
|
1804 | 6 |
-------------------------------------- |
7 |
import CoreTypes |
|
8 |
import Actions |
|
9 |
import Utils |
|
10 |
import HWProtoNEState |
|
11 |
import HWProtoLobbyState |
|
12 |
import HWProtoInRoomState |
|
13 |
||
1862 | 14 |
handleCmd, handleCmd_loggedin :: CmdHandler |
1804 | 15 |
|
16 |
handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]] |
|
17 |
||
1814 | 18 |
handleCmd clID clients rooms ("QUIT" : xs) = |
1929 | 19 |
[ByeClient msg] |
1804 | 20 |
where |
21 |
msg = if not $ null xs then head xs else "" |
|
22 |
||
1862 | 23 |
|
1928 | 24 |
handleCmd clID clients _ ["PONG"] = |
25 |
if pingsQueue client == 0 then |
|
26 |
[ProtocolError "Protocol violation"] |
|
27 |
else |
|
28 |
[ModifyClient (\cl -> cl{pingsQueue = pingsQueue cl - 1})] |
|
29 |
where |
|
30 |
client = clients IntMap.! clID |
|
31 |
||
32 |
||
1804 | 33 |
handleCmd clID clients rooms cmd = |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1814
diff
changeset
|
34 |
if not $ logonPassed client then |
1804 | 35 |
handleCmd_NotEntered clID clients rooms cmd |
1862 | 36 |
else |
37 |
handleCmd_loggedin clID clients rooms cmd |
|
38 |
where |
|
39 |
client = clients IntMap.! clID |
|
40 |
||
41 |
||
42 |
handleCmd_loggedin clID clients rooms ["INFO", asknick] = |
|
43 |
if noSuchClient then |
|
44 |
[] |
|
45 |
else |
|
46 |
[AnswerThisClient |
|
47 |
["INFO", |
|
48 |
nick client, |
|
49 |
"[" ++ host client ++ "]", |
|
50 |
protoNumber2ver $ clientProto client, |
|
2311 | 51 |
"[" ++ roomInfo ++ "]" ++ roomStatus]] |
1862 | 52 |
where |
53 |
maybeClient = find (\cl -> asknick == nick cl) clients |
|
54 |
noSuchClient = isNothing maybeClient |
|
55 |
client = fromJust maybeClient |
|
56 |
room = rooms IntMap.! roomID client |
|
2126 | 57 |
roomInfo = if roomID client /= 0 then roomMasterSign ++ "room " ++ (name room) else adminSign ++ "lobby" |
58 |
roomMasterSign = if isMaster client then "@" else "" |
|
59 |
adminSign = if isAdministrator client then "@" else "" |
|
2311 | 60 |
roomStatus = |
61 |
if gameinprogress room |
|
2318 | 62 |
then if teamsInGame client > 0 then "(playing)" else "(spectating)" |
2311 | 63 |
else "" |
1862 | 64 |
|
65 |
||
66 |
handleCmd_loggedin clID clients rooms cmd = |
|
67 |
if roomID client == 0 then |
|
1804 | 68 |
handleCmd_lobby clID clients rooms cmd |
69 |
else |
|
70 |
handleCmd_inRoom clID clients rooms cmd |
|
71 |
where |
|
72 |
client = clients IntMap.! clID |