Compare commits

...

81 Commits

Author SHA1 Message Date
azw
48807ffa1b 1 2023-11-06 02:34:49 +00:00
azw
c78c11d4b0 1 2023-08-24 08:06:52 +08:00
azw
cf75c3276d 1 2023-08-24 07:17:54 +08:00
azw
2053312e2b 1 2023-08-19 16:07:20 +08:00
azw
aa2105b30c 1 2023-08-19 16:00:12 +08:00
azw
7bdd79eb3a 1 2023-08-19 15:44:46 +08:00
azw
d692c51efa 1 2023-08-19 15:40:22 +08:00
azw
3af700f035 1 2023-08-19 15:32:49 +08:00
azw
dcd3c603f3 1 2023-08-19 15:10:10 +08:00
azw
d6f90cd4cb 1 2023-08-19 15:03:23 +08:00
azw
7bf02217b7 1 2023-08-19 14:59:08 +08:00
azw
65829307d6 1 2023-08-19 14:34:51 +08:00
azw
48c2919dc7 1 2023-08-19 14:06:38 +08:00
azw
c07aed183e 1 2023-08-19 14:03:06 +08:00
azw
0d795ff0dc 1 2023-08-19 11:23:33 +08:00
azw
8be63ace09 1 2023-08-19 10:30:54 +08:00
azw
523420bb8f 1 2023-08-19 10:29:04 +08:00
azw
39989d56da 1 2023-08-19 00:04:40 +08:00
azw
a20f329c6d 1 2023-08-18 15:42:16 +00:00
azw
08ad1ade1c 1 2023-08-18 07:39:45 +00:00
azw
2739cd3f9f 1 2023-08-18 07:36:54 +00:00
azw
6d2528d470 1 2023-08-17 11:12:26 +00:00
azw
196646803e 1 2023-08-17 09:58:20 +00:00
azw
fa680f707d 1 2023-07-24 14:30:16 +00:00
aozhiwei
dabecaffaf 1 2023-06-18 12:59:23 +08:00
aozhiwei
ef58abcb27 1 2023-06-12 13:32:36 +08:00
aozhiwei
c22f7b1c7d 1 2023-06-05 22:14:35 +08:00
aozhiwei
749e0f19cb 1 2023-05-31 21:36:31 +08:00
aozhiwei
2d8089254c 1 2023-05-28 15:49:11 +08:00
aozhiwei
608fd18c26 1 2023-05-28 15:44:19 +08:00
aozhiwei
d81957040e 1 2023-05-28 15:38:23 +08:00
aozhiwei
e3dc89e56d 1 2023-05-28 15:12:33 +08:00
aozhiwei
b67aa400f8 1 2023-05-28 14:53:46 +08:00
aozhiwei
da56c8447d 1 2023-05-28 14:48:33 +08:00
aozhiwei
824e4dbe5d 1 2023-05-28 14:46:56 +08:00
aozhiwei
50fd07946c 1 2023-05-28 10:22:29 +08:00
aozhiwei
122db4bef3 1 2023-05-28 09:14:41 +08:00
aozhiwei
869ba41905 1 2023-05-27 18:03:29 +08:00
aozhiwei
ba2b5ee8d7 1 2023-05-27 17:23:58 +08:00
aozhiwei
be058c8a41 1 2023-05-27 17:19:28 +08:00
aozhiwei
17f8ecccb0 1 2023-05-27 17:15:10 +08:00
aozhiwei
095e35f7e0 1 2023-05-27 17:04:27 +08:00
aozhiwei
fb441acc87 1 2023-05-27 17:00:26 +08:00
aozhiwei
e9b56610ba 1 2023-05-27 16:45:48 +08:00
aozhiwei
24a2508473 1 2023-05-27 15:43:10 +08:00
aozhiwei
aaac15a155 1 2023-05-27 15:07:14 +08:00
aozhiwei
1d7e8a1087 1 2023-05-27 14:52:52 +08:00
aozhiwei
1607ee5487 1 2023-05-27 14:44:43 +08:00
aozhiwei
9f0679adc2 1 2023-05-27 14:34:57 +08:00
aozhiwei
79d7cce34b 1 2023-05-27 14:31:17 +08:00
aozhiwei
bdb5e79713 1 2023-05-27 14:27:39 +08:00
aozhiwei
7e2f4181b8 1 2023-05-27 14:11:06 +08:00
aozhiwei
8683150ce8 1 2023-05-27 14:08:27 +08:00
aozhiwei
c85563a289 1 2023-05-27 14:02:25 +08:00
aozhiwei
e1e32e2800 1 2023-05-24 22:42:20 +08:00
aozhiwei
15ea46ca30 1 2023-05-24 22:38:19 +08:00
aozhiwei
43ee63e993 1 2023-05-24 22:07:19 +08:00
aozhiwei
a713a90c9e 1 2023-05-24 22:01:02 +08:00
aozhiwei
c1a4452086 1 2023-05-24 21:58:41 +08:00
aozhiwei
1632a294c9 1 2023-05-24 21:47:41 +08:00
aozhiwei
dc6b6ac09d 1 2023-05-24 21:40:08 +08:00
aozhiwei
beed72f3a9 1 2023-05-24 21:31:53 +08:00
aozhiwei
fd1386e1be 1 2023-05-24 21:21:42 +08:00
aozhiwei
3d6b01a527 1 2023-05-24 07:49:09 +08:00
aozhiwei
10c9ce7c68 1 2023-05-18 23:23:33 +08:00
aozhiwei
97fb0f0aa6 1 2023-05-18 23:00:34 +08:00
aozhiwei
2ddbc831ec 1 2023-05-18 22:51:09 +08:00
aozhiwei
a3c22feb24 1 2023-05-18 22:50:06 +08:00
aozhiwei
93c3442442 1 2023-05-18 22:45:45 +08:00
aozhiwei
a1a58f1dee 1 2023-05-18 22:32:51 +08:00
aozhiwei
755fd5dcd0 1 2023-05-18 22:25:42 +08:00
aozhiwei
edcd30b9e0 1 2023-05-18 22:12:02 +08:00
aozhiwei
99cae679b9 1 2023-05-16 22:44:48 +08:00
aozhiwei
c8f08c2975 1 2023-05-16 22:41:05 +08:00
aozhiwei
1b43f53bb2 1 2023-05-16 22:04:50 +08:00
aozhiwei
685a81bc54 1 2023-05-15 21:55:33 +08:00
aozhiwei
07b3d684ff 1 2023-05-14 16:20:27 +08:00
aozhiwei
1fc68a5d59 1 2023-05-14 15:54:52 +08:00
aozhiwei
f8c7e083bf 1 2023-05-14 09:11:59 +08:00
aozhiwei
d58896c69a 1 2023-05-14 08:52:35 +08:00
aozhiwei
08a2a26b5a 1 2023-05-14 08:47:31 +08:00
34 changed files with 3177 additions and 2 deletions

View File

