Commit graph

2316 commits

Author SHA1 Message Date
Yamagi Burmeister
5e67596d56 Strip trailing slashes from download server URL.
If the server sends us an URL with trailing slash we're generating URIs
like http://example.com//maps/foo.bsp. While double // are perfectly
valid they might me rejected by some servers. So let's play save.
2019-01-30 17:14:13 +01:00
Yamagi Burmeister
e05f95e3fb Don't free() the download queues last element twice.
While at it replace the crappy Z_TagMalloc() with the standard malloc().
Z_TagMalloc() ist just a wrapper arround malloc(), there's no functional
change.
2019-01-30 17:14:13 +01:00
Yamagi Burmeister
eb048e8611 Implement fallback logic from HTTP downloading to UDP.
This looks easy, but is rather hacky... Downloading is implemented
through the precacher. The server sends an asset list, while loading
the map another one is generated. CL_RequestNextDownload() goes
through this list, in the order models / maps -> sounds -> images,
calls CL_CheckOrDownloadFile() for each file. CL_CheckOrDownloadFile()
checks if the file is already there, return true if it is and false
if not. If the return code is false CL_RequestNextDownload() itself
returns, it's called again by CL_ParseDownload() as soon as the just
queued file finished downloading. This way all missing files are
downloaded one after the other, when CL_RequestNextDownload() finally
reaches it's end (all files are there) it send 'begin' to the server,
thus putting the client into the game.

HTTP downloads are parallel, so CL_RequestNextDownload() cannot track
which files are there and which are missing. The work around for that is
to queue the file but have CL_CheckOrDownloadFile() return true. So
CL_RequestNextDownload() thinks the file is already there, continues
with the next one, until all missing files are queued. After that it
polls CL_PendingHTTPDownloads() and sends the 'begin' as soon as all
HTTP downloads are finished.

If a HTTP download fails we cannot just queue it as UDP download,
because the precacher things that the file is already there. And we
can't tell the precacher that it's not because the precacher tracks
files only by the number of downloaded files per asste type and not
their name. Just decreasing the number of downloaded files isn't
possible since the precacher may have progressed to the next asset
type.

So: On the HTTP side it's tracked if there was an error or not.  After
CL_RequestNextDownload() has queued all files and waited for all HTTP
downloads to finish it checks the HTTP error status. If there was an
error the precacher state is reset and CL_RequestNextDownload() recurses
into itself to take another run. All files that couldn't be downloaded
are queued again, this time as UDP downloads.
2019-01-30 17:14:13 +01:00
Yamagi
78366472f9
Merge pull request #351 from CanntAim/master
Fixed menu code to correctly parse maps.lst file.
2019-01-19 16:53:52 +01:00
Yamagi
dc623840ea
Merge pull request #358 from 0lvin/delete_menu
Use separator instead action in delete menu header
2019-01-19 16:52:53 +01:00
Denis Pauk
a1773b91d7 Use separator instead action in menu header 2019-01-16 23:23:48 +02:00
Neil Richardson
a83add6ea9 Fix case error for linux -> win32 cross compile 2019-01-13 20:40:58 +01:00
Jonathan Bergeron
d82708b448 added windows implementation of sys_removedir and used snprintf in the unix one 2019-01-13 20:33:30 +01:00
JBerg
867046bb8b requested fixes my last commit: proper null checks + undid my removal of a slash + fixed my previous use of va() 2019-01-13 20:32:39 +01:00
JBerg
be8bab6603 added feature to delete savegames 2019-01-13 20:32:39 +01:00
Yamagi Burmeister
7d9016510e Fix snd_restart. it should restore the OGG playback state.
My solution to this problem is somewhat hacky. A newly added function
OGG_SaveState() can be called to save the state and OGG_RecoverState()
at a later time to restore it. There's only one state and it works
only iff OGG is state playing.

This closes #347.
2019-01-05 19:26:50 +01:00
Yamagi Burmeister
46503018f0 Require cURL in CMakeLists.txt if USE_CURL is defined. 2019-01-05 16:53:00 +01:00
Daniel Gibson
f0d848d3d3 Documentation for HTTP downloading 2019-01-03 16:54:22 -01:00
Yamagi Burmeister
ec6e0ee392 Provide a write callback to cURL.
If we're passing file handles to libcurl to write the data into, the
game may crash under Windows due to incompatible C runtimes between cURL
and quake2. This is even mentioned in the official cURL doku.
2019-01-03 17:42:22 +01:00
Yamagi Burmeister
2199b67a39 Limit the number of parallel downloads to just 1.
Since the moment I took a very first look at the download code I wasn't
a friend of parallel downloads. There're several reasons for that:

- Parallel downloading needs some ugly hacks. For example downloading a
  pak file has a high chance to make asset downloads running in parallel
  unnecessary.
- Parallel downloads are hard to debug.
- There's just no need for them. I've tested several connection, 1
  GBit/s LAN, 50 MBit/s DSL, 6 MBit/s DSL, and there wasn't a
  significant difference between 1, 4 or even 16 parallel downloads.

