Replace build and refit, and group collapse implementations Fix template creation build and refit # Conflicts: # Makefile.bundle.in # config.lib # src/animated_tile.cpp # src/blitter/32bpp_anim.hpp # src/blitter/32bpp_base.hpp # src/blitter/8bpp_base.hpp # src/blitter/null.hpp # src/build_vehicle_gui.cpp # src/command.cpp # src/command_func.h # src/console_gui.cpp # src/core/smallstack_type.hpp # src/date.cpp # src/debug.cpp # src/genworld_gui.cpp # src/ground_vehicle.hpp # src/group_gui.cpp # src/lang/korean.txt # src/linkgraph/linkgraph_gui.h # src/main_gui.cpp # src/misc_gui.cpp # src/network/core/game.h # src/network/core/packet.cpp # src/network/core/udp.cpp # src/network/core/udp.h # src/network/network_content.cpp # src/network/network_type.h # src/network/network_udp.cpp # src/newgrf_house.h # src/openttd.cpp # src/order_cmd.cpp # src/order_gui.cpp # src/os/unix/crashlog_unix.cpp # src/os/windows/crashlog_win.cpp # src/osk_gui.cpp # src/pathfinder/opf/opf_ship.cpp # src/rail_cmd.cpp # src/rail_gui.cpp # src/saveload/saveload.cpp # src/settings.cpp # src/settings_gui.cpp # src/smallmap_gui.h # src/station_base.h # src/station_cmd.cpp # src/table/gameopt_settings.ini # src/table/newgrf_debug_data.h # src/table/settings.ini # src/timetable_gui.cpp # src/toolbar_gui.cpp # src/train_gui.cpp # src/vehicle.cpp # src/vehicle_gui.cpp # src/vehiclelist.cpp # src/viewport.cpp # src/widgets/dropdown.cpp # src/window_gui.h
96 lines
3.3 KiB
C++
96 lines
3.3 KiB
C++
/* $Id$ */
|
|
|
|
/*
|
|
* This file is part of OpenTTD.
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* @file packet.h Basic functions to create, fill and read packets.
|
|
*/
|
|
|
|
#ifndef NETWORK_CORE_PACKET_H
|
|
#define NETWORK_CORE_PACKET_H
|
|
|
|
#include "config.h"
|
|
#include "core.h"
|
|
#include "../../string_type.h"
|
|
#include <string>
|
|
|
|
typedef uint16 PacketSize; ///< Size of the whole packet.
|
|
typedef uint8 PacketType; ///< Identifier for the packet
|
|
|
|
/**
|
|
* Internal entity of a packet. As everything is sent as a packet,
|
|
* all network communication will need to call the functions that
|
|
* populate the packet.
|
|
* Every packet can be at most SEND_MTU bytes. Overflowing this
|
|
* limit will give an assertion when sending (i.e. writing) the
|
|
* packet. Reading past the size of the packet when receiving
|
|
* will return all 0 values and "" in case of the string.
|
|
*
|
|
* --- Points of attention ---
|
|
* - all > 1 byte integral values are written in little endian,
|
|
* unless specified otherwise.
|
|
* Thus, 0x01234567 would be sent as {0x67, 0x45, 0x23, 0x01}.
|
|
* - all sent strings are of variable length and terminated by a '\0'.
|
|
* Thus, the length of the strings is not sent.
|
|
* - years that are leap years in the 'days since X' to 'date' calculations:
|
|
* (year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))
|
|
*/
|
|
struct Packet {
|
|
/** The next packet. Used for queueing packets before sending. */
|
|
Packet *next;
|
|
/**
|
|
* The size of the whole packet for received packets. For packets
|
|
* that will be sent, the value is filled in just before the
|
|
* actual transmission.
|
|
*/
|
|
PacketSize size;
|
|
/** The current read/write position in the packet */
|
|
PacketSize pos;
|
|
/** The buffer of this packet, of basically variable length up to SHRT_MAX. */
|
|
byte *buffer;
|
|
|
|
private:
|
|
/** Socket we're associated with. */
|
|
NetworkSocketHandler *cs;
|
|
|
|
public:
|
|
Packet(NetworkSocketHandler *cs);
|
|
Packet(PacketType type);
|
|
~Packet();
|
|
|
|
void ResetState(PacketType type);
|
|
|
|
/* Sending/writing of packets */
|
|
void PrepareToSend();
|
|
|
|
void Send_bool (bool data);
|
|
void Send_uint8 (uint8 data);
|
|
void Send_uint16(uint16 data);
|
|
void Send_uint32(uint32 data);
|
|
void Send_uint64(uint64 data);
|
|
void Send_string(const char *data);
|
|
void Send_binary(const char *data, const size_t size);
|
|
|
|
/* Reading/receiving of packets */
|
|
void ReadRawPacketSize();
|
|
void PrepareToRead();
|
|
|
|
bool CanReadFromPacket (uint bytes_to_read, bool non_fatal = false);
|
|
bool Recv_bool ();
|
|
uint8 Recv_uint8 ();
|
|
uint16 Recv_uint16();
|
|
uint32 Recv_uint32();
|
|
uint64 Recv_uint64();
|
|
void Recv_string(char *buffer, size_t size, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
|
|
void Recv_string(std::string &buffer, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
|
|
void Recv_binary(char *buffer, size_t size);
|
|
void Recv_binary(std::string &buffer, size_t size);
|
|
};
|
|
|
|
#endif /* NETWORK_CORE_PACKET_H */
|