Commit Graph

54 Commits

Author SHA1 Message Date
Rubidium d26629c15b Codechange: make encoded length of packet size and type more explicit 2024-03-17 19:48:34 +01:00
Patric Stout a3cfd23cf9
Codechange: rename byte to uint8_t (#12308) 2024-03-16 23:59:32 +01:00
Rubidium 15d02f51ed Codechange: use span to send bytes to Packet and add span recv function 2024-03-16 12:27:06 +01:00
Rubidium 6eff879e49 Codechange: pass the socket handler that is going to send the packet into the packet 2024-03-16 10:39:22 +01:00
Rubidium 36e1b32ccf Codechange: use std::deque of std::unique_ptr to queue packets 2024-02-05 16:30:49 +01:00
Rubidium eaae0bb5e7 Codechange: automatic adding of _t to (u)int types, and WChar to char32_t
for i in `find src -type f|grep -v 3rdparty/fmt|grep -v 3rdparty/catch2|grep -v 3rdparty/opengl|grep -v stdafx.h`; do sed 's/uint16& /uint16 \&/g;s/int8\([ >*),;[]\)/int8_t\1/g;s/int16\([ >*),;[]\)/int16_t\1/g;s/int32\([ >*),;[]\)/int32_t\1/g;s/int64\([ >*),;[]\)/int64_t\1/g;s/ uint32(/ uint32_t(/g;s/_uint8_t/_uint8/;s/Uint8_t/Uint8/;s/ft_int64_t/ft_int64/g;s/uint64$/uint64_t/;s/WChar/char32_t/g;s/char32_t char32_t/char32_t WChar/' -i $i; done
2023-07-19 19:30:14 +02:00
Michael Lutz a05fd7aa50 Change: [Network] Transfer command data as serialized byte stream without fixed structure.
The data will be transmitted as the length followed by the serialized data. This allows the command
data to be different for every command type in the future.
2021-12-16 22:28:32 +01:00
rubidium42 845fded2a0 Fix #9361, a2051ba: [Network] Off by one in CanWriteToPacket
Previously it did not allow writing a byte to a packet that was of size limit - 1 anymore.
2021-06-13 10:31:02 +02:00
rubidium42 bb8fd00760 Cleanup: [Network] Remove C-string Recv_string and its last use 2021-06-10 21:53:19 +02:00
Patric Stout ca9a7df752
Codechange: rename str_validate to StrMakeValid(InPlace) (#9304)
This to be more explicit the function changes the value, and not
returns yes/no.
2021-05-29 11:21:38 +02:00
Rubidium bb9121dbd4 Fix: comparison of narrow type to wide type in loop (potential for infinite loops) 2021-05-15 10:16:10 +02:00
Patric Stout a403653805
Codechange: [Network] split CloseSocket and CloseConnection more clearly (#9261)
* Codechange: [Network] split CloseSocket and CloseConnection more clearly

- CloseSocket now closes the actual OS socket.
- CloseConnection frees up the resources to just before CloseSocket.
- dtors call CloseSocket / CloseConnection where needed.
2021-05-13 11:46:51 +02:00
rubidium42 7bcc472f73 Add: [Network] Reading std::string from a packet 2021-05-03 17:56:05 +02:00
rubidium42 ba409e8c45 Add: [Network] Writing std::string to a packet 2021-05-03 17:56:05 +02:00
Charles Pigott 43b6f6915b Fix 8a95fee4: Missing initialiser in Packet constructor 2021-04-26 06:45:37 +02:00
Rubidium d6000c2ec5 Codechange: differentiate between UDP, TCP and compatibility MTU values 2021-04-25 21:27:54 +02:00
Rubidium 8b302761d4 Codechange: allow different limits in packet sizes 2021-04-25 21:27:54 +02:00
Rubidium 75386873b7 Codechange: use std::vector instead of a fixed size array for Packets 2021-04-24 20:42:01 +02:00
Rubidium 450178d780 Codechange: add accessor for the packet type to Packet and make the internal state of Packet private 2021-04-24 20:42:01 +02:00
Rubidium 3abefdf561 Codechange: remove public access to the next pointer in Packet 2021-04-24 20:42:01 +02:00
Rubidium f71fb0f54a Codechange: encapsulate reading the size of a Packet 2021-04-24 20:42:01 +02:00
Rubidium 6f161f6559 Codechange: encapsulate the logic about how many bytes can be sent from a buffer in to a Packet 2021-04-24 20:42:01 +02:00
Rubidium 38d15fc9b7 Codechange: move the logic shrinking of the packets into the Packet itself 2021-04-24 20:42:01 +02:00
Rubidium 98aa561cf7 Codechange: encapsulate reading data from sockets into Packets to prevent packet state modifications outside of the Packet 2021-04-24 20:42:01 +02:00
Rubidium a2051bad50 Codechange: move logic whether there is enough space in a packet to write data into the Packet 2021-04-24 20:42:01 +02:00
Rubidium c545cc9d70 Codechange: move more logic about packet size validity and reading into Packet 2021-04-24 20:42:01 +02:00
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 2019-11-10 17:59:20 +00:00
Henry Wilson 7c8e7c6b6e Codechange: Use null pointer literal instead of the NULL macro 2019-04-10 23:22:20 +02:00
Patric Stout e3c639a09f Remove: ENABLE_NETWORK switch
This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.

Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.

A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.

With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.

All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
2019-03-20 19:24:55 +01:00
rubidium 0463dbdc9e (svn r26482) -Codechange: add an include that allows us to undefine/redefine "unsafe" functions to prevent them from being used, and thus having to care about certain aspects of their return values 2014-04-23 20:13:33 +00:00
rubidium fefe22b4aa (svn r23590) -Codechange: make the string validation settings better expandable 2011-12-18 18:37:54 +00:00
rubidium 99ec3a044a (svn r22403) -Document: some more network/core code 2011-05-01 13:29:40 +00:00
rubidium 9c83a8975f (svn r21357) -Codechange: make it possible to resize the packet's buffer 2010-11-30 13:22:29 +00:00
rubidium 83c8c562bb (svn r18800) -Fix: in some cases with invalid packets one can crash recent trunk and 1.0.0 betas; 0.7.5 and before can't be crashed though. 2010-01-14 21:47:31 +00:00
smatz eb72a0095f (svn r17746) -Codechange: 'operator new' doesn't return NULL, NetworkSend_Init() is useless 2009-10-09 11:03:00 +00:00
rubidium 7fbc33dae1 (svn r17248) -Fix: add GPL license notice where appropriate 2009-08-21 20:21:05 +00:00
rubidium 86ca408d46 (svn r15626) -Fix [FS#2698]: UTF8 string handling could cause buffer overruns. 2009-03-06 01:23:25 +00:00
rubidium 07e135547e (svn r15135) -Fix/Change: allow str_validate (part of receiving strings from the network) to pass newlines instead of replacing them with question marks, but only when asked to do so. 2009-01-18 13:12:57 +00:00
rubidium 11da45ee55 (svn r14949) -Cleanup: pointer coding style 2009-01-10 00:31:47 +00:00
smatz f32ecbcadb (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute 2008-04-18 21:33:21 +00:00
rubidium a3ccdcea36 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary. 2008-01-07 14:23:25 +00:00
rubidium bf98e25e43 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed. 2007-12-25 09:48:53 +00:00
rubidium 01e20c9140 (svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations. 2007-12-21 19:21:21 +00:00
rubidium 8795050ff7 (svn r11290) -Fix: obiwan in the assertion that checked for overflows when writing a packet, causing still correctly sized packets to cause assertions. 2007-10-18 17:44:59 +00:00
rubidium 36bb92ae24 (svn r9050) -Codechange: Foo(void) -> Foo() 2007-03-07 11:47:46 +00:00
celestar 0ed4b64e64 (svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives). 2007-02-23 08:37:33 +00:00
rubidium 500f9a971a (svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans. 2007-02-02 23:16:58 +00:00
rubidium 16ce6def09 (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet. 2007-02-01 23:26:44 +00:00
rubidium 99f860e686 (svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size. 2007-02-01 22:30:35 +00:00
rubidium f72dde5236 (svn r8445) -Cleanup: remove some @params from comments as the parameters did not exist anymore and add comments to several variables/functions. 2007-01-28 20:47:25 +00:00