⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 px_ls_module_work.c

📁 MMORPG游戏服务器端架构及函数
💻 C
📖 第 1 页 / 共 2 页
字号:
/* must been first include begin */
#include "..\ProjectX_Common\ProjectX_Copyright.h"
#include "..\ProjectX_Common\ProjectX_Common.h"
/* must been first include end */

/* std and common include */
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>

//program specify include
#include "..\ProjectX_Common\ProjectX_Shared.h"
#include "..\ProjectX_Common\ProjectX_Utils.h"
#include "..\ProjectX_Common\ProjectX_MessageCode.h"
#include "px_ls_common.h"
#include "px_ls_config.h"
#include "px_ls_state.h"
#include "px_ls_statistic.h"
#include "px_ls_time_service.h"
#include "px_ls_ui.h"

#include "px_ls_account.h"
#include "px_ls_antihack.h"
#include "px_ls_battle_guid.h"
#include "px_ls_blacklist.h"
#include "px_ls_char.h"
#include "px_ls_char_class.h"
#include "px_ls_charge.h"
#include "px_ls_chat_radio.h"
#include "px_ls_chat_video.h"
#include "px_ls_community.h"
#include "px_ls_friends.h"
#include "px_ls_gm.h"
#include "px_ls_init.h"
#include "px_ls_item.h"
#include "px_ls_log.h"
#include "px_ls_lottery.h"
#include "px_ls_map.h"
#include "px_ls_marriage.h"
#include "px_ls_master_prentice.h"
#include "px_ls_module_dbes.h"
#include "px_ls_module_rs.h"
#include "px_ls_monster.h"
#include "px_ls_npc.h"
#include "px_ls_passive_effect.h"
#include "px_ls_pet.h"
#include "px_ls_pk.h"
#include "px_ls_roup.h"
#include "px_ls_skill.h"
#include "px_ls_speed_frame.h"
#include "px_ls_stranger.h"
#include "px_ls_task.h"
#include "px_ls_team.h"
#include "px_ls_trade.h"
#include "px_ls_trap.h"
#include "px_ls_uninit.h"
#include "px_ls_version.h"
#include "px_ls_war_guid.h"

#include "px_ls_module_work.h"

/* frame base */
FRAME_FBS_BASE				*	frame_fbs_base_head = NULL;				/* fbs */
FRAME_FCE_BASE				*	frame_fce_base_head = NULL;				/* fce */
FRAME_FCM_BASE				*	frame_fcm_base_head = NULL;				/* fcm */
FRAME_FCP_BASE				*	frame_fcp_base_head = NULL;				/* fcp */
FRAME_FCR_BASE				*	frame_fcr_base_head = NULL;				/* fcr */
FRAME_FHR_BASE				*	frame_fhr_base_head = NULL;				/* fhr */
FRAME_FLR_BASE				*	frame_flr_base_head = NULL;				/* flr */
FRAME_FMR_BASE				*	frame_fmr_base_head = NULL;				/* fmr */
FRAME_FMS_BASE				*	frame_fms_base_head = NULL;				/* fms */
FRAME_FPR_BASE				*	frame_fpr_base_head = NULL;				/* fpr */
FRAME_FSR_BASE				*	frame_fsr_base_head = NULL;				/* fsr */
FRAME_FSS_BASE				*	frame_fss_base_head = NULL;				/* fss */

//exp base
PX_LS_EXP_BASE				*	exp_base_head = NULL;					/* exp */

/* item_defence base */
ITEM_AMULET_BASE			*	item_amulet_base_head = NULL;			/* 项链 */
ITEM_ARMOR_BASE				*	item_armor_base_head = NULL;			/* 衣服 */
ITEM_BELT_BASE				*	item_belt_base_head = NULL;				/* 腰带 */
ITEM_BOOT_BASE				*	item_boot_base_head = NULL;				/* 靴子 */
ITEM_EYE_BASE				*	item_eye_base_head = NULL;				/* 眼罩 */
ITEM_GLOVE_BASE				*	item_glove_base_head = NULL;			/* 护手 */
ITEM_GUARDIANSHIP_BASE		*	item_guardianship_base_head = NULL;		/* 守护 */
ITEM_HELM_BASE				*	item_helm_base_head = NULL;				/* 头盔 */
ITEM_LEGGUARD_BASE			*	item_legguard_base_head = NULL;			/* 护腿 */
ITEM_MANTLE_BASE			*	item_mantle_base_head = NULL;			/* 披风 */
ITEM_RING_BASE				*	item_ring_base_head = NULL;				/* 戒指 */
ITEM_SHIELD_BASE			*	item_shield_base_head = NULL;			/* 盾牌 */
ITEM_SHIRT_BASE				*	item_shirt_base_head = NULL;			/* 内衣 */
ITEM_WING_BASE				*	item_wing_base_head = NULL;				/* 翅膀 */
ITEM_TALISMAN_BASE			*	item_talisman_base_head = NULL;			/* 护身符 */

