equal
deleted
inserted
replaced
14 * You should have received a copy of the GNU General Public License |
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 |
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. |
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 \-} |
17 \-} |
18 |
18 |
19 {-# LANGUAGE OverloadedStrings #-} |
19 {-# LANGUAGE OverloadedStrings,CPP #-} |
20 module Utils where |
20 module Utils where |
21 |
21 |
22 import Data.Char |
22 import Data.Char |
23 import Data.Word |
23 import Data.Word |
24 import qualified Data.Map as Map |
24 import qualified Data.Map as Map |
30 import Control.Monad |
30 import Control.Monad |
31 import qualified Data.ByteString.Lazy as BL |
31 import qualified Data.ByteString.Lazy as BL |
32 import qualified Data.ByteString.Char8 as B |
32 import qualified Data.ByteString.Char8 as B |
33 import qualified Data.ByteString.UTF8 as UTF8 |
33 import qualified Data.ByteString.UTF8 as UTF8 |
34 import Data.Maybe |
34 import Data.Maybe |
|
35 #if defined(OFFICIAL_SERVER) |
35 import qualified Data.Aeson.Types as Aeson |
36 import qualified Data.Aeson.Types as Aeson |
36 import qualified Data.Text as Text |
37 import qualified Data.Text as Text |
|
38 #endif |
37 ------------------------------------------------- |
39 ------------------------------------------------- |
38 import CoreTypes |
40 import CoreTypes |
39 |
41 |
40 |
42 |
41 sockAddr2String :: SockAddr -> IO B.ByteString |
43 sockAddr2String :: SockAddr -> IO B.ByteString |
257 | otherwise = '_' |
259 | otherwise = '_' |
258 |
260 |
259 isRegistered :: ClientInfo -> Bool |
261 isRegistered :: ClientInfo -> Bool |
260 isRegistered = (<) 0 . B.length . webPassword |
262 isRegistered = (<) 0 . B.length . webPassword |
261 |
263 |
|
264 #if defined(OFFICIAL_SERVER) |
262 instance Aeson.ToJSON B.ByteString where |
265 instance Aeson.ToJSON B.ByteString where |
263 toJSON = Aeson.toJSON . B.unpack |
266 toJSON = Aeson.toJSON . B.unpack |
264 |
267 |
265 instance Aeson.FromJSON B.ByteString where |
268 instance Aeson.FromJSON B.ByteString where |
266 parseJSON = Aeson.withText "ByteString" $ pure . B.pack . Text.unpack |
269 parseJSON = Aeson.withText "ByteString" $ pure . B.pack . Text.unpack |
268 instance Aeson.ToJSONKey B.ByteString where |
271 instance Aeson.ToJSONKey B.ByteString where |
269 toJSONKey = Aeson.toJSONKeyText (Text.pack . B.unpack) |
272 toJSONKey = Aeson.toJSONKeyText (Text.pack . B.unpack) |
270 |
273 |
271 instance Aeson.FromJSONKey B.ByteString where |
274 instance Aeson.FromJSONKey B.ByteString where |
272 fromJSONKey = Aeson.FromJSONKeyTextParser (return . B.pack . Text.unpack) |
275 fromJSONKey = Aeson.FromJSONKeyTextParser (return . B.pack . Text.unpack) |
273 |
276 #endif |