gameServer/Utils.hs
changeset 15900 fc3cb23fd26f
parent 15721 27eb5abd5058
child 15901 4c58b320056c
equal deleted inserted replaced
15899:6cb7330113d8 15900:fc3cb23fd26f
   156 caseInsensitiveCompare a b = upperCase a == upperCase b
   156 caseInsensitiveCompare a b = upperCase a == upperCase b
   157 
   157 
   158 upperCase :: B.ByteString -> B.ByteString
   158 upperCase :: B.ByteString -> B.ByteString
   159 upperCase = UTF8.fromString . map Char.toUpper . UTF8.toString
   159 upperCase = UTF8.fromString . map Char.toUpper . UTF8.toString
   160 
   160 
       
   161 roomNameByProto :: B.ByteString -> Word16 -> Word16 -> B.ByteString
       
   162 roomNameByProto roomName roomProto clientProto
       
   163     | clientProto < 60 && roomProto /= clientProto = B.concat [B.pack "[v", protoNumber2ver roomProto, B.pack "] ", roomName]
       
   164     | otherwise = roomName
       
   165 
   161 roomInfo :: Word16 -> B.ByteString -> RoomInfo -> [B.ByteString]
   166 roomInfo :: Word16 -> B.ByteString -> RoomInfo -> [B.ByteString]
   162 roomInfo p n r
   167 roomInfo p n r
   163     | p < 46 = [
   168     | p < 46 = [
   164         showB $ isJust $ gameInfo r,
   169         showB $ isJust $ gameInfo r,
   165         name r,
   170         roomNameByProto (name r) (roomProto r) p,
   166         showB $ playersIn r,
   171         showB $ playersIn r,
   167         showB $ length $ teams r,
   172         showB $ length $ teams r,
   168         n,
   173         n,
   169         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   174         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   170         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
   175         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
   171         head (Map.findWithDefault ["Default"] "AMMO" (params r))
   176         head (Map.findWithDefault ["Default"] "AMMO" (params r))
   172         ]
   177         ]
   173     | p < 48 = [
   178     | p < 48 = [
   174         showB $ isJust $ gameInfo r,
   179         showB $ isJust $ gameInfo r,
   175         name r,
   180         roomNameByProto (name r) (roomProto r) p,
       
   181         showB $ playersIn r,
       
   182         showB $ length $ teams r,
       
   183         n,
       
   184         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
       
   185         head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)),
       
   186         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
       
   187         head (Map.findWithDefault ["Default"] "AMMO" (params r))
       
   188         ]
       
   189     | p < 60 = [
       
   190         B.pack roomFlags,
       
   191         roomNameByProto (name r) (roomProto r) p,
   176         showB $ playersIn r,
   192         showB $ playersIn r,
   177         showB $ length $ teams r,
   193         showB $ length $ teams r,
   178         n,
   194         n,
   179         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   195         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   180         head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)),
   196         head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)),
   188         showB $ length $ teams r,
   204         showB $ length $ teams r,
   189         n,
   205         n,
   190         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   206         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   191         head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)),
   207         head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)),
   192         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
   208         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
   193         head (Map.findWithDefault ["Default"] "AMMO" (params r))
   209         head (Map.findWithDefault ["Default"] "AMMO" (params r)),
       
   210         showB $ roomProto r
   194         ]
   211         ]
   195     where
   212     where
   196         roomFlags = concat [
   213         roomFlags = concat [
   197             "-"
   214             "-"
   198             , ['g' | isJust $ gameInfo r]
   215             , ['g' | isJust $ gameInfo r]