From 402236e51e7a69586ed786b67e68aaf40e2df618 Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Mon, 5 Dec 2005 02:07:22 +0000 Subject: [PATCH] fixed bug at22532 --- dlls/sockets/CDataBuffer.h | 73 +++++++++++++++++++++++++++++++++++++ dlls/sockets/sockets.cpp | 47 ++++++++++++++++++------ dlls/sockets/sockets.vcproj | 4 ++ 3 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 dlls/sockets/CDataBuffer.h diff --git a/dlls/sockets/CDataBuffer.h b/dlls/sockets/CDataBuffer.h new file mode 100644 index 00000000..d8d57009 --- /dev/null +++ b/dlls/sockets/CDataBuffer.h @@ -0,0 +1,73 @@ +/* AMX Mod X +* +* by the AMX Mod X Development Team +* originally developed by OLO +* +* +* This program 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; either version 2 of the License, or (at +* your option) any later version. +* +* This program 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 this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +*/ + +// Class by Pavol "PMOnoTo" Marko + +template class DataBuffer +{ + T *m_pBuf; + size_t m_Size; +public: + DataBuffer() + { + m_pBuf = NULL; + m_Size = 0; + } + + ~DataBuffer() + { + if (m_pBuf) + delete [] m_pBuf; + } + + operator T* () + { + return m_pBuf; + } + + bool resize(size_t newSize) + { + if (newSize > m_Size) + { + char *pNew = new T[newSize]; + + if (!pNew) + return false; + if (m_pBuf) + delete [] m_pBuf; + + m_pBuf = pNew; + m_Size = newSize; + } + + return true; + } +}; diff --git a/dlls/sockets/sockets.cpp b/dlls/sockets/sockets.cpp index 41f7d0c6..bbca892d 100755 --- a/dlls/sockets/sockets.cpp +++ b/dlls/sockets/sockets.cpp @@ -11,6 +11,8 @@ * * v0.1 * - code structure renewed + * v0.2 + * - added socket_send2 to send data containing null bytes (FALUCO)(AMXX v1.65) */ #include @@ -36,6 +38,7 @@ // AMX Headers #include "amxxmodule.h" +#include "CDataBuffer.h" #define SOCKET_TCP 1 #define SOCKET_UDP 2 @@ -175,21 +178,41 @@ static cell AMX_NATIVE_CALL socket_recv(AMX *amx, cell *params) /* 2 param */ // native socket_send(_socket, _data[], _length); static cell AMX_NATIVE_CALL socket_send(AMX *amx, cell *params) /* 3 param */ { - // We get the string from amx - int len; - int socket = params[1]; - char* data = MF_GetAmxString(amx,params[2],0,&len); - // And send it to the socket - return send(socket, data, len, 0); + // We get the string from amx + int len; + int socket = params[1]; + char* data = MF_GetAmxString(amx,params[2],0,&len); + // And send it to the socket + return send(socket, data, len, 0); +} + +// native socket_send2(_socket, _data[], _length); +static cell AMX_NATIVE_CALL socket_send2(AMX *amx, cell *params) /* 3 param */ +{ + // We get the string from amx + int len = params[3]; + int socket = params[1]; + static DataBuffer buffer; + + buffer.resize(params[3]); + cell *pData = MF_GetAmxAddr(amx, params[2]); + char *pBuffer = buffer; + + while (len--) + *pBuffer++ = *pData++; + + // And send it to the socket + return send(socket, buffer, params[3], 0); } AMX_NATIVE_INFO sockets_natives[] = { - {"socket_open", socket_open}, - {"socket_close", socket_close}, - {"socket_change", socket_change}, - {"socket_recv", socket_recv}, - {"socket_send", socket_send}, - {NULL, NULL} + {"socket_open", socket_open}, + {"socket_close", socket_close}, + {"socket_change", socket_change}, + {"socket_recv", socket_recv}, + {"socket_send", socket_send}, + {"socket_send2", socket_send2}, + {NULL, NULL} }; void OnAmxxAttach() diff --git a/dlls/sockets/sockets.vcproj b/dlls/sockets/sockets.vcproj index 1fb39ae6..76ecf098 100755 --- a/dlls/sockets/sockets.vcproj +++ b/dlls/sockets/sockets.vcproj @@ -4,6 +4,7 @@ Version="7.10" Name="sockets" ProjectGUID="{F15BBA96-2F66-44BB-9DDF-D91AE6D33AE7}" + RootNamespace="sockets" Keyword="Win32Proj"> + +