1 -- This file is part of Intricacy
2 -- Copyright (C) 2013 Martin Bays <mbays@sdf.org>
4 -- This program is free software: you can redistribute it and/or modify
5 -- it under the terms of version 3 of the GNU General Public License as
6 -- published by the Free Software Foundation, or any later version.
8 -- You should have received a copy of the GNU General Public License
9 -- along with this program. If not, see http://www.gnu.org/licenses/.
11 module ServerAddr
where
13 import Control
.Applicative
17 data ServerAddr
= ServerAddr
{hostname
::String, port
::Int}
18 deriving (Eq
, Ord
, Show, Read)
19 nullSaddr
(ServerAddr host _
) = null host
21 defaultPort
=27001 -- == ('i'<<8) + 'y'
22 defaultServerAddr
= ServerAddr
"i.thegonz.net" defaultPort
23 oldDefaultServerAddrs
= [ServerAddr
"thegonz.net" defaultPort
]
25 updateDefaultSAddr
:: ServerAddr
-> ServerAddr
26 updateDefaultSAddr saddr | saddr `
elem` oldDefaultServerAddrs
= defaultServerAddr
27 updateDefaultSAddr saddr
= saddr
29 saddrStr
(ServerAddr h p
) = h
++ if p
==defaultPort
then "" else ':':show p
31 -- |windows doesn't like ':' in paths, so use '#' instead
32 saddrPath
(ServerAddr h p
) = h
++ if p
==defaultPort
then "" else '#':show p
35 case elemIndex ':' str
of
36 Nothing
-> Just
$ ServerAddr str defaultPort
38 let (addr
,portstr
) = splitAt idx str
39 port
<- fst <$> listToMaybe (reads (drop 1 portstr
))
40 return $ ServerAddr addr port