I'm leaving the parallel download code in place. I someone really wants
parallel downloads he can bump the MAX_HTTP_HANDLES define.
2019-01-03 17:40:06 +01:00
Ivan Pozdnyakov
d43a77029c
Fixed menu code to correctly parse maps.lst file. 2018-12-22 01:14:47 -05:00
Yamagi Burmeister
7b200208c5 Fix the signal handler.
The signal handler was always fishy since it modified the global process
state but worked on all common platforms. libcurl turns the process into
a multithreaded environment, thus breaking that fragile construction.
After the signal handler was called the global state is inconsistent and
there's a high chance of things going wrong. For example at the net curl
download or when setjmp() is called in Qcommon_Frame().
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
95c1bb9972 Some alterations to the libcurl search pathes.
- On Linux try libcurl.so last, because that one is for linking only.
- Support libcurl.dll on Windows.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
537e6d8de3 Port the server side of HTTP downloading from q2dos. 2018-12-20 18:01:38 +01:00
Yamagi Burmeister
5b44c9f3b4 Make the (new and old) download code UTF-8 compatible.
- Replace all remove() with Sys_Remove().
- Implement Sys_Rename() and replace all rename() with it.

This is believed to close #348.
2018-12-20 18:01:38 +01:00
Daniel Gibson
49bb6bf9f0 Don't leak download queue entries, remove them as soon ans file is done.
Until now download queues entries were created for each file, but only
removed in the unlikely event of changed download server. This leaked
about 4200 byte per file. Fix this by:

- Create a new function CL_RemoveFromQueue() that removes a queue entry
  and call it everytime when a download either finished, failed or
  aborted.
- Retire the 'download done' state, just the queue entries associated
  with a download handle to NULL to communicate that the handle is
  unused.
- Cleanup the full queue at shutdown.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
04a1a6958d Fix USE_CURL build under Windows. 2018-12-20 18:01:38 +01:00
Yamagi Burmeister
2271c0bb91 Add the HTTP and cURL stuff to cmake. 2018-12-20 18:01:38 +01:00
Yamagi Burmeister
da8bb7f7ee Add header guards and all necessary includes to download.h. 2018-12-20 18:01:38 +01:00
Yamagi Burmeister
f0d244e7b4 Rename cl_http.c to curl/download.c and http.h to download.h.
This is more in line with our file structure and other changes that
added functionality to the client.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
c0a6e4270f Load libcurl.so at runtime.
Loading libcurl at runtime instead of linking it at compile time makes
things a lot easier and more reliable on Windows. On other platform
libcurl can be installed as optional dependency instead as an hard one.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
cd1b67e489 Whitespace and indention cleanups to the HTTP download code. 2018-12-20 18:01:38 +01:00
Yamagi Burmeister
0ad406a95f Rework HTTP download console output.
We're printing only the two relevant informations: A download was queued
and a download finished or failed. That's enough to see what's going on
and not too noisy.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
29f9f48a06 Remove canceling of all downloads if the bsp failed to download...
...and fix the bugs, that were worked around with that crap, instead.
This removes some corner cases like cancelation of all HTTP downloads
and fallback to UDP if too many 404 errors were generated. If this is
still a problem in reality - for example HTTP servers blocking the
client after too many 404 or even crashing HTTP server - fix the server
and don't force the clients to work around that.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
7f085db431 Remove prioritization of pak file download.
We aren't in 1997 anymore, todays broadband connections are fast enough
to handle multiple large files. This may download some assets twice if
the server provides both a pak file with all assets and the assets as
plain files.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
df82598984 Rewrite memory buffer used by CURL.
There's no need to parse the HTTP header on our side of things, CURL can
do that. And the old buffer code was overcomplicated, simplify it. While
at it switch to normal malloc().
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
9ba97177ea General cleanup of the ported download code.
- A lot of style fixes.
- Remove unused code.
- Simplify things.
- Fix some obvious bugs.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
3a24b9d6cf Remove the download speed calculation.
While the download speed calculations may be useful their implementation
is crappy and the integration into the console is rather fragile. If we
really want to support the progress bar with HTTP downloads this needs
to be reimplemented.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
f51661133d Fix URL generation.
The URL generation logic was buggy, it took the local fs_gamedir into
account when determining the files path on the server. That could have
worked in r1q2 or q2dos since they assume that the executable dir is
also the config dir. But it breaks in YQ2 were the executable dir and
the config dir differ.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
5d9aefd4ef Implement missing client interfaces.
These are:
- CL_ResetPrecacheCheck(): Resets the precacher, forces it to reevaluate
  which assets are available and what needs to be downloaded.
- FS_FileInGamedir(): Checks if a file (and only a real file, not
  somthing in a pak) is available in fs_gamedir.
- FS_AddPAKFromGamedir(): Adds a pak in fs_gamedir to the search path.
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
0a94a8ee92 Port the HTTP / CURL download stuff from q2dos.
This is a very first cut:
* It compiles
* It doesn't crash