@ -0,0 +1,144 @@
project(robot)
cmake_minimum_required(VERSION 2.8)
set(GAME_ID 2006)
if (${RELEASE})
set(CMAKE_BUILD_TYPE "Release")
message("release mode")
else()
set(CMAKE_BUILD_TYPE "Debug")
message("debug mode")
endif()
set(LIB_DIR "ubuntu20.04_g++-9")
message(LIB_DIR: ${LIB_DIR} )
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DNDEBUG -DMAP3D -DDT_VIRTUAL_QUERYFILTER -DNEW_WEAPON_SYS=1 -DNEWBIE_ROOM=1 -DUSE_BOOST=1")
if (${ASAN})
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DDEBUG -DCXY -DSXY -DMAP3D -DDT_VIRTUAL_QUERYFILTER -DNEW_WEAPON_SYS=1 -DNEWBIE_ROOM=1 -fsanitize=address -fno-omit-frame-pointer -DUSE_BOOST=1")
else()
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DDEBUG -DCXY -DSXY -DMAP3D -DDT_VIRTUAL_QUERYFILTER -DNEW_WEAPON_SYS=1 -DNEWBIE_ROOM=1 -DUSE_BOOST=1")
endif()
include_directories(
AFTER
../../third_party/a8
../../third_party/f8
/usr/include/mysql
/usr/include/jsoncpp
/usr/include/hiredis
/usr/include/glm
../../third_party
../../third_party/behaviac/inc
../../third_party/recastnavigation/Recast/Include
../../third_party/recastnavigation/Detour/Include
../../third_party/recastnavigation/DetourTileCache/Include
behaviac_generated/types
behaviac_generated/types/internal
.
)
link_directories(
/usr/lib64/mysql
/usr/local/lib
../../third_party/behaviac/lib/${LIB_DIR}
)
aux_source_directory(../../third_party/a8/a8
SRC_LIST
)
aux_source_directory(../../third_party/f8/f8
SRC_LIST
)
aux_source_directory(../../third_party/recastnavigation/Recast/Source
SRC_LIST
)
aux_source_directory(../../third_party/recastnavigation/Detour/Source
SRC_LIST
)
aux_source_directory(../../third_party/recastnavigation/DetourTileCache/Source
SRC_LIST
)
aux_source_directory(behaviac_generated/types/internal
SRC_LIST
)
aux_source_directory(mtb
SRC_LIST
)
aux_source_directory(mt
SRC_LIST
)
aux_source_directory(buff
SRC_LIST
)
execute_process(
COMMAND touch -a cs_proto.pb.h
COMMAND touch -a cs_proto.pb.cc
COMMAND touch -a cs_msgid.pb.h
COMMAND touch -a cs_msgid.pb.cc
COMMAND touch -a ss_proto.pb.h
COMMAND touch -a ss_proto.pb.cc
COMMAND touch -a ss_msgid.pb.h
COMMAND touch -a ss_msgid.pb.cc
COMMAND touch -a navmesh.pb.h
COMMAND touch -a navmesh.pb.cc
)
aux_source_directory(.
SRC_LIST
)
set(EXECUTABLE_OUTPUT_PATH
${PROJECT_BINARY_DIR}/../bin
)
add_executable(
robot${GAME_ID} ${SRC_LIST}
)
add_custom_target(script_pb_protocol ALL)
add_custom_command(TARGET script_pb_protocol
PRE_BUILD
COMMAND python ../../third_party/tools/scripts/construct/build_pb.py --cpp_out=. --pb_files=cs_proto,cs_msgid,ss_proto,ss_msgid,navmesh --python_out=../tools/robot/virtualclient
)
add_dependencies(robot${GAME_ID} script_pb_protocol)
target_link_libraries(
robot${GAME_ID}
pthread
mysqlclient
protobuf
rt
dl
util
crypto
ssl
jsoncpp
curl
hiredis
tinyxml2
backtrace
boost_context
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_libraries(
robot${GAME_ID}
behaviac_gcc_debug
)
else()
target_link_libraries(
robot${GAME_ID}
tcmalloc
behaviac_gcc_release
)
endif()

448
server/robotserver/app.cc Normal file
View File

@ -0,0 +1,448 @@
#include "precompile.h"
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <mutex>
#include <condition_variable>
#include <regex>
#include <a8/uuid.h>
#include <a8/collision.h>
#include <a8/magicenum.h>
#include <a8/lisp.h>
#include <f8/udplog.h>
#include <f8/netmsghandler.h>
#include <f8/comgr.h>
#include "app.h"
#include "handlermgr.h"
#include "httpproxy.h"
#include "playermgr.h"
#include "iomgr.h"
#include "ss_msgid.pb.h"
#include "ss_proto.pb.h"
#include "f8/msgqueue.h"
#include "f8/tglog.h"
#include "f8/httpclientpool.h"
#include "f8/btmgr.h"
#include <f8/timer.h>
struct MsgNode
{
SocketFrom_e sockfrom;
int sockhandle;
unsigned short msgid;
unsigned int seqid;
long ip_saddr;
char* buf;
int buflen;
MsgNode* next;
};
const char* const PROJ_LOG_ROOT_FMT = "/data/logs/%s/logs";
const char* const PROJ_LOG_FILENAME_FMT = "log_$pid_%Y%m%d.log";
static void SavePerfLog()
{
}
bool App::Init(int argc, char* argv[])
{
signal(SIGPIPE, SIG_IGN);
this->argc = argc;
this->argv = argv;
if (!ParseOpt()) {
if (node_id <= 0) {
a8::XPrintf("robotserver启动失败,缺少-n参数\n", {});
} else if (node_id > MAX_NODE_ID) {
a8::XPrintf("robotserver启动失败,-n参数不能大于%d\n", {MAX_NODE_ID});
} else if (instance_id <= 0) {
a8::XPrintf("robotserver启动失败,缺少-i参数\n", {});
} else if (instance_id > MAX_INSTANCE_ID) {
a8::XPrintf("robotserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
}
return false;
}
int debug_mode = 0;
#ifdef DEBUG
debug_mode = 1;
#endif
a8::XPrintf("robotserver starting node_id: %d instance_id:%d pid:%d game_id:%d debug_mode:%d\n",
{
node_id,
instance_id,
getpid(),
GAME_ID,
debug_mode
});
loop_mutex_ = new std::mutex();
loop_cond_ = new std::condition_variable();
msg_mutex_ = new std::mutex();
srand(time(nullptr));
InitLog();
f8::MsgQueue::Instance()->Init();
HandlerMgr::Instance()->Init();
f8::Timer::Instance()->Init();
f8::TGLog::Instance()->Init(a8::Format(PROJ_NAME_FMT, {GAME_ID}), false, 0);
f8::CoMgr::Instance()->Init();
f8::HttpClientPool::Instance()->Init(MAX_ALL_HTTP_NUM, MAX_SYS_HTTP_NUM, MAX_USER_HTTP_NUM);
f8::BtMgr::Instance()->Init("exported");
#ifdef DEBUG
f8::BtMgr::Instance()->SetLogging(true);
#endif
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
IoMgr::Instance()->Init();
HttpProxy::Instance()->Init();
PlayerMgr::Instance()->Init();
{
int perf_log_time = 1000 * 30;
f8::Timer::Instance()->SetInterval
(perf_log_time,
[] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
SavePerfLog();
}
});
}
if (HasFlag(7)) {
f8::Timer::Instance()->SetTimeout
(
1000 * 60 * 1,
[] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
App::Instance()->terminated = true;
}
}
);
}
return true;
}
void App::UnInit()
{
//const char* s2 = GetEnumString<int>();
//int i = static_cast<int>(Test_e::kFlyBuffId);
PlayerMgr::Instance()->UnInit();
IoMgr::Instance()->UnInit();
HttpProxy::Instance()->UnInit();
f8::BtMgr::Instance()->UnInit();
f8::HttpClientPool::Instance()->UnInit();
HandlerMgr::Instance()->UnInit();
f8::CoMgr::Instance()->UnInit();
f8::MsgQueue::Instance()->UnInit();
f8::Timer::Instance()->UnInit();
f8::TGLog::Instance()->UnInit();
UnInitLog();
FreeSocketMsgQueue();
A8_SAFE_DELETE(msg_mutex_);
A8_SAFE_DELETE(loop_cond_);
A8_SAFE_DELETE(loop_mutex_);
}
int App::Run()
{
int ret = 0;
f8::UdpLog::Instance()->Info("robotserver running", {});
last_run_tick_ = a8::XGetTickCount();
int delta_time = 0;
while (!terminated) {
a8::tick_t begin_tick = a8::XGetTickCount();
QuickExecute(delta_time);
SlowerExecute(delta_time);
Schedule();
a8::tick_t end_tick = a8::XGetTickCount();
delta_time = end_tick - begin_tick;
}
return ret;
}
void App::AddSocketMsg(SocketFrom_e sockfrom,
int sockhandle,
long ip_saddr,
unsigned short msgid,
unsigned int seqid,
const char *msgbody,
int bodylen)
{
MsgNode *p = (MsgNode*) malloc(sizeof(MsgNode));
memset(p, 0, sizeof(MsgNode));
p->sockfrom = sockfrom;
p->ip_saddr = ip_saddr;
p->sockhandle = sockhandle;
p->msgid = msgid;
p->seqid = seqid;
p->buf = nullptr;
p->buflen = bodylen;
if (bodylen > 0) {
p->buf = (char*)malloc(bodylen);
memmove(p->buf, msgbody, bodylen);
}
msg_mutex_->lock();
if (bot_node_) {
bot_node_->next = p;
bot_node_ = p;
} else {
top_node_ = p;
bot_node_ = p;
}
++msgnode_size_;
msg_mutex_->unlock();
NotifyLoopCond();
}
void App::QuickExecute(int delta_time)
{
f8::MsgQueue::Instance()->Update();
IoMgr::Instance()->Update();
DispatchMsg();
f8::Timer::Instance()->Update();
}
void App::SlowerExecute(int delta_time)
{
f8::CoMgr::Instance()->Update();
}
void App::NotifyLoopCond()
{
std::unique_lock<std::mutex> lk(*loop_mutex_);
loop_cond_->notify_all();
}
void App::Schedule()
{
std::unique_lock<std::mutex> lk(*loop_mutex_);
loop_cond_->wait_for(lk, std::chrono::milliseconds(1));
}
bool App::HasTask()
{
{
if (!work_node_) {
msg_mutex_->lock();
if (!work_node_ && top_node_) {
work_node_ = top_node_;
top_node_ = nullptr;
bot_node_ = nullptr;
}
msg_mutex_->unlock();
}
if (work_node_) {
return true;
}
}
return false;
}
void App::DispatchMsg()
{
long long begin_tick = a8::XGetTickCount();
if (!work_node_ && top_node_) {
msg_mutex_->lock();
work_node_ = top_node_;
top_node_ = nullptr;
bot_node_ = nullptr;
working_msgnode_size_ = msgnode_size_;
msg_mutex_->unlock();
}
f8::MsgHdr hdr;
while (work_node_) {
MsgNode *pdelnode = work_node_;
work_node_ = pdelnode->next;
hdr.msgid = pdelnode->msgid;
hdr.seqid = pdelnode->seqid;
hdr.socket_handle = pdelnode->sockhandle;
hdr.buf = pdelnode->buf;
hdr.buflen = pdelnode->buflen;
hdr.offset = 0;
hdr.ip_saddr = pdelnode->ip_saddr;
switch (pdelnode->sockfrom) {
case SF_GameServer:
{
ProcessGameServerMsg(hdr);
}
break;
}
if (pdelnode->buf) {
free(pdelnode->buf);
}
free(pdelnode);
working_msgnode_size_--;
if (a8::XGetTickCount() - begin_tick > 200) {
break;
}
}//end while
if (!work_node_) {
working_msgnode_size_ = 0;
}
a8::tick_t end_tick = a8::XGetTickCount();
}
void App::ProcessGameServerMsg(f8::MsgHdr& hdr)
{
f8::NetMsgHandler* handler = f8::GetNetMsgHandler(&HandlerMgr::Instance()->gsmsghandler,
hdr.msgid);
if (handler) {
switch (handler->handlerid) {
case HID_Player:
{
auto player = PlayerMgr::Instance()->GetPlayerBySocketHandle(hdr.socket_handle);
if (player) {
ProcessNetMsg(handler, player.get(), hdr);
}
}
break;
default:
{
abort();
}
break;
}
}
}
void App::InitLog()
{
std::string filename_fmt = PROJ_LOG_FILENAME_FMT;
a8::ReplaceString(filename_fmt, "$pid", a8::XValue(getpid()));
std::string proj_root_dir = a8::Format(PROJ_ROOT_FMT, {a8::Format(PROJ_NAME_FMT,{GAME_ID})});
std::string proj_log_root_dir = a8::Format(PROJ_LOG_ROOT_FMT, {a8::Format(PROJ_NAME_FMT, {GAME_ID})});
std::string log_file_name = a8::Format(PROJ_LOG_ROOT_FMT,
{a8::Format(PROJ_NAME_FMT, {GAME_ID})}) + "/" + filename_fmt;
a8::MkDir(proj_root_dir);
a8::MkDir(proj_log_root_dir);
f8::UdpLog::Instance()->SetLogFileName(log_file_name);
f8::UdpLog::Instance()->Init();
f8::UdpLog::Instance()->Info("proj_root_dir:%s", {proj_root_dir});
f8::UdpLog::Instance()->Info("proj_log_root_dir:%s", {proj_log_root_dir});
f8::UdpLog::Instance()->Info("log_file_name:%s", {log_file_name});
}
void App::UnInitLog()
{
f8::UdpLog::Instance()->UnInit();
}
bool App::ParseOpt()
{
int ch = 0;
while ((ch = getopt(argc, argv, "i:t:r:f:n:r:")) != -1) {
switch (ch) {
case 'n':
{
node_id = a8::XValue(optarg);
}
break;
case 'i':
{
instance_id = a8::XValue(optarg);
}
break;
case 't':
{
is_test_mode = true;
test_param = a8::XValue(optarg);
}
break;
case 'f':
{
std::vector<std::string> strings;
a8::Split(optarg, strings, ',');
for (auto& str : strings) {
flags.insert(a8::XValue(str).GetInt());
}
}
break;
case 'r':
{
robot_num = a8::XValue(optarg);
robot_num = std::min(robot_num, 100);
robot_num = std::max(robot_num, 1);
}
break;
}
}
return instance_id > 0 && node_id > 0;
}
long long App::NewUuid()
{
return uuid.Generate();
}
bool App::HasFlag(int flag)
{
return flags.find(flag) != flags.end();
}
void App::SetFlag(int flag)
{
flags.insert(flag);
}
void App::UnSetFlag(int flag)
{
flags.erase(flag);
}
void App::FreeSocketMsgQueue()
{
msg_mutex_->lock();
if (!work_node_) {
work_node_ = top_node_;
top_node_ = nullptr;
bot_node_ = nullptr;
}
while (work_node_) {
MsgNode* pdelnode = work_node_;
work_node_ = work_node_->next;
if (pdelnode->buf) {
free(pdelnode->buf);
}
free(pdelnode);
if (!work_node_) {
work_node_ = top_node_;
top_node_ = nullptr;
bot_node_ = nullptr;
}
}
msg_mutex_->unlock();
}
long long App::AllocTempHeroUniId()
{
if (curr_uniid_ < 1000) {
curr_uniid_ = 1000;
}
if (curr_uniid_ > 100000000) {
curr_uniid_ = 1001;
}
++curr_uniid_;
return -curr_uniid_;
}
long long App::AllocTempWeaponUniId()
{
if (curr_uniid_ < 1000) {
curr_uniid_ = 1000;
}
if (curr_uniid_ > 100000000) {
curr_uniid_ = 1000;
}
++curr_uniid_;
return -curr_uniid_;
}

101
server/robotserver/app.h Normal file
View File

