From 3b0fee6c086d860529c7bb3096c358f2708afe5c Mon Sep 17 00:00:00 2001 From: driAn Date: Sat, 17 May 2008 23:32:06 +0000 Subject: [PATCH] fixed file loading for non-binary files, fixed sendmap packet creation git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2025 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/client.cpp | 11 ++++++----- source/src/tools.cpp | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index 5bceea91..ac7ae87b 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -442,25 +442,26 @@ void sendmap(char *mapname) if(!mapdata) return; if(!cfgdata) cfgsize = 0; - ENetPacket *packet = enet_packet_create(NULL, MAXTRANS + mapsize, ENET_PACKET_FLAG_RELIABLE); + ENetPacket *packet = enet_packet_create(NULL, MAXTRANS + mapsize + cfgsize, ENET_PACKET_FLAG_RELIABLE); ucharbuf p(packet->data, packet->dataLength); putint(p, SV_SENDMAP); sendstring(mapname, p); putint(p, mapsize); putint(p, cfgsize); - if(MAXMAPSENDSIZE - p.length() < mapsize) + if(MAXMAPSENDSIZE - p.length() < mapsize + cfgsize) { conoutf("map %s is too large to send", mapname); delete[] mapdata; + if(cfgsize) delete[] cfgdata; enet_packet_destroy(packet); return; } - p.put(mapdata, mapsize); + p.put(mapdata, mapsize); delete[] mapdata; - if(cfgdata) + if(cfgsize) { - if(MAXMAPSENDSIZE - p.length() >= cfgsize) p.put(cfgdata, cfgsize); + p.put(cfgdata, cfgsize); delete[] cfgdata; } diff --git a/source/src/tools.cpp b/source/src/tools.cpp index e838084f..b0ad85e3 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -163,12 +163,12 @@ char *loadfile(const char *fn, int *size, const char *mode) buf[len] = 0; size_t rlen = fread(buf, 1, len, f); fclose(f); - if(size_t(len)!=rlen) + if(size_t(len)!=rlen && (!mode || strchr(mode, 'b'))) { delete[] buf; return NULL; } - if(size!=NULL) *size = len; + if(size!=NULL) *size = rlen; return buf; }