What's missing:
* cmake integration
* CURL should be loaded dynamically
* Integration between download code and filesystem
* Likely UTF-8 stuff
* cl_http.c needs cleanup
* Windows support
2018-12-20 18:01:38 +01:00
Yamagi Burmeister
380642468b Use %z modifiert to print a size_t.
This fixes a gcc warning on Win32.
2018-12-20 17:59:19 +01:00
Yamagi Burmeister
aa57ec9f7b Fix oversight in last commit, the '/ 2' is evil. 2018-11-22 21:15:09 +01:00
Yamagi Burmeister
e137ff1168 Fix stupid bug in brush model indix block size calculations.
We're taking indices and converting them to pointer relative to the
hunks base. Yes, that's dirty. Since the indices are stored as 32 bit
values and hunks are generally small using 32 bit pointers is enough,
even on 64 bit platforms. So the code took the size of void* / 2...
See the problem? Yes, that's not a good idea on 32 bit platforms. Bite
the bullet and just take the size of void*. Shouldn't be a problem,
because the indices are the first thing that's loaded and the hunk is
trimmed right after it anyways. If, and just if, we really need each and
every byte in the early stages of map loading we need two cases. One for
64 bit and one for 32 bit.

This fixes issue #346. Kudos to @ricardosdl for the analysis.
2018-11-22 17:41:55 +01:00
Yamagi Burmeister
4443d0a2eb Fix Windows build.
Note to me: Ask contributors if they've tested their changes on Windows.
2018-11-22 16:55:08 +01:00
Yamagi
ee4135fd0a
Merge pull request #343 from 0lvin/cppcheck
Cppcheck fixes
2018-11-14 19:04:27 +01:00
Yamagi Burmeister
587382644c Fix lost time calculation.
Lost time is time that we spend but didn't account. So the lost time
doesn't shorten a second (in fact that would mean that we'll lose the
time twice), it lengthen a second. Since has a small but noticeable
impact on timing when running with vsync enabled.
2018-11-12 22:17:10 +01:00
Denis Pauk
25498be7ca Support retextured images.
Code based on www.quakewiki.net/quakesrc/39.html
Code ignores skin images, and is disabled by default.
2018-11-12 23:02:23 +02:00
Denis Pauk
0307361101 Remove unused cvars 2018-11-12 23:01:08 +02:00
Denis Pauk
1b2708c06e cppcheck fixes.
In src/backends/unix/network.c:
* line 181: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?
* line 276: The scope of the variable 'tmp' can be reduced.
* line 665: The scope of the variable 'mcast_addr' can be reduced.
* line 665: The scope of the variable 'mcast_port' can be reduced.
* line 666: The scope of the variable 'error' can be reduced.
* line 775: The scope of the variable 'i' can be reduced.

In src/backends/windows/network.c:
* line 186: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?
* line 287: The scope of the variable 'tmp' can be reduced.
* line 707: The scope of the variable 'mcast_addr' can be reduced.
* line 707: The scope of the variable 'mcast_port' can be reduced.
* line 1049: The scope of the variable 'err' can be reduced.
* line 1163: The scope of the variable 'i' can be reduced.

In src/client/menu/menu.c

arrayIndexOutOfBounds:
* line 1921: Array 'creditsIndex[256]' accessed at index 256, which is out of bounds.

variableScope:
* line 332: The scope of the variable 'item' can be reduced.
* line 533: The scope of the variable 'x' can be reduced.
* line 533: The scope of the variable 'y' can be reduced.
* line 838: The scope of the variable 'b' can be reduced.
* line 864: The scope of the variable 'b' can be reduced.
* line 1910: The scope of the variable 'n' can be reduced.
* line 2199: The scope of the variable 'str' can be reduced.
* line 2812: The scope of the variable 'length' can be reduced.
* line 2813: The scope of the variable 'i' can be reduced.
* line 3838: The scope of the variable 'c' can be reduced.
* line 4112: The scope of the variable 'scratch' can be reduced.
* line 4181: The scope of the variable 'i' can be reduced.
* line 4345: The scope of the variable 's' can be reduced.

In src/game/player/hud.c

arrayIndexOutOfBounds:
* line 132: Array itemlist[43] accessed at index 255 which is out of bounds.
Itemlist assigned only once, and has only 43 items, better ignore unexisted items.

variableScope:
* line 82: The scope of the variable 'n' can be reduced.
* line 217: The scope of the variable 'x' can be reduced.
* line 217: The scope of the variable 'y' can be reduced.
* line 218: The scope of the variable 'cl' can be reduced.
* line 583: The scope of the variable 'cl' can be reduced.
2018-11-12 22:59:10 +02:00
Hugo Locurcio
2bf45a4750 Fix some typos in documentation 2018-11-10 18:16:30 +01:00
Yamagi
bbdd3f1d60
Merge pull request #342 from earth-metal/master
Add support for CTF options to "start network server" menu.
2018-11-07 18:04:22 +01:00
Yamagi Burmeister
4c63f7893c Update links. 2018-11-07 16:43:54 +01:00
Yamagi Burmeister
3b71e8d309 Transform the CONTRIBUTE file into a Contributing Guide 2018-11-07 16:38:41 +01:00
Yamagi Burmeister
900ef53670 Simplify the README, link to the documentation and the homepage. 2018-11-07 16:38:41 +01:00