rendered paste body#include "SDK/amx/amx.h"#include "SDK/plugincommon.h"#include "winsock2.h"#define ERROR 1#define OK 0typedef void (*logprintf_t)(char* format, ...);logprintf_t logprintf;void **ppPluginData;extern void *pAMXFunctions;SOCKET client;PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports(){return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;}PLUGIN_EXPORT bool PLUGIN_CALL Load( void **ppData ){pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];logprintf = (logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF];logprintf( "Plugin winsock.dll by Roby65 got loaded." );return true;}PLUGIN_EXPORT void PLUGIN_CALL Unload( ){logprintf( "Plugin winsock.dll got unloaded." );}static char *pcCreateAndFillStringFromCell(AMX *amx,cell params){ char *szDest; int nLen; cell *pString; amx_GetAddr(amx,params,&pString); amx_StrLen(pString, &nLen); szDest = new char[nLen+1]; amx_GetString(szDest, pString, 0, UNLIMITED); return szDest;}static cell AMX_NATIVE_CALL winsockinit( AMX* amx, cell* params ){ logprintf( "Net_Init()" );WSADATA wsaData; WORD version; int error; version = MAKEWORD( 2, 0 ); error = WSAStartup( version, &wsaData ); if ( error != 0 ) { return ERROR; } client = socket( AF_INET, SOCK_STREAM, 0 ); logprintf( "Winsock successfully initialized" );return OK;}static cell AMX_NATIVE_CALL n_HelloWorld( AMX* amx, cell* params ){logprintf( "Hello World, from the HelloWorld plugin!" );return 1;}static cell AMX_NATIVE_CALL Connect( AMX* amx, cell* params ){logprintf( "Connect(\"IP\",port)" );struct sockaddr_in sin; memset( &sin, 0, sizeof sin ); sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(pcCreateAndFillStringFromCell(amx,params[1])); sin.sin_port = htons( params[2] ); if ( connect(client, (SOCKADDR *)&sin, sizeof(sin))==SOCKET_ERROR ) { logprintf( "Failed to connect" ); return ERROR; } logprintf( "Connected" );return OK;}static cell AMX_NATIVE_CALL Send( AMX* amx, cell* params ){logprintf( "Send()" );char *tosend=pcCreateAndFillStringFromCell(amx,params[1]);if(send(client, tosend, strlen(tosend), 0)==SOCKET_ERROR) return ERROR;logprintf( "Message (%s) sent" , tosend );return OK;}static cell AMX_NATIVE_CALL Disconnect( AMX* amx, cell* params ){logprintf( "Disconnect()" );closesocket(client);logprintf( "Disconnected" );return OK;}static cell AMX_NATIVE_CALL net_close( AMX* amx, cell* params ){logprintf( "Net_Close" );WSACleanup();logprintf( "Winsock cleaned up!" );return OK;}AMX_NATIVE_INFO HelloWorldNatives[ ] ={{ "HelloWorld", n_HelloWorld },{ "Net_Init", winsockinit },{ "Connect", Connect },{ "Disconnect", Disconnect },{ "Net_Close", net_close },{ "Send", Send },{ 0, 0 }};PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx ){return amx_Register( amx, HelloWorldNatives, -1 );}PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx ){return AMX_ERR_NONE;}