@ -0,0 +1,101 @@
#pragma once
#include <a8/uuid.h>
#include <a8/singleton.h>
#include <f8/protoutils.h>
struct MsgNode;
class App : public a8::Singleton<App>
{
private:
App() {};
friend class a8::Singleton<App>;
public:
#ifdef DEBUG
std::map<int, int> debug_params;
#endif
bool Init(int argc, char* argv[]);
void UnInit();
int Run();
void AddSocketMsg(SocketFrom_e sockfrom,
int sockhandle,
long ip_saddr,
unsigned short msgid,
unsigned int seqid,
const char *msgbody,
int bodylen);
void NotifyLoopCond();
long long NewUuid();
bool HasFlag(int flag);
void SetFlag(int flag);
void UnSetFlag(int flag);
long long AllocTempHeroUniId();
long long AllocTempWeaponUniId();
private:
void QuickExecute(int delta_time);
void SlowerExecute(int delta_time);
void Schedule();
bool HasTask();
void DispatchMsg();
void ProcessGameServerMsg(f8::MsgHdr& hdr);
void InitLog();
void UnInitLog();
bool ParseOpt();
void FreeSocketMsgQueue();
public:
int argc = 0;
char** argv = nullptr;
volatile bool terminated = false;
a8::uuid::SnowFlake uuid;
public:
int instance_id = 0;
int node_id = 0;
int robot_num = 1;
bool is_test_mode = false;
int test_param = 0;
bool servicing = true;
private:
/*
1:
2:
3: battleReport环境
4:
5:
6:
7:
8: httpclientpool压力测试
*/
std::set<int> flags;
private:
long long last_run_tick_ = 0;
std::mutex *loop_mutex_ = nullptr;
std::condition_variable *loop_cond_ = nullptr;
std::mutex *msg_mutex_ = nullptr;
MsgNode* top_node_ = nullptr;
MsgNode* bot_node_ = nullptr;
MsgNode* work_node_ = nullptr;
long long curr_uniid_ = 0;
public:
int msgnode_size_ = 0 ;
int working_msgnode_size_ = 0;
};

View File

@ -0,0 +1 @@
../gameserver/attrdefine.h

View File

@ -0,0 +1,9 @@
#pragma once
class Buff
{
public:
virtual void Activate() {}
virtual void Deactivate() {}
};

View File

@ -0,0 +1,60 @@
#pragma once
#include "buff.h"
A8_DECLARE_CLASS_ENUM(BuffCallFunc_e, int,
kAddMinorMode = 1,
kInternalRangeAddBuff = 3,
kDecHp = 4,
kMarkTag = 5,
kRemoveBuff = 7,
kFlashMove = 8,
kAddEnergyShield = 10,
kAddHp = 11,
kFlashMoveToPos = 12,
kLightCircle = 13,
kSyncProp = 16,
kSetBulletBornOffset = 17,
kSummonHeroSepcPoint = 18,
kSummonHeroSpecDistance = 19,
kClearSummonHero = 20,
kImmuneAllMove = 21,
kDmgForward = 22,
kSetGunBuffId = 23,
kSummonObstacleSepcPoint = 24,
kSummonObstacleSpecDistance = 25,
kClearSummonObstacle = 26,
kDecSkillCd = 27,
kRefreshHp = 28
);
class Weapon;
class CallFuncBuff : public Buff
{
public:
virtual void Activate() override;
virtual void Deactivate() override;
private:
void ProcIntervalRangeAddBuffFunc();
void ProcAddMinorMode();
void ProcMarkTag();
void ProcRemoveBuff();
void ProcFlashMove();
void ProcAddEnergyShield();
void ProcAddHp();
void ProcFlashMoveToPos();
void ProcLightCircle();
void ProcSyncProp();
void SummonHeroSpecPoint();
void SummonHeroSpecDistance();
void ClearSummonHero();
void SummonObstacleSpecPoint();
void SummonObstacleSpecDistance();
void ClearSummonObstacle();
void DecSkillCd();
float hold_param2_ = 0.0;
Weapon* hold_weapon_ = nullptr;
};

View File

@ -0,0 +1,525 @@
#pragma once
enum SocketFrom_e
{
SF_GameServer,
};
enum InnerMesssage_e
{
IM_ClientSocketDisconnect = 100,
IM_ExecGM,
IM_GGListenerError
};
//网络处理对象
enum NetHandler_e
{
HID_Player,
HID_PlayerMgr,
HID_Room,
HID_RoomMgr,
HID_MatchMgr,
HID_MatchTeam,
HID_GGListener,
};
enum GasMode_e
{
GasInactive = 0,
GasWaiting = 1,
GasMoving = 2,
GasJump = 3
};
enum ActionType_e
{
AT_None = 0,
AT_Reload = 1,
AT_UseItem = 2,
AT_Relive = 3,
AT_Rescue = 4
};
enum RoomType_e
{
RT_NewBrid = 0,
RT_MidBrid = 1,
RT_OldBrid1 = 2,
RT_OldBrid2 = 3,
RT_OldBrid3 = 4,
RT_Max
};
enum InventorySlot_e
{
IS_9MM = 0,
IS_556MM = 1,
IS_762MM = 2,
IS_12GAUGE = 3,
IS_RPG = 4,
IS_FRAG = 5,
IS_SMOKE = 6,
IS_HEALTHKIT = 7, //医疗包
IS_PAIN_KILLER = 8, //止痛药
IS_SHEN_BAO = 9, //肾上腺速
IS_ICE = 10, //冰
IS_1XSCOPE = 12,
IS_2XSCOPE = 13,
IS_4XSCOPE = 14,
IS_8XSCOPE = 15,
IS_15XSCOPE = 16,
IS_MINE = 17, //地雷
IS_MOLOTOR_COCKTAIL = 18, //燃烧瓶
IS_TRAP = 19, //陷井
IS_POSION_GAS_BOMB = 20, //毒气弹
IS_C4 = 21, //c4
IS_SHIELD_WALL = 22, //盾墙
IS_SINGAL_GUN = 23, //信号枪
IS_OIL_BUCKET = 24, //汽油桶
IS_GEMSTONE = 25, //能量宝石
IS_MAX = 30,
IS_END
};
enum SkillType_e
{
kActiveSkill = 1,
kPassiveSkill = 2
};
enum BuffTriggerType_e
{
kBTT_UseSkill = 1, //技能释放时触发
kBTT_Kill = 2, //击杀敌方后触发
kBTT_SkillHit = 3, //技能命中触发
kBTT_OtherBuff = 4,//其他buff触发
kBTT_UseItem = 6, //使用道具触发
kBTT_SeriesShot = 7 //连射时触发
};
enum BuffTargetType_e
{
kBuffTargetNone = 0, //无
kBuffTargetSelf = 1, //自己
kBuffTargetFriendly = 2, //友军
kBuffTargetEnemy = 3, //敌军
};
enum SkillFunc_e
{
kSkill_FuncNone = 0,
kSkill_TurnOver = 1,
kSkill_JumpTo = 2,
kSkill_Shot = 3,
kSkill_Pull = 4,
kSkill_HoldShield = 5,
kSkill_FlyHook = 7,
kSkill_FuncEnd
};
enum SkillTarget_e
{
kST_All = 0,
kST_Self = 1,
kST_FriendlyIncludeSelf = 2,
kST_FriendlyExcludeSelf = 3,
kST_EnemySingle = 6,
kST_EnemyGroup = 7,
kST_EnemyAndObject = 8,
kST_EnemyAndSelf = 9,
kST_SingleEnemyAndSelf = 10,
kST_SpecDir = 11
};
enum BuffSelectTarget_e
{
kBST_All = 0,
kBST_Self = 1,
kBST_FriendlyIncludeSelf = 2,
kBST_FriendlyExcludeSelf = 3,
kBST_Enemy = 5,
kBST_EnemyAndSelf = 6,
};
enum VirtualWeapon_e
{
VW_Gas = 9000000,
VW_Explosion = 9000001,
VW_Weapon = 9000002,
};
enum VirtualPlayer_e
{
VP_Gas = 9000000,
VP_Buff = 9000001,
VP_Explosion = 9000002,
VP_Water = 9000003,
};
enum EquipType_e
{
EQUIP_TYPE_WEAPON = 1,
EQUIP_TYPE_BULLET = 2,
EQUIP_TYPE_THROW = 3,
EQUIP_TYPE_PROTECTION = 4,
EQUIP_TYPE_BAG = 7,
EQUIP_TYPE_OLDSKIN = 8,
EQUIP_TYPE_CAR = 9,
EQUIP_TYPE_SKIN = 10,
EQUIP_TYPE_CAMOUFLAGE = 11,
EQUIP_TYPE_SPOILS = 12,
EQUIP_TYPE_SINGAL_EMITTER = 13,
EQUIP_TYPE_GIFT_PACKAGE = 14,
EQUIP_TYPE_GEMSTONE = 15,
EQUIP_TYPE_LOVE = 16,
EQUIP_TYPE_End
};
enum GunSubEquipType_e
{
GUN_SUB_EQUIP_TYPE_FLY_HOOk = 14,
GUN_SUB_EQUIP_TYPE_End
};
enum ThrowSubEquipType_e
{
THROW_EQUIP_TYPE_ADD_BUFF = 3,
THROW_SUB_EQUIP_TYPE_End
};
enum EntitySubType_e
{
EST_None = 0,
EST_Player = 1,
EST_Android = 2,
EST_PermanentObstacle = 3,
EST_RoomObstacle = 4
};
enum PropertyType_e
{
kPropHp = 1,
kPropMaxHp = 2,
kPropVolume = 3,
kPropSkillLeftTime_ = 4,
kPropSkillCd = 5,
kPropTankBulletNum = 6,
kPropTankOil = 7,
kPropBulletNum = 8,
kPropItem = 9,
kPropWeaponAmmo = 10,
kPropCar = 11,
kPropZombieId = 23,
kPropSkillLeftTime = 24,
kPropSkillCurrTimes = 25,
kPropSkillMaxTimes = 26,
kPropCarOil = 27,
kPropFollowTarget = 30,
kPropDive = 31,
kPropSkillExp = 32,
kPropShieldHp = 33,
kPropBeHook = 34,
kPropSkillMinor = 35,
kPropReviveCion = 36,
kPropCritDmg = 37,
kPropParachute = 38,
kPropFlyEffect = 39,
kPropEnergyShield = 40,
kPropGemstone = 41,
kPropPickUp = 42,
kProTeamNum = 43,
kPropTeamId = 44,
kPropTzYsTime = 45,
kPropGuideStep = 46,
};
enum SkinSlot_e
{
kSkinSlot_CLOTH = 1,
kSkinSlot_HAT = 2,
};
enum ObjectFlags_e
{
kOfWriteCache = 0,
kOfReadCache = 1,
};
enum RoomMode_e
{
kPvpMode = 0,
kPveMode = 1,
kPvpRankMode = 2,
kRoomModeEnd
};
enum PostBuffAction_e
{
kRemoveBuffByIdAction = 1,
kRemoveBuffByEffectAction = 2,
kAddBuffAction = 3
};
enum ObstacleType_e
{
kObstacleSelfExplosion = 1,
kObstacleMine = 2,
kObstacleTrap = 3,
kObstaclePosionGas = 4,
kObstacleSpring = 5,
kObstacleHideHouse = 6,
kObstacleGully = 7,
kObstacleAirDropBox = 8,
kObstacleOilBucket = 9,
kObstacleKeepRangeBuff = 10,
kObstacleShield = 11,
kObstacleStrengthenWall = 12,
kObstacleMedicalStation = 13,
};
enum BulletHit_e
{
kBulletHitPass = 1,
kBulletHitAnyDmg = 2,
kBulletHitOnlySpecDmg = 3,
kBulletHitEatDmg = 4,
};
enum CollisionHit_e
{
kCollisionHitPass = 1,
kCollisionHitBlock = 2,
kCollisionHitDeadAndDrop = 3,
kCollisionHitSpecEvent = 4,
};
enum ExplosionHit_e
{
kExplosionHitPass = 1,
kExplosionHitAnyDmg = 2,
kExplosionHitOnlySpecDmg = 3,
kExplosionHitEatDmg = 4,
};
enum EventAddBuff_e
{
kEventBuffUpdateWeaponId = 1,
kEventBuffUpdateWeaponSlot = 2,
kEventBuffUpdateWeaponType = 3,
kEventBuffShotWeaponId = 4,
kEventBuffShotWeaponSlot = 5,
kEventBuffShotWeaponType = 6,
kEventBuffKillTarget = 7,
kEventBuffDid = 8,
kEventBuffUpdateBuffId = 9,
kEventBuffUpdateBuffEffect = 10,
kEventBuffHp = 11,
kEventBuffDown = 12,
kEventBuffReceiveDmg = 13,
kEventBuffUseSkill = 14,
kEventBuffEatDrug = 15,
kEventBuffDisengageBattle = 16,
kEventBuffLimitTimeKillTarget = 17,
kEventBuffRevive = 18,
kEventBuffDmgOut = 19,
kEventBuffEnd
};
enum WeaponOpt_e
{
kWeaponOptTakeon = 0,
kWeaponOptTakeoff = 1,
kWeaponOptKeep = 2,
kWeaponOptEnd
};
enum BuffOpt_e
{
kBuffOptActive = 0,
kBuffOptDeactive = 1,
kBuffOptKeep = 2,
kBuffOptEnd
};
enum HpOpt_e
{
kHpOptLeAbs = 0,
kHpOptLeRate = 1,
kHpOptGeAbs = 2,
kHpOptGeRate = 3,
kHpOptEnd
};
enum RichTextElementType
{
kTextElement = 1,
kImageElement = 2
};
enum KillTextFieldIdx
{
kFieldIdxMasterName = 1000,
kFieldIdxKillerName,
kFieldIdxDeadName,
kFieldIdxWeaponName,
kFieldIdxWeaponTextIcon,
};
enum BulletConsumeType_e
{
kBulletConsumeOne = 0,
kBulletConsumeMulti = 1,
};
enum SamplePolyFlags
{
SAMPLE_POLYFLAGS_WALK = 0x01, // Ability to walk (ground, grass, road)
SAMPLE_POLYFLAGS_SWIM = 0x02, // Ability to swim (water).
SAMPLE_POLYFLAGS_DOOR = 0x04, // Ability to move through doors.
SAMPLE_POLYFLAGS_JUMP = 0x08, // Ability to jump.
SAMPLE_POLYFLAGS_DISABLED = 0x10, // Disabled polygon
SAMPLE_POLYFLAGS_GLASS = 0x40, // Disabled polygon
SAMPLE_POLYFLAGS_ALL = 0xffff // All abilities.
};
A8_DECLARE_ENUM(MagicType_e,
MAGIC_NONE = 0,
MAGIC_20101_HL, //20101 狐狸-爱心香风
MAGIC_20701_BAO, //20701 豹-瞬间移动回血
MAGIC_20801_LONG, //20801 龙-火力压制
MAGIC_20901_XIONG, //20901 熊野蛮冲撞
MAGIC_21001_NIU, //21001 牛-立盾防御
MAGIC_20201_HX, //20201 浣熊-火箭浣熊
MAGIC_20401_MAO, //20401 猫-飞勾
MAGIC_20601_DJS, //20601 独角兽-威力翻倍
MAGIC_20301_XL, //20301 小鹿-医疗站
MAGIC_20501_TZ, //20501 兔子-隐身
MAGIC_30101_HL, //30101 狐狸-自然恢复
MAGIC_30201_HX, //30201 浣熊-受伤加速
MAGIC_30301_XL, //30301 小鹿-击杀回血
MAGIC_30401_MAO, //30401 猫-死亡自曝
MAGIC_30501_TZ, //30501 兔子-隐身恢复
MAGIC_30601_DJS, //30601 独角兽-免疫眩晕
MAGIC_30701_BAO, //30701 豹-钩爪拉动减伤
MAGIC_30801_LONG, //30801 龙-救援防护
MAGIC_30901_XIONG, //30901 熊-复活
MAGIC_31001_NIU, //31001 牛-此面向敌
MAGIC_END
);
enum PolyExtDataFlag_e
{
kWater1ExtFlag = 1, //能打出水坑
kWater2ExtFlag = 2, //打不出水坑
kWater3ExtFlag = 3, //游泳不能射击
};
A8_DECLARE_ENUM(TimerUserEvent_e,
kCheckShotHoldStateTimerEvent = 100,
kShenBaoAddTimeTimerEvent,
kActiveDjsSkillTimerEvent,
kDeactiveDjsSkillTimerEvent
);
A8_DECLARE_CLASS_ENUM(GraspBuffTrigger_e, int,
kHit = 1,
kKill = 2,
kTakeOn = 3,
kCond = 4,
kHitAndEnd = 5,
kEnd
);
A8_DECLARE_CLASS_ENUM(GraspBuffTriggerCond_e, int,
kImprint = 1,
kEnd
);
A8_DECLARE_ENUM(WorldObjectType_e,
kLootType = 1,
kBoxType = 2,
kCarType = 3,
kBornPointType = 4
);
enum SwitchTimesType_e
{
kSwitchTimeBegin,
kDisableShotTimes,
kDisableUseSkillTimes,
kDisableMoveEffectTimes,
kEnableDmgForwardTimes,
kSwitchTimeEnd,
};
const char* const PROJ_NAME_FMT = "game%d_gameserver";
const char* const PROJ_ROOT_FMT = "/data/logs/%s";
const int SERVER_FRAME_RATE = 20;
const int SYNC_FRAME_RATE = 10;
const float FRAME_RATE_MS = 1000.0f / SERVER_FRAME_RATE;
const int NEXT_FRAME_TIMER = 2;
const int MAX_WEAPON_NUM = 14;
const int MAX_SKIN_LV = 9;
const int GUN_SLOT0 = 0;
const int GUN_SLOT1 = 1;
const int GUN_SLOT2 = 2;
const int FRAG_SLOT = 3;
const int SMOKE_SLOT = 4;
const int SPEC1_IS_BEGIN = IS_FRAG;
const int SPEC1_IS_END = IS_SMOKE;
const int SPEC2_IS_BEGIN = IS_MINE;
const int SPEC2_IS_END = IS_POSION_GAS_BOMB;
const int SPEC3_IS_BEGIN = IS_C4;
const int SPEC3_IS_END = IS_OIL_BUCKET;
const int SPEC1_SLOT_BEGIN = 3; //手雷 烟雾弹
const int SPEC2_SLOT_BEGIN = 5; //地雷 燃烧瓶 陷井 毒气弹
const int SPEC3_SLOT_BEGIN = 9; //c4 盾墙 信号抢 汽油桶
const int FIGHTING_MODE_BULLET_NUM = 10000 * 10000;
const int MAX_NODE_ID = 8;
const int MAX_INSTANCE_ID = 500;
const int MAX_TEAM_NUM = 4;
const int MAX_SYS_HTTP_NUM = 2;
const int MAX_USER_HTTP_NUM = 8;
const int MAX_ALL_HTTP_NUM = MAX_SYS_HTTP_NUM + MAX_USER_HTTP_NUM;
const int FIXED_OBJECT_MAXID = 1;
const int MAX_ROOM_IDX = 1000;
const int VIEW_RANGE = 512;
const int HUNLUAN_BUFFID = 6001;
const int MAX_SKILL_LV = 15;
const int kReviveTimeAdd = 12;
const int kSkinNum = 4;
const int MAX_WEAPON_LV = 15;

