author | unc0rr |
Sun, 22 Mar 2009 21:44:48 +0000 | |
changeset 1913 | 73d2da2df3c2 |
parent 1879 | bb114339eb4e |
child 1928 | 9bf8f4f30d6b |
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 |
|
1804 | 27 |
handleCmd clID clients rooms cmd = |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1814
diff
changeset
|
28 |
if not $ logonPassed client then |
1804 | 29 |
handleCmd_NotEntered clID clients rooms cmd |
1862 | 30 |
else |
31 |
handleCmd_loggedin clID clients rooms cmd |
|
32 |
where |
|
33 |
client = clients IntMap.! clID |
|
34 |
||
35 |
||
36 |
handleCmd_loggedin clID clients rooms ["INFO", asknick] = |
|
37 |
if noSuchClient then |
|
38 |
[] |
|
39 |
else |
|
40 |
[AnswerThisClient |
|
41 |
["INFO", |
|
42 |
nick client, |
|
43 |
"[" ++ host client ++ "]", |
|
44 |
protoNumber2ver $ clientProto client, |
|
45 |
roomInfo]] |
|
46 |
where |
|
47 |
maybeClient = find (\cl -> asknick == nick cl) clients |
|
48 |
noSuchClient = isNothing maybeClient |
|
49 |
client = fromJust maybeClient |
|
50 |
room = rooms IntMap.! roomID client |
|
51 |
roomInfo = if roomID client /= 0 then "room " ++ (name room) else "lobby" |
|
52 |
||
53 |
||
54 |
handleCmd_loggedin clID clients rooms cmd = |
|
55 |
if roomID client == 0 then |
|
1804 | 56 |
handleCmd_lobby clID clients rooms cmd |
57 |
else |
|
58 |
handleCmd_inRoom clID clients rooms cmd |
|
59 |
where |
|
60 |
client = clients IntMap.! clID |