gameServer/HWProtoCore.hs
changeset 2867 9be6693c78cb
parent 2706 935b7d618cf0
child 2961 3e057dfa601f
equal deleted inserted replaced
2866:450ca0afcd58 2867:9be6693c78cb
    14 handleCmd, handleCmd_loggedin :: CmdHandler
    14 handleCmd, handleCmd_loggedin :: CmdHandler
    15 
    15 
    16 handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]]
    16 handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]]
    17 
    17 
    18 handleCmd clID clients rooms ("QUIT" : xs) =
    18 handleCmd clID clients rooms ("QUIT" : xs) =
    19 	[ByeClient msg]
    19     [ByeClient msg]
    20 	where
    20     where
    21 		msg = if not $ null xs then head xs else ""
    21         msg = if not $ null xs then head xs else ""
    22 
    22 
    23 
    23 
    24 handleCmd clID clients _ ["PONG"] =
    24 handleCmd clID clients _ ["PONG"] =
    25 	if pingsQueue client == 0 then
    25     if pingsQueue client == 0 then
    26 		[ProtocolError "Protocol violation"]
    26         [ProtocolError "Protocol violation"]
    27 	else
    27     else
    28 		[ModifyClient (\cl -> cl{pingsQueue = pingsQueue cl - 1})]
    28         [ModifyClient (\cl -> cl{pingsQueue = pingsQueue cl - 1})]
    29 	where
    29     where
    30 		client = clients IntMap.! clID
    30         client = clients IntMap.! clID
    31 
    31 
    32 
    32 
    33 handleCmd clID clients rooms cmd =
    33 handleCmd clID clients rooms cmd =
    34 	if not $ logonPassed client then
    34     if not $ logonPassed client then
    35 		handleCmd_NotEntered clID clients rooms cmd
    35         handleCmd_NotEntered clID clients rooms cmd
    36 	else
    36     else
    37 		handleCmd_loggedin clID clients rooms cmd
    37         handleCmd_loggedin clID clients rooms cmd
    38 	where
    38     where
    39 		client = clients IntMap.! clID
    39         client = clients IntMap.! clID
    40 
    40 
    41 
    41 
    42 handleCmd_loggedin clID clients rooms ["INFO", asknick] =
    42 handleCmd_loggedin clID clients rooms ["INFO", asknick] =
    43 	if noSuchClient then
    43     if noSuchClient then
    44 		[]
    44         []
    45 	else
    45     else
    46 		[AnswerThisClient
    46         [AnswerThisClient
    47 			["INFO",
    47             ["INFO",
    48 			nick client,
    48             nick client,
    49 			"[" ++ host client ++ "]",
    49             "[" ++ host client ++ "]",
    50 			protoNumber2ver $ clientProto client,
    50             protoNumber2ver $ clientProto client,
    51 			"[" ++ roomInfo ++ "]" ++ roomStatus]]
    51             "[" ++ roomInfo ++ "]" ++ roomStatus]]
    52 	where
    52     where
    53 		maybeClient = find (\cl -> asknick == nick cl) clients
    53         maybeClient = find (\cl -> asknick == nick cl) clients
    54 		noSuchClient = isNothing maybeClient
    54         noSuchClient = isNothing maybeClient
    55 		client = fromJust maybeClient
    55         client = fromJust maybeClient
    56 		room = rooms IntMap.! roomID client
    56         room = rooms IntMap.! roomID client
    57 		roomInfo = if roomID client /= 0 then roomMasterSign ++ "room " ++ (name room) else adminSign ++ "lobby"
    57         roomInfo = if roomID client /= 0 then roomMasterSign ++ "room " ++ (name room) else adminSign ++ "lobby"
    58 		roomMasterSign = if isMaster client then "@" else ""
    58         roomMasterSign = if isMaster client then "@" else ""
    59 		adminSign = if isAdministrator client then "@" else ""
    59         adminSign = if isAdministrator client then "@" else ""
    60 		roomStatus =
    60         roomStatus =
    61 			if gameinprogress room
    61             if gameinprogress room
    62 			then if teamsInGame client > 0 then "(playing)" else "(spectating)"
    62             then if teamsInGame client > 0 then "(playing)" else "(spectating)"
    63 			else ""
    63             else ""
    64 
    64 
    65 
    65 
    66 handleCmd_loggedin clID clients rooms ["FOLLOW", asknick] =
    66 handleCmd_loggedin clID clients rooms ["FOLLOW", asknick] =
    67 	if inLobby || noSuchClient then
    67     if inLobby || noSuchClient then
    68 		[]
    68         []
    69 	else
    69     else
    70 		handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomname]
    70         handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomname]
    71 	where
    71     where
    72 		maybeClient = find (\cl -> asknick == nick cl) clients
    72         maybeClient = find (\cl -> asknick == nick cl) clients
    73 		noSuchClient = isNothing maybeClient
    73         noSuchClient = isNothing maybeClient
    74 		client = fromJust maybeClient
    74         client = fromJust maybeClient
    75 		room = rooms IntMap.! roomID client
    75         room = rooms IntMap.! roomID client
    76 		roomname = (name room)
    76         roomname = (name room)
    77 		inLobby = roomname == ""
    77         inLobby = roomname == ""
    78 
    78 
    79 
    79 
    80 handleCmd_loggedin clID clients rooms cmd =
    80 handleCmd_loggedin clID clients rooms cmd =
    81 	if roomID client == 0 then
    81     if roomID client == 0 then
    82 		handleCmd_lobby clID clients rooms cmd
    82         handleCmd_lobby clID clients rooms cmd
    83 	else
    83     else
    84 		handleCmd_inRoom clID clients rooms cmd
    84         handleCmd_inRoom clID clients rooms cmd
    85 	where
    85     where
    86 		client = clients IntMap.! clID
    86         client = clients IntMap.! clID