View File

@ -0,0 +1,138 @@
#pragma once
A8_DECLARE_ENUM(SpecBuffId_e,
kThroughWall_BUFFID = 6003,
FLY_BUFFID = 7001,
JUMP_BUFFID = 7002,
DRIVER_BUFFID = 7003,
PASSENGER_BUFFID = 7004,
kRecoilBuffId = 7005,
kInGrassBuffId = 7006,
kInIceBuffId = 7008,
kBeRecycleBuffId = 7009,
kTraceBuffId = 7011,
kInMountainTopBuffId = 7014,
kDownBuffId = 7015,
kPoisioningBuffId = 7016,
kRescuerBuffId = 7017,
kVertigoBuffId = 7018,
kPeaceModeBuffId = 7019,
kInRescueBuffId = 7020,
kKeepShotAnimiBuffId = 7021,
kVertigoEffectBuffId = 7022,
kDispelEffectBuffId = 7023,
kImmuneEffectBuffId = 7024,
kInWater1BuffId = 7026,
kInWater2BuffId = 7027,
kInWater3BuffId = 7028,
kPullToWalkableBuffId = 8003,
kDiveBuffId = 8054,
kInvincibleBuffId = 1005,
);
A8_DECLARE_ENUM(BuffEffectType_e,
kBET_Begin = 0,
kBET_SummonLoot = 1,
kBET_TurnOver = 2, //翻滚
kBET_Building = 3,
kBET_Invincible = 4, //无敌
kBET_Camouflage = 5, //伪装
kBET_Immune = 6, //免疫
kBET_CallFunc = 7, //调用功能
kBET_NewProtect = 8, //新手保护血量低于50%
kBET_BePull = 9, //拉人(被拉方)
kBET_DistanceDmgAddition = 10,
kBET_OnceChgAttr = 11, //一次性buff
kBET_UnUse12 = 12,
kBET_ModifyAttr = 13,
kBET_PlayShotAni = 14, //播放射击动画
kBET_Vertigo = 15, //眩晕
kBET_UnUse16 = 16,
kBET_PullDone = 17, //拖拽到目的地
kBET_DelayAddBuff = 18, //延迟加buff
kBET_ModifyBaseAttr = 19,
kBET_ModifyGrowAttr = 20,
kBET_DirectSetAttr = 21,
kBET_UnUse22 = 22,
kBET_HunLuan = 23, //混乱,在烟雾弹中不自动瞄准
kBET_Fly = 24, //飞行中
kBET_Jump = 25, //跳伞中
kBET_IntervalAddBuff = 26, //持续掉血
//kBET_LastAddHp = 27, //持续加血
kBET_UnUse28 = 28,
kBET_SummonHero = 29, //召唤英雄
//kBET_SummonHero = 30, //向前跳跃
kBET_UnUse31 = 31,
kBET_Hide = 32, //隐身
kBET_UnUse33 = 33,
kBET_UnUse34 = 34,
kBET_Sprint = 35, //冲刺
kBET_SummonObstacle = 36, //召唤物件
kBET_FlashMove = 37, //瞬间移动
kBET_UnUse38 = 38,
kBET_ShotCharge = 39, //射击蓄力
kBET_SelectTargetWithSelfPos = 40, //已自己坐标为中心范围内选取目标,并且批量添加buff
kBET_EventAdd = 41, //even添加buff
kBET_AddInventory = 42, //扩充库存
kBET_Down = 43, //倒下
kBET_Poisoning = 44, //中毒(毒圈中)
kBET_Rescuer = 45, //救人中(救人方)
kBET_AddCarBuff = 46, //给载具加buff
kBET_RemoveCarBuff = 47, //移除载具身上的buff
kBET_BulletThrough = 48, //穿透
kBET_FollowMaster = 49, //跟随主人
kBET_ThroughWall = 50, //穿墙
kBET_Driver = 51, //驾驶中
kBET_Passenger = 52, //乘座中
kBET_CarActive = 53, //激活载具
kBET_CarDeactive = 54, //载具待机
kBET_Recoil = 55, //后坐力
kBET_InGrass = 56, //在草丛
kBET_InWater = 57, //在水里
kBET_InIce = 58, //在冰里
kBET_PullToWalkable = 59, //从碰撞里以自己方向拖出来直到没有碰撞
kBET_BatchAddBuff = 60, //批量添加buff
kBET_BeRecycle = 61, //待回收
kBET_Trace = 62, //追踪玩家
kBET_MountainTop = 63, //在山顶
kBET_UseSkill = 64, //使用技能
kBET_CamouflageAddition = 65, //对抗伪装
kBET_AutoShot = 66, //自动射击
kBET_BeatBack = 67, //击退
kBET_Disperse = 68, //驱散
kBET_PeaceMode = 69, //和平模式
kBET_UnUse70 = 70, //
kBET_CondAdd = 71, //
kBET_Dive = 72, //下潜模式
kBET_Reverse = 73, //人物反向
kBET_UnUse74 = 74,
kBET_MachineGun = 75, //机枪
kBET_HoldShield = 76, //手持盾牌
kBET_InRescue = 77, //被救援中(被就方)
kBET_End
);
enum EntityType_e
{
ET_None = 0,
ET_Player = 1,
ET_Obstacle = 2,
ET_Building = 3,
//ET_LootSpawner = 4,
ET_Loot = 5,
//ET_DeadBody = 6,
//ET_Decal = 7,
//ET_Projectile = 8,
//ET_Smoke = 9,
ET_Hero = 10,
ET_Car = 11,
ET_Bullet = 20,
ET_MapBlock = 28,
ET_Dummy = 29,
ET_Unuse = 30,
ET_MAX
};