/* item_weapon base */
ITEM_AX_BASE				*	item_ax_base_head = NULL;				/* 斧子 */
ITEM_BOW_BASE				*	item_bow_base_head = NULL;				/* 弓 */					 
ITEM_CROSSBOW_BASE			*	item_crossbow_base_head = NULL;			/* 弩 */
ITEM_DANGGER_BASE			*	item_dangger_base_head = NULL;			/* 匕首 */
ITEM_DECONTICATETOOL_BASE	*	item_deconticatetool_base_head = NULL;	/* 剥皮工具 */
ITEM_HERBALTOOL_BASE		*	item_herbaltool_base_head = NULL;		/* 收集草药工具 */
ITEM_LEAF_BASE				*	item_leaf_base_head = NULL;				/* 亡灵荷叶 */
ITEM_MACE_BASE				*	item_mace_base_head = NULL;				/* 顶头锤 */
ITEM_MAGICSTAFF_BASE		*	item_magicstaff_base_head = NULL;		/* 法杖 */
ITEM_MININGTOOL_BASE		*	item_miningtool_base_head = NULL;		/* 采矿工具 */
ITEM_POWERSTAFF_BASE		*	item_powerstaff_base_head = NULL;		/* 权杖 */
ITEM_REAMER_BASE			*	item_reamer_base_head = NULL;			/* 刀 */
ITEM_SHAFT_BASE				*	item_shaft_base_head = NULL;			/* 矛 */
ITEM_SPEAR_BASE				*	item_spear_base_head = NULL;			/* 枪 */
ITEM_STAVE_BASE				*	item_stave_base_head = NULL;			/* 棍棒 */
ITEM_SWORD_BASE				*	item_sword_base_head = NULL;			/* 剑 */

/* item_staff base */
ITEM_CONSUMER_BASE			*	item_consumer_base_head = NULL;			/* 消耗品 */
ITEM_GEM_BASE				*	item_gem_base_head = NULL;				/* 珠宝 */
ITEM_GUID_BASE				*	item_guid_base_head = NULL;				/* 战盟或者血盟物品 */
ITEM_PET_SPAWN_BASE			*	item_pet_spawn_base_head = NULL;		/* 宠物卵 */
ITEM_RESTORE_BASE			*	item_restore_base_head = NULL;			/* 恢复药剂 */
ITEM_SKILL_BASE				*	item_skill_base_head = NULL;			/* 技能书或者技能石 */
ITEM_SPECIAL_BASE			*	item_special_base_head = NULL;			/* 特殊物品 */
ITEM_STATE_BASE				*	item_state_base_head = NULL;			/* 恢复状态类 */
ITEM_TASK_BASE				*	item_task_base_head = NULL;				/* 任务 */

/* entity base */


PET_BASE					*	pet_base_head = NULL;					/* 宠物 */
TASK_BASE					*	task_base_head = NULL;					/* 任务 */
TRAP_BASE					*	trap_base_head = NULL;					/* 陷阱 */
MONSTER_BASE				*	monster_base_head = NULL;				/* 怪物 */
NPC_BASE					*	npc_base_head = NULL;					/* npc */
TELEPORT_POINT_BASE			*	teleport_point_base_head = NULL;		/* 传送点 */

/* activity or event base */

/* 怪物复仇事件 */
EVENT_REVENGE				*	event_revenge_base_head = NULL;			/* 怪物复仇事件 */

/* entity refresh base */
MONSTER_REFRESH				*	refresh_monster_head = NULL;			/* 怪物刷新 */
REVENGE_MONSTER_REFRESH		*	refresh_revenge_monster_head = NULL;	/* 复仇怪物刷新 */
NPC_REFRESH					*	refresh_npc_fix_head = NULL;			/* 仅刷新一次的NPC */
NPC_REFRESH					*	refresh_npc_nofix_head = NULL;			/* 需要连续不停的刷新的npc */
TRAP_REFRESH				*	refresh_trap_head = NULL;				/* 陷阱刷新 */
LOTTERY_BASE				*	lottery_bast_head = NULL;				/* 彩票 */

/* entity search key */

