author | unc0rr |
Sat, 21 Nov 2015 17:07:06 +0300 | |
branch | qmlfrontend |
changeset 11423 | e045dc60c37e |
parent 11265 | 35e359585dea |
child 11575 | db7743e2fad1 |
permissions | -rw-r--r-- |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
1 |
{- |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
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:
10351
diff
changeset
|
4 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
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:
10351
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:
10351
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
8 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
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:
10351
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:
10351
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
12 |
* GNU General Public License for more details. |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
13 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
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:
10351
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:
10351
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:
10351
diff
changeset
|
17 |
\-} |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
18 |
|
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
|
19 |
{-# LANGUAGE OverloadedStrings #-} |
1804 | 20 |
module Utils where |
21 |
||
22 |
import Data.Char |
|
23 |
import Data.Word |
|
24 |
import qualified Data.Map as Map |
|
6191 | 25 |
import qualified Data.Char as Char |
1917 | 26 |
import Numeric |
27 |
import Network.Socket |
|
1964 | 28 |
import System.IO |
1917 | 29 |
import qualified Data.List as List |
2349 | 30 |
import Control.Monad |
5030
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
31 |
import qualified Data.ByteString.Lazy as BL |
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
32 |
import qualified Text.Show.ByteString as BS |
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 |
import qualified Data.ByteString.Char8 as B |
6191 | 34 |
import qualified Data.ByteString.UTF8 as UTF8 |
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:
6370
diff
changeset
|
35 |
import Data.Maybe |
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:
4972
diff
changeset
|
36 |
------------------------------------------------- |
1804 | 37 |
import CoreTypes |
38 |
||
1917 | 39 |
|
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
|
40 |
sockAddr2String :: SockAddr -> IO 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
|
41 |
sockAddr2String (SockAddrInet _ hostAddr) = liftM B.pack $ inet_ntoa hostAddr |
1917 | 42 |
sockAddr2String (SockAddrInet6 _ _ (a, b, c, d) _) = |
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 |
return $ B.pack $ (foldr1 (.) |
4932 | 44 |
$ List.intersperse (':':) |
45 |
$ concatMap (\n -> (\(a0, a1) -> [showHex a0, showHex a1]) $ divMod n 65536) [a, b, c, d]) [] |
|
1917 | 46 |
|
1804 | 47 |
maybeRead :: Read a => String -> Maybe a |
48 |
maybeRead s = case reads s of |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
49 |
[(x, rest)] | all isSpace rest -> Just x |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
50 |
_ -> Nothing |
1804 | 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 |
teamToNet :: TeamInfo -> [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
|
53 |
teamToNet team = |
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 |
"ADD_TEAM" |
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 |
: teamname team |
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 team |
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 team |
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 team |
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 team |
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
|
60 |
: teamowner team |
5030
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
61 |
: (showB . difficulty $ team) |
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
|
62 |
: hhsInfo |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
63 |
where |
4932 | 64 |
hhsInfo = concatMap (\(HedgehogInfo n hat) -> [n, hat]) $ hedgehogs team |
1804 | 65 |
|
66 |
modifyTeam :: TeamInfo -> RoomInfo -> RoomInfo |
|
67 |
modifyTeam team room = room{teams = replaceTeam team $ teams room} |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
68 |
where |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
69 |
replaceTeam _ [] = error "modifyTeam: no such team" |
4932 | 70 |
replaceTeam tm (t:ts) = |
71 |
if teamname tm == teamname t then |
|
72 |
tm : ts |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
73 |
else |
4932 | 74 |
t : replaceTeam tm ts |
1804 | 75 |
|
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
|
76 |
illegalName :: B.ByteString -> Bool |
10063 | 77 |
illegalName b = B.null b || length s > 40 || all isSpace s || isSpace (head s) || isSpace (last s) || any isIllegalChar s |
5269 | 78 |
where |
10063 | 79 |
s = UTF8.toString b |
10062
8ef80bd0402f
turned out this blocked CJK characters too. stick to ASCII control char ban only, do NOT include UTF-8 control chars
sheepluva
parents:
10059
diff
changeset
|
80 |
isIllegalChar c = c `List.elem` ("$()*+?[]^{|}\x7F" ++ ['\x00'..'\x1F']) |
2150
45b695f3a7b9
Forbid room names and nicknames consisting only of space characters
unc0rr
parents:
2113
diff
changeset
|
81 |
|
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
|
82 |
protoNumber2ver :: Word16 -> B.ByteString |
4569 | 83 |
protoNumber2ver v = Map.findWithDefault "Unknown" v vermap |
84 |
where |
|
85 |
vermap = Map.fromList [ |
|
4936
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
86 |
(17, "0.9.7-dev") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
87 |
, (19, "0.9.7") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
88 |
, (20, "0.9.8-dev") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
89 |
, (21, "0.9.8") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
90 |
, (22, "0.9.9-dev") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
91 |
, (23, "0.9.9") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
92 |
, (24, "0.9.10-dev") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
93 |
, (25, "0.9.10") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
94 |
, (26, "0.9.11-dev") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
95 |
, (27, "0.9.11") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
96 |
, (28, "0.9.12-dev") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
97 |
, (29, "0.9.12") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
98 |
, (30, "0.9.13-dev") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
99 |
, (31, "0.9.13") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
100 |
, (32, "0.9.14-dev") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
101 |
, (33, "0.9.14") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
102 |
, (34, "0.9.15-dev") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
103 |
, (35, "0.9.14.1") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
104 |
, (37, "0.9.15") |
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
105 |
, (38, "0.9.16-dev") |
5880 | 106 |
, (39, "0.9.16") |
107 |
, (40, "0.9.17-dev") |
|
6370 | 108 |
, (41, "0.9.17") |
109 |
, (42, "0.9.18-dev") |
|
7862
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7766
diff
changeset
|
110 |
, (43, "0.9.18") |
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7766
diff
changeset
|
111 |
, (44, "0.9.19-dev") |
9086 | 112 |
, (45, "0.9.19") |
113 |
, (46, "0.9.20-dev") |
|
9837 | 114 |
, (47, "0.9.20") |
115 |
, (48, "0.9.21-dev") |
|
10718
40dda24ee145
More complete fix for FULLMAPCONFIG message, also add new known protocol versions
unc0rr
parents:
10602
diff
changeset
|
116 |
, (49, "0.9.21") |
40dda24ee145
More complete fix for FULLMAPCONFIG message, also add new known protocol versions
unc0rr
parents:
10602
diff
changeset
|
117 |
, (50, "0.9.22-dev") |
11265 | 118 |
, (51, "0.9.22") |
119 |
, (52, "0.9.23-dev") |
|
4936
d65d438acd23
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
unc0rr
parents:
4932
diff
changeset
|
120 |
] |
1804 | 121 |
|
4921 | 122 |
askFromConsole :: B.ByteString -> IO B.ByteString |
1964 | 123 |
askFromConsole msg = do |
4921 | 124 |
B.putStr msg |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
125 |
hFlush stdout |
4921 | 126 |
B.getLine |
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
|
127 |
|
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
|
128 |
|
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
|
129 |
unfoldrE :: (b -> Either b (a, b)) -> b -> ([a], b) |
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
|
130 |
unfoldrE f b = |
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 |
case f b of |
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 |
Right (a, new_b) -> let (a', b') = unfoldrE f new_b in (a : a', b') |
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
|
133 |
Left new_b -> ([], new_b) |
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
|
134 |
|
5030
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
135 |
showB :: (BS.Show a) => a -> B.ByteString |
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
136 |
showB = B.concat . BL.toChunks . BS.show |
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
137 |
|
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
138 |
readInt_ :: (Num a) => B.ByteString -> a |
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
139 |
readInt_ str = |
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
140 |
case B.readInt str of |
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4975
diff
changeset
|
141 |
Just (i, t) | B.null t -> fromIntegral i |
10017 | 142 |
_ -> 0 |
5060
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
143 |
|
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
144 |
cutHost :: B.ByteString -> B.ByteString |
7d0f6e5b1c1c
Hide last two octets of IP address from usual users
unc0rr
parents:
5030
diff
changeset
|
145 |
cutHost = B.intercalate "." . flip (++) ["*","*"] . List.take 2 . B.split '.' |
6191 | 146 |
|
147 |
caseInsensitiveCompare :: B.ByteString -> B.ByteString -> Bool |
|
8396 | 148 |
caseInsensitiveCompare a b = upperCase a == upperCase b |
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:
6370
diff
changeset
|
149 |
|
8396 | 150 |
upperCase :: B.ByteString -> B.ByteString |
151 |
upperCase = UTF8.fromString . map Char.toUpper . UTF8.toString |
|
7766 | 152 |
|
9702 | 153 |
roomInfo :: Word16 -> B.ByteString -> RoomInfo -> [B.ByteString] |
10017 | 154 |
roomInfo p n r |
9702 | 155 |
| p < 46 = [ |
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:
6370
diff
changeset
|
156 |
showB $ isJust $ gameInfo r, |
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:
6370
diff
changeset
|
157 |
name r, |
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:
6370
diff
changeset
|
158 |
showB $ playersIn r, |
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:
6370
diff
changeset
|
159 |
showB $ length $ teams r, |
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:
6370
diff
changeset
|
160 |
n, |
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:
6370
diff
changeset
|
161 |
Map.findWithDefault "+rnd+" "MAP" (mapParams r), |
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:
6370
diff
changeset
|
162 |
head (Map.findWithDefault ["Default"] "SCHEME" (params r)), |
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:
6370
diff
changeset
|
163 |
head (Map.findWithDefault ["Default"] "AMMO" (params r)) |
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:
6370
diff
changeset
|
164 |
] |
10511
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
165 |
| p < 48 = [ |
9702 | 166 |
showB $ isJust $ gameInfo r, |
167 |
name r, |
|
168 |
showB $ playersIn r, |
|
169 |
showB $ length $ teams r, |
|
170 |
n, |
|
171 |
Map.findWithDefault "+rnd+" "MAP" (mapParams r), |
|
172 |
head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)), |
|
173 |
head (Map.findWithDefault ["Default"] "SCHEME" (params r)), |
|
174 |
head (Map.findWithDefault ["Default"] "AMMO" (params r)) |
|
175 |
] |
|
10511
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
176 |
| otherwise = [ |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
177 |
B.pack roomFlags, |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
178 |
name r, |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
179 |
showB $ playersIn r, |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
180 |
showB $ length $ teams r, |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
181 |
n, |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
182 |
Map.findWithDefault "+rnd+" "MAP" (mapParams r), |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
183 |
head (Map.findWithDefault ["Normal"] "SCRIPT" (params r)), |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
184 |
head (Map.findWithDefault ["Default"] "SCHEME" (params r)), |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
185 |
head (Map.findWithDefault ["Default"] "AMMO" (params r)) |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
186 |
] |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
187 |
where |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
188 |
roomFlags = concat [ |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
189 |
"-" |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
190 |
, ['g' | isJust $ gameInfo r] |
10524 | 191 |
, ['p' | not . B.null $ password r] |
10511
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
192 |
, ['j' | isRestrictedJoins r] |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
193 |
, ['r' | isRegisteredOnly r] |
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
194 |
] |
9109
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
195 |
|
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
196 |
answerFullConfigParams :: |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
197 |
ClientInfo |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
198 |
-> Map.Map B.ByteString B.ByteString |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
199 |
-> Map.Map B.ByteString [B.ByteString] |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
200 |
-> [Action] |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
201 |
answerFullConfigParams cl mpr pr |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
202 |
| clientProto cl < 38 = map (toAnswer cl) $ |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
203 |
(reverse . map (\(a, b) -> (a, [b])) $ Map.toList mpr) |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
204 |
++ (("SCHEME", pr Map.! "SCHEME") |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
205 |
: (filter (\(p, _) -> p /= "SCHEME") $ Map.toList pr)) |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
206 |
|
10602 | 207 |
| clientProto cl < 48 = map (toAnswer cl) $ |
10718
40dda24ee145
More complete fix for FULLMAPCONFIG message, also add new known protocol versions
unc0rr
parents:
10602
diff
changeset
|
208 |
("FULLMAPCONFIG", let l = Map.elems mpr in if length l > 5 then tail l else l) |
10602 | 209 |
: ("SCHEME", pr Map.! "SCHEME") |
210 |
: (filter (\(p, _) -> p /= "SCHEME") $ Map.toList pr) |
|
211 |
||
9109
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
212 |
| otherwise = map (toAnswer cl) $ |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
213 |
("FULLMAPCONFIG", Map.elems mpr) |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
214 |
: ("SCHEME", pr Map.! "SCHEME") |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
215 |
: (filter (\(p, _) -> p /= "SCHEME") $ Map.toList pr) |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
216 |
where |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
217 |
toAnswer cl (paramName, paramStrs) = AnswerClients [sendChan cl] $ "CFG" : paramName : paramStrs |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
218 |
|
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
219 |
|
9448 | 220 |
answerAllTeams :: ClientInfo -> [TeamInfo] -> [Action] |
221 |
answerAllTeams cl = concatMap toAnswer |
|
222 |
where |
|
223 |
clChan = sendChan cl |
|
224 |
toAnswer team = |
|
225 |
[AnswerClients [clChan] $ teamToNet team, |
|
226 |
AnswerClients [clChan] ["TEAM_COLOR", teamname team, teamcolor team], |
|
227 |
AnswerClients [clChan] ["HH_NUM", teamname team, showB $ hhnum team]] |
|
228 |
||
229 |
||
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8396
diff
changeset
|
230 |
loc :: B.ByteString -> B.ByteString |
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8396
diff
changeset
|
231 |
loc = id |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9702
diff
changeset
|
232 |
|
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9702
diff
changeset
|
233 |
maybeNick :: Maybe ClientInfo -> B.ByteString |
10351
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
234 |
maybeNick = fromMaybe "[]" . liftM nick |
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
235 |
|
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
236 |
-- borrowed from Data.List, just more general in types |
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
237 |
deleteBy2 :: (a -> b -> Bool) -> a -> [b] -> [b] |
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
238 |
deleteBy2 _ _ [] = [] |
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
239 |
deleteBy2 eq x (y:ys) = if x `eq` y then ys else y : deleteBy2 eq x ys |
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
240 |
|
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
241 |
deleteFirstsBy2 :: (a -> b -> Bool) -> [a] -> [b] -> [a] |
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
242 |
deleteFirstsBy2 eq = foldl (flip (deleteBy2 (flip eq))) |
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10063
diff
changeset
|
243 |