text:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="..\..\3rd\crypto\base64_decoder.c" />
    <ClCompile Include="..\..\3rd\crypto\base64_encoder.c" />
    <ClCompile Include="..\..\3rd\crypto\md5.c" />
    <ClCompile Include="..\..\3rd\crypto\sha1.c" />
    <ClCompile Include="..\..\3rd\http_parser\http_parser.c" />
    <ClCompile Include="..\..\3rd\libuv\src\fs-poll.c" />
    <ClCompile Include="..\..\3rd\libuv\src\inet.c" />
    <ClCompile Include="..\..\3rd\libuv\src\threadpool.c" />
    <ClCompile Include="..\..\3rd\libuv\src\uv-common.c" />
    <ClCompile Include="..\..\3rd\libuv\src\version.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\async.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\core.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\dl.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\error.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\fs-event.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\fs.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\getaddrinfo.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\getnameinfo.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\handle.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\loop-watcher.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\pipe.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\poll.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\process-stdio.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\process.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\req.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\signal.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\snprintf.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\stream.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\tcp.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\thread.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\timer.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\tty.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\udp.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\util.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\winapi.c" />
    <ClCompile Include="..\..\3rd\libuv\src\win\winsock.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lapi.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lauxlib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lbaselib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lbitlib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lcode.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lcorolib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lctype.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ldblib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ldebug.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ldo.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ldump.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lfunc.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lgc.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\linit.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\liolib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\llex.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lmathlib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lmem.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\loadlib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lobject.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lopcodes.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\loslib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lparser.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lstate.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lstring.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lstrlib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ltable.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ltablib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ltm.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lundump.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lutf8lib.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lvm.c" />
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lzio.c" />
    <ClCompile Include="..\..\3rd\mjson\json.c" />
    <ClCompile Include="..\..\3rd\tolua\tolua_event.c" />
    <ClCompile Include="..\..\3rd\tolua\tolua_fix.cc" />
    <ClCompile Include="..\..\3rd\tolua\tolua_is.c" />
    <ClCompile Include="..\..\3rd\tolua\tolua_map.c" />
    <ClCompile Include="..\..\3rd\tolua\tolua_push.c" />
    <ClCompile Include="..\..\3rd\tolua\tolua_to.c" />
    <ClCompile Include="..\..\apps\lua_test\TestLua.cpp" />
    <ClCompile Include="..\..\database\mysqlwarpper.cpp" />
    <ClCompile Include="..\..\database\rediswarpper.cpp" />
    <ClCompile Include="..\..\lua_wrapper\cmd_package_proto_export_to_lua.cpp" />
    <ClCompile Include="..\..\lua_wrapper\logger_export_to_lua.cpp" />
    <ClCompile Include="..\..\lua_wrapper\lua_wrapper.cpp" />
    <ClCompile Include="..\..\lua_wrapper\mysql_export_to_lua.cc" />
    <ClCompile Include="..\..\lua_wrapper\netbus_export_to_lua.cpp" />
    <ClCompile Include="..\..\lua_wrapper\redis_export_to_lua.cc" />
    <ClCompile Include="..\..\lua_wrapper\service_export_to_lua.cpp" />
    <ClCompile Include="..\..\lua_wrapper\session_export_to_lua.cpp" />
    <ClCompile Include="..\..\lua_wrapper\timer_export_to_lua.cpp" />
    <ClCompile Include="..\..\lua_wrapper\utils_export_to_lua.cpp" />
    <ClCompile Include="..\..\netbus\Netbus.cpp" />
    <ClCompile Include="..\..\netbus\protocol\CmdPackageProtocol.cpp" />
    <ClCompile Include="..\..\netbus\protocol\TcpPackageProtocol.cpp" />
    <ClCompile Include="..\..\netbus\protocol\WebSocketProtocol.cpp" />
    <ClCompile Include="..\..\netbus\service\AbstractService.cpp" />
    <ClCompile Include="..\..\netbus\service\ServiceManager.cpp" />
    <ClCompile Include="..\..\netbus\session\AbstractSession.cpp" />
    <ClCompile Include="..\..\netbus\session\TcpSession.cpp" />
    <ClCompile Include="..\..\netbus\session\UdpSession.cpp" />
    <ClCompile Include="..\..\utils\cache_alloc\cache_alloc.cpp" />
    <ClCompile Include="..\..\utils\cache_alloc\small_alloc.cpp" />
    <ClCompile Include="..\..\utils\debug\DebugUtil.cpp" />
    <ClCompile Include="..\..\utils\Encoding.cpp" />
    <ClCompile Include="..\..\utils\logger\logger.cc" />
    <ClCompile Include="..\..\utils\timer\time_list.c" />
    <ClCompile Include="..\..\utils\timestamp\timestamp.c" />
    <ClCompile Include="..\..\utils\win32\WinUtil.cpp" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="..\..\3rd\crypto\base64_decoder.h" />
    <ClInclude Include="..\..\3rd\crypto\base64_encoder.h" />
    <ClInclude Include="..\..\3rd\crypto\md5.h" />
    <ClInclude Include="..\..\3rd\crypto\sha1.h" />
    <ClInclude Include="..\..\3rd\http_parser\http_parser.h" />
    <ClInclude Include="..\..\3rd\libuv\include\android-ifaddrs.h" />
    <ClInclude Include="..\..\3rd\libuv\include\pthread-barrier.h" />
    <ClInclude Include="..\..\3rd\libuv\include\stdint-msvc2008.h" />
    <ClInclude Include="..\..\3rd\libuv\include\tree.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-aix.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-bsd.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-darwin.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-errno.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-linux.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-sunos.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-threadpool.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-unix.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-version.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv-win.h" />
    <ClInclude Include="..\..\3rd\libuv\include\uv.h" />
    <ClInclude Include="..\..\3rd\libuv\src\heap-inl.h" />
    <ClInclude Include="..\..\3rd\libuv\src\queue.h" />
    <ClInclude Include="..\..\3rd\libuv\src\uv-common.h" />
    <ClInclude Include="..\..\3rd\libuv\src\win\atomicops-inl.h" />
    <ClInclude Include="..\..\3rd\libuv\src\win\handle-inl.h" />
    <ClInclude Include="..\..\3rd\libuv\src\win\internal.h" />
    <ClInclude Include="..\..\3rd\libuv\src\win\req-inl.h" />
    <ClInclude Include="..\..\3rd\libuv\src\win\stream-inl.h" />
    <ClInclude Include="..\..\3rd\libuv\src\win\winapi.h" />
    <ClInclude Include="..\..\3rd\libuv\src\win\winsock.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lapi.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lauxlib.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lcode.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lctype.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\ldebug.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\ldo.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lfunc.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lgc.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\llex.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\llimits.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lmem.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lobject.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lopcodes.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lparser.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lprefix.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lstate.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lstring.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\ltable.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\ltm.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lua.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lua.hpp" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\luaconf.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lualib.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lundump.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lvm.h" />
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lzio.h" />
    <ClInclude Include="..\..\3rd\mjson\json.h" />
    <ClInclude Include="..\..\3rd\tolua\tolua++.h" />
    <ClInclude Include="..\..\3rd\tolua\tolua_event.h" />
    <ClInclude Include="..\..\3rd\tolua\tolua_fix.h" />
    <ClInclude Include="..\..\database\mysqlwarpper.h" />
    <ClInclude Include="..\..\database\rediswarpper.h" />
    <ClInclude Include="..\..\lua_wrapper\cmd_package_proto_export_to_lua.h" />
    <ClInclude Include="..\..\lua_wrapper\logger_export_to_lua.h" />
    <ClInclude Include="..\..\lua_wrapper\lua_wrapper.h" />
    <ClInclude Include="..\..\lua_wrapper\mysql_export_to_lua.h" />
    <ClInclude Include="..\..\lua_wrapper\netbus_export_to_lua.h" />
    <ClInclude Include="..\..\lua_wrapper\redis_export_to_lua.h" />
    <ClInclude Include="..\..\lua_wrapper\service_export_to_lua.h" />
    <ClInclude Include="..\..\lua_wrapper\session_export_to_lua.h" />
    <ClInclude Include="..\..\lua_wrapper\timer_export_to_lua.h" />
    <ClInclude Include="..\..\lua_wrapper\utils_export_to_lua.h" />
    <ClInclude Include="..\..\netbus\Netbus.h" />
    <ClInclude Include="..\..\netbus\protocol\CmdPackageProtocol.h" />
    <ClInclude Include="..\..\netbus\protocol\TcpPackageProtocol.h" />
    <ClInclude Include="..\..\netbus\protocol\WebSocketProtocol.h" />
    <ClInclude Include="..\..\netbus\service\AbstractService.h" />
    <ClInclude Include="..\..\netbus\service\ServiceManager.h" />
    <ClInclude Include="..\..\netbus\session\AbstractSession.h" />
    <ClInclude Include="..\..\netbus\session\TcpSession.h" />
    <ClInclude Include="..\..\netbus\session\UdpSession.h" />
    <ClInclude Include="..\..\utils\cache_alloc\cache_alloc.h" />
    <ClInclude Include="..\..\utils\cache_alloc\small_alloc.h" />
    <ClInclude Include="..\..\utils\debug\DebugUtil.h" />
    <ClInclude Include="..\..\utils\Encoding.h" />
    <ClInclude Include="..\..\utils\logger\logger.h" />
    <ClInclude Include="..\..\utils\timer\time_list.h" />
    <ClInclude Include="..\..\utils\timestamp\timestamp.h" />
    <ClInclude Include="..\..\utils\win32\WinUtil.h" />
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>16.0</VCProjectVersion>
    <ProjectGuid>{9F1E693F-D772-4D61-9070-08867444F8B1}</ProjectGuid>
    <RootNamespace>MobaServer</RootNamespace>
    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <OutDir>$(SolutionDir)..\bin</OutDir>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>false</SDLCheck>
      <ConformanceMode>true</ConformanceMode>
      <AdditionalIncludeDirectories>$(SolutionDir)..\..\3rd\tolua;$(SolutionDir)..\..\3rd\lua_5.3.5\src;$(SolutionDir)..\..\3rd\hiredis\include;$(SolutionDir)..\..\3rd\mysqlclient\include;$(SolutionDir)..\..\3rd\protobuf;$(SolutionDir)..\..\3rd\libuv\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
      <BrowseInformation>true</BrowseInformation>
      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <AdditionalOptions>ws2_32.lib Iphlpapi.lib Psapi.lib Userenv.lib libprotobufd.lib libprotocd.lib libmysql.lib  HiredisWrapper.lib %(AdditionalOptions)</AdditionalOptions>
      <AdditionalLibraryDirectories>$(SolutionDir)..\..\3rd\hiredis\lib;$(SolutionDir)..\..\3rd\mysqlclient\lib;$(SolutionDir)..\..\3rd\protobuf\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
    </Link>
    <Bscmake>
      <PreserveSbr>true</PreserveSbr>
    </Bscmake>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>


text:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="netbus">
      <UniqueIdentifier>{407b6e8d-8390-4376-9e21-697d156d8196}</UniqueIdentifier>
    </Filter>
    <Filter Include="app">
      <UniqueIdentifier>{63130b8e-6d83-49bb-b157-905e70628d1a}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd">
      <UniqueIdentifier>{9fb92e2d-c425-4dc2-bc66-9224e479a974}</UniqueIdentifier>
    </Filter>
    <Filter Include="utils">
      <UniqueIdentifier>{4fd09449-c90a-4e49-896d-b9a94dc1243b}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd\libuv">
      <UniqueIdentifier>{b9750e03-f633-4fd0-bf07-5d8130602932}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd\libuv\include">
      <UniqueIdentifier>{ec62f255-4b89-4b99-a34f-01783a6a13f4}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd\libuv\src">
      <UniqueIdentifier>{4d20db86-235c-4db4-9b1c-87ef04b9b9aa}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd\libuv\src\win">
      <UniqueIdentifier>{bcbe48da-9d37-4098-a3f6-70a43e102442}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd\http_parser">
      <UniqueIdentifier>{9e48b74e-61e8-4c9d-a88b-7e9879b6d462}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd\crypto">
      <UniqueIdentifier>{ba1c91bf-c8ec-42d4-aa34-4c8363e9ed50}</UniqueIdentifier>
    </Filter>
    <Filter Include="netbus\Protocol">
      <UniqueIdentifier>{a3350088-958e-4814-91c1-ba1204f6b62e}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd\mjson">
      <UniqueIdentifier>{986e44de-c089-4c4b-9ec8-c0f5b2b834d5}</UniqueIdentifier>
    </Filter>
    <Filter Include="netbus\service">
      <UniqueIdentifier>{42ec8334-5a97-463b-80c5-71243a8e7896}</UniqueIdentifier>
    </Filter>
    <Filter Include="utils\timer">
      <UniqueIdentifier>{105d3f67-8dff-461c-a8f4-09b5d97ae4d7}</UniqueIdentifier>
    </Filter>
    <Filter Include="utils\cache_alloc">
      <UniqueIdentifier>{a9781b80-b1b9-4a5c-9737-51fbe6e63f37}</UniqueIdentifier>
    </Filter>
    <Filter Include="utils\timestamp">
      <UniqueIdentifier>{0f541b9d-a711-4337-8f71-5f9e910e41b5}</UniqueIdentifier>
    </Filter>
    <Filter Include="utils\logger">
      <UniqueIdentifier>{c429cebb-28dd-4970-b22b-4223f3a9eea8}</UniqueIdentifier>
    </Filter>
    <Filter Include="netbus\session">
      <UniqueIdentifier>{b81e81bd-a428-4567-9cf1-913feb3622d0}</UniqueIdentifier>
    </Filter>
    <Filter Include="database">
      <UniqueIdentifier>{a73256cf-6c71-410a-a19f-1980e96550b1}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd\lua">
      <UniqueIdentifier>{dcc6d64f-43c1-4072-9331-e59bf30298bb}</UniqueIdentifier>
    </Filter>
    <Filter Include="lua_wrapper">
      <UniqueIdentifier>{0c123d21-7fd7-406f-aefb-f1725cf80ae2}</UniqueIdentifier>
    </Filter>
    <Filter Include="3rd\tolua">
      <UniqueIdentifier>{001931ff-aeb5-4077-8905-855a351aa5c3}</UniqueIdentifier>
    </Filter>
    <Filter Include="app\TestLua">
      <UniqueIdentifier>{eb9c021d-bcd0-49d8-aa4e-bff39342f6e7}</UniqueIdentifier>
    </Filter>
    <Filter Include="utils\win32">
      <UniqueIdentifier>{6f2cf272-8ff5-4d9f-8e79-cfae3e670b67}</UniqueIdentifier>
    </Filter>
    <Filter Include="utils\debug">
      <UniqueIdentifier>{f5003ca1-4aff-489e-a499-76fe584c328c}</UniqueIdentifier>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="..\..\3rd\libuv\src\fs-poll.c">
      <Filter>3rd\libuv\src</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\inet.c">
      <Filter>3rd\libuv\src</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\threadpool.c">
      <Filter>3rd\libuv\src</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\uv-common.c">
      <Filter>3rd\libuv\src</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\version.c">
      <Filter>3rd\libuv\src</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\async.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\core.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\dl.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\error.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\fs.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\fs-event.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\getaddrinfo.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\getnameinfo.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\handle.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\loop-watcher.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\pipe.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\poll.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\process.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\process-stdio.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\req.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\signal.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\snprintf.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\stream.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\tcp.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\thread.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\timer.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\tty.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\udp.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\util.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\winapi.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\libuv\src\win\winsock.c">
      <Filter>3rd\libuv\src\win</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\http_parser\http_parser.c">
      <Filter>3rd\http_parser</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\crypto\base64_decoder.c">
      <Filter>3rd\crypto</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\crypto\base64_encoder.c">
      <Filter>3rd\crypto</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\crypto\md5.c">
      <Filter>3rd\crypto</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\crypto\sha1.c">
      <Filter>3rd\crypto</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\mjson\json.c">
      <Filter>3rd\mjson</Filter>
    </ClCompile>
    <ClCompile Include="..\..\netbus\protocol\TcpPackageProtocol.cpp">
      <Filter>netbus\Protocol</Filter>
    </ClCompile>
    <ClCompile Include="..\..\netbus\protocol\WebSocketProtocol.cpp">
      <Filter>netbus\Protocol</Filter>
    </ClCompile>
    <ClCompile Include="..\..\netbus\protocol\CmdPackageProtocol.cpp">
      <Filter>netbus\Protocol</Filter>
    </ClCompile>
    <ClCompile Include="..\..\netbus\service\AbstractService.cpp">
      <Filter>netbus\service</Filter>
    </ClCompile>
    <ClCompile Include="..\..\netbus\service\ServiceManager.cpp">
      <Filter>netbus\service</Filter>
    </ClCompile>
    <ClCompile Include="..\..\utils\timer\time_list.c">
      <Filter>utils\timer</Filter>
    </ClCompile>
    <ClCompile Include="..\..\utils\logger\logger.cc">
      <Filter>utils\logger</Filter>
    </ClCompile>
    <ClCompile Include="..\..\utils\timestamp\timestamp.c">
      <Filter>utils\timestamp</Filter>
    </ClCompile>
    <ClCompile Include="..\..\netbus\Netbus.cpp">
      <Filter>netbus</Filter>
    </ClCompile>
    <ClCompile Include="..\..\netbus\session\AbstractSession.cpp">
      <Filter>netbus\session</Filter>
    </ClCompile>
    <ClCompile Include="..\..\netbus\session\TcpSession.cpp">
      <Filter>netbus\session</Filter>
    </ClCompile>
    <ClCompile Include="..\..\netbus\session\UdpSession.cpp">
      <Filter>netbus\session</Filter>
    </ClCompile>
    <ClCompile Include="..\..\database\mysqlwarpper.cpp">
      <Filter>database</Filter>
    </ClCompile>
    <ClCompile Include="..\..\database\rediswarpper.cpp">
      <Filter>database</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lapi.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lauxlib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lbaselib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lbitlib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lcode.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lcorolib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lctype.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ldblib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ldebug.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ldo.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ldump.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lfunc.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lgc.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\linit.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\liolib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\llex.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lmathlib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lmem.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\loadlib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lobject.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lopcodes.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\loslib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lparser.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lstate.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lstring.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lstrlib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ltable.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ltablib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\ltm.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lundump.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lutf8lib.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lvm.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\lua_5.3.5\src\lzio.c">
      <Filter>3rd\lua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\lua_wrapper.cpp">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\tolua\tolua_event.c">
      <Filter>3rd\tolua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\tolua\tolua_fix.cc">
      <Filter>3rd\tolua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\tolua\tolua_is.c">
      <Filter>3rd\tolua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\tolua\tolua_map.c">
      <Filter>3rd\tolua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\tolua\tolua_push.c">
      <Filter>3rd\tolua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\3rd\tolua\tolua_to.c">
      <Filter>3rd\tolua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\mysql_export_to_lua.cc">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\redis_export_to_lua.cc">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\service_export_to_lua.cpp">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\session_export_to_lua.cpp">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\logger_export_to_lua.cpp">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\timer_export_to_lua.cpp">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\netbus_export_to_lua.cpp">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\cmd_package_proto_export_to_lua.cpp">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\apps\lua_test\TestLua.cpp">
      <Filter>app\TestLua</Filter>
    </ClCompile>
    <ClCompile Include="..\..\utils\win32\WinUtil.cpp">
      <Filter>utils\win32</Filter>
    </ClCompile>
    <ClCompile Include="..\..\utils\Encoding.cpp">
      <Filter>utils</Filter>
    </ClCompile>
    <ClCompile Include="..\..\utils\cache_alloc\cache_alloc.cpp">
      <Filter>utils\cache_alloc</Filter>
    </ClCompile>
    <ClCompile Include="..\..\utils\cache_alloc\small_alloc.cpp">
      <Filter>utils\cache_alloc</Filter>
    </ClCompile>
    <ClCompile Include="..\..\lua_wrapper\utils_export_to_lua.cpp">
      <Filter>lua_wrapper</Filter>
    </ClCompile>
    <ClCompile Include="..\..\utils\debug\DebugUtil.cpp">
      <Filter>utils\debug</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="..\..\3rd\libuv\include\android-ifaddrs.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\pthread-barrier.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\stdint-msvc2008.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\tree.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-aix.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-bsd.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-darwin.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-errno.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-linux.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-sunos.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-threadpool.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-unix.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-version.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\include\uv-win.h">
      <Filter>3rd\libuv\include</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\heap-inl.h">
      <Filter>3rd\libuv\src</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\queue.h">
      <Filter>3rd\libuv\src</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\uv-common.h">
      <Filter>3rd\libuv\src</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\win\atomicops-inl.h">
      <Filter>3rd\libuv\src\win</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\win\handle-inl.h">
      <Filter>3rd\libuv\src\win</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\win\internal.h">
      <Filter>3rd\libuv\src\win</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\win\req-inl.h">
      <Filter>3rd\libuv\src\win</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\win\stream-inl.h">
      <Filter>3rd\libuv\src\win</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\win\winapi.h">
      <Filter>3rd\libuv\src\win</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\libuv\src\win\winsock.h">
      <Filter>3rd\libuv\src\win</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\http_parser\http_parser.h">
      <Filter>3rd\http_parser</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\crypto\base64_decoder.h">
      <Filter>3rd\crypto</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\crypto\base64_encoder.h">
      <Filter>3rd\crypto</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\crypto\md5.h">
      <Filter>3rd\crypto</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\crypto\sha1.h">
      <Filter>3rd\crypto</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\mjson\json.h">
      <Filter>3rd\mjson</Filter>
    </ClInclude>
    <ClInclude Include="..\..\netbus\protocol\TcpPackageProtocol.h">
      <Filter>netbus\Protocol</Filter>
    </ClInclude>
    <ClInclude Include="..\..\netbus\protocol\WebSocketProtocol.h">
      <Filter>netbus\Protocol</Filter>
    </ClInclude>
    <ClInclude Include="..\..\netbus\protocol\CmdPackageProtocol.h">
      <Filter>netbus\Protocol</Filter>
    </ClInclude>
    <ClInclude Include="..\..\netbus\service\AbstractService.h">
      <Filter>netbus\service</Filter>
    </ClInclude>
    <ClInclude Include="..\..\netbus\service\ServiceManager.h">
      <Filter>netbus\service</Filter>
    </ClInclude>
    <ClInclude Include="..\..\utils\timer\time_list.h">
      <Filter>utils\timer</Filter>
    </ClInclude>
    <ClInclude Include="..\..\utils\logger\logger.h">
      <Filter>utils\logger</Filter>
    </ClInclude>
    <ClInclude Include="..\..\utils\timestamp\timestamp.h">
      <Filter>utils\timestamp</Filter>
    </ClInclude>
    <ClInclude Include="..\..\netbus\Netbus.h">
      <Filter>netbus</Filter>
    </ClInclude>
    <ClInclude Include="..\..\netbus\session\AbstractSession.h">
      <Filter>netbus\session</Filter>
    </ClInclude>
    <ClInclude Include="..\..\netbus\session\TcpSession.h">
      <Filter>netbus\session</Filter>
    </ClInclude>
    <ClInclude Include="..\..\netbus\session\UdpSession.h">
      <Filter>netbus\session</Filter>
    </ClInclude>
    <ClInclude Include="..\..\database\mysqlwarpper.h">
      <Filter>database</Filter>
    </ClInclude>
    <ClInclude Include="..\..\database\rediswarpper.h">
      <Filter>database</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lapi.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lauxlib.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lcode.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lctype.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\ldebug.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\ldo.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lfunc.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lgc.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\llex.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\llimits.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lmem.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lobject.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lopcodes.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lparser.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lprefix.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lstate.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lstring.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\ltable.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\ltm.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lua.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lua.hpp">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\luaconf.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lualib.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lundump.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lvm.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\lua_5.3.5\src\lzio.h">
      <Filter>3rd\lua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\lua_wrapper.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\tolua\tolua_event.h">
      <Filter>3rd\tolua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\tolua\tolua_fix.h">
      <Filter>3rd\tolua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\3rd\tolua\tolua++.h">
      <Filter>3rd\tolua</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\mysql_export_to_lua.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\redis_export_to_lua.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\service_export_to_lua.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\session_export_to_lua.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\logger_export_to_lua.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\timer_export_to_lua.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\netbus_export_to_lua.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\cmd_package_proto_export_to_lua.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\utils\win32\WinUtil.h">
      <Filter>utils\win32</Filter>
    </ClInclude>
    <ClInclude Include="..\..\utils\Encoding.h">
      <Filter>utils</Filter>
    </ClInclude>
    <ClInclude Include="..\..\utils\cache_alloc\cache_alloc.h">
      <Filter>utils\cache_alloc</Filter>
    </ClInclude>
    <ClInclude Include="..\..\utils\cache_alloc\small_alloc.h">
      <Filter>utils\cache_alloc</Filter>
    </ClInclude>
    <ClInclude Include="..\..\lua_wrapper\utils_export_to_lua.h">
      <Filter>lua_wrapper</Filter>
    </ClInclude>
    <ClInclude Include="..\..\utils\debug\DebugUtil.h">
      <Filter>utils\debug</Filter>
    </ClInclude>
  </ItemGroup>
</Project>

mime_type: text/plain


text:
#ifndef __SERVICEMANAGER_H__
#define __SERVICEMANAGER_H__
#endif // !__SERVICEMANAGER_H__

class ServiceManager
{
public:
	static void Init();
	//注册服务
	static bool RegisterService(int serviceType, AbstractService* service);
	//Netbus收到包的回调，返回true表示正常处理了，否则要关闭socket
	static bool OnRecvCmdPackage(const AbstractSession* session, const CmdPackage* package);
	//客户端断开的回调
	static void OnSessionDisconnected(const AbstractSession* session);
};


text:
#ifndef __NETBUS_H__
#define __NETBUS_H__
#include <uv.h>
#include <string>
using std::string;

#include "protocol/CmdPackageProtocol.h"

class AbstractSession;
typedef void (*TcpConnectedCallback)(int, AbstractSession*, void*);
typedef void (*TcpListenCallback)(AbstractSession*, void*);

class Netbus
{
private:
	void* udpHandle;
public:
	//µ¥Àý
	static Netbus* Instance();
public:

	Netbus();

	void TcpListen(int port, TcpListenCallback callback=0,void* udata=0)const;
	void WebSocketListen(int port, TcpListenCallback callback = 0, void* udata = 0)const;
	void UdpListen(int port);
	void Run()const;
	void Init()const;

	void TcpConnect(const char* serverIp,
		int port,
		TcpConnectedCallback callback=0,
		void* udata=0)const;

	void UdpSendTo(char* ip, int port, unsigned char* body, int len);
};

#endif // !__NETBUS_H__


text:
#include "Netbus.h"
#include <uv.h>
#include "../../netbus/protocol/WebSocketProtocol.h"
#include "../../netbus/protocol/TcpPackageProtocol.h"
#include "../../netbus/session/TcpSession.h"

#include "service/ServiceManager.h"

#include "../utils/logger/logger.h"
#include "session/UdpSession.h"

#include "../utils/cache_alloc/small_alloc.h"

#define my_alloc small_alloc
#define my_free small_free

#pragma region 函数声明

void OnRecvCommond(AbstractSession* session, unsigned char* body, const int len);

void OnWebSocketRecvData(TcpSession* session);

void OnTcpRecvData(TcpSession* session);

#pragma endregion

struct UdpRecvBuf
{
	char* data;
	int maxRecvLen;
};

struct TcpConnectInfo
{
	TcpConnectedCallback cb;
	void* data;
};

struct TcpListenInfo
{
	TcpListenCallback cb;
	SocketType socketType;
	void* data;
};

#pragma region 回调函数

extern "C"
{
#pragma region Tcp_&_Websocket

	//Tcp申请字符串空间
	static void tcp_str_alloc(uv_handle_t* handle,
		size_t suggested_size,
		uv_buf_t* buf) {

		auto session = (TcpSession*)handle->data;

		if (session->recved < RECV_LEN)
		{
			//session的长度为 RECV_LEN 的recvBuf还没有存满
			*buf = uv_buf_init(session->recvBuf + session->recved, RECV_LEN - session->recved);
		}
		else
		{// recvBuf读满了，但是还没有读完

			if (session->long_pkg == NULL)
			{// 如果还没有new空间
				int pkgSize;
				int headSize;
				switch (session->socketType)
				{
				case SocketType::TcpSocket:
					TcpProtocol::ReadHeader((unsigned char*)session->recvBuf, session->recved, &pkgSize, &headSize);
					break;
				case SocketType::WebSocket:
					WebSocketProtocol::ReadHeader((unsigned char*)session->recvBuf, session->recved, &pkgSize, &headSize);
					break;
				}
				session->long_pkg_size = pkgSize;
				session->long_pkg = (char*)malloc(pkgSize);

				memcpy(session->long_pkg, session->recvBuf, session->recved);
			}

			*buf = uv_buf_init(session->long_pkg + session->recved, session->long_pkg_size - session->recved);
		}

	}

	//读取结束后的回调
	static void tcp_after_read(uv_stream_t* stream,
		ssize_t nread,
		const uv_buf_t* buf) {

		auto session = (TcpSession*)stream->data;

		//连接断开
		if (nread < 0) {
			session->Close();
			return;
		}

		session->recved += nread;

		switch (session->socketType)
		{
		case SocketType::TcpSocket:
			OnTcpRecvData(session);
			break;
		case SocketType::WebSocket:
			#pragma region WebSocket协议
			if (session->isWebSocketShakeHand == 0)
			{	//	shakeHand
				if (WebSocketProtocol::ShakeHand(session, session->recvBuf, session->recved))
				{	//握手成功
					log_debug("握手成功");
					session->isWebSocketShakeHand = 1;
					session->recved = 0;
				}
			}
			else//	recv/send Data
			{
				OnWebSocketRecvData(session);
			}
			#pragma endregion
			break;

		default:
			break;
		}
	}

	//TCP有用户链接进来
	static void TcpOnConnect(uv_stream_t* server, int status)
	{
		auto info = (TcpListenInfo*)server->data;
		auto session = TcpSession::Create();

		//初始化session的信息――socket类型，ip，端口，并加入libuv事件循环
		session->Init(info->socketType);

		//客户端接入服务器
		uv_accept(server, (uv_stream_t*)&session->tcpHandle);

		//回调
		if(info->cb)
			info->cb(session, info->data);

		//Session连接成功的回调
		ServiceManager::OnSessionConnect(session);

		//开始监听消息
		uv_read_start((uv_stream_t*)&session->tcpHandle, tcp_str_alloc, tcp_after_read);

	}

#pragma endregion

#pragma region Udp

	//Udp申请字符串空间
	static void udp_str_alloc(uv_handle_t* handle,
		size_t suggested_size,
		uv_buf_t* buf)
	{
		suggested_size = (suggested_size < 4096) ? 4096 : suggested_size;

		auto pBuf = (UdpRecvBuf*)handle->data;
		if (pBuf->maxRecvLen < suggested_size)
		{// 表明当前空间不够
			if (pBuf->data)
			{
				free(pBuf->data);
				pBuf->data = NULL;
			}
			pBuf->data = (char*)malloc(suggested_size);
			pBuf->maxRecvLen = suggested_size;

		}

		buf->base = pBuf->data;
		buf->len = suggested_size;
	}

	//Udp接收字符串完成
	static void udp_after_recv(uv_udp_t* handle,
		ssize_t nread,
		const uv_buf_t* buf,
		const struct sockaddr* addr,
		unsigned flags)
	{
		if (nread <= 0)
			return;
		UdpSession us;

		us.Init(handle, addr);

		OnRecvCommond(&us, (unsigned char*)buf->base, nread);
	}

#pragma endregion

	void AfterUdpSend(uv_udp_send_t* req, int status)
	{
		if (status)
		{
			log_error("udp发送失败");
		}
		my_free(req);
	}
}

#pragma endregion

static void OnRecvCommond(AbstractSession* session, unsigned char* body, const int bodyLen)
{
	RawPackage raw;
	if (CmdPackageProtocol::DecodeBytesToRawPackage(body, bodyLen, &raw))
	{
		//调用服务管理器处理各种命令
		if (!ServiceManager::OnRecvRawPackage(session, &raw))
		{
			session->Close();
		}
	}
	else
	{
		int port;
		auto ip = session->GetAddress(port);
		log_error("[%s:%d]发来的包解码失败",ip,port);
	}
}

#pragma region WebSocketProtocol

static void OnWebSocketRecvData(TcpSession* session)
{
	auto pkgData = (unsigned char*)(session->long_pkg != NULL ? session->long_pkg : session->recvBuf);

	while (session->recved > 0)
	{
		//是否是关闭包
		if (pkgData[0] == 0x88) {
			log_debug("收到关闭包");
			session->Close();
			return;
		}

		int pkgSize;
		int headSize;
		if (!WebSocketProtocol::ReadHeader(pkgData, session->recved, &pkgSize, &headSize))
		{// 读取包头失败
			log_debug("读取包头失败");
			break;
		}

		if (session->recved < pkgSize)
		{// 没有收完数据
			log_debug("没有收完数据");
			break;
		}

		//掩码位置紧随头部数据之后
		//body位置在掩码之后
		unsigned char* body = pkgData + headSize;
		unsigned char* mask = body - 4;

		//解析收到的纯数据
		WebSocketProtocol::ParserRecvData(body, mask, pkgSize - headSize);

		//处理收到的完整数据包
		OnRecvCommond(session, body, pkgSize);

		if (session->recved > pkgSize)
		{
			memmove(pkgData, pkgData + pkgSize, session->recved - pkgSize);
		}

		//每次减去读取到的长度
		session->recved -= pkgSize;

		//如果长包处理完了
		if (session->recved == 0 && session->long_pkg != NULL)
		{
			free(session->long_pkg);
			session->long_pkg = NULL;
			session->long_pkg_size = 0;
		}
	}
}

#pragma endregion

#pragma region TcpProtocol

static void OnTcpRecvData(TcpSession* session)
{
	auto tcpPkgData = (unsigned char*)(session->long_pkg != NULL ? session->long_pkg : session->recvBuf);

	while (session->recved > 0)
	{
		int tcpPkgSize;
		int tcpHeadSize;
		if (!TcpProtocol::ReadHeader(tcpPkgData, session->recved, &tcpPkgSize, &tcpHeadSize))
		{// 读取包头失败
			int port;
			auto ip = session->GetAddress(port);
			log_error("TCP读取包头失败,包体来自：[%s:%d]",ip,port);
			break;
		}

		if (tcpPkgSize < tcpHeadSize) {
			session->Close();
			int port;
			auto ip = session->GetAddress(port);
			log_warning("收到[%s:%d]发来的非法包【包体大小小于包头】，session已关闭",ip,port);
			break;
		}

		if (session->recved < tcpPkgSize)
		{// 没有收完数据
			log_debug("没有收完数据");
			break;
		}

		//body位置在掩码之后
		unsigned char* body = tcpPkgData + tcpHeadSize;

		//处理收到的完整数据包
		OnRecvCommond(session, body, tcpPkgSize - tcpHeadSize);

		if (session->recved > tcpPkgSize)
		{
			memmove(tcpPkgData, tcpPkgData + tcpPkgSize, session->recved - tcpPkgSize);
		}

		//每次减去读取到的长度
		session->recved -= tcpPkgSize;

		//如果长包处理完了
		if (session->recved == 0 && session->long_pkg != NULL)
		{
			free(session->long_pkg);
			session->long_pkg = NULL;
			session->long_pkg_size = 0;
		}
	}
}

#pragma endregion

static void after_connect(uv_connect_t* handle, int status)
{
	auto session = (AbstractSession*)handle->handle->data;
	auto info = (TcpConnectInfo*)handle->data;

	//如果有异常情况
	if (status)
	{
		if (info)
		{
			if(info->cb)
				info->cb(1, NULL, info->data);
			my_free(info);
			info = NULL;
		}
		if(session)
			session->Close();
		my_free(handle);
		return;
	}

	//如果一切正常
	if (info)
	{
		if (info->cb)
		{
			info->cb(0, session, info->data);
		}
		my_free(info);
		info = NULL;
	}
	uv_read_start(handle->handle, tcp_str_alloc, tcp_after_read);
	my_free(handle);
}

static Netbus g_instance;
Netbus* Netbus::Instance()
{
	return &g_instance;
}

Netbus::Netbus()
{
	this->udpHandle = NULL;
}

void Netbus::TcpListen(int port, TcpListenCallback callback, void* udata)const
{
	auto listen = (uv_tcp_t*)malloc(sizeof(uv_tcp_t));

	memset(listen, 0, sizeof(uv_tcp_t));

	sockaddr_in addr;
	auto ret = uv_ip4_addr("0.0.0.0", port, &addr);
	if (ret)
	{
		log_error("uv_ip4_addr error：%d", port);
		free(listen);
		listen = NULL;
		return;

	}

	uv_tcp_init(uv_default_loop(), listen);
	ret = uv_tcp_bind(listen, (const sockaddr*)&addr, 0);
	if (ret)
	{
		log_error("Tcp 端口绑定失败：%d",port);
		free(listen);
		listen = NULL;
		return;
	}

	auto pInfo = new TcpListenInfo();
	pInfo->cb = callback;
	pInfo->data = udata;
	pInfo->socketType = SocketType::TcpSocket;

	//强转记录TcpListenInfo类型
	listen->data = (void*)pInfo;

	uv_listen((uv_stream_t*)listen, SOMAXCONN, TcpOnConnect);
}

void Netbus::WebSocketListen(int port, TcpListenCallback callback, void* udata)const
{
	auto listen = (uv_tcp_t*)malloc(sizeof(uv_tcp_t));

	memset(listen, 0, sizeof(uv_tcp_t));

	sockaddr_in addr;
	auto ret = uv_ip4_addr("0.0.0.0", port, &addr);
	if (ret)
	{
		log_error("uv_ip4_addr error：%d", port);
		free(listen);
		listen = NULL;
		return;

	}

	uv_tcp_init(uv_default_loop(), listen);
	ret = uv_tcp_bind(listen, (const sockaddr*)&addr, 0);
	if (0 != ret)
	{
		log_error("WebSocket 端口绑定失败：%d",port);
		free(listen);
		listen = NULL;
		return;
	}

	auto pInfo = new TcpListenInfo();
	pInfo->cb = callback;
	pInfo->data = udata;
	pInfo->socketType = SocketType::WebSocket;

	//强转记录TcpListenInfo类型
	listen->data = (void*)pInfo;

	uv_listen((uv_stream_t*)listen, SOMAXCONN, TcpOnConnect);
}

void Netbus::UdpListen(int port)
{
	if (this->udpHandle)
	{
		log_warning("暂时不支持同时监听多个udp");
		return;
	}

	sockaddr_in addr;
	auto ret = uv_ip4_addr("0.0.0.0", port, &addr);
	if (ret)
	{
		log_error("uv_ip4_addr error：%d", port);
		return;
	}
	auto server = (uv_udp_t*)malloc(sizeof(uv_udp_t));
	memset(server, 0, sizeof(uv_udp_t));

	uv_udp_init(uv_default_loop(), server);

	server->data = malloc(sizeof(UdpRecvBuf));
	memset(server->data, 0, sizeof(UdpRecvBuf));
	ret = uv_udp_bind(server, (const sockaddr*)&addr, 0);

	if (ret)
	{
		log_error("Udp 绑定失败");
		if (server)
		{
			if (server->data)
				free(server->data);
			free(server);
			server = NULL;
			return;
		}
	}

	this->udpHandle = server;

	uv_udp_recv_start(server, udp_str_alloc, udp_after_recv);
}

void Netbus::Run()const
{
	uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}

void Netbus::Init() const
{
	ServiceManager::Init();
	InitAllocers();
}

void Netbus::TcpConnect(const char* serverIp, int port, TcpConnectedCallback callback, void* udata)const
{
	sockaddr_in addr;
	auto ret = uv_ip4_addr(serverIp, port, &addr);
	if (ret)
	{
		log_error("uv_ip4_addr error：%s:%d", serverIp,port);
		return;

	}

	//创建Session并初始化相关值――socketType,ip,port,isCliet，并加入libuv事件循环
	auto s = TcpSession::Create();
	s->Init(SocketType::TcpSocket, serverIp, port, true);

	auto req = (uv_connect_t*)my_alloc(sizeof(uv_connect_t));
	memset(req, 0, sizeof(uv_connect_t));

	auto info = (TcpConnectInfo*)my_alloc(sizeof(TcpConnectInfo));
	memset(info, 0, sizeof(TcpConnectInfo));

	info->cb = callback;
	info->data = udata;
	req->data = info;

	ret = uv_tcp_connect(req, &s->tcpHandle, (struct sockaddr*) & addr, after_connect);
}

void Netbus::UdpSendTo(char* ip, int port, unsigned char* body, int len)
{
	auto wbuf = uv_buf_init((char*)body, len);
	auto req = (uv_udp_send_t*)my_alloc(sizeof(uv_udp_send_t));

	SOCKADDR_IN addr;
	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.S_un.S_addr = inet_addr(ip);

	uv_udp_send(req, (uv_udp_t*)this->udpHandle, &wbuf, 1,(const SOCKADDR*) &addr, AfterUdpSend);
}


text:
#include "AbstractSession.h"

AbstractSession::AbstractSession()
{
	this->isClient = false;
	this->utag = 0;
	this->uid = 0;
}

void AbstractSession::Enable()
{
}

void AbstractSession::Disable()
{
}


text:
#ifndef __UDPSESSION_H__
#define __UDPSESSION_H__

#include "AbstractSession.h"

class UdpSession :
	public AbstractSession
{
private:
	uv_udp_t* udp_handler;
	const sockaddr* addr;

public:
	char clientAddress[64];
	int clientPort;

	void Init(uv_udp_t* udpHandle,const sockaddr* addr);

	virtual void Close() override;
	//发送数据
	virtual void SendData(unsigned char* body, int len) override;
	//获取IP地址和端口
	virtual const char* GetAddress(int& clientPort) const override;
	//发送自定义包
	virtual void SendCmdPackage(CmdPackage* msg)override;

	// 通过 AbstractSession 继承
	virtual void SendRawPackage(RawPackage* pkg) override;
};

#endif // !__UDPSESSION_H__


text:
#ifndef __ABSTRACTSESSION_H__
#define __ABSTRACTSESSION_H__
struct CmdPackage;
struct RawPackage;
class AbstractSession
{
public:
	bool isClient;
	unsigned int utag;
	unsigned int uid;

	AbstractSession();

	virtual void Close() = 0;
	virtual void SendData(unsigned char* body,int len) = 0;
	virtual const char* GetAddress(int & clientPort)const = 0;
	virtual void SendCmdPackage(CmdPackage* msg) = 0;
	virtual void SendRawPackage(RawPackage* pkg) = 0;

	virtual void Enable();
	virtual void Disable();

	virtual ~AbstractSession() {}
};

#endif // !__ABSTRACTSESSION_H__


text:
#ifndef __UVSESSION_H__
#define __UVSESSION_H__

#include "AbstractSession.h"
#define RECV_LEN 4096

//Socket类型
enum class SocketType
{
	TcpSocket,
	WebSocket
};

class TcpSession :
	public AbstractSession
{
public:
	static TcpSession* Create();
	static void Destory(TcpSession*& session);

	#pragma region AbstractSession

	virtual void Close() override;
	//发送数据
	virtual void SendData(unsigned char* body, int len) override;
	//获取IP地址和端口
	virtual const char* GetAddress(int & clientPort) const override;
	//发送自定义包
	virtual void SendCmdPackage(CmdPackage* msg)override;

	// 通过 AbstractSession 继承
	virtual void SendRawPackage(RawPackage* pkg) override;

	//用于对象池
	virtual void Enable()override;
	virtual void Disable()override;
	#pragma endregion

	void Init(SocketType socketType);
	void Init(SocketType socketType, const char* ip, int port, bool isClient);

	void* operator new(size_t size);
	void operator delete(void* mem);

public:
	uv_shutdown_t shutdown;
	uv_tcp_t tcpHandle;
	//记录当前会话对象的IP和端口
	char clientAddress[32];
	int clientPort;

	//控制结束数据
	char recvBuf[RECV_LEN];
	int recved;

	SocketType socketType;

	//WebSocket情况下是否已经握手
	int isWebSocketShakeHand;

	// 如果包体大小超过 RECV_LEN 包数据就保存在这里，而不是recvData
	char* long_pkg;
	int long_pkg_size;
private:
	//是否已经关闭，用于在异步时避免重复关闭
	bool isShutDown;

};

void InitAllocers();

#endif // !__UVSESSION_H__


text:
#include <uv.h>
#include "UdpSession.h"
#include "../protocol/CmdPackageProtocol.h"
#include "../../utils/logger/logger.h"
#include "../../utils/cache_alloc/small_alloc.h"

#define my_alloc small_alloc
#define my_free small_free

void AfterUdpSend(uv_udp_send_t* req, int status)
{
	if (status)
	{
		log_debug("udp 发送失败");
	}
	my_free(req);
}

void UdpSession::Init(uv_udp_t* udpHandle,const sockaddr* addr)
{
	this->udp_handler = udpHandle;
	this->addr = addr;
	uv_ip4_name((struct sockaddr_in*)addr, this->clientAddress, sizeof(this->clientAddress));
	this->clientPort = ntohs(((struct sockaddr_in*)addr)->sin_port);

}

void UdpSession::Close()
{
}

void UdpSession::SendData(unsigned char* body, int len)
{
	auto wbuf = uv_buf_init((char*)body, len);
	auto req = (uv_udp_send_t*)my_alloc(sizeof(uv_udp_send_t));
	uv_udp_send(req, this->udp_handler, &wbuf, 1, this->addr, AfterUdpSend);
}

const char* UdpSession::GetAddress(int& clientPort) const
{
	clientPort = this->clientPort;
	return this->clientAddress;
}

void UdpSession::SendCmdPackage(CmdPackage* msg)
{
	int bodyLen;
	auto rawData = CmdPackageProtocol::EncodeCmdPackageToBytes(msg, &bodyLen);
	if (rawData)
	{// 编码成功

		//发送数据
		SendData(rawData, bodyLen);

		//释放数据
		CmdPackageProtocol::FreeCmdPackageBytes(rawData);
	}
	else
	{
		log_debug("编码失败");
	}
}

void UdpSession::SendRawPackage(RawPackage* pkg)
{
	this->SendData(pkg->body, pkg->rawLen);
}


text:
#include <uv.h>
#include "../../netbus/protocol/WebSocketProtocol.h"
#include "../../netbus/protocol/TcpPackageProtocol.h"
#include "../protocol/CmdPackageProtocol.h"
#include "../service/ServiceManager.h"
#include "../../utils/logger/logger.h"
#include "../../utils/cache_alloc/cache_alloc.h"
#include "TcpSession.h"

#pragma region 内存管理

#define SESSION_CACHE_CAPCITY 3000
#define	WRITEREQ_CACHE_CAPCITY 2048
#define WRITEBUF_CACHE_CAPCITY 1024
#define CMD_CACHE_SIZE 1024

//初始化内存分配器
static cache_allocer* sessionAllocer = NULL;
static cache_allocer* wrAllocer = NULL;
cache_allocer* writeBufAllocer = NULL;

void InitAllocers()
{
	if (NULL == sessionAllocer)
	{
		sessionAllocer = create_cache_allocer(SESSION_CACHE_CAPCITY, sizeof(TcpSession));
	}
	if (NULL == wrAllocer)
	{
		wrAllocer = create_cache_allocer(WRITEREQ_CACHE_CAPCITY, sizeof(uv_write_t));
	}
	if (NULL == writeBufAllocer)
	{
		writeBufAllocer = create_cache_allocer(WRITEBUF_CACHE_CAPCITY, CMD_CACHE_SIZE);
	}
}

#pragma endregion

#pragma region 回调函数
extern "C"
{

	static void ws_after_write(uv_write_t* req, int status)
	{
		//如果写请求成功
		if (status != 0)
		{
			log_error("websocket write failed");
		}
		WebSocketProtocol::ReleasePackage((unsigned char*)req->write_buffer.base);
		cache_free(wrAllocer, req);
	}
	//关闭链接回调
	static void close_cb(uv_handle_t* handle) {
		//log_debug("用户断开链接");

		auto session = (TcpSession*)handle->data;
		TcpSession::Destory(session);
	}

	//断开链接的回调
	static void shutdown_cb(uv_shutdown_t* req, int status) {
		if (status != 0)
		{
			log_error("tcp shutdown failed");
		}
		uv_close((uv_handle_t*)(req->handle), close_cb);
	}

	//完成写请求的回调
	static void tcp_after_write(uv_write_t* req, int status)
	{
		//如果写请求成功
		if (status != 0)
		{
			log_error("tcp write failed");
		}
		TcpProtocol::ReleasePackage((unsigned char*)req->write_buffer.base);
		cache_free(wrAllocer, req);
	}
}
#pragma endregion

#pragma region Static

TcpSession* TcpSession::Create()
{
	auto temp = new TcpSession();
	temp->Enable();
	return temp;
}

void TcpSession::Destory(TcpSession*& session)
{
	session->Disable();
	delete session;
	session = NULL;
}

#pragma endregion

void TcpSession::Init(SocketType socketType)
{
	this->socketType = socketType;

	#pragma region 获取接入者IP和端口

	sockaddr_in addr;
	int len = sizeof(addr);
	uv_tcp_getpeername(&this->tcpHandle, (sockaddr*)&addr, &len);
	uv_ip4_name(&addr, this->clientAddress, sizeof(this->clientAddress));
	this->clientPort = ntohs(addr.sin_port);

	#pragma endregion

	//加入事件循环
	uv_tcp_init(uv_default_loop(), &this->tcpHandle);
}
void TcpSession::Init(SocketType socketType, const char* ip, int port, bool isClient)
{
	this->isClient = isClient;
	this->socketType = socketType;
	strcpy(this->clientAddress, ip);
	this->clientPort = port;

	//加入事件循环
	uv_tcp_init(uv_default_loop(), &this->tcpHandle);
}
void* TcpSession::operator new(size_t size)
{
	return cache_alloc(sessionAllocer, sizeof(TcpSession));
}

void TcpSession::operator delete(void* mem)
{
	cache_free(sessionAllocer, mem);
}

#pragma region Implement

void TcpSession::Close()
{
	if (this->isShutDown) {
		return;
	}

	//通知所有父物有链接断开
	ServiceManager::OnSessionDisconnected(this);

	this->isShutDown = true;
	memset(&this->shutdown, 0, sizeof(uv_shutdown_t));
	auto ret = uv_shutdown(&this->shutdown, (uv_stream_t*)&this->tcpHandle, shutdown_cb);

	if (ret)
	{
		uv_close((uv_handle_t*)&this->tcpHandle, close_cb);
	}
}

void TcpSession::SendData(unsigned char* body, int len)
{
	//测试发送给我们的客户端
	auto w_req = (uv_write_t*)cache_alloc(wrAllocer, sizeof(uv_write_t));
	uv_buf_t w_buf;
	switch (this->socketType)
	{

	#pragma region WebSocket协议
	case SocketType::WebSocket:
		if (this->isWebSocketShakeHand)
		{// 握过手
			int pkgSize;
			auto wsPkg = WebSocketProtocol::Package(body, len, &pkgSize);
			w_buf = uv_buf_init((char*)wsPkg, pkgSize);
			w_req->write_buffer.base = (char*)wsPkg;
			w_req->write_buffer.len = pkgSize;
			uv_write(w_req, (uv_stream_t*)&this->tcpHandle, &w_buf, 1, ws_after_write);
		}
		else
		{// 没有握过手
			static char respones[512];
			memcpy(respones, body, len);
			w_buf = uv_buf_init((char*)respones, len);
			uv_write(w_req, (uv_stream_t*)&this->tcpHandle, &w_buf, 1, NULL);
		}
		break;
	#pragma endregion

	#pragma region Tcp协议
	case SocketType::TcpSocket:
		int pkgSize;
		auto tcpPkg = TcpProtocol::Package(body, len, &pkgSize);
		w_buf = uv_buf_init((char*)tcpPkg, pkgSize);
		w_req->write_buffer.base = (char*)tcpPkg;
		w_req->write_buffer.len = pkgSize;
		uv_write(w_req, (uv_stream_t*)&this->tcpHandle, &w_buf, 1, tcp_after_write);
		break;
	#pragma endregion

	}
}

const char* TcpSession::GetAddress(int& clientPort) const
{
	clientPort = this->clientPort;
	return this->clientAddress;
}

void TcpSession::SendCmdPackage(CmdPackage* msg)
{
	int bodyLen;
	auto rawData = CmdPackageProtocol::EncodeCmdPackageToBytes(msg, &bodyLen);
	if (rawData)
	{// 编码成功

		//发送数据
		SendData(rawData, bodyLen);

		//释放数据
		CmdPackageProtocol::FreeCmdPackageBytes(rawData);
	}
	else
	{
		log_debug("编码失败");
	}
}

#pragma endregion

#pragma region Override

void TcpSession::Enable()
{
	AbstractSession::Enable();
	isShutDown = false;
	memset(&this->shutdown, 0, sizeof(this->shutdown));
	memset(&this->tcpHandle, 0, sizeof(this->tcpHandle));
	memset(this->clientAddress, 0, sizeof(this->clientAddress));
	this->clientPort = 0;
	this->recved = 0;
	this->isWebSocketShakeHand = 0;
	this->long_pkg = NULL;
	this->long_pkg_size = 0;

	this->tcpHandle.data = this;
}

void TcpSession::Disable()
{
	AbstractSession::Disable();
}

void TcpSession::SendRawPackage(RawPackage* pkg)
{
	this->SendData(pkg->body, pkg->rawLen);
}

#pragma endregion


text:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "WebSocketProtocol.h"
#include "../../3rd/crypto/base64_encoder.h"
#include "../../3rd/http_parser/http_parser.h"
#include "../../3rd/crypto/sha1.h"

#include "../../utils/cache_alloc/cache_alloc.h"
#include "../../utils/logger/logger.h"

#include "../../netbus/session/AbstractSession.h"

#pragma region 全局常量

static const char* wb_migic =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
// base64(sha1(key + wb_migic))
static const char* wb_accept =
"HTTP/1.1 101 Switching Protocols\r\n"
"Upgrade:websocket\r\n"
"Connection: Upgrade\r\n"
"Sec-WebSocket-Accept: %s\r\n"
"WebSocket-Protocol:chat\r\n\r\n";

#pragma endregion

#pragma region 全局变量

extern cache_allocer* writeBufAllocer;

static char filed_sec_key[512];
static char value_sec_key[512];
static int is_sec_key = 0;
static int has_sec_key = 0;
//握手是否结束
static int is_shaker_ended = 0;

#pragma endregion

#pragma region 回调函数
extern "C" {

#pragma region Http回调

	static int on_message_end(http_parser* p) {
		is_shaker_ended = 1;
		return 0;
	}

	static int on_ws_header_field(http_parser* p, const char* at, size_t length)
	{
		if (strncmp(at, "Sec-WebSocket-Key", length) == 0)
		{// 如果读到的时WebSocketKey
			is_sec_key = 1;
		}
		else
		{
			is_sec_key = 0;
		}
		return 0;
	}

	static int on_ws_header_value(http_parser* p, const char* at, size_t length)
	{
		if (!is_sec_key)
		{
			return 0;
		}

		//保存websocket header
		strncpy(value_sec_key, at, length);
		value_sec_key[length] = 0;

		has_sec_key = 1;

		return 0;
	}

#pragma endregion
}

#pragma endregion

#pragma region WebSocketProtocol

bool WebSocketProtocol::ShakeHand(AbstractSession* session, char* body, int len)
{

#pragma region 设置HTTP回调函数
	http_parser_settings settings;
	http_parser_settings_init(&settings);

	settings.on_header_field = on_ws_header_field;
	settings.on_header_value = on_ws_header_value;
	settings.on_message_complete = on_message_end;
#pragma endregion

#pragma region 解析HTTP网页

	http_parser p;
	http_parser_init(&p, HTTP_REQUEST);

	is_sec_key = 0;
	has_sec_key = 0;
	is_shaker_ended = 0;

	http_parser_execute(&p, &settings, body, len);

#pragma endregion

	if (has_sec_key && is_shaker_ended)
	{
		// 解析到了websocket里面的Sec-WebSocket-Key
		log_debug("Sec-WebSocket-Key:\t%s", value_sec_key);

		// key + migic
		static char key_migic[512];
		static char sha1_key_migic[SHA1_DIGEST_SIZE];
		static char sendClientData[512];

		sprintf(key_migic, "%s%s", value_sec_key, wb_migic);

		//密钥长度
		int sha1Size;
		crypt_sha1((unsigned char*)key_migic, strlen(key_migic), (unsigned char*)&sha1_key_migic, &sha1Size);

		//base64编码长度
		int base64_len;
		char* base64Buf = base64_encode((uint8_t*)sha1_key_migic, sha1Size, &base64_len);

		//保存下要发送的文字数据
		sprintf(sendClientData, wb_accept, base64Buf);

		//释放base64编码数据
		base64_encode_free(base64Buf);

		session->SendData((unsigned char*)sendClientData, strlen(sendClientData));

		return true;
	}

	return false;
}

//读取包头数据
bool WebSocketProtocol::ReadHeader(unsigned char* pkgData, int pkgLen, int* out_pkgSize, int* out_header_size)
{
	if (pkgData[0] != 0x81 && pkgData[0] != 0x82)
	{
		//不是有效websocket数据头，直接返回，不处理
		log_debug("不是有效websocket数据头, 直接返回");
		return false;
	}
	if (pkgLen < 2)
	{// 没有足够位存放dataLen
		log_debug("没有足够位存放dataLen");
		return false;
	}

	//这里需要去掉一个最高位，取剩下七位作长度
	unsigned int dataLen = pkgData[1] & 0x0000007f;

	int headSize = 2;
	if (dataLen == 126)
	{// 后面两个字节表示数据长度
		headSize += 2;
		if (pkgLen < headSize)
		{// 没有足够位存放dataLen
			log_debug("没有足够位存放dataLen");
			return false;
		}
		dataLen = pkgData[3] | (pkgData[2] << 8);
	}
	else if (dataLen == 127)
	{// 后面八个字节表示数据长度

		headSize += 8;
		if (pkgLen < headSize)
		{// 没有足够位存放dataLen
			log_debug("没有足够位存放dataLen");
			return false;
		}
		int low = pkgData[5] | (pkgData[4] << 8) | (pkgData[3] << 16) | (pkgData[2] << 24);
		int high = pkgData[9] | (pkgData[8] << 8) | (pkgData[7] << 16) | (pkgData[6] << 24);

		//因为这里用不到那么多数据，所以dataLen就只取低位
		dataLen = low;
	}

	//还有四个mask位
	headSize += 4;
	if (pkgLen < headSize)
	{// 没有足够位存放mask
		log_debug("没有足够位存放mask");
		return false;
	}

	*out_header_size = headSize;
	*out_pkgSize = dataLen;

	return true;
}

//解析收到的纯数据
void WebSocketProtocol::ParserRecvData(unsigned char* rawData, unsigned char* mask, int rawLen)
{
	for (int i = 0; i < rawLen; i++)
	{
		rawData[i] ^= mask[i % 4];
	}
}

//将纯数据打包成WebSocket包
unsigned char* WebSocketProtocol::Package(const unsigned char* rawData, int rowDataLen, int * out_pkgLen)
{
	int headSize = 2;
	if (rowDataLen > 125 && rowDataLen < 65536)
	{// 两个字节
		headSize += 2;
	}
	else if (rowDataLen >= 65536)
	{// 八个字节
		headSize += 8;
		//太大我们就不管了
		return NULL;
	}

	unsigned char* dataBuf = (unsigned char*)cache_alloc(writeBufAllocer,headSize + rowDataLen);

	// 0x81 指的是字符串 0x82才是二进制
	dataBuf[0] = 0x82;

	if (rowDataLen < 125) {
		dataBuf[1] = rowDataLen;
	}
	else if (rowDataLen > 125 && rowDataLen < 65536) {
		dataBuf[1] = 126;
		dataBuf[2] = (rowDataLen & 0x0000ff00) >> 8;
		dataBuf[3] = (rowDataLen & 0x000000ff);
	}

	memcpy(dataBuf + headSize, rawData, rowDataLen);

	*out_pkgLen = headSize + rowDataLen;

	return dataBuf;
}

//释放WebSocket包
void WebSocketProtocol::ReleasePackage(unsigned char* pkg)
{
	cache_free(writeBufAllocer, pkg);
}

#pragma endregion


text:
#include <cstring>
#include <cstdlib>
#include <io.h>
#include "CmdPackageProtocol.h"
#include "../../utils/logger/logger.h"
#include "../../utils/cache_alloc/small_alloc.h"
#include "../../utils/cache_alloc/cache_alloc.h"
#include <google\protobuf\dynamic_message.h>
#include <google\protobuf\compiler\importer.h>
#include "../../utils/win32/WinUtil.h"
using namespace google::protobuf;
using namespace google::protobuf::compiler;

extern cache_allocer* writeBufAllocer;

#define my_alloc small_alloc
#define my_free small_free

#pragma region 全局变量

static ProtoType g_protoType;
static map<int, map<int, string>*> g_cmdMaps;
static DynamicMessageFactory* factory;
static Importer* importer;

static bool error = false;
static string protoFileDir;
#pragma endregion

//错误收集器，输出.proto文件错误
class ErrorCollector:public MultiFileErrorCollector
{
	// 通过 MultiFileErrorCollector 继承
	virtual void AddError(const string& filename, int line, int column, const string& message) override
	{
		logger::log((filename).c_str(), line, (int)tag_ERROR, message.c_str());
	}

	virtual void AddWarning(const string& filename, int line, int column,
		const string& message)override
	{
		logger::log((filename).c_str(), line, (int)tag_WARNING, message.c_str());
	}

};

void CmdPackageProtocol::Init(::ProtoType proto_type)
{
	g_protoType = proto_type;
}

void CmdPackageProtocol::Init(::ProtoType proto_type,const string& protoFileDir)
{
	::protoFileDir = protoFileDir;
	g_protoType = proto_type;
	if (ProtoType::Protobuf == proto_type)
	{
		_finddata_t file;
		//if (_findfirst(protoFileDir.c_str(),&file)==-1l)
		//{
		//	log_error("使用protobuf但指定目录无效：%s", protoFileDir.c_str());
		//	error = true;
		//	return;
		//}

		static DiskSourceTree sourceTree;
		static ErrorCollector ec;
		sourceTree.MapPath("", protoFileDir);
		importer = new Importer(&sourceTree, &ec);
		auto size = protoFileDir.size();

		WinUtil::SearchFromDir(protoFileDir, "*.proto", -1, SearchType::ENUM_FILE,
			[=](const string& dirPath, const string& fileName)
			{
				importer->Import(fileName);
				//表示加载完这个，继续加载后面的
				return true;
			});

		factory = new DynamicMessageFactory;
	}
}

void CmdPackageProtocol::RegisterProtobufCmdMap(map<int, map<int,string>*>& src)
{
	if (error)
		return;
	auto index = 0;
	for (auto sType_cmdMap : src)
	{
		auto stype = sType_cmdMap.first;
		auto cmdMaps = src[stype];
		if (cmdMaps == NULL)
			continue;
		//log_debug("注册CmdNameMap: %d : %s", index++, x.second.c_str());
		for (auto ctype_key : *cmdMaps)
		{
			auto ctype = ctype_key.first;
			//添加到本地
			if (g_cmdMaps.find(stype) == g_cmdMaps.end())
			{// 如果没有这个key
				auto pCmdMap = new std::map<int, string>;
				g_cmdMaps[stype] = pCmdMap;
			}

			(*g_cmdMaps[stype])[ctype] = ctype_key.second;
		}

		delete cmdMaps;
	}
}

const char* CmdPackageProtocol::GetMessageName(int stype, int ctype)
{
	if (error)
		return nullptr;

	if (g_cmdMaps.find(stype) == g_cmdMaps.end())
		return nullptr;

	auto s_cmdMap = g_cmdMaps[stype];
	if (s_cmdMap->find(ctype) == s_cmdMap->end())
		return nullptr;

	return (*s_cmdMap)[ctype].c_str();
}

ProtoType CmdPackageProtocol::ProtoType()
{
	return g_protoType;
}

bool CmdPackageProtocol::DecodeBytesToRawPackage(unsigned char* cmd, const int cmd_len, RawPackage* out_msg)
{
	if (error)
		return false;

	// serviceType (2 bytes) | cmdType (2 bytes) | userTag (4 bytes) | body
	if (cmd_len < CMD_HEADER_SIZE)
	{// 数据太短
		log_error("包体数据太短，无法解析出RawPackage包头信息");
		return false;
	}
	out_msg->serviceType = cmd[0] | (cmd[1] << 8);
	out_msg->cmdType = cmd[2] | (cmd[3] << 8);
	out_msg->userTag = cmd[4] | (cmd[5] << 8) | (cmd[6] << 16) | (cmd[7] << 24);
	out_msg->body = cmd;
	out_msg->rawLen = cmd_len;

	return true;
}

bool CmdPackageProtocol::DecodeBytesToCmdPackage(unsigned char* cmd, const int cmd_len, CmdPackage*& out_msg)
{
	out_msg = NULL;

	if (error)
		return false;

	// serviceType (2 bytes) | cmdType (2 bytes) | userTag (4 bytes) | body
	if (cmd_len < CMD_HEADER_SIZE)
	{// 数据太短
		log_debug("数据太短");
		return false;
	}

	out_msg = (CmdPackage*)my_alloc(sizeof(CmdPackage));
	memset(out_msg, 0, sizeof(CmdPackage));

	out_msg->serviceType = cmd[0] | (cmd[1] << 8);
	out_msg->cmdType = cmd[2] | (cmd[3] << 8);
	out_msg->userTag = cmd[4] | (cmd[5] << 8) | (cmd[6] << 16) | (cmd[7] << 24);
	out_msg->body = NULL;

	if (cmd_len == CMD_HEADER_SIZE)
		return true;

	// 解密
	// end

	auto dataLen = cmd_len - CMD_HEADER_SIZE;
	char* tempCharPointer;
	google::protobuf::Message* tempMessagePointer;
	switch (g_protoType)
	{
		#pragma region Json
	case ProtoType::Json:
		tempCharPointer = (char*)cache_alloc(writeBufAllocer, dataLen + 1);
		memcpy(tempCharPointer, cmd + CMD_HEADER_SIZE, dataLen);
		tempCharPointer[dataLen] = 0;
		out_msg->body = tempCharPointer;
		break;
		#pragma endregion

		#pragma region Protobuf

	case ProtoType::Protobuf:
		//获取Message名字
		auto msgName = CmdPackageProtocol::GetMessageName(out_msg->serviceType, out_msg->cmdType);
		if (nullptr == msgName)
		{
			log_error("获取Message名失败为空, serviceType: %d, cmdType: %d", out_msg->serviceType, out_msg->cmdType);
			out_msg = NULL;
			return false;
		}

		//创建Message对象
		tempMessagePointer = CreateMessage(msgName);
		if (tempMessagePointer == NULL)
		{
			log_error("创建Message对象失败, serviceType: %d, cmdType: %d, messageName: %s", out_msg->serviceType, out_msg->cmdType, msgName);
			my_free(tempMessagePointer);
			out_msg = NULL;
			return false;
		}

		//解析Message内容
		if (!tempMessagePointer->ParseFromArray(cmd + CMD_HEADER_SIZE, cmd_len - CMD_HEADER_SIZE))
		{
			log_error("解析Message内容失败, serviceType: %d, cmdType: %d, messageName: %s", out_msg->serviceType, out_msg->cmdType, msgName);
			my_free(out_msg);
			out_msg = NULL;
			ReleaseMessage(tempMessagePointer);
			return false;
		}

		out_msg->body = tempMessagePointer;

		break;

		#pragma endregion
	}
	return true;
}

void CmdPackageProtocol::FreeCmdPackage(CmdPackage* msg)
{
	if (msg == NULL)
		return;
	if (msg->body)
	{
		switch (g_protoType)
		{
		case ProtoType::Json:
			cache_free(writeBufAllocer, msg->body);
			msg->body = NULL;
			break;
		case ProtoType::Protobuf:
			auto pm = (google::protobuf::Message*)msg->body;
			delete pm;
			msg->body = NULL;
			break;
		}
	}

	my_free(msg);
}

unsigned char* CmdPackageProtocol::EncodeCmdPackageToBytes(const CmdPackage* msg, int* out_len)
{

	if (error)
		return NULL;
	//加密

	unsigned char* rawData = NULL;

	char* tempCharPointer=NULL;
	int tempLen=0;
	google::protobuf::Message* tempMessagePointer=NULL;

	switch (g_protoType)
	{
	case ProtoType::Json:
		if (msg->body)
		{
			tempCharPointer = (char*)msg->body;
			tempLen = strlen(tempCharPointer);
		}

		rawData = (unsigned char*)cache_alloc(writeBufAllocer, CMD_HEADER_SIZE + tempLen);

		if (msg->body)
		{
			memcpy(rawData + CMD_HEADER_SIZE, tempCharPointer, tempLen);
		}
		break;
	case ProtoType::Protobuf:
		if (msg->body)
		{
			tempMessagePointer = (google::protobuf::Message*)msg->body;
			tempLen = tempMessagePointer->ByteSize();
		}

		rawData = (unsigned char*)cache_alloc(writeBufAllocer, CMD_HEADER_SIZE + tempLen);

		if(tempMessagePointer && !tempMessagePointer->SerializePartialToArray(rawData + CMD_HEADER_SIZE, tempLen))
		{// 如果序列化不成功
			cache_free(writeBufAllocer, rawData);
			*out_len = 0;
			return NULL;
		}

		//传出参数
		break;
	}

	*out_len = CMD_HEADER_SIZE + tempLen;

	//写包头信息
	rawData[0] = msg->serviceType & 0x000000ff;
	rawData[1] = (msg->serviceType & 0x0000ff00) >> 8;
	rawData[2] = msg->cmdType & 0x000000ff;
	rawData[3] = (msg->cmdType & 0x0000ff00) >> 8;

	//userTag
	memcpy(rawData + 4, &msg->userTag, 4);

	return rawData;
}

void CmdPackageProtocol::FreeCmdPackageBytes(unsigned char* raw)
{
	cache_free(writeBufAllocer, raw);
}

google::protobuf::Message* CmdPackageProtocol::CreateMessage(const char* typeName)
{
	if (error)
		return nullptr;
	google::protobuf::Message* message = NULL;
	const google::protobuf::Descriptor* descriptor = importer->pool()->FindMessageTypeByName(typeName);//generated_pool
	if (descriptor) {
		const google::protobuf::Message* prototype = factory->GetPrototype(descriptor);
		if (prototype) {
			message = prototype->New();
		}
	}
	return message;
}

void CmdPackageProtocol::ReleaseMessage(google::protobuf::Message* msg)
{
	delete msg;
}


text:
#include "TcpPackageProtocol.h"
#include <stdlib.h>
#include <string.h>

#include <stdio.h>
#include "../../utils/cache_alloc/cache_alloc.h"
#include "../../utils/logger/logger.h"

extern cache_allocer* writeBufAllocer;

bool TcpProtocol::ReadHeader(unsigned char* data, int dataLen, int* out_pkgSize, int* out_headerSize)
{
	if (dataLen < 2)
	{// 太短，无法解析
		log_debug("太短，无法解析");
		return false;
	}

	*out_pkgSize = data[0] | (data[1] << 8);
	*out_headerSize = 2;

	return true;
}

unsigned char* TcpProtocol::Package(const unsigned char* rawData, int len, int* pkgLen)
{
	int headSize = 2;
	unsigned char* dataBuf = (unsigned char*)cache_alloc(writeBufAllocer, headSize + len);

	//记录包体长度
	dataBuf[0] = (headSize+len) & 0x000000ff;
	dataBuf[1] = ((headSize+len) & 0x0000ff00) >> 8;

	//将数据拷贝到长度后面
	memcpy(dataBuf + headSize, rawData, len);
	*pkgLen = headSize + len;

	return dataBuf;
}

void TcpProtocol::ReleasePackage(unsigned char* package)
{
	cache_free(writeBufAllocer, package);
}


text:
#ifndef __PROTOMANAGER_H__
#define __PROTOMANAGER_H__

#include "google/protobuf/message.h"
#include <map>
#include <string>
using std::map;
using std::string;

//文本传输方式
enum class ProtoType{
	Json = 0,
	Protobuf = 1,
};

//自定义协议包
struct CmdPackage {

#define CMD_HEADER_SIZE 8
	// 包结构
	// serviceType (2 bytes) | cmdType (2 bytes) | userTag (4 bytes) | body

	int serviceType;	//服务号
	int cmdType;		//命令号
	unsigned int userTag;//用户标识
	void* body;			// JSON str 或者是message;
};

struct RawPackage
{
	int serviceType;	//服务号
	int cmdType;		//命令号
	unsigned int userTag;//用户标识

	unsigned char* body;
	int rawLen;
};

//自定义协议的管理者
//控制传输数据的加密，编码，解码
class CmdPackageProtocol
{
public:
	//初始化协议
	static void Init(::ProtoType proto_type);
	static void Init(::ProtoType proto_type, const string& protoFileDir);

	static void RegisterProtobufCmdMap(map<int, map<int, string>*>& map);

	static const char* GetMessageName(int stype, int ctype);
	static ProtoType ProtoType();

	//解码CmdPackage包头
	static bool DecodeBytesToRawPackage(unsigned char* cmd, const int cmd_len, struct RawPackage* out_msg);

	//解码CmdPackage包
	static bool DecodeBytesToCmdPackage(unsigned char* cmd, const int cmd_len, struct CmdPackage*& out_msg);
	static void FreeCmdPackage(struct CmdPackage* msg);
	//将原始数据编码成CmdPackage包
	static unsigned char* EncodeCmdPackageToBytes(const struct CmdPackage* msg, int* out_len);
	static void FreeCmdPackageBytes(unsigned char* raw);
	//创建和释放ProtobufMessage
	static google::protobuf::Message* CreateMessage(const char* typeName);
	static void ReleaseMessage(google::protobuf::Message* msg);
};

#endif // !__PROTOMANAGER_H__


text:
#ifndef __WEBSOCKETPROTOCOL_H__
#define __WEBSOCKETPROTOCOL_H__
class AbstractSession;
class WebSocketProtocol
{
public:
	//返回是否握过手
	static bool ShakeHand(AbstractSession* session, char* body, int len);
	//读取WebSocket头
	static bool ReadHeader(unsigned char* pkgData, int pkgLen, int* out_pkgSize, int* out_header_size);
	//解析收到的数据
	static void ParserRecvData(unsigned char* rawData,unsigned char* mask,int rawLen);
	//打包数据
	static unsigned char* Package(const unsigned char* rawData, int rowDataLen, int * out_pkgLen);
	//释放打包数据使用的内存
	static void ReleasePackage(unsigned char* pkg);
};

#endif // !__WEBSOCKETPROTOCOL_H__


text:
#ifndef __TCPPACKAGEPROTOCOL_H__
#define __TCPPACKAGEPROTOCOL_H__

//TCP包传输协议，处理粘包，拆包
class TcpProtocol
{
public:
	static bool ReadHeader(unsigned char* data, int dataLen,int* out_pkgSize,int* out_headerSize);
	static unsigned char* Package(const unsigned char* rawData, int rawDataLen, int* pkgLen);
	static void ReleasePackage(unsigned char* package);
};

#endif // !__TCPPACKAGEPROTOCOL_H__


text:
#include "../../netbus/session/AbstractSession.h"
#include "../../netbus/protocol/CmdPackageProtocol.h"
#include "AbstractService.h"

AbstractService::AbstractService()
{
	useRawPackage = false;
}

bool AbstractService::OnSessionRecvRawPackage(const AbstractSession* session, const RawPackage* package) const
{
	return false;
}

// if return false, close socket
bool AbstractService::OnSessionRecvCmdPackage(const AbstractSession* session, const CmdPackage* package) const
{
	return false;
}

bool AbstractService::OnSessionDisconnected(const AbstractSession* session, const int& serviceType) const
{
	return false;
}

void AbstractService::OnSessionConnected(const AbstractSession* session, const int& serviceType) const
{
}


text:
#ifndef __ABSTRACTSERVICE_H__
#define __ABSTRACTSERVICE_H__

class AbstractSession;
struct CmdPackage;
struct RawPackage;

//抽象服务类
class AbstractService
{
public:
	bool useRawPackage;

	AbstractService();

	virtual bool OnSessionRecvRawPackage(const AbstractSession* session, const RawPackage* package)const;

	//Session接收到命令时调用
	virtual bool OnSessionRecvCmdPackage(const AbstractSession* session, const CmdPackage* package)const;

	//Session断开某个服务的链接时调用关闭时调用
	virtual bool OnSessionDisconnected(const AbstractSession* session,const int & serviceType)const;

	//Session链接到否个服务的时候调用
	virtual void OnSessionConnected(const AbstractSession* session, const int& serviceType)const;

	virtual ~AbstractService() {}
};

#endif // !__ABSTRACTSERVICE_H__


text:
#ifndef __SERVICEMANAGER_H__
#define __SERVICEMANAGER_H__
#endif // !__SERVICEMANAGER_H__
class AbstractService;
struct RawPackage;
class ServiceManager
{
public:
	static void Init();
	//注册服务
	static bool RegisterService(int serviceType, AbstractService* service);
	//Netbus收到包的回调，返回true表示正常处理了，否则要关闭socket
	static bool OnRecvRawPackage(AbstractSession* session, const RawPackage* package);
	//客户端断开的回调
	static void OnSessionDisconnected(const AbstractSession* session);

	//客户端链接成功回调
	static void OnSessionConnect(const AbstractSession* session);
};


text:
#include <cstring>
#include "AbstractService.h"
#include "../../netbus/protocol/CmdPackageProtocol.h"
#include "../../netbus/session/AbstractSession.h"
#include "ServiceManager.h"
#include "../../utils/logger/logger.h"
#include <map>
using std::map;

static map<int, AbstractService*> serviceMap;

void ServiceManager::Init()
{
	//memset(g_serviceSet, 0, sizeof(g_serviceSet));
}

bool ServiceManager::RegisterService(int serviceType, AbstractService* service)
{
	if (serviceMap.find(serviceType)!=serviceMap.end())
	{// 注册过
		log_warning("服务注册失败――重复：%d", serviceType);
		return false;
	}
	serviceMap[serviceType] = service;
	return true;
}

bool ServiceManager::OnRecvRawPackage(AbstractSession* session, const RawPackage* raw)
{
	if (NULL == raw)
	{
		log_warning("RawPackage包为空");
		return false;
	}
	if (serviceMap.find(raw->serviceType)==serviceMap.end())
	{// 没有注册过
		log_warning("未注册的serviceType: %d", raw->serviceType);
		return false;
	}

	//是否使用RawPackage
	if (serviceMap[raw->serviceType]->useRawPackage)
	{
		return serviceMap[raw->serviceType]->OnSessionRecvRawPackage(session, raw);
	}

	//使用CmdPackage
	CmdPackage* cmdPackage;

	//从字符串中解析出CmdPackage
	if (CmdPackageProtocol::DecodeBytesToCmdPackage(raw->body, raw->rawLen, cmdPackage))
	{
		//根据包的serviceType调用对应的服务去处理这个包
		auto ret = serviceMap[raw->serviceType]->OnSessionRecvCmdPackage(session, cmdPackage);
		if (!ret)
		{// 如果有服务返回false，就关闭session
			session->Close();
		}

		CmdPackageProtocol::FreeCmdPackage(cmdPackage);
		return ret;
	}

	//解析失败
	return false;
}

void ServiceManager::OnSessionDisconnected(const AbstractSession* session)
{
	for (auto kv : serviceMap)
	{
		if (kv.second == NULL)
			continue;
		kv.second->OnSessionDisconnected(session, kv.first);
	}
}

void ServiceManager::OnSessionConnect(const AbstractSession* session)
{
	for (auto kv : serviceMap)
	{
		if (kv.second == NULL)
			continue;
		kv.second->OnSessionConnected(session,kv.first);
	}
}


text:
-- --------------------------------------------------------
-- 主机:                           127.0.0.1
-- 服务器版本:                        5.7.15-log - MySQL Community Server (GPL)
-- 服务器操作系统:                      Win64
-- HeidiSQL 版本:                  9.4.0.5138
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

-- 导出 moba_game 的数据库结构
CREATE DATABASE IF NOT EXISTS `moba_game` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `moba_game`;

-- 导出  表 moba_game.ugame 结构
CREATE TABLE IF NOT EXISTS `ugame` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '全局唯一的ID',
  `uid` int(11) NOT NULL DEFAULT '0' COMMENT '用户唯一ID号',
  `ucoin_1` int(11) NOT NULL DEFAULT '0' COMMENT '货币1',
  `ucoin_2` int(11) NOT NULL DEFAULT '0',
  `ucoin_3` int(11) NOT NULL DEFAULT '0',
  `uvip` int(11) NOT NULL DEFAULT '0',
  `uvip_endtime` int(11) NOT NULL DEFAULT '0',
  `uexp` int(11) NOT NULL DEFAULT '0' COMMENT '用户经验值',
  `ustatus` int(11) NOT NULL DEFAULT '0' COMMENT '账号状态，0正常',
  `uitem_1` int(11) NOT NULL DEFAULT '0' COMMENT '道具1',
  `uitem_2` int(11) NOT NULL DEFAULT '0' COMMENT '道具2',
  `uitem_3` int(11) NOT NULL DEFAULT '0' COMMENT '道具3',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='存放我们玩家在Moba游戏中的游戏数据\r\n金币，货币，道具，vip等级，账号状态，玩家经验\r\nuid为自增长的唯一ID';

-- 数据导出被取消选择。
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;


text:
-- --------------------------------------------------------
-- 主机:                           127.0.0.1
-- 服务器版本:                        5.7.15-log - MySQL Community Server (GPL)
-- 服务器操作系统:                      Win64
-- HeidiSQL 版本:                  9.4.0.5138
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

-- 导出 auth_center_db 的数据库结构
CREATE DATABASE IF NOT EXISTS `auth_center_db` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `auth_center_db`;

-- 导出  表 auth_center_db.uinfo 结构
CREATE TABLE IF NOT EXISTS `uinfo` (
  `uid` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '玩家唯一UID号',
  `unick` varchar(32) NOT NULL DEFAULT '' COMMENT '玩家昵称',
  `usex` int(8) NOT NULL DEFAULT '0' COMMENT '玩家性别，0男1女',
  `uface` int(8) NOT NULL DEFAULT '0' COMMENT '系统默认的头像',
  `uname` varchar(32) NOT NULL DEFAULT '' COMMENT '玩家账号名称',
  `upwd` varchar(32) NOT NULL DEFAULT '' COMMENT '玩家账号密码',
  `phone` varchar(16) NOT NULL DEFAULT '' COMMENT '玩家电话',
  `email` varchar(64) NOT NULL DEFAULT '' COMMENT '玩家邮箱',
  `address` varchar(64) NOT NULL DEFAULT '' COMMENT '玩家地址',
  `uvip` int(8) NOT NULL DEFAULT '0' COMMENT '玩家vip等级',
  `vip_end_time` int(32) NOT NULL DEFAULT '0' COMMENT 'vip到期时间戳',
  `is_guest` int(8) NOT NULL DEFAULT '0' COMMENT '是否为游客账号',
  `guest_key` varchar(64) NOT NULL DEFAULT '0' COMMENT '游客账号唯一key',
  `status` int(8) NOT NULL DEFAULT '0',
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='存放玩家信息';

-- 数据导出被取消选择。
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;


text:
#include<iostream>
#include<string>
using namespace std;

#include "../../lua_wrapper/lua_wrapper.h"
#include "../../netbus/Netbus.h"
#include "../../utils/logger/logger.h"
#include "../../utils/win32/WinUtil.h"
#include "../../utils/Encoding.h"

static string exeFilePath;
static string protoFileDir;
const string& GetProtoDir()
{
	return protoFileDir;
}
const string& GetExeFilePath()
{
	return exeFilePath;
}

int main(int argc, char** argv)
{
	exeFilePath = argv[0];

	//logger::init("logger/Main", "Main", true);

	Netbus::Instance()->Init();
	lua_wrapper::Init();

	//启动
	if (argc == 2)
	{
		protoFileDir = WinUtil::GetDirPath(argv[0]);
		string searchPath = "../../apps/lua_test/scripts/";
		lua_wrapper::AddSearchPath(searchPath);
		lua_wrapper::DoFile(searchPath+argv[1]);
	}
	else if(argc == 3)
	{
		protoFileDir = WinUtil::GetDirPath(argv[0]);
		string searchPath = argv[1];
		if (*(searchPath.end() - 1) != '/')
		{
			searchPath += "/";
		}
		lua_wrapper::AddSearchPath(argv[1]);
		lua_wrapper::DoFile(searchPath + argv[2]);
	}
	else {
		protoFileDir = WinUtil::GetDirPath(argv[0]);
		string searchPath = "../../apps/lua_test/scripts/";
		lua_wrapper::AddSearchPath(searchPath);
		lua_wrapper::DoFile(searchPath + "logic/logic_server_main.lua");
	}

	//运行
	Netbus::Instance()->Run();

	//退出
	lua_wrapper::Exit();
	log_debug("服务器退出");
	system("pause");
	return 0;
}


text:
return {
    Auth = 1,
    System = 2,
    Logic = 3,
};


text:
return {
	OK = 0,
	SystemError = -100,
	UserIsFreeze = -101,
	UserIsNotGuest = -102,
	InvalidParams = -103,
	UnameHasExist = -104,
	UnameOrPwdError = -105,
	InvalidOprate = -106,
};


text:
local ServiceType = require("ServiceType");

local remote_servers={};

--注册服务所部署的IP地址和端口
remote_servers[ServiceType.Auth]={
    serviceType = ServiceType.Auth,
    ip = "127.0.0.1",
    port = 8000,
    descrip = "Auth Server",
};

remote_servers[ServiceType.System]={
    serviceType = ServiceType.System,
    ip = "127.0.0.1",
    port = 8001,
    descrip = "System Server",
};

remote_servers[ServiceType.Logic]={
    serviceType = ServiceType.Logic,
    ip = "127.0.0.1",
    port = 8002,
    descrip = "Logic Server",
};

return {
    gateway_tcp_ip = "127.0.0.1",
    gateway_tcp_port = 6080,

    gateway_ws_ip = "127.0.0.1",
    gateway_ws_port = 6081,

    servers = remote_servers,

    auth_mysql={
    	host="127.0.0.1",
    	port=3306,
    	dbName="auth_center_db",
    	uname="root",
    	upwd="Zzl5201314...",
	},

    game_mysql={
        host="127.0.0.1",
        port=3306,
        dbName="moba_game",
        uname="root",
        upwd="Zzl5201314...",
    },

    center_redis={
        host="127.0.0.1",
        port=7999,
        db_index=1,
        auth="Zzl5201314...",
    },

    game_redis={
        host="127.0.0.1",
        port=7999,
        db_index=2,
        auth="Zzl5201314...",
    },

    logic_udp={
        host="127.0.0.1",
        port=8800,
    },
};


text:
return {
	--初次进入游戏数据
	ugame={
		ucoin_1=2000,
		ucoin_2=1000,
		uvip=0,
		uexp=0,
		--...
		},

	--登陆奖励
	login_bonues={
		100,
		200,
		300,
		400,
		500,
	},
};


text:
--初始化日志模块
Debug.LogInit("logger/system","system",true);
--初始化协议模块
local ProtoType={
    Json=0,
    Protobuf=1,
};
ProtoManager.Init(ProtoType.Protobuf,"F:\\Projects\\unity\\Moba\\Server\\apps\\lua_test\\scripts\\system\\Const");
--如果是Protobuf协议，还需要注册映射表
if ProtoManager.ProtoType()==ProtoType.Protobuf then
    local cmdNameMap=require("system/Const/CmdNameMap");
    if cmdNameMap then
        ProtoManager.RegisterCmdMap(cmdNameMap);
    else
    	Debug.LogError("register cmdNameMap failed");
    end
end

--读取配置文件
local config = require("GameConfig");
local sType = require("ServiceType");

local servers=config.servers;

--开启服务器
Netbus.TcpListen(servers[sType.System].port
    ,function(s)
        local ip,port = Session.GetAddress(s);
        print("new client come ["..ip..":"..port.."]");
    end);

print("System server [tcp] listen at: ",servers[sType.System].port);

--注册服务
local systemService = require("system/SystemService");
local ret = Service.Register(sType.System,systemService);
if ret then
    print("register System Service:[" .. sType.System .. "] service success");
else
    print("register System Service:[" .. sType.System .. "] service failed");
end