author | unc0rr |
Sat, 19 Jan 2013 00:55:51 +0400 | |
changeset 8402 | 659e043da6da |
parent 8401 | 87410ae372f6 |
child 8403 | fbc6e7602e05 |
permissions | -rw-r--r-- |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
1 |
{-# LANGUAGE OverloadedStrings #-} |
1804 | 2 |
module HWProtoCore where |
3 |
||
4612 | 4 |
import Control.Monad.Reader |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
5 |
import Data.Maybe |
4612 | 6 |
import qualified Data.ByteString.Char8 as B |
8396 | 7 |
import qualified Data.List as L |
1804 | 8 |
-------------------------------------- |
9 |
import CoreTypes |
|
10 |
import Actions |
|
11 |
import HWProtoNEState |
|
12 |
import HWProtoLobbyState |
|
13 |
import HWProtoInRoomState |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
14 |
import HandlerUtils |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
15 |
import RoomsAndClients |
4612 | 16 |
import Utils |
1804 | 17 |
|
4989 | 18 |
handleCmd, handleCmd_loggedin :: CmdHandler |
1804 | 19 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
20 |
|
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
21 |
handleCmd ["PING"] = answerClient ["PONG"] |
1804 | 22 |
|
23 |
||
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
24 |
handleCmd ("QUIT" : xs) = return [ByeClient msg] |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
25 |
where |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8396
diff
changeset
|
26 |
msg = if not $ null xs then head xs else loc "bye" |
1804 | 27 |
|
4568 | 28 |
|
4612 | 29 |
handleCmd ["PONG"] = do |
30 |
cl <- thisClient |
|
31 |
if pingsQueue cl == 0 then |
|
32 |
return [ProtocolError "Protocol violation"] |
|
33 |
else |
|
34 |
return [ModifyClient (\c -> c{pingsQueue = pingsQueue c - 1})] |
|
4568 | 35 |
|
8396 | 36 |
handleCmd ("CMD" : params) = |
37 |
let c = concatMap B.words params in |
|
38 |
if not $ null c then |
|
39 |
h $ (upperCase . head $ c) : tail c |
|
40 |
else |
|
41 |
return [] |
|
42 |
where |
|
43 |
h ["DELEGATE", n] = handleCmd ["DELEGATE", n] |
|
44 |
h c = return [Warning . B.concat . L.intersperse " " $ "Unknown cmd" : c] |
|
45 |
||
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
46 |
handleCmd cmd = do |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
47 |
(ci, irnc) <- ask |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
48 |
if logonPassed (irnc `client` ci) then |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
49 |
handleCmd_loggedin cmd |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
50 |
else |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
51 |
handleCmd_NotEntered cmd |
1862 | 52 |
|
4568 | 53 |
|
4612 | 54 |
handleCmd_loggedin ["INFO", asknick] = do |
55 |
(_, rnc) <- ask |
|
4614 | 56 |
maybeClientId <- clientByNick asknick |
5060
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
57 |
isAdminAsking <- liftM isAdministrator thisClient |
4612 | 58 |
let noSuchClient = isNothing maybeClientId |
59 |
let clientId = fromJust maybeClientId |
|
60 |
let cl = rnc `client` fromJust maybeClientId |
|
61 |
let roomId = clientRoom rnc clientId |
|
62 |
let clRoom = room rnc roomId |
|
63 |
let roomMasterSign = if isMaster cl then "@" else "" |
|
64 |
let adminSign = if isAdministrator cl then "@" else "" |
|
7766 | 65 |
let rInfo = if roomId /= lobbyId then B.concat [roomMasterSign, "room ", name clRoom] else adminSign `B.append` "lobby" |
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5060
diff
changeset
|
66 |
let roomStatus = if isJust $ gameInfo clRoom then |
4612 | 67 |
if teamsInGame cl > 0 then "(playing)" else "(spectating)" |
68 |
else |
|
69 |
"" |
|
5060
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
70 |
let hostStr = if isAdminAsking then host cl else cutHost $ host cl |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
71 |
if noSuchClient then |
4612 | 72 |
return [] |
73 |
else |
|
74 |
answerClient [ |
|
75 |
"INFO", |
|
76 |
nick cl, |
|
5060
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
77 |
B.concat ["[", hostStr, "]"], |
4612 | 78 |
protoNumber2ver $ clientProto cl, |
7766 | 79 |
B.concat ["[", rInfo, "]", roomStatus] |
4612 | 80 |
] |
1862 | 81 |
|
82 |
||
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
83 |
handleCmd_loggedin cmd = do |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
84 |
(ci, rnc) <- ask |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
85 |
if clientRoom rnc ci == lobbyId then |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
86 |
handleCmd_lobby cmd |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
87 |
else |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
88 |
handleCmd_inRoom cmd |