gameServer/HWProtoInRoomState.hs
author unc0rr
Sat, 03 Oct 2009 09:35:14 +0000
changeset 2403 6c5d504af2ba
parent 2381 959da8402cac
child 2408 41ebdb5f1e6e
permissions -rw-r--r--
- Proper /team command implementation - Many fixes for chat bugs in engine, frontend and server
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     1
module HWProtoInRoomState where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     2
1879
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
     3
import qualified Data.Foldable as Foldable
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     4
import qualified Data.IntMap as IntMap
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     5
import qualified Data.Map as Map
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     6
import Data.Sequence(Seq, (|>), (><), fromList, empty)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     7
import Data.List
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     8
import Maybe
2403
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
     9
import qualified Codec.Binary.UTF8.String as UTF8
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    10
--------------------------------------
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    11
import CoreTypes
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    12
import Actions
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    13
import Utils
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    14
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    15
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    16
handleCmd_inRoom :: CmdHandler
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    17
1815
3d62cf9c350e Save some more bytes in protocol
unc0rr
parents: 1814
diff changeset
    18
handleCmd_inRoom clID clients _ ["CHAT", msg] =
3d62cf9c350e Save some more bytes in protocol
unc0rr
parents: 1814
diff changeset
    19
	[AnswerOthersInRoom ["CHAT", clientNick, msg]]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    20
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    21
		clientNick = nick $ clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    22
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
    23
2207
aeea95909aba Make server accpet TEAM_CHAT protocol command, and act like on CHAT command for now
unc0rr
parents: 2126
diff changeset
    24
handleCmd_inRoom clID clients _ ["TEAM_CHAT", msg] =
aeea95909aba Make server accpet TEAM_CHAT protocol command, and act like on CHAT command for now
unc0rr
parents: 2126
diff changeset
    25
	[AnswerOthersInRoom ["TEAM_CHAT", clientNick, msg]]
aeea95909aba Make server accpet TEAM_CHAT protocol command, and act like on CHAT command for now
unc0rr
parents: 2126
diff changeset
    26
	where
aeea95909aba Make server accpet TEAM_CHAT protocol command, and act like on CHAT command for now
unc0rr
parents: 2126
diff changeset
    27
		clientNick = nick $ clients IntMap.! clID
aeea95909aba Make server accpet TEAM_CHAT protocol command, and act like on CHAT command for now
unc0rr
parents: 2126
diff changeset
    28
aeea95909aba Make server accpet TEAM_CHAT protocol command, and act like on CHAT command for now
unc0rr
parents: 2126
diff changeset
    29
1814
e5391d901cff - Remove client teams on exit
unc0rr
parents: 1813
diff changeset
    30
