* Serializes the NetworkGameInfo struct to the packet. * @param p the packet to write the data to. * @param info the NetworkGameInfo struct to serialize from. */
| 203 | * @param info the NetworkGameInfo struct to serialize from. |
| 204 | */ |
| 205 | void SerializeNetworkGameInfo(Packet &p, const NetworkServerGameInfo &info, bool send_newgrf_names) |
| 206 | { |
| 207 | p.Send_uint8 (NETWORK_GAME_INFO_VERSION); |
| 208 | |
| 209 | /* |
| 210 | * Please observe the order. |
| 211 | * The parts must be read in the same order as they are sent! |
| 212 | */ |
| 213 | |
| 214 | /* Update the documentation in game_info.h on changes |
| 215 | * to the NetworkGameInfo wire-protocol! */ |
| 216 | |
| 217 | /* NETWORK_GAME_INFO_VERSION = 7 */ |
| 218 | p.Send_uint64(info.ticks_playing); |
| 219 | |
| 220 | /* NETWORK_GAME_INFO_VERSION = 6 */ |
| 221 | p.Send_uint8(send_newgrf_names ? NST_GRFID_MD5_NAME : NST_GRFID_MD5); |
| 222 | |
| 223 | /* NETWORK_GAME_INFO_VERSION = 5 */ |
| 224 | GameInfo *game_info = Game::GetInfo(); |
| 225 | p.Send_uint32(game_info == nullptr ? -1 : (uint32_t)game_info->GetVersion()); |
| 226 | p.Send_string(game_info == nullptr ? "" : game_info->GetName()); |
| 227 | |
| 228 | /* NETWORK_GAME_INFO_VERSION = 4 */ |
| 229 | { |
| 230 | /* Only send the GRF Identification (GRF_ID and MD5 checksum) of |
| 231 | * the GRFs that are needed, i.e. the ones that the server has |
| 232 | * selected in the NewGRF GUI and not the ones that are used due |
| 233 | * to the fact that they are in [newgrf-static] in openttd.cfg */ |
| 234 | uint count = std::ranges::count_if(info.grfconfig, [](const auto &c) { return !c->flags.Test(GRFConfigFlag::Static); }); |
| 235 | p.Send_uint8 (count); // Send number of GRFs |
| 236 | |
| 237 | /* Send actual GRF Identifications */ |
| 238 | for (const auto &c : info.grfconfig) { |
| 239 | if (c->flags.Test(GRFConfigFlag::Static)) continue; |
| 240 | |
| 241 | SerializeGRFIdentifier(p, c->ident); |
| 242 | if (send_newgrf_names) p.Send_string(c->GetName()); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /* NETWORK_GAME_INFO_VERSION = 3 */ |
| 247 | p.Send_uint32(info.calendar_date.base()); |
| 248 | p.Send_uint32(info.calendar_start.base()); |
| 249 | |
| 250 | /* NETWORK_GAME_INFO_VERSION = 2 */ |
| 251 | p.Send_uint8 (info.companies_max); |
| 252 | p.Send_uint8 (info.companies_on); |
| 253 | p.Send_uint8 (info.clients_max); // Used to be max-spectators |
| 254 | |
| 255 | /* NETWORK_GAME_INFO_VERSION = 1 */ |
| 256 | p.Send_string(info.server_name); |
| 257 | p.Send_string(info.server_revision); |
| 258 | p.Send_bool (info.use_password); |
| 259 | p.Send_uint8 (info.clients_max); |
| 260 | p.Send_uint8 (info.clients_on); |
| 261 | p.Send_uint8 (info.spectators_on); |
| 262 | p.Send_uint16(info.map_width); |
no test coverage detected