author | unc0rr |
Wed, 20 Feb 2013 22:54:16 +0400 | |
changeset 8519 | 98e2dbdda8c0 |
parent 8479 | 8d71109b04d2 |
child 8547 | 6898be8aa261 |
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 |
|
8479
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
14 |
import HWProtoChecker |
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
|
15 |
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
|
16 |
import RoomsAndClients |
4612 | 17 |
import Utils |
1804 | 18 |
|
4989 | 19 |
handleCmd, handleCmd_loggedin :: CmdHandler |
1804 | 20 |
|
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
|
21 |
|
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
|
22 |
handleCmd ["PING"] = answerClient ["PONG"] |
1804 | 23 |
|
24 |
||
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
|
25 |
handleCmd ("QUIT" : xs) = return [ByeClient msg] |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
26 |
where |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8396
diff
changeset
|
27 |
msg = if not $ null xs then head xs else loc "bye" |
1804 | 28 |
|
4568 | 29 |
|
4612 | 30 |
handleCmd ["PONG"] = do |
31 |
cl <- thisClient |
|
32 |
if pingsQueue cl == 0 then |
|
8519
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8479
diff
changeset
|
33 |
return $ actionsPending cl ++ [ModifyClient (\c -> c{actionsPending = []})] |
4612 | 34 |
else |
35 |
return [ModifyClient (\c -> c{pingsQueue = pingsQueue c - 1})] |
|
4568 | 36 |
|
8396 | 37 |
handleCmd ("CMD" : params) = |
38 |
let c = concatMap B.words params in |
|
39 |
if not $ null c then |
|
40 |
h $ (upperCase . head $ c) : tail c |
|
41 |
else |
|
42 |
return [] |
|
43 |
where |
|
44 |
h ["DELEGATE", n] = handleCmd ["DELEGATE", n] |
|
8403
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
45 |
h ["STATS"] = handleCmd ["STATS"] |
8478 | 46 |
h ["PART", msg] = handleCmd ["PART", msg] |
47 |
h ["QUIT", msg] = handleCmd ["QUIT", msg] |
|
8396 | 48 |
h c = return [Warning . B.concat . L.intersperse " " $ "Unknown cmd" : c] |
49 |
||
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
|
50 |
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
|
51 |
(ci, irnc) <- ask |
8479
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
52 |
let cl = irnc `client` ci |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
53 |
if logonPassed cl then |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
54 |
if isChecker cl then |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
55 |
handleCmd_checker cmd |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
56 |
else |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
57 |
handleCmd_loggedin cmd |
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
|
58 |
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
|
59 |
handleCmd_NotEntered cmd |
1862 | 60 |
|
4568 | 61 |
|
4612 | 62 |
handleCmd_loggedin ["INFO", asknick] = do |
63 |
(_, rnc) <- ask |
|
4614 | 64 |
maybeClientId <- clientByNick asknick |
5060
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
65 |
isAdminAsking <- liftM isAdministrator thisClient |
4612 | 66 |
let noSuchClient = isNothing maybeClientId |
67 |
let clientId = fromJust maybeClientId |
|
68 |
let cl = rnc `client` fromJust maybeClientId |
|
69 |
let roomId = clientRoom rnc clientId |
|
70 |
let clRoom = room rnc roomId |
|
71 |
let roomMasterSign = if isMaster cl then "@" else "" |
|
72 |
let adminSign = if isAdministrator cl then "@" else "" |
|
7766 | 73 |
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
|
74 |
let roomStatus = if isJust $ gameInfo clRoom then |
4612 | 75 |
if teamsInGame cl > 0 then "(playing)" else "(spectating)" |
76 |
else |
|
77 |
"" |
|
5060
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
78 |
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
|
79 |
if noSuchClient then |
4612 | 80 |
return [] |
81 |
else |
|
82 |
answerClient [ |
|
83 |
"INFO", |
|
84 |
nick cl, |
|
5060
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
85 |
B.concat ["[", hostStr, "]"], |
4612 | 86 |
protoNumber2ver $ clientProto cl, |
7766 | 87 |
B.concat ["[", rInfo, "]", roomStatus] |
4612 | 88 |
] |
1862 | 89 |
|
90 |
||
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
|
91 |
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
|
92 |
(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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
handleCmd_inRoom cmd |