View File

@ -0,0 +1 @@
../gameserver/global.cc

1
server/robotserver/global.h Symbolic link
View File

@ -0,0 +1 @@
../gameserver/global.h

View File

@ -0,0 +1,160 @@
#include "precompile.h"
#include <a8/mutable_xobject.h>
#include <f8/udplog.h>
#include <f8/msgqueue.h>
#include <f8/jsonhttprequest.h>
#include "handlermgr.h"
#include "player.h"
#include "app.h"
#include "cs_proto.pb.h"
#include "ss_proto.pb.h"
static void _GMOpsSelfChecking(std::shared_ptr<f8::JsonHttpRequest> request)
{
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
request->resp_xobj->SetVal("healthy", 1);
request->resp_xobj->SetVal("servicing", App::Instance()->servicing ? 1 : 0);
}
static void _GMOpsReload(std::shared_ptr<f8::JsonHttpRequest> request)
{
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
f8::UdpLog::Instance()->Info("reload config files", {});
}
static void _GMOpsStopService(std::shared_ptr<f8::JsonHttpRequest> request)
{
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
App::Instance()->servicing = false;
}
static void _GMOpsStartService(std::shared_ptr<f8::JsonHttpRequest> request)
{
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
App::Instance()->servicing = true;
}
static void _GMOpsServerInfo(std::shared_ptr<f8::JsonHttpRequest> request)
{
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
request->resp_xobj->SetVal("node_id", App::Instance()->node_id);
request->resp_xobj->SetVal("instance_id", App::Instance()->instance_id);
}
static void _GMStatGetRealTimeOnline(std::shared_ptr<f8::JsonHttpRequest> request)
{
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
}
void HandlerMgr::Init()
{
RegisterNetMsgHandlers();
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
RegisterGMMsgHandler("Ops@reload", _GMOpsReload);
RegisterGMMsgHandler("Ops@stopService", _GMOpsStopService);
RegisterGMMsgHandler("Ops@startService", _GMOpsStartService);
RegisterGMMsgHandler("Ops@serverInfo", _GMOpsServerInfo);
RegisterGMMsgHandler("Stat@getRealTimeOnline", _GMStatGetRealTimeOnline);
f8::MsgQueue::Instance()->RegisterCallBack
(
IM_ExecGM,
[] (const a8::Args& args)
{
int socket_handle = args.Get<int>(0);
std::string url = args.Get<std::string>(1);
std::string query_str = args.Get<std::string>(2);
unsigned long saddr = args.Get<unsigned long>(3);
HandlerMgr::Instance()->ProcGMMsg
(
saddr,
socket_handle,
url,
query_str
);
});
}
void HandlerMgr::UnInit()
{
}
void HandlerMgr::RegisterNetMsgHandlers()
{
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMKcpHandshake);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMPing);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMRpcError);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMReconnect);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMWatchWar);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMLeave);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMMatchCancel);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMJoinedNotify);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMMapInfo);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMUpdate);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMRollMsg);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMVoiceNotify);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMDisconnectNotify);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMGameOver);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMDebugMsg);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMUiUpdate);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMGameStart);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMSysPiaoMsg);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMShowCountdown);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMShowTeamUI);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMUpdateMatchInfo);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMGetItemNotify);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMMatchMemberMsgNotify);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMPvePassWave);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMTeamMarkTargetPosList);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMDebugCmd);
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMNewBieEnd);
}
void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
const std::string& url, const std::string& querystr)
{
if (url != "/webapp/index.php") {
return;
}
a8::HTTPRequest request;
a8::ParserUrlQueryString(querystr.c_str(), request);
std::string msgname = a8::Get(request, "c").GetString() + "@" + a8::Get(request, "a").GetString();
auto itr = gmhandlers_.find(msgname);
if (itr != gmhandlers_.end()) {
auto request = std::make_shared<f8::JsonHttpRequest>();
request->saddr = saddr;
request->socket_handle = sockhandle;
request->query_str = querystr;
request->params->ReadFromUrlQueryString(querystr);
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
itr->second(request);
if (!request->pending){
std::string response;
request->resp_xobj->ToJsonStr(response);
//GGListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
}
} else {
//GGListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
}
}
void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname,
void (*handler)(std::shared_ptr<f8::JsonHttpRequest>))
{
gmhandlers_[msgname] = handler;
}

View File

@ -0,0 +1,37 @@
#pragma once
#include <a8/singleton.h>
#include <a8/basehttpsession.h>
#include <f8/types.h>
#include <f8/netmsghandler.h>
namespace a8
{
class MutableXObject;
}
class HandlerMgr : public a8::Singleton<HandlerMgr>
{
private:
HandlerMgr() {};
friend class a8::Singleton<HandlerMgr>;
public:
void Init();
void UnInit();
f8::NetMsgHandlerObject gsmsghandler;
void RegisterGMMsgHandler(const std::string& msgname,
void (*)(std::shared_ptr<f8::JsonHttpRequest>));
private:
void RegisterNetMsgHandlers();
void ProcGMMsg(unsigned long saddr, int sockhandle,
const std::string& url, const std::string& quyerstr);
std::map<std::string, void (*)(std::shared_ptr<f8::JsonHttpRequest>)> gmhandlers_;
};

View File

@ -0,0 +1,191 @@
#include "precompile.h"
#include <a8/sysutils.h>
#include <a8/mutable_xobject.h>
#include <a8/awaiter.h>
#include <a8/promise.h>
#include <f8/udplog.h>
#include <f8/jsonhttprequest.h>
#include "httpproxy.h"
#include "app.h"
#include "jsondatamgr.h"
#include "handlermgr.h"
#include "f8/httpclientpool.h"
struct HttpProxyRequest
{
std::string req_id;
f8::HttpProxyCb cb;
std::string url;
a8::XObject url_params;
long long add_tick = 0;
};
class HttpProxyPromise : public a8::Promise
{
public:
HttpProxyPromise(const char* url, a8::XObject url_params, bool* ret, std::shared_ptr<a8::XObject>* rsp)
{
url_ = url;
url_params_ = url_params;
ret_ = ret;
rsp_ = rsp;
}
protected:
virtual void DoAwait() override
{
f8::HttpClientPool::Instance()->HttpGet
(
[this, _self = shared_from_this()]
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
{
*ret_ = ok;
if (ok) {
**rsp_ = *rsp_obj;
}
DoDone();
},
url_.c_str(),
url_params_,
rand() % MAX_SYS_HTTP_NUM
);
}
private:
std::string url_;
a8::XObject url_params_;
bool* ret_ = nullptr;
std::shared_ptr<a8::XObject>* rsp_ = nullptr;
};
static void _ProxyCallback(std::shared_ptr<f8::JsonHttpRequest> request)
{
#ifdef DEBUG
f8::UdpLog::Instance()->Debug("ProxyCallbBack request:%s",
{
request->params->ToJsonStr()
});
#endif
std::string seq_id = request->params->Get("seq_id");
std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(seq_id);
if (req) {
a8::XObject data;
data.ReadFromJsonString(request->params->Get("data").GetString());
if (data.GetType() == a8::XOT_SIMPLE) {
data.ReadFromJsonString("{}");
}
f8::HttpContext ctx;
if (request->params->HasKey("errcode") &&
request->params->Get("errcode").GetInt() == 0) {
req->cb(true, &data, &ctx);
} else {
req->cb(false, request->params.get(), &ctx);
}
HttpProxy::Instance()->DestoryRequest(req);
}
}
void HttpProxy::Init()
{
request_prefix_ = "game2006_" + a8::XValue(a8::GetMilliSecond()).GetString() + "_";
HandlerMgr::Instance()->RegisterGMMsgHandler("Proxy@callback", _ProxyCallback);
}
void HttpProxy::UnInit()
{
}
std::string HttpProxy::HttpGet(
f8::HttpProxyCb cb,
const char* url,
a8::XObject url_params
)
{
std::shared_ptr<HttpProxyRequest> request = std::make_shared<HttpProxyRequest>();
request->req_id = CreateRequestId();
request->cb = cb;
request->url = url;
request->url_params = url_params;
request->add_tick = a8::XGetTickCount();
if (request_hash_.find(request->req_id) != request_hash_.end()) {
abort();
}
request_hash_[request->req_id] = request;
auto proxy_url_params = a8::MutableXObject::CreateObject();
proxy_url_params->SetVal("seq_id", request->req_id);
proxy_url_params->SetVal("target_url", std::string(url));
proxy_url_params->SetVal("params", url_params.ToJsonStr());
proxy_url_params->SetVal("cb_url", a8::Format("http://%s:%d/webapp/index.php?c=Proxy&a=callback",
{
JsonDataMgr::Instance()->ip,
JsonDataMgr::Instance()->listen_port
}));
std::string proxy_url;
JsonDataMgr::Instance()->GetHttpProxyUrl(proxy_url);
f8::HttpClientPool::Instance()->HttpGet
(
[request] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
{
long long cost_time = a8::XGetTickCount() - request->add_tick;
if (ok) {
#ifdef DEBUG
f8::UdpLog::Instance()->Debug("ProxyHttpGet ok cost_time:%d url:%s params:%s",
{
cost_time,
request->url,
request->url_params.ToJsonStr(),
});
#endif
} else {
f8::UdpLog::Instance()->Warning("ProxyHttpGet error cost_time:%d url:%s params:%s response:%s",
{
cost_time,
request->url,
request->url_params.ToJsonStr(),
ctx->response
});
request->cb(false, rsp_obj, ctx);
HttpProxy::Instance()->DestoryRequest(request);
}
},
proxy_url.c_str(),
*proxy_url_params,
rand() % MAX_SYS_HTTP_NUM
);
return request->req_id;
}
std::string HttpProxy::CreateRequestId()
{
return request_prefix_ + a8::XValue(App::Instance()->NewUuid()).GetString();
}
std::shared_ptr<HttpProxyRequest> HttpProxy::GetRequest(const std::string& req_id)
{
auto itr = request_hash_.find(req_id);
return itr != request_hash_.end() ? itr->second : nullptr;
}
void HttpProxy::DestoryRequest(std::shared_ptr<HttpProxyRequest> request)
{
request_hash_.erase(request->req_id);
}
std::shared_ptr<a8::Awaiter> HttpProxy::CoHttpGet(const char* url,
a8::XObject url_params,
bool* ret,
std::shared_ptr<a8::XObject>* rsp)
{
*ret = false;
*rsp = std::make_shared<a8::XObject>();
return std::make_shared<HttpProxyPromise>(url, url_params, ret, rsp);
}