handleCmd_inRoom clID clients rooms ["PART"] =
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    31
	[RoomRemoveThisClient "part"]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    32
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    33
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    34
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
    35
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    36
handleCmd_inRoom clID clients rooms ("CFG" : paramName : paramStrs)
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    37
	| isMaster client =
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    38
		[ModifyRoom (\r -> r{params = Map.insert paramName paramStrs (params r)}),
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    39
		AnswerOthersInRoom ("CFG" : paramName : paramStrs)]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    40
	| otherwise = [ProtocolError "Not room master"]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    41
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    42
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    43
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    44
handleCmd_inRoom clID clients rooms ("ADD_TEAM" : name : color : grave : fort : voicepack : difStr : hhsInfo)
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    45
	| length hhsInfo /= 16 = []
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    46
	| length (teams room) == 6 = [Warning "too many teams"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    47
	| canAddNumber <= 0 = [Warning "too many hedgehogs"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    48
	| isJust findTeam = [Warning "There's already a team with same name in the list"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    49
	| gameinprogress room = [Warning "round in progress"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    50
	| isRestrictedTeams room = [Warning "restricted"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    51
	| otherwise =
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    52
		[ModifyRoom (\r -> r{teams = teams r ++ [newTeam]}),
2403
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
    53
		ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = color}),
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    54
		AnswerThisClient ["TEAM_ACCEPTED", name],
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    55
		AnswerOthersInRoom $ teamToNet newTeam,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    56
		AnswerOthersInRoom ["TEAM_COLOR", name, color]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    57
		]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    58
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    59
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    60
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    61
		canAddNumber = 48 - (sum . map hhnum $ teams room)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    62
		findTeam = find (\t -> name == teamname t) $ teams room
2403
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
    63
		newTeam = (TeamInfo clID (nick client) name color grave fort voicepack difficulty newTeamHHNum (hhsList hhsInfo))
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    64
		difficulty = fromMaybe 0 (maybeRead difStr :: Maybe Int)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    65
		hhsList [] = []
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    66
		hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    67
		newTeamHHNum = min 4 canAddNumber
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    68
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    69
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    70
handleCmd_inRoom clID clients rooms ["REMOVE_TEAM", teamName]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    71
	| noSuchTeam = [Warning "REMOVE_TEAM: no such team"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    72
	| nick client /= teamowner team = [ProtocolError "Not team owner!"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    73
	| otherwise =
2245
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
    74
			[RemoveTeam teamName,
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    75
			ModifyClient (\c -> c{teamsInGame = teamsInGame c - 1})
2245
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
    76
			]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    77
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    78
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    79
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    80
		noSuchTeam = isNothing findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    81
		team = fromJust findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    82
		findTeam = find (\t -> teamName == teamname t) $ teams room
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    83
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    84
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    85
handleCmd_inRoom clID clients rooms ["HH_NUM", teamName, numberStr]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    86
	| not $ isMaster client = [ProtocolError "Not room master"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    87
	| hhNumber < 1 || hhNumber > 8 || noSuchTeam || hhNumber > (canAddNumber + (hhnum team)) = []
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    88
	| otherwise =
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    89
		[ModifyRoom $ modifyTeam team{hhnum = hhNumber},
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
    90
		AnswerOthersInRoom ["HH_NUM", teamName, show hhNumber]]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    91
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    92
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    93
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    94
		hhNumber = fromMaybe 0 (maybeRead numberStr :: Maybe Int)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    95
		noSuchTeam = isNothing findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    96
		team = fromJust findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    97
		findTeam = find (\t -> teamName == teamname t) $ teams room
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    98
		canAddNumber = 48 - (sum . map hhnum $ teams room)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    99
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   100
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   101
handleCmd_inRoom clID clients rooms ["TEAM_COLOR", teamName, newColor]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   102
	| not $ isMaster client = [ProtocolError "Not room master"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   103
	| noSuchTeam = []
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   104
	| otherwise = [ModifyRoom $ modifyTeam team{teamcolor = newColor},
2403
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   105
			AnswerOthersInRoom ["TEAM_COLOR", teamName, newColor],
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   106
			ModifyClient2 (teamownerId team) (\c -> c{clientClan = newColor})]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   107
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   108
		noSuchTeam = isNothing findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   109
		team = fromJust findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   110
		findTeam = find (\t -> teamName == teamname t) $ teams room
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   111
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   112
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   113
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   114
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   115
handleCmd_inRoom clID clients rooms ["TOGGLE_READY"] =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   116
	[ModifyClient (\c -> c{isReady = not $ isReady client}),
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   117
	ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady client then -1 else 1)}),
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   118
	AnswerThisRoom [if isReady client then "NOT_READY" else "READY", nick client]]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   119
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   120
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   121
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   122
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   123
handleCmd_inRoom clID clients rooms ["START_GAME"] =
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   124
	if isMaster client && (playersIn room == readyPlayers room) && (not . gameinprogress) room then
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   125
		if enoughClans then
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   126
			[ModifyRoom
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   127
					(\r -> r{
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   128
						gameinprogress = True,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   129
						roundMsgs = empty,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   130
						leftTeams = [],
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   131
						teamsAtStart = teams r}
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   132
					),
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   133
			AnswerThisRoom ["RUN_GAME"]]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   134
		else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   135
			[Warning "Less than two clans!"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   136
	else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   137
		[]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   138
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   139
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   140
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   141
		enoughClans = not $ null $ drop 1 $ group $ map teamcolor $ teams room
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   142
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   143
2245
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   144
handleCmd_inRoom clID clients rooms ["EM", msg] =
2381
959da8402cac Don't store keepalive messages in game server spectators buffer
unc0rr
parents: 2352
diff changeset
   145
	if (teamsInGame client > 0) && isLegal then
959da8402cac Don't store keepalive messages in game server spectators buffer
unc0rr
parents: 2352
diff changeset
   146
		(AnswerOthersInRoom ["EM", msg]) : [ModifyRoom (\r -> r{roundMsgs = roundMsgs r |> msg}) | not isKeepAlive]
2245
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   147
	else
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   148
		[]
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   149
	where
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   150
		client = clients IntMap.! clID
2381
959da8402cac Don't store keepalive messages in game server spectators buffer
unc0rr
parents: 2352
diff changeset
   151
		(isLegal, isKeepAlive) = checkNetCmd msg
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   152
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   153
handleCmd_inRoom clID clients rooms ["ROUNDFINISHED"] =
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   154
	if isMaster client then
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   155
		[ModifyRoom
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   156
				(\r -> r{
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   157
					gameinprogress = False,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   158
					readyPlayers = 0,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   159
					roundMsgs = empty,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   160
					leftTeams = [],
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   161
					teamsAtStart = []}
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   162
				),
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   163
		UnreadyRoomClients
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   164
		] ++ answerRemovedTeams
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   165
	else
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   166
		[]
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   167
	where
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   168
		client = clients IntMap.! clID
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   169
		room = rooms IntMap.! (roomID client)
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   170
		answerRemovedTeams = map (\t -> AnswerThisRoom ["REMOVE_TEAM", t]) $ leftTeams room
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   171
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   172
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   173
handleCmd_inRoom clID clients _ ["TOGGLE_RESTRICT_JOINS"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   174
	| isMaster client = [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r})]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   175
	| otherwise = [ProtocolError "Not room master"]
1831
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   176
	where
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   177
		client = clients IntMap.! clID
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   178
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   179
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   180
handleCmd_inRoom clID clients _ ["TOGGLE_RESTRICT_TEAMS"]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   181
	| isMaster client = [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})]
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   182
	| otherwise = [ProtocolError "Not room master"]
1831
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   183
	where
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   184
		client = clients IntMap.! clID
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   185
1879
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   186
handleCmd_inRoom clID clients rooms ["KICK", kickNick] =
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2337
diff changeset
   187
	[KickRoomClient kickID | isMaster client && not noSuchClient && (kickID /= clID) && (roomID client == roomID kickClient)]
1879
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   188
	where
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   189
		client = clients IntMap.! clID
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   190
		maybeClient = Foldable.find (\cl -> kickNick == nick cl) clients
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   191
		noSuchClient = isNothing maybeClient
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   192
		kickClient = fromJust maybeClient
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   193
		kickID = clientUID kickClient
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   194
1831
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   195
2403
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   196
handleCmd_inRoom clID clients _ ["TEAMCHAT", msg] =
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   197
	if (teamsInGame client > 0) then
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   198
		[AnswerSameClan ["EM", engineMsg]]
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   199
	else
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   200
		[]
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   201
	where
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   202
		client = clients IntMap.! clID
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   203
		engineMsg = toEngineMsg $ 'b' : (nick client ++ "(team): " ++ decodedMsg ++ "\x20\x20")
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   204
		decodedMsg = UTF8.decodeString msg
6c5d504af2ba - Proper /team command implementation
unc0rr
parents: 2381
diff changeset
   205
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   206
handleCmd_inRoom clID _ _ _ = [ProtocolError "Incorrect command (state: in room)"]