gameServer/Utils.hs
branchqmlfrontend
changeset 10515 7705784902e1
parent 10511 c33b2f001730
child 10524 2bc0ff00e95b
equal deleted inserted replaced
10458:f7a199346c3e 10515:7705784902e1
       
     1 {-
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
       
    17  \-}
       
    18 
     1 {-# LANGUAGE OverloadedStrings #-}
    19 {-# LANGUAGE OverloadedStrings #-}
     2 module Utils where
    20 module Utils where
     3 
    21 
     4 import Data.Char
    22 import Data.Char
     5 import Data.Word
    23 import Data.Word
   138         n,
   156         n,
   139         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   157         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   140         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
   158         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
   141         head (Map.findWithDefault ["Default"] "AMMO" (params r))
   159         head (Map.findWithDefault ["Default"] "AMMO" (params r))
   142         ]
   160         ]
   143     | otherwise = [
   161     | p < 48 = [
   144         showB $ isJust $ gameInfo r,
   162         showB $ isJust $ gameInfo r,
   145         name r,
   163         name r,
   146         showB $ playersIn r,
   164         showB $ playersIn r,
   147         showB $ length $ teams r,
   165         showB $ length $ teams r,
   148         n,
   166         n,
   149         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   167         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
   150         head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)),
   168         head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)),
   151         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
   169         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
   152         head (Map.findWithDefault ["Default"] "AMMO" (params r))
   170         head (Map.findWithDefault ["Default"] "AMMO" (params r))
   153         ]
   171         ]
       
   172     | otherwise = [
       
   173         B.pack roomFlags,
       
   174         name r,
       
   175         showB $ playersIn r,
       
   176         showB $ length $ teams r,
       
   177         n,
       
   178         Map.findWithDefault "+rnd+" "MAP" (mapParams r),
       
   179         head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)),
       
   180         head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
       
   181         head (Map.findWithDefault ["Default"] "AMMO" (params r))
       
   182         ]
       
   183     where
       
   184         roomFlags = concat [
       
   185             "-"
       
   186             , ['g' | isJust $ gameInfo r]
       
   187             , ['p' | B.null $ password r]
       
   188             , ['j' | isRestrictedJoins  r]
       
   189             , ['r' | isRegisteredOnly  r]
       
   190             ]
   154 
   191 
   155 answerFullConfigParams ::
   192 answerFullConfigParams ::
   156             ClientInfo
   193             ClientInfo
   157             -> Map.Map B.ByteString B.ByteString
   194             -> Map.Map B.ByteString B.ByteString
   158             -> Map.Map B.ByteString [B.ByteString]
   195             -> Map.Map B.ByteString [B.ByteString]