View File

@ -0,0 +1,46 @@
#pragma once
#include <a8/singleton.h>
#include "f8/httpclientpool.h"
namespace a8
{
class Awaiter;
}
struct HttpProxyRequest;
class HttpProxy : public a8::Singleton<HttpProxy>
{
private:
HttpProxy() {};
friend class a8::Singleton<HttpProxy>;
public:
void Init();
void UnInit();
std::string HttpGet(
f8::HttpProxyCb cb,
const char* url,
a8::XObject url_params
);
std::shared_ptr<HttpProxyRequest> GetRequest(const std::string& req_id);
void DestoryRequest(std::shared_ptr<HttpProxyRequest> request);
std::shared_ptr<a8::Awaiter> CoHttpGet(const char* url,
a8::XObject url_params,
bool* ret,
std::shared_ptr<a8::XObject>* rsp);
private:
std::string CreateRequestId();
private:
std::map<std::string, std::shared_ptr<HttpProxyRequest>> request_hash_;
std::string request_prefix_;
};

View File

@ -0,0 +1,56 @@
#include "precompile.h"
#include "iomgr.h"
static const int IC_Max = 4;
void IoMgr::Init()
{
for (int i = 0; i < IC_Max; ++i) {
io_contexts_.push_back(std::vector<std::shared_ptr<asio::io_context>>());
io_works_.push_back(std::vector<std::shared_ptr<asio::io_context::work>>());
auto& contexts = io_contexts_.at(i);
auto& works = io_works_.at(i);
auto c = std::make_shared<asio::io_context>();
auto w = std::make_shared<asio::io_context::work>(*c);
works.push_back(w);
contexts.push_back(c);
new std::thread(&IoMgr::WorkerThreadProc, this, contexts.at(0));
}
}
void IoMgr::UnInit()
{
}
void IoMgr::Update()
{
#if 0
for (auto type_io_contexts : io_contexts_) {
for (auto io_context : type_io_contexts) {
io_context->poll();
}
}
#endif
}
std::shared_ptr<asio::io_context> IoMgr::GetIoContext(int type)
{
if (type >= 0 && type < io_contexts_.size()) {
auto& contexts = io_contexts_.at(type);
if (!contexts.empty()) {
return contexts.at(rand() % contexts.size());
}
}
return nullptr;
}
void IoMgr::WorkerThreadProc(std::shared_ptr<asio::io_context> io_context)
{
while (true) {
io_context->run();
a8::XPrintf("2222222\n", {});
io_context->reset();
}
}

View File

@ -0,0 +1,27 @@
#pragma once
#include <a8/singleton.h>
#include <asio.hpp>
class IoMgr : public a8::Singleton<IoMgr>
{
private:
IoMgr() {};
friend class a8::Singleton<IoMgr>;
public:
void Init();
void UnInit();
void Update();
std::shared_ptr<asio::io_context> GetIoContext(int type);
private:
void WorkerThreadProc(std::shared_ptr<asio::io_context> io_context);
private:
std::vector<std::vector<std::shared_ptr<asio::io_context::work>>> io_works_;
std::vector<std::vector<std::shared_ptr<asio::io_context>>> io_contexts_;
};

View File

