Update syntax
This commit is contained in:
+39
-36
@@ -5,7 +5,10 @@
|
||||
#include <sourcemod>
|
||||
#include <socket>
|
||||
|
||||
public Plugin:myinfo = {
|
||||
#pragma newdecls required
|
||||
#pragma semicolon 1
|
||||
|
||||
public Plugin myinfo = {
|
||||
name = "socket extension sendto selftest",
|
||||
author = "Player",
|
||||
description = "basic functionality testing",
|
||||
@@ -13,101 +16,101 @@ public Plugin:myinfo = {
|
||||
url = "http://www.player.to/"
|
||||
};
|
||||
|
||||
public OnPluginStart() {
|
||||
SocketSetOption(INVALID_HANDLE, DebugMode, 1);
|
||||
public void OnPluginStart() {
|
||||
view_as<Socket>(null).SetOption(DebugMode, 1);
|
||||
|
||||
new port = 12346;
|
||||
int port = 12346;
|
||||
|
||||
new Handle:socket = SocketCreate(SOCKET_UDP, OnLSocketError);
|
||||
Socket socket = new Socket(SOCKET_UDP, OnLSocketError);
|
||||
|
||||
SocketBind(socket, "0.0.0.0", port);
|
||||
SocketListen(socket, OnLSocketIncoming);
|
||||
socket.Bind("0.0.0.0", port);
|
||||
socket.Listen(OnLSocketIncoming);
|
||||
|
||||
new Handle:socket2 = SocketCreate(SOCKET_UDP, OnCSocketError);
|
||||
Socket socket2 = new Socket(SOCKET_UDP, OnCSocketError);
|
||||
//SocketConnect(socket2, OnCSocketConnect, OnCSocketReceive, OnCSocketDisconnect, "127.0.0.1", port);
|
||||
}
|
||||
|
||||
public OnLSocketIncoming(Handle:socket, Handle:newSocket, String:remoteIP[], remotePort, any:arg) {
|
||||
public void OnLSocketIncoming(Socket socket, Socket newSocket, char[] remoteIP, int remotePort, any arg) {
|
||||
PrintToServer("%s:%d connected", remoteIP, remotePort);
|
||||
|
||||
SocketSetReceiveCallback(newSocket, OnChildSocketReceive);
|
||||
SocketSetDisconnectCallback(newSocket, OnChildSocketDisconnect);
|
||||
SocketSetErrorCallback(newSocket, OnChildSocketError);
|
||||
newSocket.SetReceiveCallback(OnChildSocketReceive);
|
||||
newSocket.SetDisconnectCallback(OnChildSocketDisconnect);
|
||||
newSocket.SetErrorCallback(OnChildSocketError);
|
||||
|
||||
SocketSend(newSocket, "\x00abc\x00def\x01\x02\x03\x04", 12);
|
||||
SocketSetSendqueueEmptyCallback(newSocket, OnChildSocketSQEmpty);
|
||||
newSocket.Send("\x00abc\x00def\x01\x02\x03\x04", 12);
|
||||
newSocket.SetSendqueueEmptyCallback(OnChildSocketSQEmpty);
|
||||
}
|
||||
|
||||
public OnLSocketError(Handle:socket, const errorType, const errorNum, any:arg) {
|
||||
public void OnLSocketError(Socket socket, const int errorType, const int errorNum, any arg) {
|
||||
LogError("listen socket error %d (errno %d)", errorType, errorNum);
|
||||
CloseHandle(socket);
|
||||
}
|
||||
|
||||
public OnChildSocketReceive(Handle:socket, String:receiveData[], const dataSize, any:arg) {
|
||||
public void OnChildSocketReceive(Socket socket, char[] receiveData, const int dataSize, any arg) {
|
||||
// send (echo) the received data back
|
||||
//SocketSend(socket, receiveData);
|
||||
//socket.Send(receiveData);
|
||||
// close the connection/socket/handle if it matches quit
|
||||
//if (strncmp(receiveData, "quit", 4) == 0) CloseHandle(socket);
|
||||
}
|
||||
|
||||
public OnChildSocketSQEmpty(Handle:socket, any:arg) {
|
||||
public void OnChildSocketSQEmpty(Socket socket, any arg) {
|
||||
PrintToServer("sq empty");
|
||||
CloseHandle(socket);
|
||||
}
|
||||
|
||||
public OnChildSocketDisconnect(Handle:socket, any:arg) {
|
||||
public void OnChildSocketDisconnect(Socket socket, any arg) {
|
||||
// remote side disconnected
|
||||
PrintToServer("disc");
|
||||
CloseHandle(socket);
|
||||
}
|
||||
|
||||
public OnChildSocketError(Handle:socket, const errorType, const errorNum, any:arg) {
|
||||
public void OnChildSocketError(Socket socket, const int errorType, const int errorNum, any arg) {
|
||||
// a socket error occured
|
||||
|
||||
LogError("child socket error %d (errno %d)", errorType, errorNum);
|
||||
CloseHandle(socket);
|
||||
}
|
||||
|
||||
public OnCSocketConnect(Handle:socket, any:arg) {
|
||||
public void OnCSocketConnect(Socket socket, any arg) {
|
||||
// send (echo) the received data back
|
||||
//SocketSend(socket, receiveData);
|
||||
//socket.Send(receiveData);
|
||||
// close the connection/socket/handle if it matches quit
|
||||
//if (strncmp(receiveData, "quit", 4) == 0) CloseHandle(socket);
|
||||
}
|
||||
|
||||
new String:recvBuffer[128];
|
||||
new recvBufferPos = 0;
|
||||
char g_sRecvBuffer[128];
|
||||
int g_irecvBufferPos = 0;
|
||||
|
||||
public OnCSocketReceive(Handle:socket, String:receiveData[], const dataSize, any:arg) {
|
||||
public void OnCSocketReceive(Socket socket, char[] receiveData, const int dataSize, any arg) {
|
||||
PrintToServer("received %d bytes", dataSize);
|
||||
|
||||
if (recvBufferPos < 512) {
|
||||
for (new i=0; i<dataSize && recvBufferPos<sizeof(recvBuffer); i++, recvBufferPos++) {
|
||||
recvBuffer[recvBufferPos] = receiveData[i];
|
||||
if (g_irecvBufferPos < 512) {
|
||||
for (int i = 0; i < dataSize && g_irecvBufferPos < sizeof(g_sRecvBuffer); i++, g_irecvBufferPos++) {
|
||||
g_sRecvBuffer[g_irecvBufferPos] = receiveData[i];
|
||||
}
|
||||
}
|
||||
// send (echo) the received data back
|
||||
//SocketSend(socket, receiveData);
|
||||
//socket.Send(receiveData);
|
||||
// close the connection/socket/handle if it matches quit
|
||||
//if (strncmp(receiveData, "quit", 4) == 0) CloseHandle(socket);
|
||||
}
|
||||
|
||||
public OnCSocketDisconnect(Handle:socket, any:arg) {
|
||||
new String:cmp[] = "\x00abc\x00def\x01\x02\x03\x04";
|
||||
new i;
|
||||
for (i=0; i<recvBufferPos && i<12; i++) {
|
||||
if (recvBuffer[i] != cmp[i]) {
|
||||
public void OnCSocketDisconnect(Socket socket, any arg) {
|
||||
char[] cmp = "\x00abc\x00def\x01\x02\x03\x04";
|
||||
int i;
|
||||
for (i = 0; i < g_irecvBufferPos && i < 12; i++) {
|
||||
if (g_sRecvBuffer[i] != cmp[i]) {
|
||||
PrintToServer("comparison failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PrintToServer("comparison finished at pos %d/%d", i, recvBufferPos);
|
||||
PrintToServer("comparison finished at pos %d/%d", i, g_irecvBufferPos);
|
||||
|
||||
CloseHandle(socket);
|
||||
}
|
||||
|
||||
public OnCSocketError(Handle:socket, const errorType, const errorNum, any:arg) {
|
||||
public void OnCSocketError(Socket socket, const int errorType, const int errorNum, any arg) {
|
||||
// a socket error occured
|
||||
|
||||
LogError("connect socket error %d (errno %d)", errorType, errorNum);
|
||||
|
||||
Reference in New Issue
Block a user