author | unc0rr |
Thu, 05 Mar 2009 21:41:18 +0000 | |
changeset 1863 | 705c01571196 |
parent 1862 | 7f303aa066da |
child 1879 | bb114339eb4e |
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) = |
19 |
(if isMaster client then [RemoveRoom] else removeClientTeams) |
|
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 "" |
|
1814 | 25 |
room = rooms IntMap.! (roomID client) |
26 |
clientTeams = filter (\t -> teamowner t == nick client) $ teams room |
|
27 |
removeClientTeams = map (RemoveTeam . teamname) clientTeams |
|
1804 | 28 |
|
1862 | 29 |
|
1804 | 30 |
handleCmd clID clients rooms cmd = |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1814
diff
changeset
|
31 |
if not $ logonPassed client then |
1804 | 32 |
handleCmd_NotEntered clID clients rooms cmd |
1862 | 33 |
else |
34 |
handleCmd_loggedin clID clients rooms cmd |
|
35 |
where |
|
36 |
client = clients IntMap.! clID |
|
37 |
||
38 |
||
39 |
handleCmd_loggedin clID clients rooms ["INFO", asknick] = |
|
40 |
if noSuchClient then |
|
41 |
[] |
|
42 |
else |
|
43 |
[AnswerThisClient |
|
44 |
["INFO", |
|
45 |
nick client, |
|
46 |
"[" ++ host client ++ "]", |
|
47 |
protoNumber2ver $ clientProto client, |
|
48 |
roomInfo]] |
|
49 |
where |
|
50 |
maybeClient = find (\cl -> asknick == nick cl) clients |
|
51 |
noSuchClient = isNothing maybeClient |
|
52 |
client = fromJust maybeClient |
|
53 |
room = rooms IntMap.! roomID client |
|
54 |
roomInfo = if roomID client /= 0 then "room " ++ (name room) else "lobby" |
|
55 |
||
56 |
||
57 |
handleCmd_loggedin clID clients rooms cmd = |
|
58 |
if roomID client == 0 then |
|
1804 | 59 |
handleCmd_lobby clID clients rooms cmd |
60 |
else |
|
61 |
handleCmd_inRoom clID clients rooms cmd |
|
62 |
where |
|
63 |
client = clients IntMap.! clID |