fixed bug at22532

This commit is contained in:
Borja Ferrer 2005-12-05 02:07:22 +00:00
parent 2ebf822dea
commit 402236e51e
3 changed files with 112 additions and 12 deletions

View File

@ -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 T> 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;
}
};

View File

@ -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 <stdlib.h>
@ -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<char> 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()

View File

@ -4,6 +4,7 @@
Version="7.10"
Name="sockets"
ProjectGUID="{F15BBA96-2F66-44BB-9DDF-D91AE6D33AE7}"
RootNamespace="sockets"
Keyword="Win32Proj">
<Platforms>
<Platform
@ -124,6 +125,9 @@
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\CDataBuffer.h">
</File>
<Filter
Name="SDK"
Filter="">