diff --git a/.hgignore b/.hgignore new file mode 100644 index 00000000..4b97af97 --- /dev/null +++ b/.hgignore @@ -0,0 +1,15 @@ +# Binaries +\.dll$ +\.exe$ +\.so$ + +# Files generated by Visual Studio +\.aps$ +\.ncb$ +\.suo$ +\.user$ + +# Build directories +/CrazyDebug.* +/Debug.* +/Release.* diff --git a/configs/core.cfg b/configs/core.cfg index 70b897f2..86163810 100644 --- a/configs/core.cfg +++ b/configs/core.cfg @@ -106,7 +106,7 @@ /** * Sets the server to connect to for auotmatic gamedata updates. */ - "AutoUpdateServer" "hayate.alliedmods.net" + "AutoUpdateServer" "smupdate.alliedmods.net" /** * Sets the port to connect to on the AutoUpdateServer server diff --git a/core/Makefile b/core/Makefile index 899a6e67..38ea2128 100644 --- a/core/Makefile +++ b/core/Makefile @@ -5,8 +5,7 @@ SMSDK = .. SRCDS_BASE = ~/srcds HL2SDK_ORIG = ../../hl2sdk HL2SDK_OB = ../../hl2sdk-ob -SOURCEMM14 = ../../sourcemm-1.4 -SOURCEMM16 = ../../sourcemm-1.6 +MMSOURCE17 = ../../mmsource-1.7 ##################################### ### EDIT BELOW FOR OTHER PROJECTS ### @@ -51,7 +50,7 @@ ifeq "$(ENGINE)" "original" HL2SDK = $(HL2SDK_ORIG) HL2PUB = $(HL2SDK_ORIG)/public HL2LIB = $(HL2SDK_ORIG)/linux_sdk - METAMOD = $(SOURCEMM14) + METAMOD = $(MMSOURCE17)/core-legacy INCLUDE += -I$(HL2SDK)/public/dlls SRCDS = $(SRCDS_BASE) BINARY = sourcemod.1.ep1.so @@ -62,7 +61,7 @@ ifeq "$(ENGINE)" "orangebox" HL2PUB = $(HL2SDK_OB)/public HL2LIB = $(HL2SDK_OB)/lib/linux CFLAGS += -DORANGEBOX_BUILD - METAMOD = $(SOURCEMM16) + METAMOD = $(MMSOURCE17)/core INCLUDE += -I$(HL2SDK)/public/game/server SRCDS = $(SRCDS_BASE)/orangebox BINARY = sourcemod.2.ep2.so @@ -71,14 +70,10 @@ endif LINK += $(HL2LIB)/tier1_i486.a $(HL2LIB)/mathlib_i486.a vstdlib_i486.so \ tier0_i486.so -lpthread -static-libgcc - -INCLUDE_SMSDK = -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn - -INCLUDE_SM16 = -I. -I.. -I$(SOURCEMM16)/sourcehook $(INCLUDE_SMSDK) INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \ -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 -I$(METAMOD) -I$(METAMOD)/sourcehook \ - -I$(METAMOD)/sourcemm -Isystems $(INCLUDE_SMSDK) + -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror \ @@ -120,7 +115,7 @@ all: check $(MAKE) -f Makefile sourcemod check: - if [ "$(ENGSET)" == "false" ]; then \ + if [ "$(ENGSET)" = "false" ]; then \ echo "You must supply ENGINE=orangebox or ENGINE=original"; \ exit 1; \ fi diff --git a/core/msvc8/sourcemod_mm.vcproj b/core/msvc8/sourcemod_mm.vcproj index 9aea667c..b8206d2c 100644 --- a/core/msvc8/sourcemod_mm.vcproj +++ b/core/msvc8/sourcemod_mm.vcproj @@ -39,9 +39,8 @@ /> + + + + @@ -877,6 +888,14 @@ RelativePath="..\HalfLife2.cpp" > + + + + @@ -925,10 +944,22 @@ RelativePath="..\PlayerManager.cpp" > + + + + + + @@ -1043,6 +1074,14 @@ RelativePath="..\EventManager.h" > + + + + @@ -1059,6 +1098,14 @@ RelativePath="..\HalfLife2.h" > + + + + @@ -1107,10 +1154,22 @@ RelativePath="..\PlayerManager.h" > + + + + + + @@ -1281,79 +1340,6 @@ > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LocalToString(params[2], &buffer); + if (params[4] != -1) + { + if (size_t(params[4]) > size_t(params[3])) + { + return pContext->ThrowNativeError("read_count (%u) is greater than buffer size (%u)", + params[4], + params[3]); + } + + num_read = (cell_t)fread(buffer, 1, params[4], pFile); + + if (num_read != params[4] && ferror(pFile)) + { + return -1; + } + + return num_read; + } + char val; while (1) { - /* If we're in stop mode, break as soon as the buffer is full. */ - if (params[4] && (params[3] == 0 || num_read >= params[3] - 1)) + if (params[3] == 0 || num_read >= params[3] - 1) { break; } diff --git a/extensions/bintools/Makefile b/extensions/bintools/Makefile index 60a5df27..bcd84c29 100644 --- a/extensions/bintools/Makefile +++ b/extensions/bintools/Makefile @@ -5,8 +5,7 @@ SMSDK = ../.. SRCDS_BASE = ~/srcds HL2SDK_ORIG = ../../../hl2sdk HL2SDK_OB = ../../../hl2sdk-ob -SOURCEMM14 = ../../../sourcemm-1.4 -SOURCEMM16 = ../../../sourcemm-1.6 +MMSOURCE17 = ../../../mmsource-1.7 ##################################### ### EDIT BELOW FOR OTHER PROJECTS ### @@ -34,7 +33,7 @@ ifeq "$(ENGINE)" "original" HL2SDK = $(HL2SDK_ORIG) HL2PUB = $(HL2SDK_ORIG)/public HL2LIB = $(HL2SDK_ORIG)/linux_sdk - METAMOD = $(SOURCEMM14) + METAMOD = $(MMSOURCE17)/core-legacy INCLUDE += -I$(HL2SDK)/public/dlls SRCDS = $(SRCDS_BASE) override ENGSET = true @@ -44,7 +43,7 @@ ifeq "$(ENGINE)" "orangebox" HL2PUB = $(HL2SDK_OB)/public HL2LIB = $(HL2SDK_OB)/lib/linux CFLAGS += -DORANGEBOX_BUILD - METAMOD = $(SOURCEMM16) + METAMOD = $(MMSOURCE17)/core INCLUDE += -I$(HL2SDK)/public/game/server SRCDS = $(SRCDS_BASE)/orangebox override ENGSET = true @@ -56,8 +55,7 @@ ifeq "$(USEMETA)" "true" LINK += $(LINK_HL2) INCLUDE += -I. -I.. -Isdk -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 \ - -I$(METAMOD) -I$(METAMOD)/sourcehook -I$(METAMOD)/sourcemm -I$(SMSDK)/public \ - -I$(SMSDK)/public/sourcepawn + -I$(METAMOD) -I$(METAMOD)/sourcehook -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/extensions -I$(SMSDK)/public/jit \ -I$(SMSDK)/public/jit/x86 -I$(SMSDK)/public/sourcepawn @@ -101,14 +99,14 @@ $(BIN_DIR)/%.o: %.cpp all: check mkdir -p $(BIN_DIR)/sdk - if [ "$(USEMETA)" == "true" ]; then \ + if [ "$(USEMETA)" = "true" ]; then \ ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so; \ ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so; \ fi $(MAKE) -f Makefile extension check: - if [ "$(USEMETA)" == "true" ] && [ "$(ENGSET)" == "false" ]; then \ + if [ "$(USEMETA)" = "true" ] && [ "$(ENGSET)" = "false" ]; then \ echo "You must supply ENGINE=orangebox or ENGINE=original"; \ exit 1; \ fi diff --git a/extensions/clientprefs/Makefile b/extensions/clientprefs/Makefile index b951a39f..74c1c915 100644 --- a/extensions/clientprefs/Makefile +++ b/extensions/clientprefs/Makefile @@ -5,8 +5,7 @@ SMSDK = ../.. SRCDS_BASE = ~/srcds HL2SDK_ORIG = ../../../hl2sdk HL2SDK_OB = ../../../hl2sdk-ob -SOURCEMM14 = ../../../sourcemm-1.4 -SOURCEMM16 = ../../../sourcemm-1.6 +MMSOURCE17 = ../../../mmsource-1.7 ##################################### ### EDIT BELOW FOR OTHER PROJECTS ### @@ -34,7 +33,7 @@ ifeq "$(ENGINE)" "original" HL2SDK = $(HL2SDK_ORIG) HL2PUB = $(HL2SDK_ORIG)/public HL2LIB = $(HL2SDK_ORIG)/linux_sdk - METAMOD = $(SOURCEMM14) + METAMOD = $(MMSOURCE17)/core-legacy INCLUDE += -I$(HL2SDK)/public/dlls SRCDS = $(SRCDS_BASE) override ENGSET = true @@ -44,7 +43,7 @@ ifeq "$(ENGINE)" "orangebox" HL2PUB = $(HL2SDK_OB)/public HL2LIB = $(HL2SDK_OB)/lib/linux CFLAGS += -DORANGEBOX_BUILD - METAMOD = $(SOURCEMM16) + METAMOD = $(MMSOURCE17)/core INCLUDE += -I$(HL2SDK)/public/game/server SRCDS = $(SRCDS_BASE)/orangebox override ENGSET = true @@ -56,11 +55,10 @@ ifeq "$(USEMETA)" "true" LINK += $(LINK_HL2) INCLUDE += -I. -I.. -Isdk -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 \ - -I$(METAMOD) -I$(METAMOD)/sourcehook -I$(METAMOD)/sourcemm -I$(SMSDK)/public \ - -I$(SMSDK)/public/sourcepawn + -I$(METAMOD) -I$(METAMOD)/sourcehook -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn -I$(SMSDK)/public/extensions \ - -I$(SOURCEMM16)/sourcehook + -I$(MMSOURCE17)/core/sourcehook endif LINK += -static-libgcc @@ -101,14 +99,14 @@ $(BIN_DIR)/%.o: %.cpp all: check mkdir -p $(BIN_DIR)/sdk - if [ "$(USEMETA)" == "true" ]; then \ + if [ "$(USEMETA)" = "true" ]; then \ ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so; \ ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so; \ fi $(MAKE) -f Makefile extension check: - if [ "$(USEMETA)" == "true" ] && [ "$(ENGSET)" == "false" ]; then \ + if [ "$(USEMETA)" = "true" ] && [ "$(ENGSET)" = "false" ]; then \ echo "You must supply ENGINE=orangebox or ENGINE=original"; \ exit 1; \ fi diff --git a/extensions/clientprefs/msvc8/clientprefs.vcproj b/extensions/clientprefs/msvc8/clientprefs.vcproj index 47d6402a..855e1e8b 100644 --- a/extensions/clientprefs/msvc8/clientprefs.vcproj +++ b/extensions/clientprefs/msvc8/clientprefs.vcproj @@ -40,7 +40,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - max_size. diff --git a/plugins/include/sdktools_stocks.inc b/plugins/include/sdktools_stocks.inc index f71b4b1c..13e2159a 100644 --- a/plugins/include/sdktools_stocks.inc +++ b/plugins/include/sdktools_stocks.inc @@ -58,7 +58,7 @@ stock FindTeamByName(const String:name[]) { GetTeamName(i, team_name, sizeof(team_name)); - if (strncmp(team_name, name, name_len) == 0) + if (strncmp(team_name, name, name_len, false) == 0) { if (found_team >= 0) { diff --git a/plugins/sql-admin-manager.sp b/plugins/sql-admin-manager.sp index 1926985f..9b085847 100644 --- a/plugins/sql-admin-manager.sp +++ b/plugins/sql-admin-manager.sp @@ -828,9 +828,9 @@ public Action:Command_AddAdmin(client, args) decl String:password[32]; decl String:safe_password[80]; - if (args > 4) + if (args >= 6) { - GetCmdArg(5, password, sizeof(password)); + GetCmdArg(6, password, sizeof(password)); SQL_EscapeString(db, password, safe_password, sizeof(safe_password)); } else { safe_password[0] = '\0'; diff --git a/plugins/testsuite/filetest.sp b/plugins/testsuite/filetest.sp new file mode 100644 index 00000000..7a6a1f1e --- /dev/null +++ b/plugins/testsuite/filetest.sp @@ -0,0 +1,62 @@ +#include + +public Plugin:myinfo = +{ + name = "File test", + author = "AlliedModders LLC", + description = "Tests file functions", + version = "1.0.0.0", + url = "http://www.sourcemod.net/" +}; + +public OnPluginStart() +{ + RegServerCmd("test_fread1", Test_ReadBinStr); +} + +Handle:OpenFile2(const String:path[], const String:mode[]) +{ + new Handle:file = OpenFile(path, mode); + if (file == INVALID_HANDLE) + PrintToServer("Failed to open file %s for %s", path, mode); + else + PrintToServer("Opened file handle %x: %s", file, path); + return file; +} + +public Action:Test_ReadBinStr(args) +{ + new items[] = {1, 3, 5, 7, 0, 92, 193, 26, 0, 84, 248, 2}; + new Handle:of = OpenFile2("smbintest", "wb"); + if (of == INVALID_HANDLE) + return Plugin_Handled; + WriteFile(of, items, sizeof(items), 1); + CloseHandle(of); + + new Handle:inf = OpenFile2("smbintest", "rb"); + new String:buffer[sizeof(items)]; + ReadFileString(inf, buffer, sizeof(items), sizeof(items)); + FileSeek(inf, 0, SEEK_SET); + new items2[sizeof(items)]; + ReadFile(inf, items2, sizeof(items), 1); + CloseHandle(inf); + + for (new i = 0; i < sizeof(items); i++) + { + if (buffer[i] != items[i]) + { + PrintToServer("FAILED ON INDEX %d: %d != %d", i, buffer[i], items[i]); + return Plugin_Handled; + } + else if (items2[i] != items[i]) + { + PrintToServer("FAILED ON INDEX %d: %d != %d", i, items2[i], items[i]); + return Plugin_Handled; + } + } + + PrintToServer("Test passed!"); + + return Plugin_Handled; +} + diff --git a/public/mms_sample_ext/Makefile b/public/mms_sample_ext/Makefile index 87801801..8d55d366 100644 --- a/public/mms_sample_ext/Makefile +++ b/public/mms_sample_ext/Makefile @@ -5,8 +5,7 @@ SMSDK = .. SRCDS_BASE = ~/srcds HL2SDK_ORIG = ../../../hl2sdk HL2SDK_OB = ../../../hl2sdk-ob -SOURCEMM14 = ../../../sourcemm-1.4 -SOURCEMM16 = ../../../sourcemm-1.6 +MMSOURCE17 = ../../../mmsource-1.7 ##################################### ### EDIT BELOW FOR OTHER PROJECTS ### @@ -31,7 +30,7 @@ ifeq "$(ENGINE)" "original" HL2SDK = $(HL2SDK_ORIG) HL2PUB = $(HL2SDK_ORIG)/public HL2LIB = $(HL2SDK_ORIG)/linux_sdk - METAMOD = $(SOURCEMM14) + METAMOD = $(MMSOURCE17)/core-legacy INCLUDE += -I$(HL2SDK)/public/dlls SRCDS = $(SRCDS_BASE) override ENGSET = true @@ -41,7 +40,7 @@ ifeq "$(ENGINE)" "orangebox" HL2PUB = $(HL2SDK_OB)/public HL2LIB = $(HL2SDK_OB)/lib/linux CFLAGS += -DORANGEBOX_BUILD - METAMOD = $(SOURCEMM16) + METAMOD = $(MMSOURCE17)/core INCLUDE += -I$(HL2SDK)/public/game/server SRCDS = $(SRCDS_BASE)/orangebox override ENGSET = true @@ -50,8 +49,8 @@ endif LINK = vstdlib_i486.so tier0_i486.so -static-libgcc INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 \ - -I$(METAMOD) -I$(METAMOD)/sourcehook -I$(METAMOD)/sourcemm -I$(SMSDK) -I$(SMSDK)/jit \ - -I$(SMSDK)/jit/x86 -I$(SMSDK)/extensions -I$(SMSDK)/sourcepawn + -I$(METAMOD) -I$(METAMOD)/sourcehook -I$(SMSDK) -I$(SMSDK)/jit -I$(SMSDK)/jit/x86 \ + -I$(SMSDK)/extensions -I$(SMSDK)/sourcepawn CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -mfpmath=sse \ @@ -90,7 +89,7 @@ all: check $(MAKE) -f Makefile mms_ext check: - if [ "$(ENGSET)" == "false" ]; then \ + if [ "$(ENGSET)" = "false" ]; then \ echo "You must supply ENGINE=orangebox or ENGINE=original"; \ exit 1; \ fi diff --git a/public/sample_ext/Makefile b/public/sample_ext/Makefile index b68f5bd1..ea256b8c 100644 --- a/public/sample_ext/Makefile +++ b/public/sample_ext/Makefile @@ -5,8 +5,7 @@ SMSDK = ../.. SRCDS_BASE = ~/srcds HL2SDK_ORIG = ../../../hl2sdk HL2SDK_OB = ../../../hl2sdk-ob -SOURCEMM14 = ../../../sourcemm-1.4 -SOURCEMM16 = ../../../sourcemm-1.6 +MMSOURCE17 = ../../../mmsource-1.7 ##################################### ### EDIT BELOW FOR OTHER PROJECTS ### @@ -34,7 +33,7 @@ ifeq "$(ENGINE)" "original" HL2SDK = $(HL2SDK_ORIG) HL2PUB = $(HL2SDK_ORIG)/public HL2LIB = $(HL2SDK_ORIG)/linux_sdk - METAMOD = $(SOURCEMM14) + METAMOD = $(MMSOURCE17)/core-legacy INCLUDE += -I$(HL2SDK)/public/dlls SRCDS = $(SRCDS_BASE) override ENGSET = true @@ -44,7 +43,7 @@ ifeq "$(ENGINE)" "orangebox" HL2PUB = $(HL2SDK_OB)/public HL2LIB = $(HL2SDK_OB)/lib/linux CFLAGS += -DORANGEBOX_BUILD - METAMOD = $(SOURCEMM16) + METAMOD = $(MMSOURCE17)/core INCLUDE += -I$(HL2SDK)/public/game/server SRCDS = $(SRCDS_BASE)/orangebox override ENGSET = true @@ -56,8 +55,7 @@ ifeq "$(USEMETA)" "true" LINK += $(LINK_HL2) INCLUDE += -I. -I.. -Isdk -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 \ - -I$(METAMOD) -I$(METAMOD)/sourcehook -I$(METAMOD)/sourcemm -I$(SMSDK)/public \ - -I$(SMSDK)/public/sourcepawn + -I$(METAMOD) -I$(METAMOD)/sourcehook -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn else INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn endif @@ -100,14 +98,14 @@ $(BIN_DIR)/%.o: %.cpp all: check mkdir -p $(BIN_DIR)/sdk - if [ "$(USEMETA)" == "true" ]; then \ + if [ "$(USEMETA)" = "true" ]; then \ ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so; \ ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so; \ fi $(MAKE) -f Makefile extension check: - if [ "$(USEMETA)" == "true" ] && [ "$(ENGSET)" == "false" ]; then \ + if [ "$(USEMETA)" = "true" ] && [ "$(ENGSET)" = "false" ]; then \ echo "You must supply ENGINE=orangebox or ENGINE=original"; \ exit 1; \ fi diff --git a/public/sample_ext/msvc8/sdk.vcproj b/public/sample_ext/msvc8/sdk.vcproj index d0ad2229..0016aec1 100644 --- a/public/sample_ext/msvc8/sdk.vcproj +++ b/public/sample_ext/msvc8/sdk.vcproj @@ -201,7 +201,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pushbuild.txt b/pushbuild.txt index d25d059a..089db4f9 100644 --- a/pushbuild.txt +++ b/pushbuild.txt @@ -1 +1,2 @@ -a billion and TRILLIONS \ No newline at end of file +a billion and TRILLIONS +timeout dance \ No newline at end of file diff --git a/sourcepawn/jit/Makefile b/sourcepawn/jit/Makefile index 51df620e..e1c429f7 100644 --- a/sourcepawn/jit/Makefile +++ b/sourcepawn/jit/Makefile @@ -2,7 +2,7 @@ # Makefile written by David "BAILOPAN" Anderson SMSDK = ../.. -SOURCEHOOK = ../../../sourcemm-1.6/sourcehook +MMSOURCE17 = ../../../mmsource-1.7 ##################################### ### EDIT BELOW FOR OTHER PROJECTS ### @@ -47,7 +47,7 @@ CPP = gcc-4.1 LINK = -static-libgcc INCLUDE = -I. -I.. -I$(SMSDK)/public -I$(SMSDK)/public/jit -I$(SMSDK)/public/jit/x86 \ - -I$(SMSDK)/public/sourcepawn -I$(SOURCEHOOK) -I$(SMSDK)/knight/shared -Ix86 + -I$(SMSDK)/public/sourcepawn -I$(MMSOURCE17)/core/sourcehook -I$(SMSDK)/knight/shared -Ix86 CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \ -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -DHAVE_STDINT_H \ diff --git a/sourcepawn/jit/msvc8/jit-x86.vcproj b/sourcepawn/jit/msvc8/jit-x86.vcproj index 86122d5b..0cb5da49 100644 --- a/sourcepawn/jit/msvc8/jit-x86.vcproj +++ b/sourcepawn/jit/msvc8/jit-x86.vcproj @@ -40,7 +40,7 @@ - - - - - - #include "smud.h" #include "smud_threads.h" @@ -8,6 +9,7 @@ char fileNames[NUM_FILES][30] = { "core.games.txt", "sdktools.games.txt", "sdktools.games.ep2.txt", + "sdktools.games.l4d.txt", "sm-cstrike.games.txt", "sm-tf2.games.txt", }; @@ -29,7 +31,9 @@ int main(int argc, char **argv) char filename[100]; struct stat sbuf; - printf("Loading Gamedata files into memory\n"); +#if defined DEBUG + fprintf(stdout, "Loading Gamedata files into memory\n"); +#endif for (int i=0; iStart()) { + fprintf(stderr, "Could not initialize thread pool!\n"); return 1; } +#if defined DEBUG printf("Create Server Socket\n"); +#endif memset(&serverAddress, 0, sizeof(serverAddress)); serverAddress.sin_family = AF_INET; @@ -76,6 +90,7 @@ int main(int argc, char **argv) if (pProtocol == NULL) { + fprintf(stderr, "Could not get tcp proto: %s", strerror(errno)); return 1; } @@ -83,6 +98,7 @@ int main(int argc, char **argv) if (serverSocket < 0) { + fprintf(stderr, "Could not open socket: %s", strerror(errno)); return 1; } @@ -91,34 +107,45 @@ int main(int argc, char **argv) if (bind(serverSocket, (struct sockaddr *)&serverAddress, sizeof(serverAddress)) < 0) { + fprintf(stderr, "Could not bind socket: %s", strerror(errno)); return 1; } if (listen(serverSocket, LISTEN_QUEUE_LENGTH) < 0) { + fprintf(stderr, "Could not listen on socket: %s", strerror(errno)); return 1; } - printf("Entering Main Loop\n"); + fprintf(stdout, "Server has started.\n"); while (1) { addressLen = sizeof(clientAddress); - if ( (clientSocket = accept(serverSocket, (struct sockaddr *)&clientAddress, (socklen_t *)&addressLen)) < 0) + clientSocket = accept(serverSocket, + (struct sockaddr *)&clientAddress, + (socklen_t *)&addressLen); + if (clientSocket < 0) { + fprintf(stderr, "Could not accept client: %s", strerror(errno)); continue; } opts = fcntl(clientSocket, F_GETFL, 0); if (fcntl(clientSocket, F_SETFL, opts|O_NONBLOCK) < 0) { + fprintf(stderr, "Could not non-block client: %s", strerror(errno)); closesocket(clientSocket); continue; } - - printf("Connection Received!\n"); +#if defined DEBUG + fprintf(stdout, + "Accepting connection from client (sock %d, ip %s)", + clientSocket, + inet_ntoa(clientAddress.sin_addr)); +#endif pool->AddConnection(clientSocket); } diff --git a/tools/daemon/smud.h b/tools/daemon/smud.h index 468024ca..5c047fb8 100644 --- a/tools/daemon/smud.h +++ b/tools/daemon/smud.h @@ -16,7 +16,7 @@ #define closesocket close -#define NUM_FILES 5 +#define NUM_FILES 6 extern char fileNames[NUM_FILES][30]; extern void *fileLocations[NUM_FILES]; diff --git a/tools/daemon/smud_connections.cpp b/tools/daemon/smud_connections.cpp index 89624d61..3ffddd68 100644 --- a/tools/daemon/smud_connections.cpp +++ b/tools/daemon/smud_connections.cpp @@ -1,3 +1,4 @@ +#include #include "smud_connections.h" #include "smud.h" @@ -19,8 +20,6 @@ void ConnectionPool::AddConnection( int fd ) pthread_mutex_lock(&m_AddLock); m_AddQueue.push_back(connection); pthread_mutex_unlock(&m_AddLock); - - printf("New Connection Added\n"); } void ConnectionPool::Process( bool *terminate ) @@ -48,9 +47,10 @@ void ConnectionPool::Process( bool *terminate ) /* Add all connections that want processing to the sets */ while (iter != m_Links.end()) { - con = (smud_connection *)*iter; + con = *iter; pollReturn = poll(&(con->pollData), 1, 0); + assert(pollReturn <= 1); if (pollReturn == -1) { @@ -66,11 +66,11 @@ void ConnectionPool::Process( bool *terminate ) if (result == QueryResult_Complete) { iter = m_Links.erase(iter); +#if defined DEBUG + fprintf(stdout, "Closing socket %d\n", con->fd); +#endif closesocket(con->fd); delete con; - - printf("Connection Completed!\n"); - continue; } @@ -145,31 +145,61 @@ QueryResult ConnectionPool::ProcessConnection( smud_connection *con ) void ConnectionPool::ReadQueryHeader( smud_connection *con ) { - char data[11]; + if (con->buffer == NULL) + { + con->buffer = new char[QUERY_HEADER_SIZE]; + con->writtenCount = 0; + } + + int bytesReceived = 0; - if (recv(con->fd, data, sizeof(data), 0) == -1) + bytesReceived = recv(con->fd, con->buffer+con->writtenCount, QUERY_HEADER_SIZE-con->writtenCount, 0); + + if (bytesReceived == -1) { if (errno != EAGAIN && errno != EWOULDBLOCK) { con->state = ConnectionState_Complete; + delete [] con->buffer; + con->buffer = NULL; + con->writtenCount = 0; } return; } - if (data[0] != 'A' || data[1] != 'G') + con->writtenCount += bytesReceived; + + assert(con->writtenCount <= QUERY_HEADER_SIZE); + + if (con->writtenCount < QUERY_HEADER_SIZE) + { + /* Don't change the connection status, so next cycle we will come back to here and continue receiving data */ + return; + } + + if (con->buffer[0] != 'A' || con->buffer[1] != 'G') { con->state = ConnectionState_Complete; + delete [] con->buffer; + con->buffer = NULL; + con->writtenCount = 0; return; } //Ignore the next 8 bytes for the moment. Versioning data is currently unused // uint16[4] - source version major/minor/something/rev - con->sentSums = data[10]; + con->sentSums = con->buffer[10]; con->state = ConnectionState_ReadQueryData; - printf("Query Header Read Complete, %i md5's expected\n", con->sentSums); +#if defined DEBUG + fprintf(stdout, "Query Header Read Complete, %i md5's expected\n", con->sentSums); +#endif + + delete [] con->buffer; + con->buffer = NULL; + con->writtenCount = 0; } void ConnectionPool::ReplyQuery(smud_connection *con) @@ -186,35 +216,68 @@ void ConnectionPool::ReplyQuery(smud_connection *con) data[11] = (char)con->sendCount; - if (send(con->fd, data, sizeof(data), 0) == -1) + int bytesSent = send(con->fd, data+con->writtenCount, sizeof(data)-con->writtenCount, 0); + + if (bytesSent == -1) { if (errno != EAGAIN && errno != EWOULDBLOCK) { con->state = ConnectionState_Complete; + con->writtenCount = 0; } return; } - - //Now we need more send sub functions for all the damn files. Geh. - //Alternatively we could just send all at once here. Could make for a damn big query. 100k anyone? + con->writtenCount += bytesSent; + + assert(con->writtenCount <= 12); + + if (con->writtenCount < 12) + { + /** Still more data needs to be sent - Return so we come back here next cycle */ + return; + } + con->state = ConnectionState_SendingFiles; + con->writtenCount = 0; +#if defined DEBUG printf("Query Reply Header Complete\n"); +#endif } void ConnectionPool::ReadQueryContent( smud_connection *con ) { - char *data = new char[16*(con->sentSums)](); + if (con->buffer == NULL) + { + con->buffer = new char[QUERY_CONTENT_SIZE*con->sentSums]; + con->writtenCount = 0; + } - if (recv(con->fd, data, 16*(con->sentSums), 0) == -1) + int bytesReceived = 0; + + bytesReceived = recv(con->fd, con->buffer+con->writtenCount, (QUERY_CONTENT_SIZE*con->sentSums)-con->writtenCount, 0); + + if (bytesReceived == -1) { if (errno != EAGAIN && errno != EWOULDBLOCK) { con->state = ConnectionState_Complete; + delete [] con->buffer; + con->buffer = NULL; + con->writtenCount = 0; } - delete [] data; + return; + } + + con->writtenCount += bytesReceived; + + assert(con->writtenCount <= (QUERY_CONTENT_SIZE*con->sentSums)); + + if (con->writtenCount < (QUERY_CONTENT_SIZE*con->sentSums)) + { + /* Don't change the connection status, so next cycle we will come back to here and continue receiving data */ return; } @@ -225,11 +288,13 @@ void ConnectionPool::ReadQueryContent( smud_connection *con ) for (int i=0; isentSums; i++) { con->fileLocation[i] = -1; - con->shouldSend[i] = GetMD5UpdateStatus(data + (16*i), con, i); + con->shouldSend[i] = GetMD5UpdateStatus(con->buffer + (QUERY_CONTENT_SIZE*i), con, i); if (con->shouldSend[i] == MD5Status_NeedsUpdate) { - printf("File %i needs updating\n", i); +#if defined DEBUG + fprintf(stdout, "File %i needs updating\n", i); +#endif con->sendCount++; con->headerSent[i] = false; continue; @@ -237,15 +302,21 @@ void ConnectionPool::ReadQueryContent( smud_connection *con ) if (con->shouldSend[i] == MD5Status_Unknown) { - printf("File %i is unknown\n", i); +#if defined DEBUG + fprintf(stdout, "File %i is unknown\n", i); +#endif con->unknownCount++; } } con->state = ConnectionState_ReplyQuery; con->pollData.events = POLLOUT; - delete [] data; - printf("Query Data Read Complete\n"); + delete [] con->buffer; + con->buffer = NULL; + con->writtenCount = 0; +#if defined DEBUG + fprintf(stdout, "Query Data Read Complete\n"); +#endif } MD5Status ConnectionPool::GetMD5UpdateStatus( const char *md5 , smud_connection *con, int fileNum) @@ -263,7 +334,9 @@ MD5Status ConnectionPool::GetMD5UpdateStatus( const char *md5 , smud_connection strcat(path, md5String); - printf("checking for file \"%s\"\n", path); +#if defined DEBUG + fprintf(stdout, "checking for file \"%s\"\n", path); +#endif FILE *file = fopen(path, "r"); @@ -275,7 +348,9 @@ MD5Status ConnectionPool::GetMD5UpdateStatus( const char *md5 , smud_connection char latestMD5[33]; fgets(latestMD5, 33, file); - printf("Latest md5 is: %s\n", latestMD5); +#if defined DEBUG + fprintf(stdout, "Latest md5 is: %s\n", latestMD5); +#endif if (strcmp(latestMD5, md5String) == 0) { @@ -298,7 +373,9 @@ MD5Status ConnectionPool::GetMD5UpdateStatus( const char *md5 , smud_connection fclose(file); - printf("Filename is %s\n", filename); +#if defined DEBUG + fprintf(stdout, "Filename is %s\n", filename); +#endif //We now need to match this filename with one of our mmap'd files in memory and store it until send gets called. for (int i=0; ifileLocation[fileNum] = i; - printf("File %i mapped to local file %i\n", fileNum, i); +#if defined DEBUG + fprintf(stdout, "File %i mapped to local file %i\n", fileNum, i); +#endif return MD5Status_NeedsUpdate; } } @@ -317,7 +396,8 @@ MD5Status ConnectionPool::GetMD5UpdateStatus( const char *md5 , smud_connection void ConnectionPool::SendFile( smud_connection *con ) { //Find the next file to send. - while (con->currentFile < con->sentSums && + while (con->writtenCount == 0 && + con->currentFile < con->sentSums && con->shouldSend[con->currentFile] != MD5Status_NeedsUpdate) { con->currentFile++; @@ -326,16 +406,26 @@ void ConnectionPool::SendFile( smud_connection *con ) //All files have been sent. if (con->currentFile >= con->sentSums) { - printf("All files sent!\n"); +#if defined DEBUG + fprintf(stdout, "All files sent!\n"); +#endif con->state = ConnectionState_SendUnknownList; + con->writtenCount = 0; return; } void *file = fileLocations[con->fileLocation[con->currentFile]]; int filelength = fileLength[con->fileLocation[con->currentFile]]; - printf("Sending file of length %i\n", filelength); - printf("Current file index is: %i, maps to file index: %i\n", con->currentFile, con->fileLocation[con->currentFile]); +#if defined DEBUG + fprintf(stdout, "Sending file of length %i\n", filelength); + fprintf(stdout, + "Current file index is: %i, maps to file index: %i\n", + con->currentFile, + con->fileLocation[con->currentFile]); +#endif + + int sentBytes = 0; if (!con->headerSent[con->currentFile]) { @@ -343,31 +433,59 @@ void ConnectionPool::SendFile( smud_connection *con ) buffer[0] = con->currentFile; *((int *)&buffer[1]) = filelength; - if (send(con->fd, buffer, 5, 0) == -1) + sentBytes = send(con->fd, buffer+con->writtenCount, 5-con->writtenCount, 0); + + if (sentBytes == -1) { if (errno != EAGAIN && errno != EWOULDBLOCK) { con->state = ConnectionState_Complete; + con->writtenCount = 0; } return; } + con->writtenCount += sentBytes; + + assert(con->writtenCount <= 5); + + if (con->writtenCount < 5) + { + return; + } + con->headerSent[con->currentFile] = true; + con->writtenCount = 0; } - if (send(con->fd, file, filelength, 0) == -1) + sentBytes = send(con->fd, (unsigned char *)file+con->writtenCount, filelength-con->writtenCount, 0); + + if (sentBytes == -1) { if (errno != EAGAIN && errno != EWOULDBLOCK) { con->state = ConnectionState_Complete; + con->writtenCount = 0; } return; } + con->writtenCount += sentBytes; + + assert(con->writtenCount <= filelength); + + if (con->writtenCount < filelength) + { + return; + } + con->currentFile++; - printf("Sent a file!: %s\n", fileNames[con->fileLocation[con->currentFile-1]]); + con->writtenCount = 0; +#if defined DEBUG + fprintf(stdout, "Sent a file!: %s\n", fileNames[con->fileLocation[con->currentFile-1]]); +#endif } void ConnectionPool::SendUnknownList( smud_connection *con ) @@ -377,7 +495,9 @@ void ConnectionPool::SendUnknownList( smud_connection *con ) packet[0] = con->unknownCount; - printf("%i Files are unknown\n", con->unknownCount); +#if defined DEBUG + fprintf(stdout, "%i Files are unknown\n", con->unknownCount); +#endif int i=1; @@ -390,16 +510,32 @@ void ConnectionPool::SendUnknownList( smud_connection *con ) } } - if (send(con->fd, packet, size, 0) == -1) + int sentBytes = send(con->fd, packet+con->writtenCount, size-con->writtenCount, 0); + + if (sentBytes == -1) { if (errno != EAGAIN && errno != EWOULDBLOCK) { con->state = ConnectionState_Complete; + con->writtenCount = 0; } return; } + con->writtenCount += sentBytes; + + assert(con->writtenCount <= size); + + if (con->writtenCount < size) + { + return; + } + con->state = ConnectionState_Complete; - printf("Unknown's Sent\n"); + con->writtenCount = 0; +#if defined DEBUG + fprintf(stdout, "Unknowns Sent\n"); +#endif } + diff --git a/tools/daemon/smud_connections.h b/tools/daemon/smud_connections.h index 5fe29d68..dbc75ac3 100644 --- a/tools/daemon/smud_connections.h +++ b/tools/daemon/smud_connections.h @@ -5,6 +5,9 @@ #include #include "poll.h" +#define QUERY_HEADER_SIZE 11 +#define QUERY_CONTENT_SIZE 16 + enum ConnectionState { ConnectionState_ReadQueryHeader, @@ -54,6 +57,8 @@ struct smud_connection state = ConnectionState_ReadQueryHeader; this->fd = fd; pollData.fd = fd; + buffer = NULL; + writtenCount = 0; } ~smud_connection() @@ -77,6 +82,8 @@ struct smud_connection int unknownCount; /** Number of files that were unknown */ int currentFile; /** Current file being sent (index into the above 3 arrays) */ pollfd pollData; /** Data to be passed into poll() */ + char *buffer; /** Temporary storage buffer to hold data until all of it is available */ + int writtenCount; /** Number of bytes written into the storage buffer */ };