author | nemo |
Sat, 01 Nov 2014 11:20:37 -0400 | |
changeset 10462 | dd3cf0c91cc9 |
parent 10212 | 5fb3bb2de9d2 |
child 10460 | 8dcea9087d75 |
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 |
1804 | 7 |
-------------------------------------- |
8 |
import CoreTypes |
|
9 |
import HWProtoNEState |
|
10 |
import HWProtoLobbyState |
|
11 |
import HWProtoInRoomState |
|
8479
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
12 |
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
|
13 |
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
|
14 |
import RoomsAndClients |
4612 | 15 |
import Utils |
1804 | 16 |
|
4989 | 17 |
handleCmd, handleCmd_loggedin :: CmdHandler |
1804 | 18 |
|
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
|
19 |
|
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 |
handleCmd ["PING"] = answerClient ["PONG"] |
1804 | 21 |
|
22 |
||
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
|
23 |
handleCmd ("QUIT" : xs) = return [ByeClient msg] |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
24 |
where |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8396
diff
changeset
|
25 |
msg = if not $ null xs then head xs else loc "bye" |
1804 | 26 |
|
4568 | 27 |
|
4612 | 28 |
handleCmd ["PONG"] = do |
29 |
cl <- thisClient |
|
30 |
if pingsQueue cl == 0 then |
|
8897
d6c310c65c91
- Revert server workaround over desync from r98e2dbdda8c0
unc0rr
parents:
8547
diff
changeset
|
31 |
return [ProtocolError "Protocol violation"] |
4612 | 32 |
else |
33 |
return [ModifyClient (\c -> c{pingsQueue = pingsQueue c - 1})] |
|
4568 | 34 |
|
10039 | 35 |
handleCmd ["CMD", parameters] = uncurry h $ extractParameters parameters |
8396 | 36 |
where |
9105 | 37 |
h "DELEGATE" n | not $ B.null n = handleCmd ["DELEGATE", n] |
10195 | 38 |
h "SAVEROOM" n | not $ B.null n = handleCmd ["SAVEROOM", n] |
39 |
h "LOADROOM" n | not $ B.null n = handleCmd ["LOADROOM", n] |
|
10194 | 40 |
h "SAVE" n | not $ B.null n = handleCmd ["SAVE", n] |
41 |
h "DELETE" n | not $ B.null n = handleCmd ["DELETE", n] |
|
9105 | 42 |
h "STATS" _ = handleCmd ["STATS"] |
43 |
h "PART" m | not $ B.null m = handleCmd ["PART", m] |
|
44 |
| otherwise = handleCmd ["PART"] |
|
45 |
h "QUIT" m | not $ B.null m = handleCmd ["QUIT", m] |
|
46 |
| otherwise = handleCmd ["QUIT"] |
|
47 |
h "RND" p = handleCmd ("RND" : B.words p) |
|
48 |
h "GLOBAL" p = do |
|
9035
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
9034
diff
changeset
|
49 |
cl <- thisClient |
8547
6898be8aa261
Global notice with /global command. Can now warn users when doing server restart.
unc0rr
parents:
8519
diff
changeset
|
50 |
rnc <- liftM snd ask |
6898be8aa261
Global notice with /global command. Can now warn users when doing server restart.
unc0rr
parents:
8519
diff
changeset
|
51 |
let chans = map (sendChan . client rnc) $ allClients rnc |
9105 | 52 |
return [AnswerClients chans ["CHAT", "[global notice]", p] | isAdministrator cl] |
9448 | 53 |
h "WATCH" f = return [QueryReplay f] |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9448
diff
changeset
|
54 |
h "FIX" _ = handleCmd ["FIX"] |
9770 | 55 |
h "UNFIX" _ = handleCmd ["UNFIX"] |
9787 | 56 |
h "GREETING" msg = handleCmd ["GREETING", msg] |
10039 | 57 |
h "CALLVOTE" msg | B.null msg = handleCmd ["CALLVOTE"] |
58 |
| otherwise = let (c, p) = extractParameters msg in |
|
59 |
if B.null p then handleCmd ["CALLVOTE", c] else handleCmd ["CALLVOTE", c, p] |
|
60 |
h "VOTE" msg = handleCmd ["VOTE", upperCase msg] |
|
10195 | 61 |
h c p = return [Warning $ B.concat ["Unknown cmd: /", c, " ", p]] |
8396 | 62 |
|
10039 | 63 |
extractParameters p = let (a, b) = B.break (== ' ') p in (upperCase a, B.dropWhile (== ' ') b) |
64 |
||
65 |
||
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
|
66 |
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
|
67 |
(ci, irnc) <- ask |
8479
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
68 |
let cl = irnc `client` ci |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
69 |
if logonPassed cl then |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
70 |
if isChecker cl then |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
71 |
handleCmd_checker cmd |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
72 |
else |
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8478
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
handleCmd_NotEntered cmd |
1862 | 76 |
|
4568 | 77 |
|
4612 | 78 |
handleCmd_loggedin ["INFO", asknick] = do |
79 |
(_, rnc) <- ask |
|
4614 | 80 |
maybeClientId <- clientByNick asknick |
5060
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
81 |
isAdminAsking <- liftM isAdministrator thisClient |
4612 | 82 |
let noSuchClient = isNothing maybeClientId |
83 |
let clientId = fromJust maybeClientId |
|
84 |
let cl = rnc `client` fromJust maybeClientId |
|
85 |
let roomId = clientRoom rnc clientId |
|
86 |
let clRoom = room rnc roomId |
|
9061 | 87 |
let roomMasterSign = if isMaster cl then "+" else "" |
4612 | 88 |
let adminSign = if isAdministrator cl then "@" else "" |
9061 | 89 |
let rInfo = if roomId /= lobbyId then B.concat [adminSign, 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
|
90 |
let roomStatus = if isJust $ gameInfo clRoom then |
4612 | 91 |
if teamsInGame cl > 0 then "(playing)" else "(spectating)" |
92 |
else |
|
93 |
"" |
|
10061
b7161f00a6ca
hide complete IP of other users, when non-admin requests player info. showing the first two parts of the IP was kinda pointless to begin with (what for?) and has recently lead to increased abuse and lobby flooding due to bots collecting/posting IP tracking information
sheepluva
parents:
10039
diff
changeset
|
94 |
let hostStr = if isAdminAsking then host cl else B.empty |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2706
diff
changeset
|
95 |
if noSuchClient then |
4612 | 96 |
return [] |
97 |
else |
|
98 |
answerClient [ |
|
99 |
"INFO", |
|
100 |
nick cl, |
|
5060
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
101 |
B.concat ["[", hostStr, "]"], |
4612 | 102 |
protoNumber2ver $ clientProto cl, |
7766 | 103 |
B.concat ["[", rInfo, "]", roomStatus] |
4612 | 104 |
] |
1862 | 105 |
|
106 |
||
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
|
107 |
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
|
108 |
(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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
handleCmd_inRoom cmd |