@ -0,0 +1,125 @@
#include "precompile.h"
#include "jsondatamgr.h"
#include "app.h"
#include <f8/utils.h>
#include <f8/udplog.h>
void JsonDataMgr::Init()
{
if (!f8::IsOnlineEnv()) {
if (f8::IsTestEnv()) {
work_path_ = a8::Format("../../../conf_test/game%d/gameserver.test",
{
GAME_ID
});
} else {
work_path_ = a8::Format("../../../conf_test/game%d/gameserver.dev",
{
GAME_ID
});
}
}
std::string gameserver_cluster_json_file;
std::string setting_json_file;
std::string httpproxy_json_file;
gameserver_cluster_json_file = a8::Format("%s/node%d/game%d.gameserver.cluster.json",
{
work_path_,
App::Instance()->node_id,
GAME_ID
});
setting_json_file = a8::Format("%s/setting.json",
{
work_path_,
});
httpproxy_json_file = a8::Format("%s/httpproxy.cluster.json",
{
work_path_,
});
gameserver_cluster_json_.ReadFromFile(gameserver_cluster_json_file);
setting_json_.ReadFromFile(setting_json_file);
httpproxy_cluster_json_.ReadFromFile(httpproxy_json_file);
if (setting_json_.GetType() == a8::XOT_OBJECT &&
setting_json_.HasKey("api_url")) {
api_url_ = setting_json_.Get("api_url").GetString();
}
ip = GetConf()->At("ip")->AsXValue().GetString();
listen_port = GetConf()->At("listen_port")->AsXValue();
if (GetConf()->HasKey("channel")) {
channel = GetConf()->At("channel")->AsXValue();
}
#ifdef DEBUG
if (!f8::IsOnlineEnv()) {
if (!f8::IsTestEnv()) {
bool ok = a8::GetLocalIp(ip);
if (getenv("HOST_IP")) {
ip = getenv("HOST_IP");
}
if (!ok) {
A8_ABORT();
}
}
}
#endif
server_info = a8::Format("%s:%d", {ip, listen_port});
Reload();
f8::UdpLog::Instance()->Info("api_url:%s",
{
api_url_
});
}
void JsonDataMgr::UnInit()
{
}
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
{
for (int i = 0; i < gameserver_cluster_json_.Size(); ++i) {
std::shared_ptr<a8::XObject> conf = gameserver_cluster_json_.At(i);
if (conf->At("instance_id")->AsXValue().GetInt() == App::Instance()->instance_id) {
return conf;
}
}
A8_ABORT();
}
std::shared_ptr<a8::XObject> JsonDataMgr::GetMasterServerClusterConf()
{
return std::make_shared<a8::XObject>(masterserver_cluster_json_);
}
void JsonDataMgr::Reload()
{
std::string masterserver_cluster_json_file;
masterserver_cluster_json_file = a8::Format("%s/node%d/game%d.masterserver.cluster.json",
{
work_path_,
App::Instance()->node_id,
GAME_ID
});
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
}
void JsonDataMgr::GetApiUrl(std::string& url)
{
if (!api_url_.empty()) {
url = api_url_;
}
}
void JsonDataMgr::GetHttpProxyUrl(std::string& url)
{
url = "http://192.168.100.21:8321/webapp/index.php?c=Proxy&a=get";
return;
if (httpproxy_cluster_json_.Size() > 0) {
std::shared_ptr<a8::XObject> conf = httpproxy_cluster_json_.At(0);
url = conf->At("url")->AsXValue().GetString();
}
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <a8/singleton.h>
class JsonDataMgr : public a8::Singleton<JsonDataMgr>
{
private:
JsonDataMgr() {};
friend class a8::Singleton<JsonDataMgr>;
public:
void Init();
void UnInit();
std::shared_ptr<a8::XObject> GetConf();
std::shared_ptr<a8::XObject> GetMasterServerClusterConf();
std::string ip;
int listen_port = 0;
int channel = 0;
std::string server_info;
void Reload();
void GetApiUrl(std::string& url);
void GetHttpProxyUrl(std::string& url);
private:
std::string api_url_;
private:
std::string work_path_ = "../config";
a8::XObject setting_json_;
a8::XObject gameserver_cluster_json_;
a8::XObject masterserver_cluster_json_;
a8::XObject httpproxy_cluster_json_;
};

View File

@ -0,0 +1,320 @@
#include "precompile.h"
#include "lispenv.h"
#include "buff.h"
#if 0
#include "netdata.h"
#include "creature.h"
#include "glmhelper.h"
#include "room.h"
#endif
#include "mt/Skill.h"
#include "mt/SkillNumber.h"
class SkillScope : public a8::lisp::GlobalScope
{
public:
void Init()
{
#if 0
RegisterCProc
(
"!getSkillNumber",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0;
if (params->size() != 1) {
abort();
}
a8::lisp::Atom atom = std::any_cast<a8::lisp::Atom>(params->at(0)->value);
int idx = atom.val;
result = context_.buff->skill_meta->_number_meta->GetAttrByIdx(idx);
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"buff.get_buff_var",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0;
if (params->size() != 1) {
abort();
}
a8::lisp::Atom atom = std::any_cast<a8::lisp::Atom>(params->at(0)->value);
int idx = atom.val;
result = context_.buff->buff_vars->at(idx);
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"entity.get_pos_x",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
a8::lisp::Atom atom = std::any_cast<a8::lisp::Atom>(params->at(0)->value);
Entity* e = context_.buff->owner->room->GetEntityByUniId(atom.val);
if (!e) {
abort();
}
double result = e->GetPos().GetX();
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"entity.get_pos_y",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
a8::lisp::Atom atom = std::any_cast<a8::lisp::Atom>(params->at(0)->value);
Entity* e = context_.buff->owner->room->GetEntityByUniId(atom.val);
if (!e) {
abort();
}
double result = e->GetPos().GetY();
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"entity.get_pos_z",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
a8::lisp::Atom atom = std::any_cast<a8::lisp::Atom>(params->at(0)->value);
Entity* e = context_.buff->owner->room->GetEntityByUniId(atom.val);
if (!e) {
abort();
}
double result = e->GetPos().GetZ();
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"myself.get_hero_atk",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = context_.buff->owner->GetBattleContext()->GetHeroTotalAtk();
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"myself.get_max_hp",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = context_.buff->owner->GetMaxHP();
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_hero_atk",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
result = context_.buff->GetCaster().Get()->GetBattleContext()->GetHeroTotalAtk();
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_skill_recover_effect",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
context_.buff->GetCaster().Get()->GetBattleContext()->GetRecoverHpAdd();
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_skill_distance",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
result = GlmHelper::Norm(context_.buff->owner->context_real_pos -
context_.buff->owner->GetPos().ToGlmVec3());
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_skill_raycast_distance",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
result = context_.buff->GetCaster().Get()->GetSkillRaycastDistance();
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_skill_pos_x",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
result = context_.buff->GetCaster().Get()->skill_pos.x;
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_skill_pos_y",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
result = context_.buff->GetCaster().Get()->skill_pos.y;
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_skill_pos_z",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
result = context_.buff->GetCaster().Get()->skill_pos.z;
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_skill_target_pos_x",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
result = context_.buff->GetCaster().Get()->context_pos.GetX();
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_skill_target_pos_y",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
result = context_.buff->GetCaster().Get()->context_pos.GetY();
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
RegisterCProc
(
"caster.get_skill_target_pos_z",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{
double result = 0.0f;
if (context_.buff->GetCaster().Get()) {
result = context_.buff->GetCaster().Get()->context_pos.GetZ();
}
return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
});
#endif
}
float Eval(std::shared_ptr<a8::lisp::Value> expr,
Buff* buff)
{
context_.buff = buff;
auto result = a8::lisp::Expr::Eval(expr, shared_from_this());
context_.buff = nullptr;
if (!result) {
abort();
}
if (!result->IsType(a8::lisp::ValueType::kAtom)) {
abort();
}
auto&& atom = std::any_cast<a8::lisp::Atom>(result->value);
return atom.val;
}
std::shared_ptr<a8::lisp::Value> Compile(const std::string& script)
{
auto expr = a8::lisp::Expr::Compile(script, shared_from_this());
if (!expr) {
abort();
}
if (!expr->IsType(a8::lisp::ValueType::kList)) {
abort();
}
Transform(nullptr, expr);
a8::XPrintf("script:%s ast:%s\n", {script, expr->ToXObject().ToJsonStr()});
return expr;
}
void Transform(std::shared_ptr<a8::lisp::Value> parent_node, std::shared_ptr<a8::lisp::Value> node)
{
if (node->IsType(a8::lisp::ValueType::kSymbol)) {
auto func_call_exprs = std::make_shared<a8::lisp::List::element_type>();
auto&& symbol = std::any_cast<a8::lisp::Symbol>(node->value);
int idx = mt::SkillNumber::GetAttrIdxByName(symbol.name);
if (idx < 0) {
abort();
} else {
{
auto cproc = Find("!getSkillNumber");
if (!cproc) {
abort();
}
if (!cproc->IsType(a8::lisp::ValueType::kCProc)) {
abort();
}
func_call_exprs->push_back(cproc);
func_call_exprs->push_back
(std::make_shared<a8::lisp::Value>(a8::lisp::Atom(idx)));
}
}
if (parent_node &&
parent_node->IsType(a8::lisp::ValueType::kList) &&
std::any_cast<a8::lisp::List>(parent_node->value)->size() == 1
) {
parent_node->Assign(func_call_exprs);
} else {
node->Assign(func_call_exprs);
}
} else if (node->IsType(a8::lisp::ValueType::kList)) {
auto list = std::any_cast<a8::lisp::List>(node->value);
for (auto child_node : *list) {
Transform(node, child_node);
}
}
}
private:
struct {
Buff* buff = nullptr;
} context_;
};
void LispEnv::Init()
{
skill_env_ = std::make_shared<SkillScope>();
skill_env_->Init();
}
void LispEnv::UnInit()
{
}
std::shared_ptr<a8::lisp::Value> LispEnv::CompileSkillNumberExpr(const std::string& script)
{
return skill_env_->Compile(script);
}
float LispEnv::EvalSkillNumberExpr(std::shared_ptr<a8::lisp::Value> expr,
Buff* buff)
{
return skill_env_->Eval(expr, buff);
}

View File

@ -0,0 +1,29 @@
#pragma once
#include <a8/singleton.h>
#include <a8/lisp.h>
class Buff;
class Creature;
class SkillScope;
class LispEnv : public a8::Singleton<LispEnv>
{
private:
LispEnv() {};
friend class a8::Singleton<LispEnv>;
public:
void Init();
void UnInit();
std::shared_ptr<a8::lisp::Value> CompileSkillNumberExpr(const std::string& script);
float EvalSkillNumberExpr(std::shared_ptr<a8::lisp::Value> expr,
Buff* buff
);
private:
std::shared_ptr<SkillScope> skill_env_;
};

View File

@ -0,0 +1,12 @@
#include "precompile.h"
#include "app.h"
int main(int argc, char* argv[])
{
int exitcode = 0;
if (App::Instance()->Init(argc, argv)) {
exitcode = App::Instance()->Run();
App::Instance()->UnInit();
}
return exitcode;
}

View File

@ -0,0 +1,114 @@
#pragma once
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/euler_angles.hpp>
namespace mc
{
const float MAP_SCALE = 10;
enum ColliderType_e
{
kNoneCollider = 0,
kBoxCollider = 1,
kMeshCollider = 2
};
enum ColliderAssembly_e
{
kCA_Floor = 0,//地板
kCA_Wall = 1,//墙壁
kCA_Roof = 2,//屋顶
kCA_FloororRoof = 3,//屋顶+上层地板
kCA_Stairs = 4,//楼梯
kCA_Window = 9,//窗,主要为了射击穿透
kCA_Other = 10,//其他,装饰品
kCA_Grass = 19,//草,需要抖动
kCA_Water = 20,//水
kCA_Box = 21,//箱子
kCA_Shield = 22,//盾
kCA_WallShield = 23,//能量盾
kCA_Surface = 100,//地表
kCA_End
};
struct Bounds
{
glm::vec3 center = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 size = glm::vec3(0.0f, 0.0f, 0.0f);
};
struct ColliderNode;
struct Triangle
{
ColliderNode* node = nullptr;
glm::vec3 vert0 = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 vert1 = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 vert2 = glm::vec3(0.0f, 0.0f, 0.0f);
float min_y = 0.0f;
float max_y = 0.0f;
int check_flag = 0;
};
struct Transform
{
glm::vec3 local_position = glm::vec3(0.0f, 0.0f, 0.0f);
glm::quat local_rotation = glm::quat_identity<float, glm::qualifier::defaultp>();
glm::vec3 local_scale = glm::vec3(0.0f, 0.0f, 0.0f);
void Read(std::shared_ptr<a8::XObject> xobj);
};
struct Mesh
{
std::vector<glm::vec3> vertices;
std::vector<int> raw_triangles;
std::vector<Triangle> triangles;
Bounds bounds;
};
struct Collider
{
int type = kNoneCollider;
int ca_type = 0;
bool enabled = false;
bool is_trigger = false;
Bounds bounds;
virtual ~Collider() {};
virtual void Read(std::shared_ptr<a8::XObject> xobj){};
};
struct MeshCollider : public Collider
{
Mesh mesh;
virtual void Read(std::shared_ptr<a8::XObject> xobj) override {};
};
struct BoxCollider : public Collider
{
glm::vec3 center = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 size = glm::vec3(0.0f, 0.0f, 0.0f);
std::vector<Triangle> triangles;
virtual void Read(std::shared_ptr<a8::XObject> xobj) override {};
};
struct ColliderNode
{
ColliderNode* parent = nullptr;
std::string name;
Bounds bounds;
Transform transform;
std::vector<Collider*> colliders;
std::map<std::string, ColliderNode*> childs;
void Read(std::shared_ptr<a8::XObject> xobj){};
};
void RotateBounds(const glm::vec3& center,
const glm::vec3& size,
const glm::quat& quat,
std::vector<glm::vec3>& points);
};

1
server/robotserver/mt Symbolic link
View File

@ -0,0 +1 @@
../gameserver/mt

1
server/robotserver/mtb Symbolic link
View File

@ -0,0 +1 @@
../gameserver/mtb

View File

@ -0,0 +1,282 @@
#include "precompile.h"
#include <a8/awaiter.h>
#include <a8/promise.h>
#include <a8/websocketclient.h>
#include <f8/coroutine.h>
#include <f8/comgr.h>
#include <f8/udplog.h>
#include <f8/utils.h>
#include "player.h"
#include "app.h"
void Player::Update()
{
}
void Player::Init(int idx,
const std::string& account_id,
const std::string& session_id,
std::shared_ptr<a8::WebSocketClient> socket)
{
socket_handle_ = idx;
account_id_ = account_id;
session_id_ = session_id;
web_socket_ = socket;
web_socket_->on_error =
[this] (a8::WebSocketClient*,int err_code)
{
f8::UdpLog::Instance()->Warning
("WebSocketClient on_error %d", {err_code});
};
web_socket_->on_connect =
[this] (a8::WebSocketClient* )
{
net_connected_ = true;
f8::UdpLog::Instance()->Info
("WebSocketClient on_connect", {});
};
web_socket_->on_disconnect =
[this] (a8::WebSocketClient* )
{
f8::UdpLog::Instance()->Warning
("WebSocketClient on_disconnect", {});
};
web_socket_->on_decode_userpacket =
[this, socket_handle = GetSocketId()]
(char* buf, int& offset, unsigned int buflen)
{
bool warning = false;
while (buflen - offset >= sizeof(f8::PackHead)) {
f8::PackHead* p = (f8::PackHead*)&buf[offset];
if (p->magic_code == f8::MAGIC_CODE) {
if (buflen - offset < sizeof(f8::PackHead) + p->packlen) {
break;
}
App::Instance()->AddSocketMsg
(SF_GameServer,
socket_handle,
//p->ip_saddr,
0,
p->msgid,
p->seqid,
&buf[offset + sizeof(f8::PackHead)],
p->packlen);
offset += sizeof(f8::PackHead) + p->packlen;
} else {
warning = true;
offset++;
continue;
}
}
if (warning) {
f8::UdpLog::Instance()->Warning("收到client非法数据包", {});
}
};
f8::CoMgr::Instance()->CreateCo
(
[this] (f8::Coroutine* co)
{
CoGame(co);
});
}
void Player::CoGame(f8::Coroutine* co)
{
{
web_socket_->Open();
while (!net_connected_) {
co->CoYield();
}
f8::UdpLog::Instance()->Info
("WebSocketClient on_connect ok", {});
}
{
cs::CMJoin msg;
msg.set_server_id(6);
msg.set_account_id(account_id_);
msg.set_session_id(session_id_);
msg.set_hero_id(30800);
SendMsg(msg);
}
{
while (!join_ok_) {
co->CoYield();
}
f8::UdpLog::Instance()->Info
("join ok", {});
}
{
int seq_id = 0;
long long last_ping_tick = a8::XGetTickCount();
long long last_cmmove_tick = a8::XGetTickCount();
while (true) {
long long tick = a8::XGetTickCount();
if (tick - last_ping_tick > 1000) {
cs::CMPing msg;
SendMsg(msg);
last_ping_tick = tick;
}
if (tick - last_cmmove_tick >= 100) {
cs::CMMove msg;
msg.set_seq(++seq_id);
SendMsg(msg);
last_cmmove_tick = tick;
}
co->CoYield();
}
}
}
void Player::InternalSendMsg(int msgid, ::google::protobuf::Message& msg)
{
int packlen = msg.ByteSize();
char* buff = (char*)malloc(sizeof(f8::PackHead) + packlen);
f8::PackHead* head = (f8::PackHead*)buff;
head->packlen = packlen;
head->msgid = msgid;
head->magic_code = f8::MAGIC_CODE;
msg.SerializeToArray(buff + sizeof(f8::PackHead), packlen);
web_socket_->SendBuff(buff, sizeof(f8::PackHead) + packlen);
}
void Player::_SMKcpHandshake(f8::MsgHdr& hdr, const cs::SMKcpHandshake& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMPing(f8::MsgHdr& hdr, const cs::SMPing& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMRpcError(f8::MsgHdr& hdr, const cs::SMRpcError& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMReconnect(f8::MsgHdr& hdr, const cs::SMReconnect& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMWatchWar(f8::MsgHdr& hdr, const cs::SMWatchWar& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMLeave(f8::MsgHdr& hdr, const cs::SMLeave& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMMatchCancel(f8::MsgHdr& hdr, const cs::SMMatchCancel& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMJoinedNotify(f8::MsgHdr& hdr, const cs::SMJoinedNotify& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
join_ok_ = true;
}
void Player::_SMMapInfo(f8::MsgHdr& hdr, const cs::SMMapInfo& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMUpdate(f8::MsgHdr& hdr, const cs::SMUpdate& msg)
{
//f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMRollMsg(f8::MsgHdr& hdr, const cs::SMRollMsg& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMVoiceNotify(f8::MsgHdr& hdr, const cs::SMVoiceNotify& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMDisconnectNotify(f8::MsgHdr& hdr, const cs::SMDisconnectNotify& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMGameOver(f8::MsgHdr& hdr, const cs::SMGameOver& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMDebugMsg(f8::MsgHdr& hdr, const cs::SMDebugMsg& msg)
{
//f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMUiUpdate(f8::MsgHdr& hdr, const cs::SMUiUpdate& msg)
{
//f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMGameStart(f8::MsgHdr& hdr, const cs::SMGameStart& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMSysPiaoMsg(f8::MsgHdr& hdr, const cs::SMSysPiaoMsg& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMShowCountdown(f8::MsgHdr& hdr, const cs::SMShowCountdown& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMShowTeamUI(f8::MsgHdr& hdr, const cs::SMShowTeamUI& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMUpdateMatchInfo(f8::MsgHdr& hdr, const cs::SMUpdateMatchInfo& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMGetItemNotify(f8::MsgHdr& hdr, const cs::SMGetItemNotify& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMMatchMemberMsgNotify(f8::MsgHdr& hdr, const cs::SMMatchMemberMsgNotify& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMPvePassWave(f8::MsgHdr& hdr, const cs::SMPvePassWave& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMTeamMarkTargetPosList(f8::MsgHdr& hdr, const cs::SMTeamMarkTargetPosList& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMDebugCmd(f8::MsgHdr& hdr, const cs::SMDebugCmd& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}
void Player::_SMNewBieEnd(f8::MsgHdr& hdr, const cs::SMNewBieEnd& msg)
{
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
}

View File

@ -0,0 +1,84 @@
#pragma once
#include <f8/protoutils.h>
#include "cs_proto.pb.h"
namespace a8
{
class WebSocketClient;
}
namespace f8
{
class Coroutine;
}
class Player
{
public:
enum { HID = HID_Player };
public:
void Update();
void Init(int idx,
const std::string& account_id,
const std::string& session_id,
std::shared_ptr<a8::WebSocketClient> socket);
template <typename T>
void SendMsg(T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
InternalSendMsg(msgid, msg);
}
int GetSocketId() { return socket_handle_; }
bool NetConnected() { return net_connected_; }
const std::string& GetAccountId() { return account_id_; }
auto GetWebSocket() { return web_socket_; }
void _SMKcpHandshake(f8::MsgHdr& hdr, const cs::SMKcpHandshake& msg);
void _SMPing(f8::MsgHdr& hdr, const cs::SMPing& msg);
void _SMRpcError(f8::MsgHdr& hdr, const cs::SMRpcError& msg);
void _SMReconnect(f8::MsgHdr& hdr, const cs::SMReconnect& msg);
void _SMWatchWar(f8::MsgHdr& hdr, const cs::SMWatchWar& msg);
void _SMLeave(f8::MsgHdr& hdr, const cs::SMLeave& msg);
void _SMMatchCancel(f8::MsgHdr& hdr, const cs::SMMatchCancel& msg);
void _SMJoinedNotify(f8::MsgHdr& hdr, const cs::SMJoinedNotify& msg);
void _SMMapInfo(f8::MsgHdr& hdr, const cs::SMMapInfo& msg);
void _SMUpdate(f8::MsgHdr& hdr, const cs::SMUpdate& msg);
void _SMRollMsg(f8::MsgHdr& hdr, const cs::SMRollMsg& msg);
void _SMVoiceNotify(f8::MsgHdr& hdr, const cs::SMVoiceNotify& msg);
void _SMDisconnectNotify(f8::MsgHdr& hdr, const cs::SMDisconnectNotify& msg);
void _SMGameOver(f8::MsgHdr& hdr, const cs::SMGameOver& msg);
void _SMDebugMsg(f8::MsgHdr& hdr, const cs::SMDebugMsg& msg);
void _SMUiUpdate(f8::MsgHdr& hdr, const cs::SMUiUpdate& msg);
void _SMGameStart(f8::MsgHdr& hdr, const cs::SMGameStart& msg);
void _SMSysPiaoMsg(f8::MsgHdr& hdr, const cs::SMSysPiaoMsg& msg);
void _SMShowCountdown(f8::MsgHdr& hdr, const cs::SMShowCountdown& msg);
void _SMShowTeamUI(f8::MsgHdr& hdr, const cs::SMShowTeamUI& msg);
void _SMUpdateMatchInfo(f8::MsgHdr& hdr, const cs::SMUpdateMatchInfo& msg);
void _SMGetItemNotify(f8::MsgHdr& hdr, const cs::SMGetItemNotify& msg);
void _SMMatchMemberMsgNotify(f8::MsgHdr& hdr, const cs::SMMatchMemberMsgNotify& msg);
void _SMPvePassWave(f8::MsgHdr& hdr, const cs::SMPvePassWave& msg);
void _SMTeamMarkTargetPosList(f8::MsgHdr& hdr, const cs::SMTeamMarkTargetPosList& msg);
void _SMDebugCmd(f8::MsgHdr& hdr, const cs::SMDebugCmd& msg);
void _SMNewBieEnd(f8::MsgHdr& hdr, const cs::SMNewBieEnd& msg);
private:
void CoGame(f8::Coroutine* co);
void InternalSendMsg(int msgid, ::google::protobuf::Message& msg);
private:
int socket_handle_ = 0;
std::string account_id_;
std::string session_id_;
std::string remote_ip_;
int remote_port_ = 0;
bool net_connected_ = false;
bool join_ok_ = false;
std::shared_ptr<a8::WebSocketClient> web_socket_;
};

View File

@ -0,0 +1,128 @@
#include "precompile.h"
#include <a8/websocketclient.h>
#include <a8/mutable_xobject.h>
#include <f8/udplog.h>
#include <f8/utils.h>
#include <f8/msgqueue.h>
#include <f8/comgr.h>
#include <f8/coroutine.h>
#include "playermgr.h"
#include "player.h"
#include "httpproxy.h"
#include "iomgr.h"
#include "app.h"
void PlayerMgr::Init()
{
for (int i = 1; i <= App::Instance()->robot_num; ++i) {
f8::CoMgr::Instance()->CreateCo
(
[this, i] (f8::Coroutine* co)
{
CoWebLogin(i, co);
});
}
}
void PlayerMgr::UnInit()
{
}
void PlayerMgr::Update()
{
for (auto& pair : account_id_hash_) {
pair.second->Update();
}
}
void PlayerMgr::CoWebLogin(int idx, f8::Coroutine* co)
{
std::string account_id;
std::string session_id;
{
bool ret = false;
auto url_params = a8::MutableXObject::CreateObject();
url_params->SetVal("c", "Login");
url_params->SetVal("a", "auth");
url_params->SetVal("gameid", 2006);
url_params->SetVal("channel", 6513);
url_params->SetVal("openid", idx);
std::shared_ptr<a8::XObject> rsp;
co->CoAwait
(HttpProxy::Instance()->CoHttpGet
(
"https://login-test.kingsome.cn/webapp/index.php",
*url_params,
&ret,
&rsp
)
);
if (ret) {
auto rsp_obj = a8::XObject();
rsp_obj.ReadFromJsonString(rsp->ToJsonStr());
account_id = rsp_obj.At("account_id")->AsXValue().GetString();
session_id = rsp_obj.At("session_id")->AsXValue().GetString();
a8::XPrintf("rsp:%s\n", {rsp->ToJsonStr()});
} else {
abort();
}
}
{
bool ret = false;
auto url_params = a8::MutableXObject::CreateObject();
url_params->SetVal("c", "User");
url_params->SetVal("a", "login");
url_params->SetVal("account_id", account_id);
url_params->SetVal("session_id", session_id);
std::shared_ptr<a8::XObject> rsp;
co->CoAwait
(HttpProxy::Instance()->CoHttpGet
(
"https://game2006api-test.kingsome.cn/webapp/index.php",
*url_params,
&ret,
&rsp
)
);
if (ret) {
auto rsp_obj = a8::XObject();
rsp_obj.ReadFromJsonString(rsp->ToJsonStr());
a8::XPrintf("rsp:%s\n", {rsp->ToJsonStr()});
} else {
abort();
}
}
CoCreatePlayer(co, idx, account_id, session_id);
}
void PlayerMgr::CoCreatePlayer(f8::Coroutine* co,
int idx,
const std::string& account_id,
const std::string& session_id)
{
auto socket = std::make_shared<a8::WebSocketClient>
(
IoMgr::Instance()->GetIoContext(0),
"192.168.100.21",
7601
);
auto hum = std::make_shared<Player>();
hum->Init(idx, account_id, session_id, socket);
account_id_hash_[hum->GetAccountId()] = hum;
socket_id_hash_[hum->GetSocketId()] = hum;
}
std::shared_ptr<Player> PlayerMgr::GetPlayerByAccountId(const std::string& account_id)
{
auto itr = account_id_hash_.find(account_id);
return itr != account_id_hash_.end() ? itr->second : nullptr;
}
std::shared_ptr<Player> PlayerMgr::GetPlayerBySocketHandle(int socket_handle)
{
auto itr = socket_id_hash_.find(socket_handle);
return itr != socket_id_hash_.end() ? itr->second : nullptr;
}

View File

@ -0,0 +1,33 @@
#pragma once
#include <a8/singleton.h>
class Player;
class PlayerMgr : public a8::Singleton<PlayerMgr>
{
public:
enum { HID = HID_PlayerMgr };
private:
PlayerMgr() {};
friend class a8::Singleton<PlayerMgr>;
public:
void Init();
void UnInit();
void Update();
std::shared_ptr<Player> GetPlayerByAccountId(const std::string& account_id);
std::shared_ptr<Player> GetPlayerBySocketHandle(int socket_handle);
private:
void CoWebLogin(int idx, f8::Coroutine* co);
void CoCreatePlayer(f8::Coroutine* co,
int idx,
const std::string& account_id,
const std::string& session_id);
private:
std::map<int, std::shared_ptr<Player>> socket_id_hash_;
std::map<std::string, std::shared_ptr<Player>> account_id_hash_;
};

View File

@ -0,0 +1,13 @@
#pragma once
#include <a8/a8.h>
#include <f8/f8.h>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include "constant.h"
#include "constant_export.h"
#include "types.h"
#include "mt/Forward.h"
#include "global.h"

View File

@ -0,0 +1,27 @@
#pragma once
class Bullet;
class Creature;
class RoomObstacle;
class SkillHelper
{
public:
static void Init();
static void GetMagicIdAndBaseSkillId(int skill_id, int& magic_id, int& base_skill_id) {};
//医疗站
static int GetYlzRange(const mt::Skill* skill_meta);
static int GetYlzRecoverHp(Creature* sender, Creature* target, const mt::Skill* skill_meta);
static int GetYlzDamage(Creature* sender, Creature* target, const mt::Skill* skill_meta);
static void ProcBulletHitBuff(IBullet* bullet, Creature* c, int buff_uniid);
static bool ProcBulletDmg(IBullet* bullet, Creature* target, float& finaly_dmg);
static void ProcSummonObstacle(const mt::Skill* skill_meta, RoomObstacle* ob);
private:
static std::map<int, int> magic_skill_hash_;
static std::map<int, int> skill_magic_hash_;
};

View File

@ -0,0 +1,5 @@
#include "precompile.h"
#include <math.h>
#include <glm/gtc/matrix_transform.hpp>

View File

@ -0,0 +1,20 @@
#pragma once
class IBullet
{
public:
//virtual const Position& GetPos() = 0;
virtual const glm::vec3& GetDir() = 0;
virtual float GetStrengthenWall() = 0;
virtual long long GetWeaponUniId() = 0;
//virtual const mt::Skill* GetSkillMeta() = 0;
//virtual const mt::Equip* GetGunMeta() = 0;
//virtual const mt::Equip* GetBulletMeta() = 0;
//virtual CreatureWeakPtr GetSender() = 0;
//virtual CreatureWeakPtr GetPassenger() = 0;
virtual bool IsBomb() = 0;
virtual bool IsPreBattleBullet() = 0;
//virtual Room* GetRoom() = 0;
virtual float GetHitRadius() = 0;
virtual void ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos) = 0;
};

2
third_party/a8 vendored

@ -1 +1 @@
Subproject commit 73a4706673d6b773ca2e5cf102c45e0f2245aa5b
Subproject commit 261a025565fb8ad5977c3376a9bebf58239a6e98

2
third_party/f8 vendored

@ -1 +1 @@
Subproject commit f856de73d2a3087289495690e3ea9bd7b1aa79ef
Subproject commit 0b0158805fcdfaaf336f10a99f8f4f7421f28aa4