author | unc0rr |
Fri, 27 Mar 2009 20:36:50 +0000 | |
changeset 1928 | 9bf8f4f30d6b |
parent 1879 | bb114339eb4e |
child 1929 | 7e6cc8da1c58 |
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) = |
1879 | 19 |
(if isMaster client then [RemoveRoom] else [RemoveClientTeams clID]) |
1804 | 20 |
++ [ByeClient msg] |
21 |
where |
|
22 |
client = clients IntMap.! clID |
|
23 |
clientNick = nick client |
|
24 |
msg = if not $ null xs then head xs else "" |
|
25 |
||
1862 | 26 |
|
1928 | 27 |
handleCmd clID clients _ ["PONG"] = |
28 |
if pingsQueue client == 0 then |
|
29 |
[ProtocolError "Protocol violation"] |
|
30 |
else |
|
31 |
[ModifyClient (\cl -> cl{pingsQueue = pingsQueue cl - 1})] |
|
32 |
where |
|
33 |
client = clients IntMap.! clID |
|
34 |
||
35 |
||
1804 | 36 |
handleCmd clID clients rooms cmd = |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1814
diff
changeset
|
37 |
if not $ logonPassed client then |
1804 | 38 |
handleCmd_NotEntered clID clients rooms cmd |
1862 | 39 |
else |
40 |
handleCmd_loggedin clID clients rooms cmd |
|
41 |
where |
|
42 |
client = clients IntMap.! clID |
|
43 |
||
44 |
||
45 |
handleCmd_loggedin clID clients rooms ["INFO", asknick] = |
|
46 |
if noSuchClient then |
|
47 |
[] |
|
48 |
else |
|
49 |
[AnswerThisClient |
|
50 |
["INFO", |
|
51 |
nick client, |
|
52 |
"[" ++ host client ++ "]", |
|
53 |
protoNumber2ver $ clientProto client, |
|
54 |
roomInfo]] |
|
55 |
where |
|
56 |
maybeClient = find (\cl -> asknick == nick cl) clients |
|
57 |
noSuchClient = isNothing maybeClient |
|
58 |
client = fromJust maybeClient |
|
59 |
room = rooms IntMap.! roomID client |
|
60 |
roomInfo = if roomID client /= 0 then "room " ++ (name room) else "lobby" |
|
61 |
||
62 |
||
63 |
handleCmd_loggedin clID clients rooms cmd = |
|
64 |
if roomID client == 0 then |
|
1804 | 65 |
handleCmd_lobby clID clients rooms cmd |
66 |
else |
|
67 |
handleCmd_inRoom clID clients rooms cmd |
|
68 |
where |
|
69 |
client = clients IntMap.! clID |