This commit is contained in:
aozhiwei 2020-05-02 21:26:10 +08:00
parent eed8c1d256
commit f5a00b3142
7 changed files with 21 additions and 210 deletions

View File

@ -1,13 +1,6 @@
project(masterserver)
project(friend_masterserver)
cmake_minimum_required(VERSION 2.8)
if (${GAME_ID})
message(GAME_ID: ${GAME_ID})
else()
set(GAME_ID 2001)
message(GAME_ID: ${GAME_ID})
endif()
if (${RELEASE})
set(CMAKE_BUILD_TYPE "Release")
message("release mode")
@ -15,8 +8,8 @@ else()
set(CMAKE_BUILD_TYPE "Debug")
message("debug mode")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -std=gnu++11 -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DDEBUG")
include_directories(
AFTER
@ -70,7 +63,7 @@ set(EXECUTABLE_OUTPUT_PATH
)
add_executable(
masterserver${GAME_ID} ${SRC_LIST}
friend_masterserver ${SRC_LIST}
)
add_custom_target(script_pb_protocol ALL)
@ -78,12 +71,12 @@ add_custom_command(TARGET script_pb_protocol
PRE_BUILD
COMMAND python ../../third_party/tools/scripts/construct/build_pb.py --cpp_out=. --pb_files=ss_proto,ss_msgid --nohooks 1
)
add_dependencies(masterserver${GAME_ID} script_pb_protocol)
add_dependencies(friend_masterserver script_pb_protocol)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_libraries(
masterserver${GAME_ID}
friend_masterserver
pthread
mysqlclient
protobuf
@ -101,7 +94,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
)
else()
target_link_libraries(
masterserver${GAME_ID}
friend_masterserver
pthread
mysqlclient
protobuf

View File

@ -59,30 +59,20 @@ static void SavePerfLog()
void App::Init(int argc, char* argv[])
{
#if 0
{
Vector2D dir;
dir.Normalize();
}
#endif
signal(SIGPIPE, SIG_IGN);
this->argc = argc;
this->argv = argv;
if (!ParseOpt()) {
terminated = true;
if (node_id <= 0) {
a8::XPrintf("gameserver启动失败,缺少-n参数\n", {});
} else if (node_id > MAX_NODE_ID) {
a8::XPrintf("gameserver启动失败,-n参数不能大于%d\n", {MAX_NODE_ID});
} else if (instance_id <= 0) {
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
if (instance_id <= 0) {
a8::XPrintf("friend_masterserver启动失败,缺少-i参数\n", {});
} else if (instance_id > MAX_INSTANCE_ID) {
a8::XPrintf("gameserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
a8::XPrintf("friend_masterserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
}
return;
}
a8::XPrintf("masterserver starting instance_id:%d pid:%d game_id:%d\n", {instance_id, getpid(), GAME_ID});
a8::XPrintf("masterserver starting instance_id:%d pid:%d\n", {instance_id, getpid()});
loop_mutex_ = new std::mutex();
loop_cond_ = new std::condition_variable();
@ -94,9 +84,9 @@ void App::Init(int argc, char* argv[])
HandlerMgr::Instance()->Init();
a8::Timer::Instance()->Init();
f8::MsgQueue::Instance()->Init();
f8::TGLog::Instance()->Init(a8::Format(PROJ_NAME_FMT, {GAME_ID}), false);
f8::TGLog::Instance()->Init(a8::Format(PROJ_NAME_FMT, {}), false);
JsonDataMgr::Instance()->Init();
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
uuid.SetMachineId(instance_id);
GGListener::Instance()->Init();
GSMgr::Instance()->Init();
@ -390,10 +380,10 @@ 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 proj_root_dir = a8::Format(PROJ_ROOT_FMT, {a8::Format(PROJ_NAME_FMT,{})});
std::string proj_log_root_dir = a8::Format(PROJ_LOG_ROOT_FMT, {a8::Format(PROJ_NAME_FMT, {})});
std::string log_file_name = a8::Format(PROJ_LOG_ROOT_FMT,
{a8::Format(PROJ_NAME_FMT, {GAME_ID})}) + "/" + filename_fmt;
{a8::Format(PROJ_NAME_FMT, {})}) + "/" + filename_fmt;
a8::MkDir(proj_root_dir);
a8::MkDir(proj_log_root_dir);
@ -414,11 +404,6 @@ bool App::ParseOpt()
int ch = 0;
while ((ch = getopt(argc, argv, "n:i:t:r:f:")) != -1) {
switch (ch) {
case 'n':
{
node_id = a8::XValue(optarg);
}
break;
case 'i':
{
instance_id = a8::XValue(optarg);
@ -441,7 +426,7 @@ bool App::ParseOpt()
break;
}
}
return instance_id > 0 && node_id > 0;
return instance_id > 0;
}
long long App::NewUuid()

View File

@ -57,7 +57,6 @@ public:
a8::uuid::SnowFlake uuid;
public:
int node_id = 0;
int instance_id = 0;
bool is_test_mode = false;
int test_param = 0;

View File

@ -22,128 +22,10 @@ enum NetHandler_e
HID_GSMgr,
};
enum PlayerState_e
{
PS_None
};
enum VirtualItemId_e
{
VID_Item_Gold = 50001,
VID_Item_Exp = 50002,
VID_Soul_Stone = 50018,
VID_Pickaxe = 50019
};
enum SyncData_e
{
SYNC_Data_Exp = 0,
};
enum DoorState_e
{
DoorStateClose = 0,
DoorStateOpen = 1
};
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 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_1XSCOPE = 12,
IS_2XSCOPE = 13,
IS_4XSCOPE = 14,
IS_8XSCOPE = 15,
IS_15XSCOPE = 16,
IS_END
};
enum SkillType_e
{
ST_Hide = 1,
ST_SummonHero = 2,
ST_Accelerate = 3,
ST_DamageAdd = 4,
ST_DefAdd = 5,
ST_RecoverHP = 6,
ST_ReflectDamage = 7,
ST_SelfDetonate = 8
};
enum SkillCond_e
{
SC_Active = 1,
SC_Passive = 2
};
enum VirtualWeapon_e
{
VW_SafeArea = 9000000,
VW_Spectate = 9000001,
VW_SelfDetonate = 9000002,
VW_Mine = 9000003,
};
enum VirtualPlayer_e
{
VP_SafeArea = 9000000,
VP_Spectate = 9000001,
VP_SelfDetonate = 9000002,
VP_Mine = 9000003,
};
const char* const PROJ_NAME_FMT = "game%d_masterserver";
const char* const PROJ_NAME_FMT = "friend_masterserver";
const char* const PROJ_ROOT_FMT = "/data/logs/%s";
const float TEN_W = 10000 * 10;
const int SYS_RESET_TIME = 2*60; //每日两点重置
const int DEF_WEAPON_ID = 12103;
const int SERVER_FRAME_RATE = 20;
const int SYNC_FRAME_RATE = 10;
const float FRAME_RATE_MS = 1000.0f / SERVER_FRAME_RATE;
const int MAX_WEAPON_NUM = 5;
const int GUN_SLOT1 = 1;
const int GUN_SLOT2 = 2;
const int FRAG_SLOT = 3;
const int SMOKE_SLOT = 4;
const int MAP_HEIGHT = 8192;
const int MAP_WIDTH = 8192;
const int MAP_CELL_WIDTH = 64 * 8;
const int DOOR_THING_ID = 61701;
const int MAX_NODE_ID = 8;
const int MAX_INSTANCE_ID = 500;

View File

@ -1,37 +1,4 @@
#include "precompile.h"
#include "global.h"
int g_hint_flags = 0;
bool Global::IsVirtualItem(int itemid)
{
return (itemid == VID_Item_Exp ||
itemid == VID_Item_Gold ||
itemid == VID_Soul_Stone ||
itemid == VID_Pickaxe);
}
time_t Global::BetweenDays(time_t time1, time_t time2)
{
return (time1 + g_time_zone*3600)/3600/24 - (time2 + g_time_zone*3600)/3600/24;
}
time_t Global::GetDaySeconds(time_t time, int incdays)
{
return time_t((time + g_time_zone * 3600)/3600/24 + incdays) * 3600 * 24 - 3600 * g_time_zone;
}
bool Global::IsTimeToReset(int time)
{
return BetweenDays(g_nowtime - 60 * SYS_RESET_TIME, time - 60 * SYS_RESET_TIME) > 0;
}
int Global::g_nowtime = time(nullptr);
int Global::g_time_zone = 8;
bool Global::g_shutdown = false;
bool IsValidSlotId(int slot_id)
{
return slot_id >= 0 && slot_id < IS_END;
}

View File

@ -9,14 +9,5 @@ class Global : public a8::Singleton<Global>
friend class a8::Singleton<Global>;
public:
static bool IsVirtualItem(int itemid);
static bool IsTimeToReset(int time);
static time_t BetweenDays(time_t time1, time_t time2);
static time_t GetDaySeconds(time_t time, int incdays = 0);
static int g_nowtime;
static int g_time_zone; // 默认东八区
static bool g_shutdown;
};
bool IsValidSlotId(int slot_id);

View File

@ -10,26 +10,20 @@ void JsonDataMgr::Init()
std::string masterserver_cluster_json_file;
if (!f8::IsOnlineEnv()) {
if (f8::IsTestEnv()) {
work_path_ = a8::Format("/root/pub/%d/%d/conf_test/game%d/masterserver.test",
work_path_ = a8::Format("/root/pub/friend/%d/conf_test/friend/masterserver.test",
{
GAME_ID,
App::Instance()->instance_id,
GAME_ID
});
} else {
work_path_ = a8::Format("/root/pub/%d/%d/conf_test/game%d/masterserver.dev",
work_path_ = a8::Format("/root/pub/friend/%d/conf_test/friend/masterserver.dev",
{
GAME_ID,
App::Instance()->instance_id,
GAME_ID
});
}
}
masterserver_cluster_json_file = a8::Format("%s/node%d/game%d.masterserver.cluster.json",
masterserver_cluster_json_file = a8::Format("%s/friend_masterserver.cluster.json",
{
work_path_,
App::Instance()->node_id,
GAME_ID
});
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
}