ACCOUNT_KEY					*	account_key_head = NULL;				/* 帐号 */
CHAR_GROP_INFO				*	char_group_info_key_head = NULL;		/* 集群内LS服务器链表 */
BATTLE_GUID_KEY				*	battle_guid_key_head = NULL;			/* 血盟 */
CHAT_RADIO_KEY				*	chat_radio_key_head = NULL;				/* 音频聊天 */
CHAT_VIDEO_KEY				*	chat_video_key_head = NULL;				/* 视频聊天 */
LOTTERY_KEY					*	lottery_key_head = NULL;				/* 彩票 */
ROUP_KEY					*	roup_key_head = NULL;					/* 拍卖 */
WAR_GUID_KEY				*	war_guid_key_head = NULL;				/* 战盟 */
MONSTER_KEY					*	monster_key_head = NULL;				/* 怪物 */
TEAM_KEY					*	team_key_head = NULL;					/* 组队 */
TRAP_KEY					*	trap_key_head = NULL;					/* 陷阱 */
SCROLL_DOOR_KEY				*	scroll_door_key_head = NULL;			/* 传送门 */
NPC_KEY						*	npc_key_head = NULL;					/* npc */
GM_KEY						*	gm_key_head = NULL;						/* gm */				
TRADE_KEY					*	trade_key_head = NULL;					/* 交易 */
MARRIAGE_KEY				*	marriage_key_head = NULL;				/* 婚姻 */
MASTER_PRENTICE_KEY			*	master_prentice_key_head = NULL;		/* 师徒关系 */
ITEM_GROUND_KEY				*	item_ground_key_head = NULL;			/* 处于地面上或者类似的道具 */
PK_PVP_KEY					*	pk_pvp_key_head = NULL;					/* single player vs single player using pk */
PK_WVW_KEY					*	pk_wvw_key_head = NULL;					/* war_guid vs war_guid using pk */
PK_TVT_KEY					*	pk_tvt_key_head = NULL;					/* team vs team using pk */





/* 以下为服务器全局变量 */
PX_LS_CONFIG				*	g_config = NULL;						/* LS服务器配置信息 */
PX_LS_CL_VERSION			*	g_cl_version_head = NULL;				/* cl版本访问控制 */
PX_LS_IPBAN					*	g_ip_ban_head = NULL;					/* ip访问控制 */
PX_LS_STATISTIC				*	g_stat = NULL;							/* 统计信息 */
PX_LS_TIME_SERVICE			*	g_time_service = NULL;					/* 服务器时间服务 */
PX_LS_MAP					*	g_map_head = NULL;						/* 小型地图,适用于MapVersion > 1.00.0142 */	
PX_LS_PERFORMANCE			*	g_performance = NULL;					//性能计数
HASH_TABLE_RS				*	g_hash_table_rs = NULL;					//指向rs模块用来快速搜索hash表
HASH_TABLE_DBES				*	g_hash_table_dbes = NULL;				//指向dbes模块用来快速搜索hash表

BOOL							bln_run_workthread = TRUE;				/* 是否继续运行工作者线程 */
HANDLE							h_winsock2 = NULL;						/* winsock2 句柄 */
char							base_path[FILENAME_MAX];				/* 程序基文件地址 */
char						**	pcfg_buf;								/* 配置缓存 */	
//extern variant define			

extern HANDLE					h_event_routing;						/* 连接到rs的线程信号 */
extern HANDLE					h_event_dbes;							/* 连接到dbes的线程信号 */
extern PX_LS_STATE			*	g_state;								/* 服务器全局状态 */

BOOL valid_ls_state(byte state){
	BOOL ret = FALSE;
	EnterCriticalSection(g_state->cts_state);
	if (g_state->curr_state == state) {
		ret = TRUE;
	}
	LeaveCriticalSection(g_state->cts_state);
	return ret;
}
BOOL set_ls_state(byte state){
	EnterCriticalSection(g_state->cts_state);
	g_state->prev_state = g_state->curr_state;
	g_state->prev_time = g_state->curr_time;
	g_state->curr_state = state;
	g_state->curr_time = GetTime64();
	LeaveCriticalSection(g_state->cts_state);
	return TRUE;
}

void ls_do_state_no_init(){
	Sleep(1000);
	return;
}
void ls_do_state_request_init(){
	init_winsock2();
	init_subproc();
	init_module_rs();
	init_module_dbes();
	if ((valid_module_rs_state(STATE_MODULE_INIT_DONE))&&(valid_module_dbes_state(STATE_MODULE_INIT_DONE))) {
		set_ls_state(STATE_MODULE_INIT_DONE);
	}else{
		close_module_rs();
		close_module_dbes();
		free_module_rs_resource();
		free_module_dbes_resource();
		ls_uninit_subproc();
		uninit_winsock2();
		set_ls_state(STATE_MAIN_NO_INIT);
	}
	return;
}
void ls_do_state_init_done(){
	Sleep(500);
	set_ls_state(STATE_MAIN_RUN);
	return;
}
void ls_do_state_run(){
	handle_time_service_start();
	calculate_ls_performance();
	//handle dbes  
	if (valid_module_dbes_state(STATE_MODULE_RUN)) {
		handle_module_dbes_recv_buf();
	}else if (valid_module_dbes_state(STATE_MODULE_INIT_DONE)) {
		SetEvent(h_event_dbes);
	}else {
		tell_module_rs_close_all_client();
		tell_module_rs_ls_need_close();
		Sleep(1000);
		close_module_dbes();
		close_module_rs();
		free_module_dbes_resource();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -