Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
增加luaApi_HttpGet和luaApi_HttpPost
Browse files Browse the repository at this point in the history
  • Loading branch information
huoji120 committed Oct 9, 2023
1 parent 9e57953 commit 0ab028c
Show file tree
Hide file tree
Showing 35 changed files with 5,603 additions and 10 deletions.
65 changes: 65 additions & 0 deletions csgo2/Server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "server.h"
namespace Server {
size_t receive_data(void* contents, size_t size, size_t nmemb, void* stream) {
std::string* str = (std::string*)stream;
(*str).append((char*)contents, size * nmemb);
return size * nmemb;
}
CURLcode HttpGet(const std::string& strUrl, std::string& strResponse,
std::string header, int nTimeout) {
CURLcode res;
CURL* pCURL = curl_easy_init();
if (pCURL == NULL) {
return CURLE_FAILED_INIT;
}
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, (char*)header.c_str());
curl_easy_setopt(pCURL, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(pCURL, CURLOPT_URL, strUrl.c_str());
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(pCURL, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(pCURL, CURLOPT_TIMEOUT, nTimeout);
curl_easy_setopt(pCURL, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(pCURL, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(pCURL, CURLOPT_WRITEFUNCTION, receive_data);
curl_easy_setopt(pCURL, CURLOPT_WRITEDATA, (void*)&strResponse);
res = curl_easy_perform(pCURL);
curl_easy_cleanup(pCURL);
return res;
}

CURLcode HttpPost(const std::string& strUrl, std::string header,
std::string szJson, std::string& strResponse, int nTimeout) {
CURLcode res;
CURL* pCURL = curl_easy_init();
struct curl_slist* headers = NULL;
if (pCURL == NULL) {
return CURLE_FAILED_INIT;
}
CURLcode ret;
ret = curl_easy_setopt(pCURL, CURLOPT_URL, strUrl.c_str());
// std::string data = curl_easy_escape(pCURL, szJson.c_str(),
// szJson.size());
std::string data = szJson;
ret = curl_easy_setopt(pCURL, CURLOPT_POST, 1L);
// headers = curl_slist_append(headers, "expect: ");
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers,
"Content-Type: application/json"); // text/html
headers = curl_slist_append(headers, "charsets: utf-8");
ret = curl_easy_setopt(pCURL, CURLOPT_HTTPHEADER, headers);
ret = curl_easy_setopt(pCURL, CURLOPT_POSTFIELDS, data.c_str());
ret = curl_easy_setopt(pCURL, CURLOPT_TIMEOUT, 60);
ret = curl_easy_setopt(pCURL, CURLOPT_NOSIGNAL, 1);
ret = curl_easy_setopt(pCURL, CURLOPT_TIMEOUT_MS, 60000);
ret = curl_easy_setopt(pCURL, CURLOPT_SSL_VERIFYPEER, false);
ret = curl_easy_setopt(pCURL, CURLOPT_NOPROGRESS, 1L);
ret = curl_easy_setopt(pCURL, CURLOPT_WRITEFUNCTION, receive_data);
ret = curl_easy_setopt(pCURL, CURLOPT_WRITEDATA, (void*)&strResponse);
res = curl_easy_perform(pCURL);
curl_slist_free_all(headers);
curl_easy_cleanup(pCURL);
return res;
}

} // namespace Server
9 changes: 9 additions & 0 deletions csgo2/Server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include "head.h"
#include "libcurl/libcurl.h"
namespace Server {
CURLcode HttpPost(const std::string& strUrl, std::string header,
std::string szJson, std::string& strResponse, int nTimeout);
CURLcode HttpGet(const std::string& strUrl, std::string& strResponse,
std::string header, int nTimeout);
} // namespace Server
12 changes: 12 additions & 0 deletions csgo2/csgo2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@
<IncludePath>$(MSBuildProjectDirectory)\sdk\protobuf-2.6.1\src;$(MSBuildProjectDirectory)\LuaBridge;$(IncludePath)</IncludePath>
<TargetName>$(ProjectName)</TargetName>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<LibraryPath>$(ProjectDir)libcurl\lib\;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(MSBuildProjectDirectory)\sdk\protobuf-2.6.1\src;$(MSBuildProjectDirectory)\LuaBridge;$(IncludePath)</IncludePath>
<TargetName>$(ProjectName)</TargetName>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<LibraryPath>$(ProjectDir)libcurl\lib\;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -137,6 +139,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -158,6 +161,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -167,6 +171,9 @@
<ClInclude Include="head.h" />
<ClInclude Include="hooks.h" />
<ClInclude Include="interface.h" />
<ClInclude Include="lua-cjson\fpconv.h" />
<ClInclude Include="lua-cjson\lua_cjson.h" />
<ClInclude Include="lua-cjson\strbuf.h" />
<ClInclude Include="lua\lapi.h" />
<ClInclude Include="lua\lauxlib.h" />
<ClInclude Include="lua\lcode.h" />
Expand Down Expand Up @@ -242,6 +249,7 @@
<ClInclude Include="sdk\tier1\UtlString.hpp" />
<ClInclude Include="sdk\tier1\UtlVector.hpp" />
<ClInclude Include="sdk_tools.h" />
<ClInclude Include="Server.h" />
<ClInclude Include="stb.hh" />
<ClInclude Include="timer.h" />
<ClInclude Include="tools.h" />
Expand All @@ -257,6 +265,9 @@
<ClCompile Include="global.cpp" />
<ClCompile Include="hooks.cpp" />
<ClCompile Include="interface.cpp" />
<ClCompile Include="lua-cjson\fpconv.c" />
<ClCompile Include="lua-cjson\lua_cjson.c" />
<ClCompile Include="lua-cjson\strbuf.c" />
<ClCompile Include="lua\lapi.c" />
<ClCompile Include="lua\lauxlib.c" />
<ClCompile Include="lua\lbaselib.c" />
Expand Down Expand Up @@ -312,6 +323,7 @@
<ClCompile Include="sdk\convar\convar.cpp" />
<ClCompile Include="sdk\tier1\UtlString.cpp" />
<ClCompile Include="sdk_tools.cpp" />
<ClCompile Include="Server.cpp" />
<ClCompile Include="timer.cpp" />
<ClCompile Include="tools.cpp" />
<ClCompile Include="version_hijack.cpp" />
Expand Down
33 changes: 33 additions & 0 deletions csgo2/csgo2.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@
<Filter Include="源文件\hijack">
<UniqueIdentifier>{23cedcbc-aa1d-444b-baf2-0f55c87c525e}</UniqueIdentifier>
</Filter>
<Filter Include="源文件\script_engine\lua_cjson">
<UniqueIdentifier>{40443ff4-f9c7-4ed8-824e-244fc667bcf3}</UniqueIdentifier>
</Filter>
<Filter Include="源文件\http">
<UniqueIdentifier>{766101f1-81fc-457d-b23e-f896d2582e12}</UniqueIdentifier>
</Filter>
<Filter Include="头文件\http">
<UniqueIdentifier>{6733acfb-5291-4538-9448-3e945dc649ce}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h">
Expand Down Expand Up @@ -354,6 +363,18 @@
<ClInclude Include="sdk\public\Vector_Sdk.h">
<Filter>头文件\sdk\public</Filter>
</ClInclude>
<ClInclude Include="lua-cjson\lua_cjson.h">
<Filter>源文件\script_engine\lua_cjson</Filter>
</ClInclude>
<ClInclude Include="lua-cjson\strbuf.h">
<Filter>源文件\script_engine\lua_cjson</Filter>
</ClInclude>
<ClInclude Include="lua-cjson\fpconv.h">
<Filter>源文件\script_engine\lua_cjson</Filter>
</ClInclude>
<ClInclude Include="Server.h">
<Filter>头文件\http</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand Down Expand Up @@ -536,6 +557,18 @@
<ClCompile Include="version_hijack.cpp">
<Filter>源文件\hijack</Filter>
</ClCompile>
<ClCompile Include="lua-cjson\lua_cjson.c">
<Filter>源文件\script_engine\lua_cjson</Filter>
</ClCompile>
<ClCompile Include="lua-cjson\strbuf.c">
<Filter>源文件\script_engine\lua_cjson</Filter>
</ClCompile>
<ClCompile Include="lua-cjson\fpconv.c">
<Filter>源文件\script_engine\lua_cjson</Filter>
</ClCompile>
<ClCompile Include="Server.cpp">
<Filter>源文件\http</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
Expand Down
2 changes: 2 additions & 0 deletions csgo2/head.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ static void DebugPrintA(const char* format, ...) {
#include "script_callbacks.h"
#include "timer.h"
#include "weapon.h"
#include "lua-cjson/lua_cjson.h"
#include "Server.h"
14 changes: 14 additions & 0 deletions csgo2/libcurl/inc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# include

Public include files for libcurl, external users.

They're all placed in the curl subdirectory here for better fit in any kind of
environment. You must include files from here using...

#include <curl/curl.h>

... style and point the compiler's include path to the directory holding the
curl subdirectory. It makes it more likely to survive future modifications.

The public curl include files can be shared freely between different platforms
and different architectures.
3 changes: 3 additions & 0 deletions csgo2/libcurl/inc/curl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
curlver.h.dist
stamp-h2
stamp-h3
39 changes: 39 additions & 0 deletions csgo2/libcurl/inc/curl/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2020, Daniel Stenberg, <[email protected]>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
###########################################################################
pkginclude_HEADERS = \
curl.h curlver.h easy.h mprintf.h stdcheaders.h multi.h \
typecheck-gcc.h system.h urlapi.h options.h

pkgincludedir= $(includedir)/curl

CHECKSRC = $(CS_$(V))
CS_0 = @echo " RUN " $@;
CS_1 =
CS_ = $(CS_0)

checksrc:
$(CHECKSRC)@PERL@ $(top_srcdir)/lib/checksrc.pl -D$(top_srcdir)/include/curl $(pkginclude_HEADERS)

if CURLDEBUG
# for debug builds, we scan the sources on all regular make invokes
all-local: checksrc
endif
Loading

0 comments on commit 0ab028c

Please sign in to comment.