gameServer/HWProtoInRoomState.hs
author unc0rr
Wed, 02 Sep 2009 08:50:45 +0000
changeset 2343 3ab763dc14a3
parent 2337 723f1cbe2ef3
child 2352 7eaf82cf0890
permissions -rw-r--r--
Send leaving message and remove room admin's teams when he exits
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
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     9
--------------------------------------
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    10
import CoreTypes
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    11
import Actions
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    12
import Utils
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    13
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    14
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    15
handleCmd_inRoom :: CmdHandler
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    16
1815
3d62cf9c350e Save some more bytes in protocol
unc0rr
parents: 1814
diff changeset
    17
handleCmd_inRoom clID clients _ ["CHAT", msg] =
3d62cf9c350e Save some more bytes in protocol
unc0rr
parents: 1814
diff changeset
    18
	[AnswerOthersInRoom ["CHAT", clientNick, msg]]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    19
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    20
		clientNick = nick $ clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    21
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
    22
2207
aeea95909aba Make server accpet TEAM_CHAT protocol command, and act like on CHAT command for now
unc0rr
parents: 2126
diff changeset
    23
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
    24
	[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
    25
	where
aeea95909aba Make server accpet TEAM_CHAT protocol command, and act like on CHAT command for now
unc0rr
parents: 2126
diff changeset
    26
		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
    27
aeea95909aba Make server accpet TEAM_CHAT protocol command, and act like on CHAT command for now
unc0rr
parents: 2126
diff changeset
    28
1814
e5391d901cff - Remove client teams on exit
unc0rr
parents: 1813
diff changeset
    29
handleCmd_inRoom clID clients rooms ["PART"] =
2126
cb249fa8e3da - Prevent server from producing zombies
unc0rr
parents: 1977
diff changeset
    30
		[RoomRemoveThisClient "part"]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    31
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    32
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    33
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
    34
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    35
handleCmd_inRoom clID clients rooms ("CFG" : paramName : paramStrs) =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    36
	if isMaster client then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    37
		[ModifyRoom (\r -> r{params = Map.insert paramName paramStrs (params r)})
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    38
		, AnswerOthersInRoom ("CFG" : paramName : paramStrs)]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    39
	else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    40
		[ProtocolError "Not room master"]
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)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    45
	| length hhsInfo == 16 =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    46
	if length (teams room) == 6 then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    47
		[Warning "too many teams"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    48
	else if canAddNumber <= 0 then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    49
		[Warning "too many hedgehogs"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    50
	else if isJust findTeam then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    51
		[Warning "already have a team with same name"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    52
	else if gameinprogress room then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    53
		[Warning "round in progress"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    54
	else if isRestrictedTeams room then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    55
		[Warning "restricted"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    56
	else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    57
		[ModifyRoom (\r -> r{teams = teams r ++ [newTeam]}),
2245
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
    58
		ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1}),
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    59
		AnswerThisClient ["TEAM_ACCEPTED", name],
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    60
		AnswerOthersInRoom $ teamToNet newTeam,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    61
		AnswerOthersInRoom ["TEAM_COLOR", name, color]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    62
		]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    63
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    64
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    65
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    66
		canAddNumber = 48 - (sum . map hhnum $ teams room)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    67
		findTeam = find (\t -> name == teamname t) $ teams room
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    68
		newTeam = (TeamInfo (nick client) name color grave fort voicepack difficulty newTeamHHNum (hhsList hhsInfo))
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    69
		difficulty = fromMaybe 0 (maybeRead difStr :: Maybe Int)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    70
		hhsList [] = []
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    71
		hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    72
		newTeamHHNum = min 4 canAddNumber
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    73
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    74
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    75
handleCmd_inRoom clID clients rooms ["REMOVE_TEAM", teamName] =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    76
	if noSuchTeam then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    77
		[Warning "REMOVE_TEAM: no such team"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    78
	else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    79
		if not $ nick client == teamowner team then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    80
			[ProtocolError "Not team owner!"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    81
		else
2245
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
    82
			[RemoveTeam teamName,
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
    83
			ModifyClient (\c -> c{teamsInGame = teamsInGame c - 1})	
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
    84
			]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    85
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    86
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    87
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    88
		noSuchTeam = isNothing findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    89
		team = fromJust findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    90
		findTeam = find (\t -> teamName == teamname t) $ teams room
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    91
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    92
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    93
handleCmd_inRoom clID clients rooms ["HH_NUM", teamName, numberStr] =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    94
	if not $ isMaster client then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    95
		[ProtocolError "Not room master"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    96
	else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    97
		if hhNumber < 1 || hhNumber > 8 || noSuchTeam || hhNumber > (canAddNumber + (hhnum team)) then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    98
			[]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    99
		else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   100
			[ModifyRoom $ modifyTeam team{hhnum = hhNumber},
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   101
			AnswerOthersInRoom ["HH_NUM", teamName, show hhNumber]]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   102
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   103
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   104
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   105
		hhNumber = fromMaybe 0 (maybeRead numberStr :: Maybe Int)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   106
		noSuchTeam = isNothing findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   107
		team = fromJust findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   108
		findTeam = find (\t -> teamName == teamname t) $ teams room
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   109
		canAddNumber = 48 - (sum . map hhnum $ teams room)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   110
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   111
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   112
handleCmd_inRoom clID clients rooms ["TEAM_COLOR", teamName, newColor] =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   113
	if not $ isMaster client then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   114
		[ProtocolError "Not room master"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   115
	else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   116
		if noSuchTeam then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   117
			[]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   118
		else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   119
			[ModifyRoom $ modifyTeam team{teamcolor = newColor},
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   120
			AnswerOthersInRoom ["TEAM_COLOR", teamName, newColor]]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   121
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   122
		noSuchTeam = isNothing findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   123
		team = fromJust findTeam
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   124
		findTeam = find (\t -> teamName == teamname t) $ teams room
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   125
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   126
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   127
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   128
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   129
handleCmd_inRoom clID clients rooms ["TOGGLE_READY"] =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   130
	[ModifyClient (\c -> c{isReady = not $ isReady client}),
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   131
	ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady client then -1 else 1)}),
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   132
	AnswerThisRoom $ [if isReady client then "NOT_READY" else "READY", nick client]]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   133
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   134
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   135
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   136
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   137
handleCmd_inRoom clID clients rooms ["START_GAME"] =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   138
	if isMaster client && (playersIn room == readyPlayers room) && (not $ gameinprogress room) then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   139
		if enoughClans then
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   140
			[ModifyRoom
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   141
					(\r -> r{
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   142
						gameinprogress = True,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   143
						roundMsgs = empty,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   144
						leftTeams = [],
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   145
						teamsAtStart = teams r}
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   146
					),
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   147
			AnswerThisRoom ["RUN_GAME"]]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   148
		else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   149
			[Warning "Less than two clans!"]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   150
	else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   151
		[]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   152
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   153
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   154
		room = rooms IntMap.! (roomID client)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   155
		enoughClans = not $ null $ drop 1 $ group $ map teamcolor $ teams room
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   156
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   157
2245
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   158
handleCmd_inRoom clID clients rooms ["EM", msg] =
2304
a6e733ad0366 Implement filtering in server
unc0rr
parents: 2245
diff changeset
   159
	if (teamsInGame client > 0) && (isLegalNetCommand msg) then
2245
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   160
		[ModifyRoom (\r -> r{roundMsgs = roundMsgs r |> msg}),
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   161
		AnswerOthersInRoom ["EM", msg]]
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   162
	else
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   163
		[]
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   164
	where
c011aecc95e5 unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents: 2207
diff changeset
   165
		client = clients IntMap.! clID
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   166
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   167
handleCmd_inRoom clID clients rooms ["ROUNDFINISHED"] =
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   168
	if isMaster client then
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   169
		[ModifyRoom
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   170
				(\r -> r{
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   171
					gameinprogress = False,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   172
					readyPlayers = 0,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   173
					roundMsgs = empty,
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   174
					leftTeams = [],
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   175
					teamsAtStart = []}
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   176
				),
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   177
		UnreadyRoomClients
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   178
		] ++ answerRemovedTeams
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   179
	else
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   180
		[]
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   181
	where
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   182
		client = clients IntMap.! clID
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   183
		room = rooms IntMap.! (roomID client)
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   184
		answerRemovedTeams = map (\t -> AnswerThisRoom ["REMOVE_TEAM", t]) $ leftTeams room
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   185
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   186
1831
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   187
handleCmd_inRoom clID clients _ ["TOGGLE_RESTRICT_JOINS"] =
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   188
	if isMaster client then
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   189
		[ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r})]
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   190
	else
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   191
		[ProtocolError "Not room master"]
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   192
	where
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   193
		client = clients IntMap.! clID
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   194
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   195
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   196
handleCmd_inRoom clID clients _ ["TOGGLE_RESTRICT_TEAMS"] =
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   197
	if isMaster client then
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   198
		[ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})]
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   199
	else
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   200
		[ProtocolError "Not room master"]
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   201
	where
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   202
		client = clients IntMap.! clID
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   203
1879
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   204
handleCmd_inRoom clID clients rooms ["KICK", kickNick] =
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   205
	if not $ isMaster client then
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   206
		[]
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   207
	else
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   208
		if noSuchClient then
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   209
			[]
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   210
		else
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   211
			if (kickID == clID) || (roomID client /= roomID kickClient) then
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   212
				[]
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   213
			else
1929
7e6cc8da1c58 - Fix bug with kicking players
unc0rr
parents: 1879
diff changeset
   214
				[KickRoomClient kickID]
1879
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   215
	where
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   216
		client = clients IntMap.! clID
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   217
		maybeClient = Foldable.find (\cl -> kickNick == nick cl) clients
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   218
		noSuchClient = isNothing maybeClient
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   219
		kickClient = fromJust maybeClient
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   220
		kickID = clientUID kickClient
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   221
1831
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   222
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   223
handleCmd_inRoom clID _ _ _ = [ProtocolError "Incorrect command (state: in room)"]