gameServer/CoreTypes.hs
author Wuzzy <Wuzzy2@mail.ru>
Mon, 29 Apr 2019 23:12:40 +0200
changeset 14873 56293aa24e81
parent 14862 111c4d750c6d
child 15469 88770c206c31
permissions -rw-r--r--
Fix crash when pressing key bind reset button in settings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10460
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     1
{-
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10983
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
10460
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     4
 *
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     8
 *
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    12
 * GNU General Public License for more details.
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    13
 *
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    14
 * You should have received a copy of the GNU General Public License
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    15
 * along with this program; if not, write to the Free Software
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    17
 \-}
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    18
11320
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
    19
{-# LANGUAGE CPP, OverloadedStrings, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    20
module CoreTypes where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    21
4579
4e61c2a42121 Explicitly kill listening thread in try to prevent messages recieving bugs
unc0rr
parents: 4337
diff changeset
    22
import Control.Concurrent
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    23
import Data.Word
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    24
import qualified Data.Map as Map
1926
cb46fbdcaa41 Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents: 1921
diff changeset
    25
import Data.Time
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    26
import Network
2352
7eaf82cf0890 Fixes suggested by hlint tool
unc0rr
parents: 2245
diff changeset
    27
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
    28
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
    29
import Data.Unique
4959
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
    30
import Control.Exception
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
    31
import Data.Typeable
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4988
diff changeset
    32
import Data.TConfig
8519
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    33
import Control.DeepSeq
4959
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
    34
-----------------------
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
    35
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
    36
8519
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    37
#if __GLASGOW_HASKELL__ < 706
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    38
instance NFData B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    39
#endif
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    40
10983
6aba07ea908b Lazy fix for server build
unc0rr
parents: 10977
diff changeset
    41
instance NFData (Chan a) where rnf a  = a `seq` ()
8519
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    42
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    43
instance NFData Action where
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    44
    rnf (AnswerClients chans msg) = chans `deepseq` msg `deepseq` ()
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    45
    rnf a = a `seq` ()
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    46
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    47
data Action =
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    48
    AnswerClients ![ClientChan] ![B.ByteString]
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    49
    | SendServerMessage
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    50
    | SendServerVars
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    51
    | MoveToRoom RoomIndex
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    52
    | MoveToLobby B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    53
    | RemoveTeam B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    54
    | SendTeamRemovalMessage B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    55
    | RemoveRoom
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    56
    | FinishGame
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    57
    | UnreadyRoomClients
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    58
    | JoinLobby
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    59
    | ProtocolError B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    60
    | Warning B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    61
    | NoticeMessage Notice
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    62
    | ByeClient B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    63
    | KickClient ClientIndex
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    64
    | KickRoomClient ClientIndex
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    65
    | BanClient NominalDiffTime B.ByteString ClientIndex
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    66
    | BanIP B.ByteString NominalDiffTime B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    67
    | BanNick B.ByteString NominalDiffTime B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    68
    | BanList
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    69
    | Unban B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    70
    | ChangeMaster (Maybe ClientIndex)
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    71
    | RemoveClientTeams
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    72
    | ModifyClient (ClientInfo -> ClientInfo)
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    73
    | ModifyClient2 ClientIndex (ClientInfo -> ClientInfo)
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    74
    | ModifyRoomClients (ClientInfo -> ClientInfo)
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    75
    | ModifyRoom (RoomInfo -> RoomInfo)
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    76
    | ModifyServerInfo (ServerInfo -> ServerInfo)
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    77
    | AddRoom B.ByteString B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    78
    | SendUpdateOnThisRoom
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    79
    | CheckRegistered
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    80
    | ClearAccountsCache
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    81
    | ProcessAccountInfo AccountInfo
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    82
    | AddClient ClientInfo
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    83
    | DeleteClient ClientIndex
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    84
    | PingAll
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    85
    | StatsAction
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    86
    | RestartServer
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    87
    | AddNick2Bans B.ByteString B.ByteString UTCTime
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    88
    | AddIP2Bans B.ByteString B.ByteString UTCTime
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    89
    | CheckBanned Bool
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    90
    | SaveReplay
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    91
    | Stats
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    92
    | CheckRecord
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    93
    | CheckFailed B.ByteString
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
    94
    | CheckSuccess [B.ByteString]
9035
e84d42a4311c '/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents: 8897
diff changeset
    95
    | Random [ClientChan] [B.ByteString]
11575
db7743e2fad1 More work on best time ghost feature
unc0rr
parents: 11556
diff changeset
    96
    | LoadGhost B.ByteString
9446
4fd5df03deb8 Start support of achievement replay query:
unc0rr
parents: 9435
diff changeset
    97
    | QueryReplay B.ByteString
4fd5df03deb8 Start support of achievement replay query:
unc0rr
parents: 9435
diff changeset
    98
    | ShowReplay B.ByteString
9973
7589978c9912 Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents: 9884
diff changeset
    99
    | Cleanup
10090
a471a7bbc339 - Start work on flood detector
unc0rr
parents: 10076
diff changeset
   100
    | RegisterEvent Event
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   101
    | SaveRoom B.ByteString
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   102
    | LoadRoom B.ByteString
10212
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   103
    | ReactCmd [B.ByteString]
10215
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   104
    | CheckVotes
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   105
    | SetRandomSeed
14401
8ad85859dd3f /registered_only now tells in chat whether the state is on or off
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   106
    | ShowRegisteredOnlyState [ClientChan]
10090
a471a7bbc339 - Start work on flood detector
unc0rr
parents: 10076
diff changeset
   107
a471a7bbc339 - Start work on flood detector
unc0rr
parents: 10076
diff changeset
   108
a471a7bbc339 - Start work on flood detector
unc0rr
parents: 10076
diff changeset
   109
data Event = LobbyChatMessage
a471a7bbc339 - Start work on flood detector
unc0rr
parents: 10076
diff changeset
   110
           | EngineMessage
a471a7bbc339 - Start work on flood detector
unc0rr
parents: 10076
diff changeset
   111
           | RoomJoin
14862
111c4d750c6d Limit room name change rate
unc0rr
parents: 14442
diff changeset
   112
           | RoomNameUpdate
10094
d3a2fe9f04f2 Define some boundaries to detect events
unc0rr
parents: 10093
diff changeset
   113
d3a2fe9f04f2 Define some boundaries to detect events
unc0rr
parents: 10093
diff changeset
   114
type EventsInfo = [(Int, UTCTime)]
8519
98e2dbdda8c0 Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents: 8509
diff changeset
   115
10093
ada172d33988 More work on flood detector
unc0rr
parents: 10090
diff changeset
   116
newEventsInfo :: EventsInfo
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   117
newEventsInfo = []
10212
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   118
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
   119
type ClientChan = Chan [B.ByteString]
3435
4e4f88a7bdf2 Some more steps in refactoring
unc0rr
parents: 3425
diff changeset
   120
8507
f4475782cf45 Some more work on checker
unc0rr
parents: 8479
diff changeset
   121
data CheckInfo =
f4475782cf45 Some more work on checker
unc0rr
parents: 8479
diff changeset
   122
    CheckInfo
f4475782cf45 Some more work on checker
unc0rr
parents: 8479
diff changeset
   123
    {
8509
eda9f2106d8d Sort checked files into dirs
unc0rr
parents: 8507
diff changeset
   124
        recordFileName :: String,
11246
09a2d3988569 Also pass script information alongwith winner/achievements info, so that we could potentially have per mode ratings
unc0rr
parents: 11046
diff changeset
   125
        recordTeams :: [TeamInfo],
11320
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   126
        details :: Maybe GameDetails
8507
f4475782cf45 Some more work on checker
unc0rr
parents: 8479
diff changeset
   127
    }
f4475782cf45 Some more work on checker
unc0rr
parents: 8479
diff changeset
   128
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   129
data ClientInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   130
    ClientInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   131
    {
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   132
        clUID :: !Unique,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   133
        sendChan :: !ClientChan,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   134
        clientSocket :: !Socket,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   135
        host :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   136
        connectTime :: !UTCTime,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   137
        nick :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   138
        webPassword :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   139
        serverSalt :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   140
        logonPassed :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   141
        isVisible :: !Bool,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   142
        clientProto :: !Word16,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   143
        pingsQueue :: !Word,
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   144
        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
   145
        isReady :: !Bool,
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   146
        isInGame :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   147
        isAdministrator :: !Bool,
11467
f2c36df8c7b1 Allow server admins to join passworded/restricted rooms when it is really needed
unc0rr
parents: 11466
diff changeset
   148
        hasSuperPower :: !Bool,
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   149
        isChecker :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   150
        isContributor :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   151
        isKickedFromServer :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   152
        isJoinedMidGame :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   153
        hasAskedList :: !Bool,
8433
3b318a130a62 Some fixes
unc0rr
parents: 8431
diff changeset
   154
        clientClan :: !(Maybe B.ByteString),
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   155
        checkInfo :: !(Maybe CheckInfo),
10093
ada172d33988 More work on flood detector
unc0rr
parents: 10090
diff changeset
   156
        eiLobbyChat,
ada172d33988 More work on flood detector
unc0rr
parents: 10090
diff changeset
   157
        eiEM,
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   158
        eiJoin :: !EventsInfo,
11466
4b5c7a5c49fd Defer kicking to the time when everything is in consistent state
unc0rr
parents: 11465
diff changeset
   159
        teamsInGame :: !Word,
11556
af9aa8d5863c Filter out hog speech messages with non-local team index (not tested)
unc0rr
parents: 11467
diff changeset
   160
        teamIndexes :: ![Word8],
11466
4b5c7a5c49fd Defer kicking to the time when everything is in consistent state
unc0rr
parents: 11465
diff changeset
   161
        pendingActions :: ![Action]
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   162
    }
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   163
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   164
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
   165
    (==) = (==) `on` clientSocket
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   166
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   167
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
   168
    HedgehogInfo B.ByteString B.ByteString
5143
649d87819682 Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents: 5007
diff changeset
   169
    deriving (Show, Read)
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   170
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   171
data TeamInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   172
    TeamInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   173
    {
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   174
        teamowner :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   175
        teamname :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   176
        teamcolor :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   177
        teamgrave :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   178
        teamfort :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   179
        teamvoicepack :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   180
        teamflag :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   181
        isOwnerRegistered :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   182
        difficulty :: !Int,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   183
        hhnum :: !Int,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   184
        hedgehogs :: ![HedgehogInfo]
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   185
    }
5143
649d87819682 Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents: 5007
diff changeset
   186
    deriving (Show, Read)
7321
57bd4f201401 - Try sending remove message in 'finally' as a last resort
unc0rr
parents: 7126
diff changeset
   187
8431
74c2c95ab07b Fix finding player's another clan
unc0rr
parents: 8428
diff changeset
   188
instance Eq TeamInfo where
74c2c95ab07b Fix finding player's another clan
unc0rr
parents: 8428
diff changeset
   189
    (==) = (==) `on` teamname
8479
8d71109b04d2 Some work on loading replay and interaction with checker
unc0rr
parents: 8433
diff changeset
   190
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
   191
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
   192
    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
   193
    {
8369
31033e521653 Throw away stupid Data.Seq
unc0rr
parents: 8245
diff changeset
   194
        roundMsgs :: [B.ByteString],
9304
3f4c3fc146c2 Fix spectator desync in rare conditions (there was team which left during its turn, and last command with timestamp from it was '+')
unc0rr
parents: 9109
diff changeset
   195
        lastFilteredTimedMsg :: Maybe B.ByteString,
7126
8daa5c8e84c0 Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents: 7124
diff changeset
   196
        leftTeams :: [B.ByteString],
10814
810ac1d21fd0 This should help with second rejoin bug. (reverting previous workaround over frontend bug and making a new one)
unc0rr
parents: 10786
diff changeset
   197
        rejoinedTeams :: [B.ByteString], -- for 0.9.21 frontend workaround
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
   198
        teamsAtStart :: [TeamInfo],
6756
344d32bb1328 Also consider game finished when the last player reports ROUNDFINISHED despite the correctness parameter.
unc0rr
parents: 6737
diff changeset
   199
        teamsInGameNumber :: Int,
8428
73ab5a17ee55 Fix crashers
unc0rr
parents: 8372
diff changeset
   200
        allPlayersHaveRegisteredAccounts :: !Bool,
6069
d59745e525ec GameInfo needs room params copy
unc0rr
parents: 5996
diff changeset
   201
        giMapParams :: Map.Map B.ByteString B.ByteString,
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10215
diff changeset
   202
        giParams :: Map.Map B.ByteString [B.ByteString],
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10215
diff changeset
   203
        isPaused :: Bool
6069
d59745e525ec GameInfo needs room params copy
unc0rr
parents: 5996
diff changeset
   204
    } deriving (Show, Read)
7321
57bd4f201401 - Try sending remove message in 'finally' as a last resort
unc0rr
parents: 7126
diff changeset
   205
7766
98edc0724a28 Fix most of server warnings
unc0rr
parents: 7757
diff changeset
   206
newGameInfo :: [TeamInfo]
98edc0724a28 Fix most of server warnings
unc0rr
parents: 7757
diff changeset
   207
                -> Int
98edc0724a28 Fix most of server warnings
unc0rr
parents: 7757
diff changeset
   208
                -> Bool
98edc0724a28 Fix most of server warnings
unc0rr
parents: 7757
diff changeset
   209
                -> Map.Map ByteString ByteString
98edc0724a28 Fix most of server warnings
unc0rr
parents: 7757
diff changeset
   210
                -> Map.Map ByteString [ByteString]
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10215
diff changeset
   211
                -> Bool
7766
98edc0724a28 Fix most of server warnings
unc0rr
parents: 7757
diff changeset
   212
                -> GameInfo
7321
57bd4f201401 - Try sending remove message in 'finally' as a last resort
unc0rr
parents: 7126
diff changeset
   213
newGameInfo =
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
   214
    GameInfo
8369
31033e521653 Throw away stupid Data.Seq
unc0rr
parents: 8245
diff changeset
   215
        []
9304
3f4c3fc146c2 Fix spectator desync in rare conditions (there was team which left during its turn, and last command with timestamp from it was '+')
unc0rr
parents: 9109
diff changeset
   216
        Nothing
7126
8daa5c8e84c0 Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents: 7124
diff changeset
   217
        []
10814
810ac1d21fd0 This should help with second rejoin bug. (reverting previous workaround over frontend bug and making a new one)
unc0rr
parents: 10786
diff changeset
   218
        []
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   219
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10094
diff changeset
   220
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   221
data RoomInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   222
    RoomInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   223
    {
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   224
        masterID :: !(Maybe ClientIndex),
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   225
        name :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   226
        password :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   227
        roomProto :: !Word16,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   228
        teams :: ![TeamInfo],
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   229
        gameInfo :: !(Maybe GameInfo),
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   230
        playersIn :: !Int,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   231
        readyPlayers :: !Int,
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   232
        isRestrictedJoins :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   233
        isRestrictedTeams :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   234
        isRegisteredOnly :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   235
        isSpecial :: !Bool,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   236
        defaultHedgehogsNumber :: !Int,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   237
        teamsNumberLimit :: !Int,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   238
        greeting :: !B.ByteString,
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   239
        voting :: !(Maybe Voting),
8002
8113afd3858f More strictness on room bans
unc0rr
parents: 7862
diff changeset
   240
        roomBansList :: ![B.ByteString],
11464
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   241
        mapParams :: !(Map.Map B.ByteString B.ByteString),
a9957113404a Allow only one query per session
unc0rr
parents: 11320
diff changeset
   242
        params :: !(Map.Map B.ByteString [B.ByteString]),
11575
db7743e2fad1 More work on best time ghost feature
unc0rr
parents: 11556
diff changeset
   243
        roomSaves :: !(Map.Map B.ByteString (B.ByteString, Map.Map B.ByteString B.ByteString, Map.Map B.ByteString [B.ByteString]))
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   244
    }
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   245
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
   246
newRoom :: RoomInfo
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4918
diff changeset
   247
newRoom =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   248
    RoomInfo
9753
9579596cf471 - Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents: 9528
diff changeset
   249
        Nothing
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   250
        ""
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   251
        ""
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   252
        0
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   253
        []
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
   254
        Nothing
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   255
        0
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   256
        0
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   257
        False
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   258
        False
8232
fb5aa767a2a0 "Registered users only" room flag
unc0rr
parents: 8002
diff changeset
   259
        False
9753
9579596cf471 - Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents: 9528
diff changeset
   260
        False
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   261
        4
10882
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10814
diff changeset
   262
        8
9787
0da6ba2f1f93 - /greeting command for room greeting message
unc0rr
parents: 9753
diff changeset
   263
        ""
10041
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   264
        Nothing
7537
833a0c34fafc Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
unc0rr
parents: 7321
diff changeset
   265
        []
4941
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
   266
        (
9753
9579596cf471 - Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents: 9528
diff changeset
   267
            Map.fromList $ Prelude.zip
10482
b49b82351ad3 - Not only that, nemo, not only that (.cpp)
unc0rr
parents: 10480
diff changeset
   268
                ["FEATURE_SIZE", "MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"]
b49b82351ad3 - Not only that, nemo, not only that (.cpp)
unc0rr
parents: 10480
diff changeset
   269
                ["12", "+rnd+", "0", "0", "seed", "0"]
4941
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
   270
        )
9753
9579596cf471 - Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents: 9528
diff changeset
   271
        (
9579596cf471 - Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents: 9528
diff changeset
   272
            Map.fromList $ Prelude.zip
10066
1a6e1aad58d6 - Add SCHEME which is needed in room config
unc0rr
parents: 10065
diff changeset
   273
                ["AMMO", "SCHEME", "SCRIPT", "THEME"]
1a6e1aad58d6 - Add SCHEME which is needed in room config
unc0rr
parents: 10065
diff changeset
   274
                [["Default"], ["Default"], ["Normal"], ["avematan"]]
9753
9579596cf471 - Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents: 9528
diff changeset
   275
        )
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10094
diff changeset
   276
        Map.empty
9753
9579596cf471 - Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents: 9528
diff changeset
   277
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   278
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   279
data StatisticsInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   280
    StatisticsInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   281
    {
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   282
        playersNumber :: Int,
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   283
        roomsNumber :: Int
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   284
    }
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   285
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4988
diff changeset
   286
data ServerInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   287
    ServerInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   288
    {
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   289
        isDedicated :: Bool,
11465
0ae2e4c13bd1 Allow toggling registration requirement on live server
unc0rr
parents: 11464
diff changeset
   290
        isRegisteredUsersOnly :: 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
   291
        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
   292
        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
   293
        latestReleaseVersion :: Word16,
4988
bd540ba66599 Store more parameters in ini file
unc0rr
parents: 4987
diff changeset
   294
        earliestCompatibleVersion :: Word16,
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   295
        listenPort :: PortNumber,
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
   296
        dbHost :: B.ByteString,
4982
3572eaf14340 Add dbName parameter to .ini file, fix some warnings
unc0rr
parents: 4975
diff changeset
   297
        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
   298
        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
   299
        dbPassword :: B.ByteString,
5007
c401891fe5e0 Get rid of lastLogins, implement bans system
unc0rr
parents: 5006
diff changeset
   300
        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
   301
        shutdownPending :: Bool,
5210
a5329e52a71b Pass correct arguments on restart
unc0rr
parents: 5209
diff changeset
   302
        runArgs :: [String],
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   303
        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
   304
        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
   305
        serverSocket :: Maybe Socket,
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4988
diff changeset
   306
        serverConfig :: Maybe Conf
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   307
    }
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   308
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   309
5209
f7a610e2ef5f On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents: 5143
diff changeset
   310
newServerInfo :: Chan CoreMessage -> Chan DBQuery -> Maybe Socket -> Maybe Conf -> ServerInfo
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4918
diff changeset
   311
newServerInfo =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   312
    ServerInfo
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   313
        True
11465
0ae2e4c13bd1 Allow toggling registration requirement on live server
unc0rr
parents: 11464
diff changeset
   314
        False
13512
36f3f77e9b1b Switch from http:// to https:// URLs where possible
Wuzzy <Wuzzy2@mail.ru>
parents: 13303
diff changeset
   315
        "<h2><p align=center><a href=\"https://www.hedgewars.org/\">https://www.hedgewars.org/</a></p></h2>"
14408
1465f34973b5 Whoops. Forgot to bump default gameServer MOTD to 0.9.25. :(
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   316
        "<font color=yellow><h3 align=center>Hedgewars 0.9.25 is out! Please update.</h3><p align=center><a href=https://hedgewars.org/download.html>Download page here</a></font>"
1465f34973b5 Whoops. Forgot to bump default gameServer MOTD to 0.9.25. :(
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   317
        57 -- latestReleaseVersion
7862
bd76ca40db68 Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents: 7766
diff changeset
   318
        41 -- earliestCompatibleVersion
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   319
        46631
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   320
        ""
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   321
        ""
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   322
        ""
4982
3572eaf14340 Add dbName parameter to .ini file, fix some warnings
unc0rr
parents: 4975
diff changeset
   323
        ""
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   324
        []
4955
84543ecae8c3 Don't forkIO main loop
unc0rr
parents: 4941
diff changeset
   325
        False
5210
a5329e52a71b Pass correct arguments on restart
unc0rr
parents: 5209
diff changeset
   326
        []
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   327
10041
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   328
data Voting = Voting {
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   329
        voteTTL :: Int,
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   330
        entitledToVote :: [Unique],
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   331
        votes :: [(Unique, Bool)],
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   332
        voteType :: VoteType
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   333
    }
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   334
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   335
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   336
data VoteType = VoteKick B.ByteString
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   337
              | VoteMap B.ByteString
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10215
diff changeset
   338
              | VotePause
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   339
              | VoteNewSeed
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   340
              | VoteHedgehogsPerTeam Int
10041
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   341
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   342
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10041
diff changeset
   343
newVoting :: VoteType -> Voting
4ed428389c4e - Implement /callvote
unc0rr
parents: 10041
diff changeset
   344
newVoting = Voting 2 [] []
10041
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   345
82d062e36e96 restore gameServer changes
koda
parents: 9990
diff changeset
   346
1839
5dd4cb7fd7e5 Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents: 1833
diff changeset
   347
data AccountInfo =
9435
59eec19cb31a 'c' flag for contributors
unc0rr
parents: 9401
diff changeset
   348
    HasAccount B.ByteString Bool Bool
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   349
    | Guest
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   350
    | Admin
9446
4fd5df03deb8 Start support of achievement replay query:
unc0rr
parents: 9435
diff changeset
   351
    | ReplayName B.ByteString
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   352
    deriving (Show, Read)
2116
dec7ead2d178 Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents: 2104
diff changeset
   353
dec7ead2d178 Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents: 2104
diff changeset
   354
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
   355
    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
   356
    | ClearCache
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   357
    | SendStats Int Int
11320
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   358
    | StoreAchievements Word16 B.ByteString [(B.ByteString, B.ByteString)] GameDetails [B.ByteString]
9446
4fd5df03deb8 Start support of achievement replay query:
unc0rr
parents: 9435
diff changeset
   359
    | GetReplayName ClientIndex Int B.ByteString
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   360
    deriving (Show, Read)
1839
5dd4cb7fd7e5 Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents: 1833
diff changeset
   361
11320
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   362
data GameDetails =
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   363
    GameDetails {
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   364
        gameScript :: B.ByteString
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   365
        , infRope
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   366
        , isVamp
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   367
        , infAttacks :: Bool
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   368
    } deriving (Show, Read)
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   369
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   370
instance NFData GameDetails where
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   371
    rnf (GameDetails a b c d) = a `deepseq` b `deepseq` c `deepseq` d `deepseq` ()
556eafd1443a Store some more details on game config in the database
unc0rr
parents: 11265
diff changeset
   372
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   373
data CoreMessage =
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   374
    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
   375
    | 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
   376
    | ClientAccountInfo ClientIndex Int AccountInfo
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   377
    | 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
   378
    | Remove ClientIndex
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   379
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
   380
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
   381
type IRnC = IRoomsAndClients RoomInfo ClientInfo
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   382
4622
8bdc879ee6b2 Implement room delegation when admin lefts it
unc0rr
parents: 4610
diff changeset
   383
data Notice =
8bdc879ee6b2 Implement room delegation when admin lefts it
unc0rr
parents: 4610
diff changeset
   384
    NickAlreadyInUse
8bdc879ee6b2 Implement room delegation when admin lefts it
unc0rr
parents: 4610
diff changeset
   385
    | AdminLeft
6912
831416764d2d Allow LIST command while in room to not annoy old frontends (0.9.17 or less) with warnings
unc0rr
parents: 6756
diff changeset
   386
    | WrongPassword
4959
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   387
    deriving Enum
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   388
4960
unc0rr
parents: 4959
diff changeset
   389
data ShutdownException =
unc0rr
parents: 4959
diff changeset
   390
    ShutdownException
4959
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   391
     deriving (Show, Typeable)
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   392
09f4978b4fb0 ShutdownException for server shutdown
unc0rr
parents: 4957
diff changeset
   393
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
   394
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
   395
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
   396
     deriving Typeable
4996
76ef3d8bd78e Fix crash (accessing already deleted client record) by reverting to old client removing handling + throwTo
unc0rr
parents: 4989
diff changeset
   397
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
   398
instance Show ShutdownThreadException where
5001
312f4dd41753 Better quit message
unc0rr
parents: 5000
diff changeset
   399
    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
   400
instance Exception ShutdownThreadException
5006
6913d677c891 - Remove not needed Show instances
unc0rr
parents: 5001
diff changeset
   401
6913d677c891 - Remove not needed Show instances
unc0rr
parents: 5001
diff changeset
   402
data BanInfo =
5007
c401891fe5e0 Get rid of lastLogins, implement bans system
unc0rr
parents: 5006
diff changeset
   403
    BanByIP B.ByteString B.ByteString UTCTime
c401891fe5e0 Get rid of lastLogins, implement bans system
unc0rr
parents: 5006
diff changeset
   404
    | BanByNick B.ByteString B.ByteString UTCTime
5006
6913d677c891 - Remove not needed Show instances
unc0rr
parents: 5001
diff changeset
   405
    deriving (Show, Read)