author | unC0Rr |
Tue, 03 Sep 2024 13:56:35 +0200 | |
branch | transitional_engine |
changeset 16029 | 9cbd18220eb7 |
parent 15983 | 2c92499daa67 |
permissions | -rw-r--r-- |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
diff
changeset
|
1 |
{- |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
diff
changeset
|
4 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
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:
9973
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:
9973
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
diff
changeset
|
8 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
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:
9973
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:
9973
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
diff
changeset
|
12 |
* GNU General Public License for more details. |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
diff
changeset
|
13 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
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:
9973
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:
9973
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:
9973
diff
changeset
|
17 |
\-} |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9973
diff
changeset
|
18 |
|
3458 | 19 |
module ServerState |
20 |
( |
|
21 |
module RoomsAndClients, |
|
9973
7589978c9912
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents:
8452
diff
changeset
|
22 |
module JoinsMonitor, |
3458 | 23 |
clientRoomA, |
24 |
ServerState(..), |
|
3501 | 25 |
client's, |
3502 | 26 |
allClientsS, |
8452 | 27 |
allRoomsS, |
4601 | 28 |
roomClientsS, |
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
29 |
sameProtoClientsS, |
4601 | 30 |
io |
3458 | 31 |
) where |
32 |
||
15983 | 33 |
import Control.Monad |
3741
73246d25dfe1
Add some more strictness, use unsafeThaw and unsafeFreeze functions which work at O(1)
unc0rr
parents:
3645
diff
changeset
|
34 |
import Control.Monad.State.Strict |
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
35 |
import Data.Set as Set(Set) |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
36 |
import Data.Word |
3458 | 37 |
---------------------- |
38 |
import RoomsAndClients |
|
39 |
import CoreTypes |
|
9973
7589978c9912
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents:
8452
diff
changeset
|
40 |
import JoinsMonitor |
3458 | 41 |
|
4989 | 42 |
data ServerState = ServerState { |
3807 | 43 |
clientIndex :: !(Maybe ClientIndex), |
4989 | 44 |
serverInfo :: !ServerInfo, |
3807 | 45 |
removedClients :: !(Set.Set ClientIndex), |
9973
7589978c9912
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents:
8452
diff
changeset
|
46 |
roomsClients :: !MRnC, |
7589978c9912
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents:
8452
diff
changeset
|
47 |
joinsMonitor :: !JoinsMonitor |
3458 | 48 |
} |
49 |
||
50 |
||
4989 | 51 |
clientRoomA :: StateT ServerState IO RoomIndex |
3458 | 52 |
clientRoomA = do |
53 |
(Just ci) <- gets clientIndex |
|
54 |
rnc <- gets roomsClients |
|
4622 | 55 |
io $ clientRoomM rnc ci |
3458 | 56 |
|
4989 | 57 |
client's :: (ClientInfo -> a) -> StateT ServerState IO a |
3501 | 58 |
client's f = do |
3458 | 59 |
(Just ci) <- gets clientIndex |
60 |
rnc <- gets roomsClients |
|
4622 | 61 |
io $ client'sM rnc f ci |
3645 | 62 |
|
4989 | 63 |
allClientsS :: StateT ServerState IO [ClientInfo] |
3502 | 64 |
allClientsS = gets roomsClients >>= liftIO . clientsM |
65 |
||
8452 | 66 |
allRoomsS :: StateT ServerState IO [RoomInfo] |
67 |
allRoomsS = gets roomsClients >>= liftIO . roomsM |
|
68 |
||
4989 | 69 |
roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo] |
3502 | 70 |
roomClientsS ri = do |
71 |
rnc <- gets roomsClients |
|
4622 | 72 |
io $ roomClientsM rnc ri |
4601 | 73 |
|
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
74 |
sameProtoClientsS :: Word16 -> StateT ServerState IO [ClientInfo] |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
75 |
sameProtoClientsS p = liftM f allClientsS |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
76 |
where |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
77 |
f = filter (\c -> clientProto c == p) |
8371 | 78 |
|
4989 | 79 |
io :: IO a -> StateT ServerState IO a |
4601 | 80 |
io = liftIO |