gameServer/CoreTypes.hs
author unc0rr
Wed, 29 Feb 2012 23:44:49 +0400
changeset 6753 e95b1f62d0de
parent 6737 ce5fbd98370f
child 6756 344d32bb1328
permissions -rw-r--r--
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others. This should fix problems with ghost teams in frontend. Not tested at all, successfully built on first attempt, which is considered as a bad sign :D Server still thinks game proceeds, so restart isn't possible.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4959
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
     1
{-# LANGUAGE OverloadedStrings, DeriveDataTypeable #-}
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     2
module CoreTypes where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     3
4579
4e61c2a42121 Explicitly kill listening thread in try to prevent messages recieving bugs
unc0rr
parents: 4337
diff changeset
     4
import Control.Concurrent
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     5
import Data.Word
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     6
import qualified Data.Map as Map
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     7
import Data.Sequence(Seq, empty)
1926
cb46fbdcaa41 Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents: 1921
diff changeset
     8
import Data.Time
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     9
import Network
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2245
diff changeset
    10
import Data.Function
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    11
import Data.ByteString.Char8 as B
4918
c6d3aec73f93 Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents: 4907
diff changeset
    12
import Data.Unique
4959
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
    13
import Control.Exception
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
    14
import Data.Typeable
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4988
diff changeset
    15
import Data.TConfig
4959
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
    16
-----------------------
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    17
import RoomsAndClients
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    18
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    19
type ClientChan = Chan [B.ByteString]
3435
4e4f88a7bdf2 Some more steps in refactoring
unc0rr
parents: 3425
diff changeset
    20
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    21
data ClientInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    22
    ClientInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    23
    {
4918
c6d3aec73f93 Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents: 4907
diff changeset
    24
        clUID :: Unique,
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    25
        sendChan :: ClientChan,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    26
        clientSocket :: Socket,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    27
        host :: B.ByteString,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    28
        connectTime :: UTCTime,
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    29
        nick :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    30
        webPassword :: B.ByteString,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    31
        logonPassed :: Bool,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    32
        clientProto :: !Word16,
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    33
        roomID :: RoomIndex,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    34
        pingsQueue :: !Word,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    35
        isMaster :: Bool,
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    36
        isReady :: !Bool,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    37
        isAdministrator :: Bool,
4986
33fe91b2bcbf Use Maybe for storing client's clan, allows less error-prone spectator checks
unc0rr
parents: 4982
diff changeset
    38
        clientClan :: Maybe B.ByteString,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    39
        teamsInGame :: Word
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    40
    }
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    41
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    42
instance Eq ClientInfo where
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    43
    (==) = (==) `on` clientSocket
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    44
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    45
data HedgehogInfo =
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    46
    HedgehogInfo B.ByteString B.ByteString
5143
649d87819682 Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents: 5007
diff changeset
    47
    deriving (Show, Read)
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    48
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    49
data TeamInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    50
    TeamInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    51
    {
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    52
        teamownerId :: ClientIndex,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    53
        teamowner :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    54
        teamname :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    55
        teamcolor :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    56
        teamgrave :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    57
        teamfort :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    58
        teamvoicepack :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    59
        teamflag :: B.ByteString,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    60
        difficulty :: Int,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    61
        hhnum :: Int,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    62
        hedgehogs :: [HedgehogInfo]
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    63
    }
5143
649d87819682 Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents: 5007
diff changeset
    64
    deriving (Show, Read)
5996
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    65
    
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    66
data GameInfo =
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    67
    GameInfo
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    68
    {
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    69
        roundMsgs :: Seq B.ByteString,
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    70
        leftTeams :: [B.ByteString],
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    71
        teamsAtStart :: [TeamInfo],
6069
d59745e525ec GameInfo needs room params copy
unc0rr
parents: 5996
diff changeset
    72
        allPlayersHaveRegisteredAccounts :: Bool,
d59745e525ec GameInfo needs room params copy
unc0rr
parents: 5996
diff changeset
    73
        giMapParams :: Map.Map B.ByteString B.ByteString,
d59745e525ec GameInfo needs room params copy
unc0rr
parents: 5996
diff changeset
    74
        giParams :: Map.Map B.ByteString [B.ByteString]
d59745e525ec GameInfo needs room params copy
unc0rr
parents: 5996
diff changeset
    75
    } deriving (Show, Read)
5996
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    76
    
6069
d59745e525ec GameInfo needs room params copy
unc0rr
parents: 5996
diff changeset
    77
--newGameInfo ::  -> GameInfo 
5996
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    78
newGameInfo = 
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    79
    GameInfo
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    80
        Data.Sequence.empty
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    81
        []
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    82
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    83
data RoomInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    84
    RoomInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    85
    {
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    86
        masterID :: ClientIndex,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    87
        name :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    88
        password :: B.ByteString,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    89
        roomProto :: Word16,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    90
        teams :: [TeamInfo],
5996
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
    91
        gameInfo :: Maybe GameInfo,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    92
        playersIn :: !Int,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    93
        readyPlayers :: !Int,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    94
        isRestrictedJoins :: Bool,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    95
        isRestrictedTeams :: Bool,
4941
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
    96
        mapParams :: Map.Map B.ByteString B.ByteString,
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
    97
        params :: Map.Map B.ByteString [B.ByteString]
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
    98
    }
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    99
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   100
newRoom :: RoomInfo
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4918
diff changeset
   101
newRoom =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   102
    RoomInfo
4987
cf9470964dba Use 'undefined' less (replace with default values and 'error')
unc0rr
parents: 4986
diff changeset
   103
        (error "No room master defined")
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   104
        ""
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   105
        ""
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   106
        0
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   107
        []
5996
2c72fe81dd37 Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents: 5210
diff changeset
   108
        Nothing
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   109
        0
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   110
        0
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   111
        False
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   112
        False
4941
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
   113
        (
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
   114
            Map.fromList $ Prelude.zipWith (,)
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
   115
                ["MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"]
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
   116
                ["+rnd+", "0", "0", "seed", "0"]
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
   117
        )
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
   118
        (Map.singleton "SCHEME" ["Default"])
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   119
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   120
data StatisticsInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   121
    StatisticsInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   122
    {
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   123
        playersNumber :: Int,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   124
        roomsNumber :: Int
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   125
    }
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   126
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4988
diff changeset
   127
data ServerInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   128
    ServerInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   129
    {
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   130
        isDedicated :: Bool,
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   131
        serverMessage :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   132
        serverMessageForOldVersions :: B.ByteString,
3260
b44b88908758 Allow to set motd for old client versions (not used yet, as server needs some refactoring)
unc0rr
parents: 2868
diff changeset
   133
        latestReleaseVersion :: Word16,
4988
bd540ba66599 Store more parameters in ini file
unc0rr
parents: 4987
diff changeset
   134
        earliestCompatibleVersion :: Word16,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   135
        listenPort :: PortNumber,
6737
ce5fbd98370f - Increase server version number due to rooms list protocol changes
unc0rr
parents: 6403
diff changeset
   136
        --nextRoomID :: Int,
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   137
        dbHost :: B.ByteString,
4982
3572eaf14340 Add dbName parameter to .ini file, fix some warnings
unc0rr
parents: 4975
diff changeset
   138
        dbName :: B.ByteString,
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   139
        dbLogin :: B.ByteString,
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   140
        dbPassword :: B.ByteString,
5007
c401891fe5e0 Get rid of lastLogins, implement bans system
unc0rr
parents: 5006
diff changeset
   141
        bans :: [BanInfo],
5209
f7a610e2ef5f On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents: 5143
diff changeset
   142
        shutdownPending :: Bool,
5210
a5329e52a71b Pass correct arguments on restart
unc0rr
parents: 5209
diff changeset
   143
        runArgs :: [String],
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   144
        coreChan :: Chan CoreMessage,
4975
31da8979e5b1 Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents: 4960
diff changeset
   145
        dbQueries :: Chan DBQuery,
5209
f7a610e2ef5f On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents: 5143
diff changeset
   146
        serverSocket :: Maybe Socket,
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4988
diff changeset
   147
        serverConfig :: Maybe Conf
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   148
    }
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   149
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   150
5209
f7a610e2ef5f On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents: 5143
diff changeset
   151
newServerInfo :: Chan CoreMessage -> Chan DBQuery -> Maybe Socket -> Maybe Conf -> ServerInfo
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4918
diff changeset
   152
newServerInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   153
    ServerInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   154
        True
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   155
        "<h2><p align=center><a href=\"http://www.hedgewars.org/\">http://www.hedgewars.org/</a></p></h2>"
6737
ce5fbd98370f - Increase server version number due to rooms list protocol changes
unc0rr
parents: 6403
diff changeset
   156
        "<font color=yellow><h3 align=center>Hedgewars 0.9.17 is out! Please update.</h3><p align=center><a href=http://hedgewars.org/download.html>Download page here</a></font>"
ce5fbd98370f - Increase server version number due to rooms list protocol changes
unc0rr
parents: 6403
diff changeset
   157
        41
ce5fbd98370f - Increase server version number due to rooms list protocol changes
unc0rr
parents: 6403
diff changeset
   158
        43 -- 0.9.18
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   159
        46631
6737
ce5fbd98370f - Increase server version number due to rooms list protocol changes
unc0rr
parents: 6403
diff changeset
   160
        --0
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   161
        ""
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   162
        ""
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   163
        ""
4982
3572eaf14340 Add dbName parameter to .ini file, fix some warnings
unc0rr
parents: 4975
diff changeset
   164
        ""
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   165
        []
4955
84543ecae8c3 Don't forkIO main loop
unc0rr
parents: 4941
diff changeset
   166
        False
5210
a5329e52a71b Pass correct arguments on restart
unc0rr
parents: 5209
diff changeset
   167
        []
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   168
1839
5dd4cb7fd7e5 Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents: 1833
diff changeset
   169
data AccountInfo =
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   170
    HasAccount B.ByteString Bool
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   171
    | Guest
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   172
    | Admin
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   173
    deriving (Show, Read)
2116
dec7ead2d178 Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents: 2104
diff changeset
   174
dec7ead2d178 Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents: 2104
diff changeset
   175
data DBQuery =
4918
c6d3aec73f93 Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents: 4907
diff changeset
   176
    CheckAccount ClientIndex Int B.ByteString B.ByteString
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   177
    | ClearCache
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   178
    | SendStats Int Int
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   179
    deriving (Show, Read)
1839
5dd4cb7fd7e5 Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents: 1833
diff changeset
   180
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   181
data CoreMessage =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   182
    Accept ClientInfo
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   183
    | ClientMessage (ClientIndex, [B.ByteString])
4918
c6d3aec73f93 Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents: 4907
diff changeset
   184
    | ClientAccountInfo ClientIndex Int AccountInfo
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   185
    | TimerAction Int
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   186
    | Remove ClientIndex
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   187
4295
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   188
type MRnC = MRoomsAndClients RoomInfo ClientInfo
1f5604cd99be This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents: 4242
diff changeset
   189
type IRnC = IRoomsAndClients RoomInfo ClientInfo
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   190
4622
8bdc879ee6b2 Implement room delegation when admin lefts it
unc0rr
parents: 4610
diff changeset
   191
data Notice =
8bdc879ee6b2 Implement room delegation when admin lefts it
unc0rr
parents: 4610
diff changeset
   192
    NickAlreadyInUse
8bdc879ee6b2 Implement room delegation when admin lefts it
unc0rr
parents: 4610
diff changeset
   193
    | AdminLeft
4959
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   194
    deriving Enum
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   195
4960
unc0rr
parents: 4959
diff changeset
   196
data ShutdownException =
unc0rr
parents: 4959
diff changeset
   197
    ShutdownException
4959
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   198
     deriving (Show, Typeable)
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   199
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   200
instance Exception ShutdownException
4996
76ef3d8bd78e Fix crash (accessing already deleted client record) by reverting to old client removing handling + throwTo
unc0rr
parents: 4989
diff changeset
   201
5000
72d8fb26223d - Don't pretend client sent some message from sending thread (fixes crash when client is already deleted by recieveng thread)
unc0rr
parents: 4996
diff changeset
   202
data ShutdownThreadException = ShutdownThreadException String
72d8fb26223d - Don't pretend client sent some message from sending thread (fixes crash when client is already deleted by recieveng thread)
unc0rr
parents: 4996
diff changeset
   203
     deriving Typeable
4996
76ef3d8bd78e Fix crash (accessing already deleted client record) by reverting to old client removing handling + throwTo
unc0rr
parents: 4989
diff changeset
   204
5000
72d8fb26223d - Don't pretend client sent some message from sending thread (fixes crash when client is already deleted by recieveng thread)
unc0rr
parents: 4996
diff changeset
   205
instance Show ShutdownThreadException where
5001
312f4dd41753 Better quit message
unc0rr
parents: 5000
diff changeset
   206
    show (ShutdownThreadException s) = s
4996
76ef3d8bd78e Fix crash (accessing already deleted client record) by reverting to old client removing handling + throwTo
unc0rr
parents: 4989
diff changeset
   207
instance Exception ShutdownThreadException
5006
6913d677c891 - Remove not needed Show instances
unc0rr
parents: 5001
diff changeset
   208
6913d677c891 - Remove not needed Show instances
unc0rr
parents: 5001
diff changeset
   209
data BanInfo =
5007
c401891fe5e0 Get rid of lastLogins, implement bans system
unc0rr
parents: 5006
diff changeset
   210
    BanByIP B.ByteString B.ByteString UTCTime
c401891fe5e0 Get rid of lastLogins, implement bans system
unc0rr
parents: 5006
diff changeset
   211
    | BanByNick B.ByteString B.ByteString UTCTime
5006
6913d677c891 - Remove not needed Show instances
unc0rr
parents: 5001
diff changeset
   212
    deriving (Show, Read)