Updated for 1.11 windows build & added methodmap
This commit is contained in:
+448
@@ -0,0 +1,448 @@
|
||||
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
||||
import os, sys
|
||||
|
||||
# Simple extensions do not need to modify this file.
|
||||
|
||||
class SDK(object):
|
||||
def __init__(self, sdk, ext, aDef, name, platform, dir):
|
||||
self.folder = 'hl2sdk-' + dir
|
||||
self.envvar = sdk
|
||||
self.ext = ext
|
||||
self.code = aDef
|
||||
self.define = name
|
||||
self.platform = platform
|
||||
self.name = dir
|
||||
self.path = None # Actual path
|
||||
|
||||
WinOnly = ['windows']
|
||||
WinLinux = ['windows', 'linux']
|
||||
WinLinuxMac = ['windows', 'linux', 'mac']
|
||||
|
||||
PossibleSDKs = {
|
||||
'episode1': SDK('HL2SDK', '1.ep1', '1', 'EPISODEONE', WinLinux, 'episode1'),
|
||||
'ep2': SDK('HL2SDKOB', '2.ep2', '3', 'ORANGEBOX', WinLinux, 'orangebox'),
|
||||
'css': SDK('HL2SDKCSS', '2.css', '6', 'CSS', WinLinuxMac, 'css'),
|
||||
'hl2dm': SDK('HL2SDKHL2DM', '2.hl2dm', '7', 'HL2DM', WinLinuxMac, 'hl2dm'),
|
||||
'dods': SDK('HL2SDKDODS', '2.dods', '8', 'DODS', WinLinuxMac, 'dods'),
|
||||
'sdk2013': SDK('HL2SDK2013', '2.sdk2013', '9', 'SDK2013', WinLinuxMac, 'sdk2013'),
|
||||
'tf2': SDK('HL2SDKTF2', '2.tf2', '11', 'TF2', WinLinuxMac, 'tf2'),
|
||||
'l4d': SDK('HL2SDKL4D', '2.l4d', '12', 'LEFT4DEAD', WinLinuxMac, 'l4d'),
|
||||
'nucleardawn': SDK('HL2SDKND', '2.nd', '13', 'NUCLEARDAWN', WinLinuxMac, 'nucleardawn'),
|
||||
'l4d2': SDK('HL2SDKL4D2', '2.l4d2', '15', 'LEFT4DEAD2', WinLinuxMac, 'l4d2'),
|
||||
'darkm': SDK('HL2SDK-DARKM', '2.darkm', '2', 'DARKMESSIAH', WinOnly, 'darkm'),
|
||||
'swarm': SDK('HL2SDK-SWARM', '2.swarm', '16', 'ALIENSWARM', WinOnly, 'swarm'),
|
||||
'bgt': SDK('HL2SDK-BGT', '2.bgt', '4', 'BLOODYGOODTIME', WinOnly, 'bgt'),
|
||||
'eye': SDK('HL2SDK-EYE', '2.eye', '5', 'EYE', WinOnly, 'eye'),
|
||||
'csgo': SDK('HL2SDKCSGO', '2.csgo', '21', 'CSGO', WinLinuxMac, 'csgo'),
|
||||
'portal2': SDK('HL2SDKPORTAL2', '2.portal2', '17', 'PORTAL2', [], 'portal2'),
|
||||
'blade': SDK('HL2SDKBLADE', '2.blade', '18', 'BLADE', WinLinux, 'blade'),
|
||||
'insurgency': SDK('HL2SDKINSURGENCY', '2.insurgency', '19', 'INSURGENCY', WinLinuxMac, 'insurgency'),
|
||||
'contagion': SDK('HL2SDKCONTAGION', '2.contagion', '14', 'CONTAGION', WinOnly, 'contagion'),
|
||||
'bms': SDK('HL2SDKBMS', '2.bms', '10', 'BMS', WinLinux, 'bms'),
|
||||
'doi': SDK('HL2SDKDOI', '2.doi', '20', 'DOI', WinLinuxMac, 'doi'),
|
||||
}
|
||||
|
||||
def ResolveEnvPath(env, folder):
|
||||
if env in os.environ:
|
||||
path = os.environ[env]
|
||||
if os.path.isdir(path):
|
||||
return path
|
||||
return None
|
||||
|
||||
head = os.getcwd()
|
||||
oldhead = None
|
||||
while head != None and head != oldhead:
|
||||
path = os.path.join(head, folder)
|
||||
if os.path.isdir(path):
|
||||
return path
|
||||
oldhead = head
|
||||
head, tail = os.path.split(head)
|
||||
|
||||
return None
|
||||
|
||||
def Normalize(path):
|
||||
return os.path.abspath(os.path.normpath(path))
|
||||
|
||||
class ExtensionConfig(object):
|
||||
def __init__(self):
|
||||
self.sdks = {}
|
||||
self.binaries = []
|
||||
self.extensions = []
|
||||
self.generated_headers = None
|
||||
self.mms_root = None
|
||||
self.sm_root = None
|
||||
|
||||
@property
|
||||
def tag(self):
|
||||
if builder.options.debug == '1':
|
||||
return 'Debug'
|
||||
return 'Release'
|
||||
|
||||
def detectSDKs(self):
|
||||
sdk_list = builder.options.sdks.split(',')
|
||||
use_all = sdk_list[0] == 'all'
|
||||
use_present = sdk_list[0] == 'present'
|
||||
|
||||
for sdk_name in PossibleSDKs:
|
||||
sdk = PossibleSDKs[sdk_name]
|
||||
if builder.target_platform in sdk.platform:
|
||||
if builder.options.hl2sdk_root:
|
||||
sdk_path = os.path.join(builder.options.hl2sdk_root, sdk.folder)
|
||||
else:
|
||||
sdk_path = ResolveEnvPath(sdk.envvar, sdk.folder)
|
||||
if sdk_path is None or not os.path.isdir(sdk_path):
|
||||
if use_all or sdk_name in sdk_list:
|
||||
raise Exception('Could not find a valid path for {0}'.format(sdk.envvar))
|
||||
continue
|
||||
if use_all or use_present or sdk_name in sdk_list:
|
||||
sdk.path = Normalize(sdk_path)
|
||||
self.sdks[sdk_name] = sdk
|
||||
|
||||
if len(self.sdks) < 1:
|
||||
raise Exception('At least one SDK must be available.')
|
||||
|
||||
if builder.options.sm_path:
|
||||
self.sm_root = builder.options.sm_path
|
||||
else:
|
||||
self.sm_root = ResolveEnvPath('SOURCEMOD18', 'sourcemod-1.8')
|
||||
if not self.sm_root:
|
||||
self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod')
|
||||
if not self.sm_root:
|
||||
self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central')
|
||||
|
||||
if not self.sm_root or not os.path.isdir(self.sm_root):
|
||||
raise Exception('Could not find a source copy of SourceMod')
|
||||
self.sm_root = Normalize(self.sm_root)
|
||||
|
||||
if builder.options.mms_path:
|
||||
self.mms_root = builder.options.mms_path
|
||||
else:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10')
|
||||
if not self.mms_root:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source')
|
||||
if not self.mms_root:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central')
|
||||
|
||||
if not self.mms_root or not os.path.isdir(self.mms_root):
|
||||
raise Exception('Could not find a source copy of Metamod:Source')
|
||||
self.mms_root = Normalize(self.mms_root)
|
||||
|
||||
def configure(self):
|
||||
cxx = builder.DetectCompilers()
|
||||
|
||||
if cxx.like('gcc'):
|
||||
self.configure_gcc(cxx)
|
||||
elif cxx.vendor == 'msvc':
|
||||
self.configure_msvc(cxx)
|
||||
|
||||
# Optimizaiton
|
||||
if builder.options.opt == '1':
|
||||
cxx.defines += ['NDEBUG']
|
||||
|
||||
# Debugging
|
||||
if builder.options.debug == '1':
|
||||
cxx.defines += ['DEBUG', '_DEBUG']
|
||||
|
||||
# Platform-specifics
|
||||
if builder.target_platform == 'linux':
|
||||
self.configure_linux(cxx)
|
||||
elif builder.target_platform == 'mac':
|
||||
self.configure_mac(cxx)
|
||||
elif builder.target_platform == 'windows':
|
||||
self.configure_windows(cxx)
|
||||
|
||||
# Finish up.
|
||||
cxx.includes += [
|
||||
os.path.join(self.sm_root, 'public'),
|
||||
]
|
||||
|
||||
def configure_gcc(self, cxx):
|
||||
cxx.defines += [
|
||||
'stricmp=strcasecmp',
|
||||
'_stricmp=strcasecmp',
|
||||
'_snprintf=snprintf',
|
||||
'_vsnprintf=vsnprintf',
|
||||
'HAVE_STDINT_H',
|
||||
'GNUC',
|
||||
]
|
||||
cxx.cflags += [
|
||||
'-pipe',
|
||||
'-fno-strict-aliasing',
|
||||
'-Wall',
|
||||
'-Werror',
|
||||
'-Wno-unused',
|
||||
'-Wno-switch',
|
||||
'-Wno-array-bounds',
|
||||
'-msse',
|
||||
'-m32',
|
||||
'-fvisibility=hidden',
|
||||
]
|
||||
cxx.cxxflags += [
|
||||
'-std=c++11',
|
||||
'-fno-exceptions',
|
||||
'-fno-threadsafe-statics',
|
||||
'-Wno-non-virtual-dtor',
|
||||
'-Wno-overloaded-virtual',
|
||||
'-fvisibility-inlines-hidden',
|
||||
]
|
||||
cxx.linkflags += ['-m32']
|
||||
|
||||
have_gcc = cxx.vendor == 'gcc'
|
||||
have_clang = cxx.vendor == 'clang'
|
||||
if cxx.version >= 'clang-3.6':
|
||||
cxx.cxxflags += ['-Wno-inconsistent-missing-override']
|
||||
if have_clang or (cxx.version >= 'gcc-4.6'):
|
||||
cxx.cflags += ['-Wno-narrowing']
|
||||
if have_clang or (cxx.version >= 'gcc-4.7'):
|
||||
cxx.cxxflags += ['-Wno-delete-non-virtual-dtor']
|
||||
if cxx.version >= 'gcc-4.8':
|
||||
cxx.cflags += ['-Wno-unused-result']
|
||||
|
||||
if have_clang:
|
||||
cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch']
|
||||
if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4':
|
||||
cxx.cxxflags += ['-Wno-deprecated-register']
|
||||
else:
|
||||
cxx.cxxflags += ['-Wno-deprecated']
|
||||
cxx.cflags += ['-Wno-sometimes-uninitialized']
|
||||
|
||||
if have_gcc:
|
||||
cxx.cflags += ['-mfpmath=sse']
|
||||
|
||||
if builder.options.opt == '1':
|
||||
cxx.cflags += ['-O3']
|
||||
|
||||
def configure_msvc(self, cxx):
|
||||
if builder.options.debug == '1':
|
||||
cxx.cflags += ['/MTd']
|
||||
cxx.linkflags += ['/NODEFAULTLIB:libcmt']
|
||||
else:
|
||||
cxx.cflags += ['/MT']
|
||||
cxx.defines += [
|
||||
'_CRT_SECURE_NO_DEPRECATE',
|
||||
'_CRT_SECURE_NO_WARNINGS',
|
||||
'_CRT_NONSTDC_NO_DEPRECATE',
|
||||
'_ITERATOR_DEBUG_LEVEL=0',
|
||||
]
|
||||
cxx.cflags += [
|
||||
'/W3',
|
||||
]
|
||||
cxx.cxxflags += [
|
||||
'/EHsc',
|
||||
'/GR-',
|
||||
'/TP',
|
||||
]
|
||||
cxx.linkflags += [
|
||||
'/MACHINE:X86',
|
||||
'kernel32.lib',
|
||||
'user32.lib',
|
||||
'gdi32.lib',
|
||||
'winspool.lib',
|
||||
'comdlg32.lib',
|
||||
'advapi32.lib',
|
||||
'shell32.lib',
|
||||
'ole32.lib',
|
||||
'oleaut32.lib',
|
||||
'uuid.lib',
|
||||
'odbc32.lib',
|
||||
'odbccp32.lib',
|
||||
]
|
||||
|
||||
if builder.options.opt == '1':
|
||||
cxx.cflags += ['/Ox', '/Zo']
|
||||
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
|
||||
|
||||
if builder.options.debug == '1':
|
||||
cxx.cflags += ['/Od', '/RTC1']
|
||||
|
||||
# This needs to be after our optimization flags which could otherwise disable it.
|
||||
# Don't omit the frame pointer.
|
||||
cxx.cflags += ['/Oy-']
|
||||
|
||||
def configure_linux(self, cxx):
|
||||
cxx.defines += ['_LINUX', 'POSIX']
|
||||
cxx.linkflags += ['-Wl,--exclude-libs,ALL', '-lm']
|
||||
if cxx.vendor == 'gcc':
|
||||
cxx.linkflags += ['-static-libgcc']
|
||||
elif cxx.vendor == 'clang':
|
||||
cxx.linkflags += ['-lgcc_eh']
|
||||
|
||||
def configure_mac(self, cxx):
|
||||
cxx.defines += ['OSX', '_OSX', 'POSIX']
|
||||
cxx.cflags += ['-mmacosx-version-min=10.5']
|
||||
cxx.linkflags += [
|
||||
'-mmacosx-version-min=10.5',
|
||||
'-arch', 'i386',
|
||||
'-lstdc++',
|
||||
'-stdlib=libstdc++',
|
||||
]
|
||||
cxx.cxxflags += ['-stdlib=libstdc++']
|
||||
|
||||
def configure_windows(self, cxx):
|
||||
cxx.defines += ['WIN32', '_WINDOWS']
|
||||
|
||||
def ConfigureForExtension(self, context, compiler):
|
||||
compiler.cxxincludes += [
|
||||
os.path.join(context.currentSourcePath),
|
||||
os.path.join(context.currentSourcePath, 'sdk'),
|
||||
os.path.join(self.sm_root, 'public'),
|
||||
os.path.join(self.sm_root, 'public', 'extensions'),
|
||||
os.path.join(self.sm_root, 'sourcepawn', 'include'),
|
||||
os.path.join(self.sm_root, 'public', 'amtl', 'amtl'),
|
||||
os.path.join(self.sm_root, 'public', 'amtl'),
|
||||
]
|
||||
return compiler
|
||||
|
||||
def ConfigureForHL2(self, binary, sdk):
|
||||
compiler = binary.compiler
|
||||
|
||||
if sdk.name == 'episode1':
|
||||
mms_path = os.path.join(self.mms_root, 'core-legacy')
|
||||
else:
|
||||
mms_path = os.path.join(self.mms_root, 'core')
|
||||
|
||||
compiler.cxxincludes += [
|
||||
os.path.join(mms_path),
|
||||
os.path.join(mms_path, 'sourcehook'),
|
||||
]
|
||||
|
||||
defines = ['SE_' + PossibleSDKs[i].define + '=' + PossibleSDKs[i].code for i in PossibleSDKs]
|
||||
compiler.defines += defines
|
||||
|
||||
paths = [
|
||||
['public'],
|
||||
['public', 'engine'],
|
||||
['public', 'mathlib'],
|
||||
['public', 'vstdlib'],
|
||||
['public', 'tier0'],
|
||||
['public', 'tier1']
|
||||
]
|
||||
if sdk.name == 'episode1' or sdk.name == 'darkm':
|
||||
paths.append(['public', 'dlls'])
|
||||
paths.append(['game_shared'])
|
||||
else:
|
||||
paths.append(['public', 'game', 'server'])
|
||||
paths.append(['public', 'toolframework'])
|
||||
paths.append(['game', 'shared'])
|
||||
paths.append(['common'])
|
||||
|
||||
compiler.defines += ['SOURCE_ENGINE=' + sdk.code]
|
||||
|
||||
if sdk.name in ['sdk2013', 'bms'] and compiler.like('gcc'):
|
||||
# The 2013 SDK already has these in public/tier0/basetypes.h
|
||||
compiler.defines.remove('stricmp=strcasecmp')
|
||||
compiler.defines.remove('_stricmp=strcasecmp')
|
||||
compiler.defines.remove('_snprintf=snprintf')
|
||||
compiler.defines.remove('_vsnprintf=vsnprintf')
|
||||
|
||||
if compiler.like('msvc'):
|
||||
compiler.defines += ['COMPILER_MSVC', 'COMPILER_MSVC32']
|
||||
else:
|
||||
compiler.defines += ['COMPILER_GCC']
|
||||
|
||||
# For everything after Swarm, this needs to be defined for entity networking
|
||||
# to work properly with sendprop value changes.
|
||||
if sdk.name in ['blade', 'insurgency', 'doi', 'csgo']:
|
||||
compiler.defines += ['NETWORK_VARS_ENABLED']
|
||||
|
||||
if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2']:
|
||||
if builder.target_platform in ['linux', 'mac']:
|
||||
compiler.defines += ['NO_HOOK_MALLOC', 'NO_MALLOC_OVERRIDE']
|
||||
|
||||
if sdk.name == 'csgo' and builder.target_platform == 'linux':
|
||||
compiler.linkflags += ['-lstdc++']
|
||||
|
||||
for path in paths:
|
||||
compiler.cxxincludes += [os.path.join(sdk.path, *path)]
|
||||
|
||||
if builder.target_platform == 'linux':
|
||||
if sdk.name == 'episode1':
|
||||
lib_folder = os.path.join(sdk.path, 'linux_sdk')
|
||||
elif sdk.name in ['sdk2013', 'bms']:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux32')
|
||||
else:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'linux')
|
||||
elif builder.target_platform == 'mac':
|
||||
if sdk.name in ['sdk2013', 'bms']:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'osx32')
|
||||
else:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'mac')
|
||||
|
||||
if builder.target_platform in ['linux', 'mac']:
|
||||
if sdk.name in ['sdk2013', 'bms']:
|
||||
compiler.postlink += [
|
||||
compiler.Dep(os.path.join(lib_folder, 'tier1.a')),
|
||||
compiler.Dep(os.path.join(lib_folder, 'mathlib.a'))
|
||||
]
|
||||
else:
|
||||
compiler.postlink += [
|
||||
compiler.Dep(os.path.join(lib_folder, 'tier1_i486.a')),
|
||||
compiler.Dep(os.path.join(lib_folder, 'mathlib_i486.a'))
|
||||
]
|
||||
|
||||
if sdk.name in ['blade', 'insurgency', 'doi', 'csgo']:
|
||||
compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'interfaces_i486.a'))]
|
||||
|
||||
dynamic_libs = []
|
||||
if builder.target_platform == 'linux':
|
||||
if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', 'sdk2013', 'bms', 'nucleardawn', 'l4d2', 'insurgency', 'doi']:
|
||||
dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so']
|
||||
elif sdk.name in ['l4d', 'blade', 'insurgency', 'doi', 'csgo']:
|
||||
dynamic_libs = ['libtier0.so', 'libvstdlib.so']
|
||||
else:
|
||||
dynamic_libs = ['tier0_i486.so', 'vstdlib_i486.so']
|
||||
elif builder.target_platform == 'mac':
|
||||
compiler.linkflags.append('-liconv')
|
||||
dynamic_libs = ['libtier0.dylib', 'libvstdlib.dylib']
|
||||
elif builder.target_platform == 'windows':
|
||||
libs = ['tier0', 'tier1', 'vstdlib', 'mathlib']
|
||||
if sdk.name in ['swarm', 'blade', 'insurgency', 'doi', 'csgo']:
|
||||
libs.append('interfaces')
|
||||
for lib in libs:
|
||||
lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib'
|
||||
compiler.linkflags.append(compiler.Dep(lib_path))
|
||||
|
||||
for library in dynamic_libs:
|
||||
source_path = os.path.join(lib_folder, library)
|
||||
output_path = os.path.join(binary.localFolder, library)
|
||||
|
||||
def make_linker(source_path, output_path):
|
||||
def link(context, binary):
|
||||
cmd_node, (output,) = context.AddSymlink(source_path, output_path)
|
||||
return output
|
||||
return link
|
||||
|
||||
linker = make_linker(source_path, output_path)
|
||||
compiler.linkflags[0:0] = [compiler.Dep(library, linker)]
|
||||
|
||||
return binary
|
||||
|
||||
def HL2Library(self, context, name, sdk):
|
||||
binary = context.compiler.Library(name)
|
||||
self.ConfigureForExtension(context, binary.compiler)
|
||||
return self.ConfigureForHL2(binary, sdk)
|
||||
|
||||
def HL2Project(self, context, name):
|
||||
project = context.compiler.LibraryProject(name)
|
||||
self.ConfigureForExtension(context, project.compiler)
|
||||
return project
|
||||
|
||||
def HL2Config(self, project, name, sdk):
|
||||
binary = project.Configure(name, '{0} - {1}'.format(self.tag, sdk.name))
|
||||
return self.ConfigureForHL2(binary, sdk)
|
||||
|
||||
Extension = ExtensionConfig()
|
||||
Extension.detectSDKs()
|
||||
Extension.configure()
|
||||
|
||||
# Add additional buildscripts here
|
||||
BuildScripts = [
|
||||
'AMBuilder',
|
||||
]
|
||||
|
||||
if builder.backend == 'amb2':
|
||||
BuildScripts += [
|
||||
'PackageScript',
|
||||
]
|
||||
|
||||
builder.RunBuildScripts(BuildScripts, { 'Extension': Extension})
|
||||
@@ -0,0 +1,31 @@
|
||||
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
||||
import os, sys
|
||||
|
||||
projectName = 'socket'
|
||||
|
||||
# smsdk_ext.cpp will be automatically added later
|
||||
sourceFiles = [
|
||||
'extension.cpp',
|
||||
]
|
||||
|
||||
###############
|
||||
# Make sure to edit PackageScript, which copies your files to their appropriate locations
|
||||
# Simple extensions do not need to modify past this point.
|
||||
|
||||
project = Extension.HL2Project(builder, projectName + '.ext')
|
||||
|
||||
if os.path.isfile(os.path.join(builder.currentSourcePath, 'sdk', 'smsdk_ext.cpp')):
|
||||
# Use the copy included in the project
|
||||
project.sources += [os.path.join('sdk', 'smsdk_ext.cpp')]
|
||||
else:
|
||||
# Use the copy included with SM 1.6 and newer
|
||||
project.sources += [os.path.join(Extension.sm_root, 'public', 'smsdk_ext.cpp')]
|
||||
|
||||
project.sources += sourceFiles
|
||||
|
||||
for sdk_name in Extension.sdks:
|
||||
sdk = Extension.sdks[sdk_name]
|
||||
|
||||
binary = Extension.HL2Config(project, projectName + '.ext.' + sdk.ext, sdk)
|
||||
|
||||
Extension.extensions = builder.Add(project)
|
||||
+32
-19
@@ -440,25 +440,38 @@ cell_t SocketGetHostName(IPluginContext *pContext, const cell_t *params) {
|
||||
}
|
||||
|
||||
const sp_nativeinfo_t smsock_natives[] = {
|
||||
{"SocketIsConnected", SocketIsConnected},
|
||||
{"SocketCreate", SocketCreate},
|
||||
{"SocketBind", SocketBind},
|
||||
{"SocketConnect", SocketConnect},
|
||||
{"SocketDisconnect", SocketDisconnect},
|
||||
{"SocketListen", SocketListen},
|
||||
{"SocketSend", SocketSend},
|
||||
{"SocketSendTo", SocketSendTo},
|
||||
{"SocketSetOption", SocketSetOption},
|
||||
{"SocketSetReceiveCallback", SocketSetReceiveCallback},
|
||||
{"SocketSetSendqueueEmptyCallback", SocketSetSendqueueEmptyCallback},
|
||||
{"SocketSetDisconnectCallback", SocketSetDisconnectCallback},
|
||||
{"SocketSetErrorCallback", SocketSetErrorCallback},
|
||||
{"SocketSetArg", SocketSetArg},
|
||||
{"SocketGetHostName", SocketGetHostName},
|
||||
{"SocketIsConnected", SocketIsConnected},
|
||||
|
||||
{"SocketCreate", SocketCreate},
|
||||
{"SocketBind", SocketBind},
|
||||
{"SocketConnect", SocketConnect},
|
||||
{"SocketDisconnect", SocketDisconnect},
|
||||
{"SocketListen", SocketListen},
|
||||
{"SocketSend", SocketSend},
|
||||
{"SocketSendTo", SocketSendTo},
|
||||
{"SocketSetOption", SocketSetOption},
|
||||
// Transitional syntax support.
|
||||
{"Socket.Socket", SocketCreate},
|
||||
{"Socket.Bind", SocketBind},
|
||||
{"Socket.Connect", SocketConnect},
|
||||
{"Socket.Disconnect", SocketDisconnect},
|
||||
{"Socket.Listen", SocketListen},
|
||||
{"Socket.Send", SocketSend},
|
||||
{"Socket.SendTo", SocketSendTo},
|
||||
{"Socket.SetOption", SocketSetOption},
|
||||
{"Socket.SetReceiveCallback", SocketSetReceiveCallback},
|
||||
{"Socket.SetSendqueueEmptyCallback",SocketSetSendqueueEmptyCallback},
|
||||
{"Socket.SetDisconnectCallback", SocketSetDisconnectCallback},
|
||||
{"Socket.SetErrorCallback", SocketSetErrorCallback},
|
||||
{"Socket.SetArg", SocketSetArg},
|
||||
{"Socket.GetHostName", SocketGetHostName},
|
||||
{"Socket.Connected.get", SocketIsConnected},
|
||||
|
||||
{"SocketSetReceiveCallback", SocketSetReceiveCallback},
|
||||
{"SocketSetSendqueueEmptyCallback", SocketSetSendqueueEmptyCallback},
|
||||
{"SocketSetDisconnectCallback", SocketSetDisconnectCallback},
|
||||
{"SocketSetErrorCallback", SocketSetErrorCallback},
|
||||
|
||||
{"SocketSetArg", SocketSetArg},
|
||||
|
||||
{"SocketGetHostName", SocketGetHostName},
|
||||
|
||||
{NULL, NULL},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# makefile
|
||||
|
||||
SMSDK = /home/m/build/sourcemod-1-0
|
||||
SOURCEMM = /home/m/build/mmsource-1-4
|
||||
# SMSDK = /home/m/build/sourcemod-1-0
|
||||
SMSDK = G:/Documents/SMBuild/sourcemod
|
||||
# SOURCEMM = /home/m/build/mmsource-1-4
|
||||
SOURCEMM = G:/Documents/SMBuild/mmsource-1.10
|
||||
|
||||
PROJECT = socket
|
||||
|
||||
@@ -20,8 +22,8 @@ C_DEBUG_FLAGS = -g -ggdb3
|
||||
CPP = gcc
|
||||
|
||||
LINK = -lpthread -Wl,-Bstatic -static-libgcc -lboost_thread -lboost_system -lstdc++ -Wl,-Bdynamic
|
||||
INCLUDE = -I. -I$(SOURCEMM) -I$(SOURCEMM)/sourcehook -I$(SOURCEMM)/sourcemm \
|
||||
-I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn -I$(SMSDK)/public/extensions
|
||||
INCLUDE = -I. -I$(SOURCEMM) -I$(SOURCEMM)/core-legacy/sourcehook -I$(SOURCEMM)/core-legacy \
|
||||
-I$(SMSDK)/public -I$(SMSDK)/sourcepawn/include -I$(SMSDK)/public/extensions
|
||||
|
||||
CFLAGS = -D_LINUX -DSOURCEMOD_BUILD -Wall -fPIC -m32
|
||||
CPPFLAGS =
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# vim: set ts=8 sts=2 sw=2 tw=99 et ft=python:
|
||||
import os
|
||||
|
||||
# This is where the files will be output to
|
||||
# package is the default
|
||||
builder.SetBuildFolder('package')
|
||||
|
||||
# Add any folders you need to this list
|
||||
folder_list = [
|
||||
'addons/sourcemod/extensions',
|
||||
#'addons/sourcemod/scripting/include',
|
||||
#'addons/sourcemod/gamedata',
|
||||
#'addons/sourcemod/configs',
|
||||
]
|
||||
|
||||
# Create the distribution folder hierarchy.
|
||||
folder_map = {}
|
||||
for folder in folder_list:
|
||||
norm_folder = os.path.normpath(folder)
|
||||
folder_map[folder] = builder.AddFolder(norm_folder)
|
||||
|
||||
# Do all straight-up file copies from the source tree.
|
||||
def CopyFiles(src, dest, files):
|
||||
if not dest:
|
||||
dest = src
|
||||
dest_entry = folder_map[dest]
|
||||
for source_file in files:
|
||||
source_path = os.path.join(builder.sourcePath, src, source_file)
|
||||
builder.AddCopy(source_path, dest_entry)
|
||||
|
||||
# Include files
|
||||
#CopyFiles('include', 'addons/sourcemod/scripting/include',
|
||||
# [ 'sample.inc', ]
|
||||
#)
|
||||
|
||||
# GameData files
|
||||
#CopyFiles('gamedata', 'addons/sourcemod/gamedata',
|
||||
# [ 'myfile.txt',
|
||||
# 'file2.txt'
|
||||
# ]
|
||||
#)
|
||||
|
||||
# Config Files
|
||||
#CopyFiles('configs', 'addons/sourcemod/configs',
|
||||
# [ 'configfile.cfg',
|
||||
# 'otherconfig.cfg,
|
||||
# ]
|
||||
#)
|
||||
|
||||
# Copy binaries.
|
||||
for cxx_task in Extension.extensions:
|
||||
builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions'])
|
||||
+12
-12
@@ -163,7 +163,7 @@ bool Socket<SocketType>::Bind(const char* hostname, uint16_t port, bool async) {
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (std::exception& e) {
|
||||
} catch (std::exception&) {
|
||||
if (resolver) delete resolver;
|
||||
if (handlerLock) delete handlerLock;
|
||||
}
|
||||
@@ -230,11 +230,11 @@ bool Socket<SocketType>::Connect(const char* hostname, uint16_t port, bool async
|
||||
|
||||
if (error) throw boost::system::system_error(error);
|
||||
|
||||
ReceiveHandler(new char[16384], 16384, 0, boost::system::posix_error::make_error_code(boost::system::posix_error::success), new boost::shared_lock<boost::shared_mutex>(handlerMutex));
|
||||
ReceiveHandler(new char[16384], 16384, 0, boost::system::errc::make_error_code(boost::system::errc::success), new boost::shared_lock<boost::shared_mutex>(handlerMutex));
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (std::exception& e) {
|
||||
} catch (std::exception&) {
|
||||
if (resolver) delete resolver;
|
||||
if (handlerLock) delete handlerLock;
|
||||
}
|
||||
@@ -282,7 +282,7 @@ void Socket<SocketType>::ConnectPostConnectHandler(typename SocketType::resolver
|
||||
}
|
||||
} // ~lock
|
||||
|
||||
ReceiveHandler(new char[16384], 16384, 0, boost::system::posix_error::make_error_code(boost::system::posix_error::success), handlerLock);
|
||||
ReceiveHandler(new char[16384], 16384, 0, boost::system::errc::make_error_code(boost::system::errc::success), handlerLock);
|
||||
|
||||
delete resolver;
|
||||
|
||||
@@ -296,7 +296,7 @@ void Socket<SocketType>::ConnectPostConnectHandler(typename SocketType::resolver
|
||||
}
|
||||
} // ~lock
|
||||
|
||||
ConnectPostResolveHandler(resolver, endpointIterator, boost::system::posix_error::make_error_code(boost::system::posix_error::success), handlerLock);
|
||||
ConnectPostResolveHandler(resolver, endpointIterator, boost::system::errc::make_error_code(boost::system::errc::success), handlerLock);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -321,7 +321,7 @@ bool Socket<SocketType>::Disconnect() {
|
||||
socket->close();
|
||||
|
||||
return true;
|
||||
} catch (std::exception& e) {
|
||||
} catch (std::exception&) {
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -371,7 +371,7 @@ bool Socket<tcp>::Listen() {
|
||||
handlerLock));
|
||||
|
||||
return true;
|
||||
} catch (std::exception& e) {
|
||||
} catch (std::exception&) {
|
||||
if (handlerLock) delete handlerLock;
|
||||
if (nextAsioSocket) delete nextAsioSocket;
|
||||
}
|
||||
@@ -393,7 +393,7 @@ void Socket<tcp>::ListenIncomingHandler(tcp::socket* newAsioSocket, const boost:
|
||||
newSocket->socket = newAsioSocket;
|
||||
callbackHandler.AddCallback(new Callback(CallbackEvent_Incoming, this, newSocket, newAsioSocket->remote_endpoint()));
|
||||
|
||||
newSocket->ReceiveHandler(new char[16384], 16384, 0, boost::system::posix_error::make_error_code(boost::system::posix_error::success), new boost::shared_lock<boost::shared_mutex>(newSocket->handlerMutex));
|
||||
newSocket->ReceiveHandler(new char[16384], 16384, 0, boost::system::errc::make_error_code(boost::system::errc::success), new boost::shared_lock<boost::shared_mutex>(newSocket->handlerMutex));
|
||||
|
||||
tcp::socket* nextAsioSocket = new tcp::socket(*socketHandler.ioService);
|
||||
|
||||
@@ -455,7 +455,7 @@ bool Socket<SocketType>::Send(const std::string& data, bool async) {
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (std::exception& e) {
|
||||
} catch (std::exception&) {
|
||||
if (buf) delete[] buf;
|
||||
if (handlerLock) delete handlerLock;
|
||||
}
|
||||
@@ -532,7 +532,7 @@ bool Socket<udp>::SendTo(const std::string& data, const char* hostname, uint16_t
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (std::exception& e) {
|
||||
} catch (std::exception&) {
|
||||
if (resolver) delete resolver;
|
||||
if (buf) delete[] buf;
|
||||
if (handlerLock) delete handlerLock;
|
||||
@@ -587,7 +587,7 @@ void Socket<SocketType>::SendToPostSendHandler(typename SocketType::resolver* re
|
||||
}
|
||||
|
||||
} else if (endpointIterator != typename SocketType::resolver::iterator()) {
|
||||
SendToPostResolveHandler(resolver, endpointIterator, buf, bufLen, boost::system::posix_error::make_error_code(boost::system::posix_error::success), handlerLock);
|
||||
SendToPostResolveHandler(resolver, endpointIterator, buf, bufLen, boost::system::errc::make_error_code(boost::system::errc::success), handlerLock);
|
||||
return;
|
||||
|
||||
} else {
|
||||
@@ -710,7 +710,7 @@ bool Socket<SocketType>::SetOption(SM_SocketOption so, int value, bool lock) {
|
||||
|
||||
if (l) delete l;
|
||||
return true;
|
||||
} catch (std::exception& e) {
|
||||
} catch (std::exception&) {
|
||||
if (l) delete l;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef INC_SEXT_SOCKET_H
|
||||
#define INC_SEXT_SOCKET_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
#include <boost/asio.hpp>
|
||||
@@ -16,60 +15,58 @@ class SocketHandler;
|
||||
template <class SocketType>
|
||||
class Socket {
|
||||
public:
|
||||
Socket(SM_SocketType st, typename SocketType::socket* asioSocket = NULL);
|
||||
Socket(SM_SocketType st, typename SocketType::socket *asioSocket = nullptr);
|
||||
~Socket();
|
||||
|
||||
bool IsOpen();
|
||||
|
||||
bool Bind(const char* hostname, uint16_t port, bool async = true);
|
||||
bool Connect(const char* hostname, uint16_t port, bool async = true);
|
||||
bool Bind(const char *hostname, uint16_t port, bool async = true);
|
||||
bool Connect(const char *hostname, uint16_t port, bool async = true);
|
||||
bool Disconnect();
|
||||
bool Listen();
|
||||
bool Send(const std::string& data, bool async = true);
|
||||
bool SendTo(const std::string& data, const char* hostname, uint16_t port, bool async = true);
|
||||
bool SetOption(SM_SocketOption so, int value, bool lock=true);
|
||||
bool Send(const std::string &data, bool async = true);
|
||||
bool SendTo(const std::string &data, const char *hostname, uint16_t port, bool async = true);
|
||||
bool SetOption(SM_SocketOption so, int value, bool lock = true);
|
||||
|
||||
IPluginFunction* connectCallback;
|
||||
IPluginFunction* incomingCallback;
|
||||
IPluginFunction* receiveCallback;
|
||||
IPluginFunction* sendqueueEmptyCallback;
|
||||
IPluginFunction* disconnectCallback;
|
||||
IPluginFunction* errorCallback;
|
||||
IPluginFunction *connectCallback;
|
||||
IPluginFunction *incomingCallback;
|
||||
IPluginFunction *receiveCallback;
|
||||
IPluginFunction *sendqueueEmptyCallback;
|
||||
IPluginFunction *disconnectCallback;
|
||||
IPluginFunction *errorCallback;
|
||||
|
||||
int32_t smHandle;
|
||||
int32_t smCallbackArg;
|
||||
volatile unsigned int sendQueueLength;
|
||||
|
||||
private:
|
||||
void ReceiveHandler(char* buf, size_t bufferSize, size_t bytes, const boost::system::error_code&, boost::shared_lock<boost::shared_mutex>*);
|
||||
void ReceiveHandler(char *buf, size_t bufferSize, size_t bytes, const boost::system::error_code &, boost::shared_lock<boost::shared_mutex> *);
|
||||
|
||||
void BindPostResolveHandler(typename SocketType::resolver*, typename SocketType::resolver::iterator, const boost::system::error_code&, boost::shared_lock<boost::shared_mutex>*);
|
||||
void BindPostResolveHandler(typename SocketType::resolver *, typename SocketType::resolver::iterator, const boost::system::error_code &, boost::shared_lock<boost::shared_mutex> *);
|
||||
|
||||
void ConnectPostResolveHandler(typename SocketType::resolver*, typename SocketType::resolver::iterator, const boost::system::error_code&, boost::shared_lock<boost::shared_mutex>*);
|
||||
void ConnectPostConnectHandler(typename SocketType::resolver*, typename SocketType::resolver::iterator, const boost::system::error_code&, boost::shared_lock<boost::shared_mutex>*);
|
||||
void ConnectPostResolveHandler(typename SocketType::resolver *, typename SocketType::resolver::iterator, const boost::system::error_code &, boost::shared_lock<boost::shared_mutex> *);
|
||||
void ConnectPostConnectHandler(typename SocketType::resolver *, typename SocketType::resolver::iterator, const boost::system::error_code &, boost::shared_lock<boost::shared_mutex> *);
|
||||
|
||||
void ListenIncomingHandler(boost::asio::ip::tcp::socket* newAsioSocket, const boost::system::error_code&, boost::shared_lock<boost::shared_mutex>*);
|
||||
void ListenIncomingHandler(boost::asio::ip::tcp::socket *newAsioSocket, const boost::system::error_code &, boost::shared_lock<boost::shared_mutex> *);
|
||||
|
||||
void SendPostSendHandler(char* buf, size_t bytes, const boost::system::error_code& err, boost::shared_lock<boost::shared_mutex>*);
|
||||
void SendPostSendHandler(char *buf, size_t bytes, const boost::system::error_code &err, boost::shared_lock<boost::shared_mutex> *);
|
||||
|
||||
void SendToPostResolveHandler(typename SocketType::resolver*, typename SocketType::resolver::iterator, char* buf, size_t bufLen, const boost::system::error_code&, boost::shared_lock<boost::shared_mutex>*);
|
||||
void SendToPostSendHandler(typename SocketType::resolver*, typename SocketType::resolver::iterator, char* buf, size_t bufLen, size_t bytesTransferred, const boost::system::error_code&, boost::shared_lock<boost::shared_mutex>*);
|
||||
void SendToPostResolveHandler(typename SocketType::resolver *, typename SocketType::resolver::iterator, char *buf, size_t bufLen, const boost::system::error_code &, boost::shared_lock<boost::shared_mutex> *);
|
||||
void SendToPostSendHandler(typename SocketType::resolver *, typename SocketType::resolver::iterator, char *buf, size_t bufLen, size_t bytesTransferred, const boost::system::error_code &, boost::shared_lock<boost::shared_mutex> *);
|
||||
|
||||
//void InitializeResolver();
|
||||
void InitializeSocket();
|
||||
|
||||
SM_SocketType sm_sockettype;
|
||||
std::queue<SocketOption*> socketOptionQueue;
|
||||
std::queue<SocketOption *> socketOptionQueue;
|
||||
|
||||
typename SocketType::socket* socket;
|
||||
typename SocketType::socket *socket;
|
||||
boost::mutex socketMutex;
|
||||
//typename SocketType::resolver* resolver;
|
||||
typename SocketType::endpoint* localEndpoint;
|
||||
boost::mutex* localEndpointMutex;
|
||||
boost::asio::ip::tcp::acceptor* tcpAcceptor;
|
||||
boost::mutex* tcpAcceptorMutex;
|
||||
typename SocketType::endpoint *localEndpoint;
|
||||
boost::mutex *localEndpointMutex;
|
||||
boost::asio::ip::tcp::acceptor *tcpAcceptor;
|
||||
boost::mutex *tcpAcceptorMutex;
|
||||
|
||||
boost::shared_mutex handlerMutex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# vim: set sts=2 ts=8 sw=2 tw=99 et:
|
||||
import sys
|
||||
from ambuild2 import run
|
||||
|
||||
# Simple extensions do not need to modify this file.
|
||||
|
||||
builder = run.PrepareBuild(sourcePath = sys.path[0])
|
||||
|
||||
builder.options.add_option('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None,
|
||||
help='Root search folder for HL2SDKs')
|
||||
builder.options.add_option('--mms-path', type=str, dest='mms_path', default=None,
|
||||
help='Path to Metamod:Source')
|
||||
builder.options.add_option('--sm-path', type=str, dest='sm_path', default=None,
|
||||
help='Path to SourceMod')
|
||||
builder.options.add_option('--enable-debug', action='store_const', const='1', dest='debug',
|
||||
help='Enable debugging symbols')
|
||||
builder.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt',
|
||||
help='Enable optimization')
|
||||
builder.options.add_option('-s', '--sdks', default='all', dest='sdks',
|
||||
help='Build against specified SDKs; valid args are "all", "present", or '
|
||||
'comma-delimited list of engine names (default: %default)')
|
||||
|
||||
builder.Configure()
|
||||
+11
-7
@@ -17,10 +17,12 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
@@ -50,8 +52,8 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..;$(SOURCEMOD)\public;$(SOURCEMOD)\public\sourcepawn;$(BOOST155);$(MSINTTYPES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;SOCKET_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;WIN32;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..;$(SOURCEMOD)\public;$(SOURCEMOD)\sourcepawn\include;$(SOURCEMOD)\public\amtl;$(BOOST155);$(MSINTTYPES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;SOCKET_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;WIN32;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions);__STDC_LIMIT_MACROS </PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@@ -62,7 +64,7 @@
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<OutputFile>$(OutDir)socket.ext.dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(BOOST155)\stage\lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(BOOST155)\stage\lib;$(BOOST155)\stage\lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
@@ -70,8 +72,8 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..;$(SOURCEMOD)\public;$(SOURCEMOD)\public\sourcepawn;$(BOOST155);$(MSINTTYPES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;SOCKET_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;WIN32;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..;$(SOURCEMOD)\public;$(SOURCEMOD)\sourcepawn\include;$(SOURCEMOD)\public\amtl;$(BOOST155);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;SOCKET_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;WIN32;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions);__STDC_LIMIT_MACROS</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
@@ -80,7 +82,7 @@
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<OutputFile>$(OutDir)$(ProjectName).ext.dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(BOOST155)\stage\lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(BOOST155)\stage\lib;$(BOOST155)\stage\lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
@@ -104,7 +106,9 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\Callback.cpp" />
|
||||
<ClCompile Include="..\CallbackHandler.cpp" />
|
||||
<ClCompile Include="..\Extension.cpp" />
|
||||
<ClCompile Include="..\Extension.cpp">
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..;$(SOURCEMOD)\public;$(SOURCEMOD)\$(SOURCEMOD)\sourcepawn\include;$(BOOST155);$(MSINTTYPES);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\sdk\smsdk_ext.cpp" />
|
||||
<ClCompile Include="..\Socket.cpp" />
|
||||
<ClCompile Include="..\SocketHandler.cpp" />
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
+200
-31
@@ -47,7 +47,7 @@ enum SocketOption {
|
||||
* @note don't forget to set your buffer sizes at least to the value passed to this function, but
|
||||
* always at least to 4096
|
||||
*
|
||||
* @param cell_t 0(=default) to disable or max. chunk size including \0 terminator in bytes
|
||||
* @param int 0(=default) to disable or max. chunk size including \0 terminator in bytes
|
||||
* @return bool true on success
|
||||
*/
|
||||
ConcatenateCallbacks = 1,
|
||||
@@ -75,7 +75,7 @@ enum SocketOption {
|
||||
*
|
||||
* @note this option will affect all sockets from all plugins, use it with caution!
|
||||
*
|
||||
* @param cell_t maximum amount of callbacks per gameframe
|
||||
* @param int maximum amount of callbacks per gameframe
|
||||
* @return bool true on success
|
||||
*/
|
||||
CallbacksPerFrame,
|
||||
@@ -107,7 +107,7 @@ enum SocketOption {
|
||||
* This option specifies how long a socket will wait if it's being closed and its send buffer is
|
||||
* still filled. This is a wrapper for setting SO_LINGER.
|
||||
*
|
||||
* @param cell_t 0 (=default) to disable or time in s
|
||||
* @param int 0 (=default) to disable or time in s
|
||||
* @return bool true on success
|
||||
*/
|
||||
SocketLinger,
|
||||
@@ -123,7 +123,7 @@ enum SocketOption {
|
||||
* This option specifies how large the send buffer will be. This is a wrapper for setting
|
||||
* SO_SNDBUF.
|
||||
*
|
||||
* @param cell_t size in bytes
|
||||
* @param int size in bytes
|
||||
* @return bool true on success
|
||||
*/
|
||||
SocketSendBuffer,
|
||||
@@ -131,7 +131,7 @@ enum SocketOption {
|
||||
* This option specifies how large the receive buffer will be. This is a wrapper for setting
|
||||
* SO_RCVBUF.
|
||||
*
|
||||
* @param cell_t size in bytes
|
||||
* @param int size in bytes
|
||||
* @return bool true on success
|
||||
*/
|
||||
SocketReceiveBuffer,
|
||||
@@ -150,7 +150,7 @@ enum SocketOption {
|
||||
*
|
||||
* @note this can probably block the extension, use it with caution!
|
||||
*
|
||||
* @param cell_t size in bytes
|
||||
* @param int size in bytes
|
||||
* @return bool true on success
|
||||
*/
|
||||
SocketReceiveLowWatermark,
|
||||
@@ -158,7 +158,7 @@ enum SocketOption {
|
||||
* This option specifies how long a socket will try to receive data before it times out and
|
||||
* processes the data. This is a wrapper for setting SO_RCVTIMEO.
|
||||
*
|
||||
* @param cell_t 0 (=default) to disable or time in ms
|
||||
* @param int 0 (=default) to disable or time in ms
|
||||
* @return bool true on success
|
||||
*/
|
||||
SocketReceiveTimeout,
|
||||
@@ -168,7 +168,7 @@ enum SocketOption {
|
||||
*
|
||||
* @note this can probably block the extension, use it with caution!
|
||||
*
|
||||
* @param cell_t size in bytes
|
||||
* @param int size in bytes
|
||||
* @return bool true on success
|
||||
*/
|
||||
SocketSendLowWatermark,
|
||||
@@ -176,7 +176,7 @@ enum SocketOption {
|
||||
* This option specifies how long a socket will try to send data before it times out and
|
||||
* retries it later. This is a wrapper for setting SO_SNDTIMEO.
|
||||
*
|
||||
* @param cell_t 0 (=default) to disable or time in ms
|
||||
* @param int 0 (=default) to disable or time in ms
|
||||
* @return bool true on success
|
||||
*/
|
||||
SocketSendTimeout,
|
||||
@@ -189,12 +189,181 @@ enum SocketOption {
|
||||
DebugMode
|
||||
}
|
||||
|
||||
// Methodmap
|
||||
methodmap Socket < Handle {
|
||||
/**
|
||||
* Creates a new socket.
|
||||
*
|
||||
* @note this function may be relatively expensive, reuse sockets if possible
|
||||
*
|
||||
* @param SocketType protocol The protocol to use, SOCKET_TCP is default
|
||||
* @param SocketErrorCB efunc The error callback
|
||||
* @return Handle The socket handle. Returns INVALID_HANDLE on failure
|
||||
*/
|
||||
public native Socket(SocketType protocol=SOCKET_TCP, SocketErrorCB efunc);
|
||||
|
||||
/**
|
||||
* Binds the socket to a local address
|
||||
*
|
||||
* @param String hostname The hostname (or IP) to bind the socket to.
|
||||
* @param int port The port to bind the socket to.
|
||||
* @return bool true on success
|
||||
*/
|
||||
public native bool Bind(const char[] hostname, int port);
|
||||
|
||||
/**
|
||||
* Connects a socket
|
||||
*
|
||||
* @note this native is threaded, it may be still running after it executed, use the connect callback
|
||||
* @note invokes the SocketError callback with errorType = CONNECT_ERROR or EMPTY_HOST if it fails
|
||||
* @note invokes the SocketConnect callback if it succeeds
|
||||
*
|
||||
* @param SocketConnectCB cfunc The connect callback
|
||||
* @param SocketReceiveCB rfunc The receive callback
|
||||
* @param SocketDisconnectCB dfunc The disconnect callback
|
||||
* @param String hostname The hostname (or IP) to connect to.
|
||||
* @param int port The port to connect to.
|
||||
* @noreturn
|
||||
*/
|
||||
public native void Connect(SocketConnectCB cfunc, SocketReceiveCB rfunc, SocketDisconnectCB dfunc, const char[] hostname, int port);
|
||||
|
||||
/**
|
||||
* Disconnects a socket
|
||||
*
|
||||
* @note this will not close the handle, the socket will be reset to a state similar to after SocketCreate()
|
||||
* @note this won't trigger any disconnect/error callbacks
|
||||
*
|
||||
* @return bool true on success
|
||||
*/
|
||||
public native bool Disconnect();
|
||||
|
||||
/**
|
||||
* Makes a socket listen for incoming connections
|
||||
*
|
||||
* @param SocketIncomingCB ifunc The callback for incoming connections
|
||||
* @return bool true on success
|
||||
*/
|
||||
public native bool Listen(SocketIncomingCB ifunc);
|
||||
|
||||
/**
|
||||
* Sends data through the socket.
|
||||
*
|
||||
* @note specify size for binary safe operation
|
||||
* @note if size is not specified the \0 terminator will not be included
|
||||
* @note This native is threaded, it may be still running after it executed (not atomic).
|
||||
* @note Use the SendqueueEmpty callback to determine when all data has been successfully sent.
|
||||
* @note The socket extension will ensure that the data will be send in the correct order and split
|
||||
* the data if required.
|
||||
*
|
||||
* @param String data The data to send.
|
||||
* @noreturn
|
||||
*/
|
||||
public native void Send(const char[] data, int size = -1);
|
||||
|
||||
/**
|
||||
* Sends UDP data through the socket to a specific destination.
|
||||
*
|
||||
* @note specify size for binary safe operation
|
||||
* @note if size is not specified the \0 terminator will not be included
|
||||
* @note This native is threaded, it may be still running after it executed (not atomic).
|
||||
* @note Use the SendqueueEmpty callback to determine when all data has been successfully sent.
|
||||
* @note The socket extension will ensure that the data will be send in the correct order and split
|
||||
* the data if required.
|
||||
*
|
||||
* @param String data The data to send.
|
||||
* @param String hostname The hostname (or IP) to send to.
|
||||
* @param int port The port to send to.
|
||||
* @noreturn
|
||||
*/
|
||||
public native void SendTo(const char[] data, int size = -1, const char[] hostname, int port);
|
||||
|
||||
/**
|
||||
* Set a socket option.
|
||||
*
|
||||
* @param SocketOption option The option to modify (see enum SocketOption for details).
|
||||
* @param int value The value to set the option to.
|
||||
* @return int 1 on success.
|
||||
*/
|
||||
public native int SetOption(SocketOption option, int value);
|
||||
|
||||
/**
|
||||
* Defines the callback function for when the socket receives data
|
||||
*
|
||||
* @note this is only useful and required for child-sockets spawned by listen-sockets
|
||||
* (otherwise you already set it in SocketConnect())
|
||||
*
|
||||
* @param SocketReceiveCB rfunc The receive callback
|
||||
* @noreturn
|
||||
*/
|
||||
public native void SetReceiveCallback(SocketReceiveCB rfunc);
|
||||
|
||||
/**
|
||||
* Defines the callback function for when the socket sent all items in its send queue
|
||||
*
|
||||
* @note this must be called AFTER sending (queueing) the data
|
||||
* @note if no send-data is queued this will fire the callback itself
|
||||
* @note the callback is guaranteed to fire
|
||||
*
|
||||
* @param SocketDisconnectCB dfunc The disconnect callback
|
||||
* @noreturn
|
||||
*/
|
||||
public native void SetSendqueueEmptyCallback(SocketSendqueueEmptyCB sfunc);
|
||||
|
||||
/**
|
||||
* Defines the callback function for when the socket was properly disconnected by the remote side
|
||||
*
|
||||
* @note this is only useful and required for child-sockets spawned by listen-sockets
|
||||
* (otherwise you already set it in SocketConnect())
|
||||
*
|
||||
* @param SocketDisconnectCB dfunc The disconnect callback
|
||||
* @noreturn
|
||||
*/
|
||||
public native void SetDisconnectCallback(SocketDisconnectCB dfunc);
|
||||
|
||||
/**
|
||||
* Defines the callback function for when the socket triggered an error
|
||||
*
|
||||
* @note this is only useful and required for child-sockets spawned by listen-sockets
|
||||
* (otherwise you already set it in SocketCreate())
|
||||
*
|
||||
* @param SocketErrorCB efunc The error callback
|
||||
* @noreturn
|
||||
*/
|
||||
public native void SetErrorCallback(SocketErrorCB efunc);
|
||||
|
||||
/**
|
||||
* Sets the argument being passed to callbacks
|
||||
*
|
||||
* @param any arg The argument to set
|
||||
* @noreturn
|
||||
*/
|
||||
public native void SetArg(any arg);
|
||||
|
||||
/**
|
||||
* Retrieve the local system's hostname as the command "hostname" does.
|
||||
*
|
||||
* @param dest Destination string buffer to copy to.
|
||||
* @param destLen Destination buffer length (includes null terminator).
|
||||
*
|
||||
* @return 1 on success
|
||||
*/
|
||||
public static int GetHostName(char[] dest, int destLen);
|
||||
|
||||
/**
|
||||
* Returns whether a socket is connected or not.
|
||||
*
|
||||
* @return bool The connection status
|
||||
*/
|
||||
property bool Connected {
|
||||
public native get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/******************************************* callbacks *******************************************/
|
||||
/*************************************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* triggered if a normal sockets finished connecting and is ready to be used
|
||||
*
|
||||
@@ -202,20 +371,20 @@ enum SocketOption {
|
||||
* @param arg The argument set by SocketSetArg()
|
||||
* @noreturn
|
||||
*/
|
||||
typedef SocketConnectCB = function void (Handle socket, any arg);
|
||||
typedef SocketConnectCB = function void (Socket socket, any arg);
|
||||
|
||||
/**
|
||||
* triggered if a listening socket received an incoming connection and is ready to be used
|
||||
*
|
||||
* @note The child-socket won't work until receive-, disconnect-, and errorcallback for it are set.
|
||||
*
|
||||
* @param Handle socket The socket handle pointing to the calling listen-socket
|
||||
* @param Handle newSocket The socket handle to the newly spawned child socket
|
||||
* @param Socket socket The socket handle pointing to the calling listen-socket
|
||||
* @param Socket newSocket The socket handle to the newly spawned child socket
|
||||
* @param String remoteIP The remote IP
|
||||
* @param any arg The argument set by SocketSetArg() for the listen-socket
|
||||
* @noreturn
|
||||
*/
|
||||
typedef SocketIncomingCB = function void (Handle socket, Handle newSocket, const char[] remoteIP, int remotePort, any arg);
|
||||
typedef SocketIncomingCB = function void (Socket socket, Socket newSocket, const char[] remoteIP, int remotePort, any arg);
|
||||
|
||||
/**
|
||||
* triggered if a socket receives data
|
||||
@@ -225,46 +394,46 @@ typedef SocketIncomingCB = function void (Handle socket, Handle newSocket, const
|
||||
* @note if not set otherwise by SocketSetOption(..., ConcatenateCallbacks, ...) receiveData will
|
||||
* never be longer than 4096 characters including \0 terminator
|
||||
*
|
||||
* @param Handle socket The socket handle pointing to the calling socket
|
||||
* @param Socket socket The socket handle pointing to the calling socket
|
||||
* @param String receiveData The data which arrived, 0-terminated at receiveData[dataSize]
|
||||
* @param cell_t dataSize The length of the arrived data excluding the 0-termination
|
||||
* @param int dataSize The length of the arrived data excluding the 0-termination
|
||||
* @param any arg The argument set by SocketSetArg() for the socket
|
||||
* @noreturn
|
||||
*/
|
||||
typedef SocketReceiveCB = function void (Handle socket, const char[] receiveData, const int dataSize, any arg);
|
||||
typedef SocketReceiveCB = function void (Socket socket, const char[] receiveData, const int dataSize, any arg);
|
||||
|
||||
/**
|
||||
* called after a socket sent all items in its send queue successfully
|
||||
*
|
||||
* @param Handle socket The socket handle pointing to the calling socket
|
||||
* @param Socket socket The socket handle pointing to the calling socket
|
||||
* @param any arg The argument set by SocketSetArg() for the socket
|
||||
* @noreturn
|
||||
*/
|
||||
typedef SocketSendqueueEmptyCB = function void (Handle socket, any arg);
|
||||
typedef SocketSendqueueEmptyCB = function void (Socket socket, any arg);
|
||||
|
||||
/**
|
||||
* called if a socket has been properly disconnected by the remote side
|
||||
*
|
||||
* @note You should call CloseHandle(socket) or reuse the socket before this function ends
|
||||
*
|
||||
* @param Handle socket The socket handle pointing to the calling socket
|
||||
* @param Socket socket The socket handle pointing to the calling socket
|
||||
* @param any arg The argument set by SocketSetArg() for the socket
|
||||
* @noreturn
|
||||
*/
|
||||
typedef SocketDisconnectCB = function void (Handle socket, any arg);
|
||||
typedef SocketDisconnectCB = function void (Socket socket, any arg);
|
||||
|
||||
/**
|
||||
* called if an unrecoverable error occured, close the socket without an additional call to a disconnect callback
|
||||
*
|
||||
* @note You should call CloseHandle(socket) or reuse the socket before this function ends
|
||||
*
|
||||
* @param Handle socket The socket handle pointing to the calling socket
|
||||
* @param cell_t errorType The error type, see defines above
|
||||
* @param cell_t errorNum The errno, see errno.h for details
|
||||
* @param Socket socket The socket handle pointing to the calling socket
|
||||
* @param int errorType The error type, see defines above
|
||||
* @param int errorNum The errno, see errno.h for details
|
||||
* @param any arg The argument set by SocketSetArg() for the socket
|
||||
* @noreturn
|
||||
*/
|
||||
typedef SocketErrorCB = function void (Handle socket, const int errorType, const int errorNum, any arg);
|
||||
typedef SocketErrorCB = function void (Socket socket, const int errorType, const int errorNum, any arg);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/******************************************** natives ********************************************/
|
||||
@@ -287,16 +456,16 @@ native bool SocketIsConnected(Handle socket);
|
||||
*
|
||||
* @param SocketType protocol The protocol to use, SOCKET_TCP is default
|
||||
* @param SocketErrorCB efunc The error callback
|
||||
* @return Handle The socket handle. Returns INVALID_HANDLE on failure
|
||||
* @return Socket The socket handle. Returns INVALID_HANDLE on failure
|
||||
*/
|
||||
native Handle SocketCreate(SocketType protocol=SOCKET_TCP, SocketErrorCB efunc);
|
||||
native Socket SocketCreate(SocketType protocol=SOCKET_TCP, SocketErrorCB efunc);
|
||||
|
||||
/**
|
||||
* Binds the socket to a local address
|
||||
*
|
||||
* @param Handle socket The handle of the socket to be used.
|
||||
* @param String hostname The hostname (or IP) to bind the socket to.
|
||||
* @param cell_t port The port to bind the socket to.
|
||||
* @param int port The port to bind the socket to.
|
||||
* @return bool true on success
|
||||
*/
|
||||
native bool SocketBind(Handle socket, const char[] hostname, int port);
|
||||
@@ -313,7 +482,7 @@ native bool SocketBind(Handle socket, const char[] hostname, int port);
|
||||
* @param SocketReceiveCB rfunc The receive callback
|
||||
* @param SocketDisconnectCB dfunc The disconnect callback
|
||||
* @param String hostname The hostname (or IP) to connect to.
|
||||
* @param cell_t port The port to connect to.
|
||||
* @param int port The port to connect to.
|
||||
* @noreturn
|
||||
*/
|
||||
native void SocketConnect(Handle socket, SocketConnectCB cfunc, SocketReceiveCB rfunc, SocketDisconnectCB dfunc, const char[] hostname, int port);
|
||||
@@ -366,7 +535,7 @@ native void SocketSend(Handle socket, const char[] data, int size=-1);
|
||||
* @param Handle socket The handle of the socket to be used.
|
||||
* @param String data The data to send.
|
||||
* @param String hostname The hostname (or IP) to send to.
|
||||
* @param cell_t port The port to send to.
|
||||
* @param int port The port to send to.
|
||||
* @noreturn
|
||||
*/
|
||||
native void SocketSendTo(Handle socket, const char[] data, int size=-1, const char[] hostname, int port);
|
||||
@@ -377,7 +546,7 @@ native void SocketSendTo(Handle socket, const char[] data, int size=-1, const ch
|
||||
* @param Handle socket The handle of the socket to be used. May be INVALID_HANDLE if not essential.
|
||||
* @param SocketOption option The option to modify (see enum SocketOption for details).
|
||||
* @param cellt_ value The value to set the option to.
|
||||
* @return cell_t 1 on success.
|
||||
* @return int 1 on success.
|
||||
*/
|
||||
native int SocketSetOption(Handle socket, SocketOption option, int value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user