stoneage8.5/石器时代服务器端最新完整源代码/Serv/gmsv/main.c

414 lines
8.1 KiB
C
Raw Normal View History

#include "version.h"
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
#include <setjmp.h>
#include "init.h"
#include "net.h"
#ifdef _EPOLL_ET_MODE
#include "epollnet.h"
#endif
#include "handletime.h"
#include "char.h"
#include "map_warppoint.h"
#include "npcgen.h"
#include "log.h"
#include "configfile.h"
#include "battle.h"
#include "petmail.h"
#include "autil.h"
#include "family.h"
#include "trade.h"
#include "longzoro/attestation.h"
#include "longzoro/sasql.h"
#ifdef _ALLBLUES_LUA
#include "mylua/ablua.h"
#endif
#ifdef _CHATROOMPROTOCOL // (<28><><EFBFBD>ɿ<EFBFBD>) Syu ADD <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>
#include "chatroom.h"
#endif
#include "shop.h"
jmp_buf mark;
static void ShutdownProc( void);
void mainloop( void );
struct tm tmNow, tmOld;
void family_proc();
#ifdef _CHANNEL_MODIFY
extern int InitOccChannel(void);
#endif
#ifdef _GMSV_DEBUG
extern char *DebugMainFunction;
#endif
#ifdef _ANGEL_SUMMON
#define ANGELTIMELIMIT 3*24*60*60 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>(<28><>)
int AngelReady =0;
int AngelTimelimit = ANGELTIMELIMIT;
time_t AngelNextTime;
void AngelReadyProc();
#endif
//#include "genver.h"
void warplog_proc();
int main( int argc , char** argv, char** env )
{
/* <20><>Իؤ<D4BB><D8A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ëɬ<C3AB><C9AC><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD> */
setNewTime();
ShopData_Init();
/* if ( argc > 1 && 0==strcmp(argv[1],"-v"))
{
printf("%s",genver);
exit(0);
}
else fprintf(stderr,"%s",genver);*/
EXITWITHEXITCODEIFFALSE( util_Init() , 1);
LoadAnnounce(); // Arminius 7.12 loginannounce
/* <20><><EFBFBD><EFBFBD>ɬ<EFBFBD><C9AC> */
memcpy( &tmOld, localtime( (time_t *)&NowTime.tv_sec), sizeof( tmNow ) );
EXITWITHEXITCODEIFFALSE( init(argc , argv ,env ) , 1);
LoadPetTalk(); // Arminius 8.14 pet talk
#ifdef _GAMBLE_BANK
Load_GambleBankItems();
#endif
#ifdef _CFREE_petskill
Load_PetSkillCodes();
#endif
#ifdef _ITEM_PILEFORTRADE
TRADE_InitTradeList();
#endif
#ifdef _SASQL
if(sasql_init()==FALSE){
exit(1);
}
#endif
mainloop();
return 0;
}
void mainloop( void )
{
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>NPC...");
NPC_generateLoop( 1 );
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>signal1...");
signal(SIGUSR1,sigusr1);
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>signal2...");
signal(SIGUSR2,sigusr2);
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
#ifdef _MAP_WARPPOINT
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>...");
MAPPOINT_InitMapWarpPoint();
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
if( !MAPPOINT_loadMapWarpPoint() ){
return;
}
#endif
#ifdef _ASSESS_SYSEFFICACY
Assess_InitSysEfficacy();
#endif
#ifdef _CHATROOMPROTOCOL // (<28><><EFBFBD>ɿ<EFBFBD>) Syu ADD <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ...");
InitChatRoom();
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
#endif
#ifdef _CHAR_PROFESSION // WON ADD <20><><EFBFBD><EFBFBD>ְҵ
#ifdef _CHANNEL_MODIFY
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ְҵƵ<EFBFBD><EFBFBD>...");
if(!InitOccChannel()) return; // <20><>ʼ<EFBFBD><CABC>ְҵƵ<D2B5><C6B5>
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
#endif
#endif
#ifdef _ANGEL_SUMMON
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼʱ<EFBFBD><EFBFBD>...");
AngelReady = 0;
#ifdef _ANGEL_TIME
AngelNextTime = time(NULL) + getAngelPlayerTime();
#else
AngelNextTime = time(NULL) + 1*60;
#endif
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
#endif
//#ifdef _ALLDOMAN
// print("<22><>ʼ<EFBFBD><CABC>Ӣ<EFBFBD>۱<EFBFBD><DBB1><EFBFBD>...");
// InitHeroList();
// print("<22><><EFBFBD><EFBFBD>\n");
//#endif
#ifdef _JZ_NEWSCRIPT_LUA
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>LNS<EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
NPC_Lua_Init(getLuaFile());
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
#endif
#ifdef _ALLBLUES_LUA
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>LUA<EFBFBD>ű<EFBFBD>...");
LoadAllbluesLUA("data/ablua");
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
#endif
#ifdef _EPOLL_ET_MODE
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>...");
if(Start_PacketWrapper() != 0 )
{
print("ʧ<EFBFBD><EFBFBD>\n");
return;
}
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>߳<EFBFBD>
// print("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>߳<EFBFBD>...");
// if(Start_Epoll_SendLoop() != 0 )
// {
// print("ʧ<><CAA7>\n");
// return;
// }
// print("<22><><EFBFBD><EFBFBD>\n");
//<2F><><EFBFBD><EFBFBD>epoll<6C><6C>ѭ<EFBFBD><D1AD><EFBFBD>߳<EFBFBD>
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>epoll<EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>...");
if( Start_Epoll_Loop() != 0 )
{
print("ʧ<EFBFBD><EFBFBD>\n");
return;
}
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
#endif
while(1){
#ifdef _ASSESS_SYSEFFICACY
Assess_SysEfficacy( 0 );
#endif
setNewTime();
memcpy(&tmNow, localtime( (time_t *)&NowTime.tv_sec),
sizeof( tmNow ) );
if( tmOld.tm_hour != getLogHour( ) && tmNow.tm_hour == getLogHour( ) ){
#ifdef _GMSV_DEBUG
DebugMainFunction="backupAllLogFile";
#endif
backupAllLogFile( &tmOld );
}
setNewTime();
#ifdef _ASSESS_SYSEFFICACY_SUB //<2F><>ʾLOOPʱ<50><CAB1>
Assess_SysEfficacy_sub( 0, 1);
#ifdef _GMSV_DEBUG
DebugMainFunction="netloop_faster";
#endif
#ifdef _EPOLL_ET_MODE
System_Loop();
#else
netloop_faster();
#endif
Assess_SysEfficacy_sub( 1, 1);
Assess_SysEfficacy_sub( 0, 2);
#ifdef _GMSV_DEBUG
DebugMainFunction="NPC_generateLoop";
#endif
NPC_generateLoop( 0 );
Assess_SysEfficacy_sub( 1, 2);
Assess_SysEfficacy_sub( 0, 3);
#ifdef _GMSV_DEBUG
DebugMainFunction="BATTLE_Loop";
#endif
BATTLE_Loop();
Assess_SysEfficacy_sub( 1, 3);
Assess_SysEfficacy_sub( 0, 4);
#ifdef _GMSV_DEBUG
DebugMainFunction="CHAR_Loop";
#endif
CHAR_Loop();
Assess_SysEfficacy_sub( 1, 4);
#ifdef _GMSV_DEBUG
DebugMainFunction="PETMAIL_proc";
#endif
PETMAIL_proc();
#ifdef _GMSV_DEBUG
DebugMainFunction="family_proc";
#endif
family_proc();
#ifdef _GMSV_DEBUG
DebugMainFunction="chardatasavecheck";
#endif
chardatasavecheck();
#ifdef _ANGEL_SUMMON
#ifdef _GMSV_DEBUG
DebugMainFunction="AngelReadyProc";
#endif
AngelReadyProc();
#endif
tmOld = tmNow;
if( tmOld.tm_sec != tmNow.tm_sec ) {
#ifdef _GMSV_DEBUG
DebugMainFunction="CHAR_checkEffectLoop";
#endif
CHAR_checkEffectLoop();
}
if( SERVSTATE_getShutdown()> 0 ) {
ShutdownProc();
#ifdef _GMSV_DEBUG
DebugMainFunction="ShutdownProc";
#endif
}
tmOld = tmNow;
#ifdef _ASSESS_SYSEFFICACY
Assess_SysEfficacy( 1 );
#endif
#endif
}
}
static void sendmsg_toall( char *msg )
{
int i;
int playernum = CHAR_getPlayerMaxNum();
for( i = 0 ; i < playernum ; i++) {
if( CHAR_getCharUse(i) != FALSE ) {
CHAR_talkToCli( i, -1, msg, CHAR_COLORYELLOW);
}
}
}
static void ShutdownProc( void)
{
#define SYSINFO_SHUTDOWN_MSG "%d <20><><EFBFBD>Ӻ<EFBFBD><D3BA><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ϵͳͣ<CDB3><CDA3>ά<EFBFBD><CEAC>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>ʧ<EFBFBD><CAA7>"
#define SYSINFO_SHUTDOWN_MSG_COMP "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹرա<D8B1>"
int diff,hun;
diff = NowTime.tv_sec - SERVSTATE_getShutdown();
hun = SERVSTATE_getLimittime() - (diff/60);
if( hun != SERVSTATE_getDsptime() ){
char buff[256];
if( hun != 0 ) {
snprintf( buff, sizeof(buff), SYSINFO_SHUTDOWN_MSG, hun);
}
else {
strcpy( buff, SYSINFO_SHUTDOWN_MSG_COMP);
}
sendmsg_toall( buff);
SERVSTATE_setDsptime(hun);
if( hun == 1 ) {
SERVSTATE_SetAcceptMore( 0 );
}
}
/* closesallsockets */
if( hun == 0) {
closeAllConnectionandSaveData();
SERVSTATE_setShutdown(0);
SERVSTATE_setDsptime(0);
SERVSTATE_setLimittime(0);
}
}
void family_proc()
{
static unsigned long gettime = 0;
static unsigned long checktime = 0;
static unsigned long proctime = 0;
if( time(NULL) < proctime ) return;
proctime = time(NULL)+5;
if( (unsigned long)NowTime.tv_sec > gettime ){
getNewFMList();
gettime = (unsigned long)NowTime.tv_sec + 60*10;
}
if( (unsigned long)NowTime.tv_sec > checktime ){
checkFamilyIndex();
checktime = (unsigned long)NowTime.tv_sec + 60*30;
}
}
void warplog_proc()
{
static unsigned long checktime = 0;
if( (unsigned long)NowTime.tv_sec > checktime ){
warplog_to_file();
checktime = (unsigned long)NowTime.tv_sec + 300;
}
}
#ifdef _ANGEL_SUMMON
extern int player_online;
void AngelReadyProc()
{
//static time_t lastCreateTime = time(NULL);
time_t nowTime;
//static unsigned long AngelNextTime = 30*60;
struct tm *temptime;
char msg[1024];
nowTime = time(NULL);
if( nowTime < AngelNextTime )
return;
#ifdef _ANGEL_TIME
if( player_online <= getAngelPlayerMun() )
#else
if( player_online <= 10 )
#endif
{
// print("\n<><6E><EFBFBD><EFBFBD><EFBFBD>ٻ<EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=%d\n", player_online );
return;
}
AngelReady = 1;
//AngelNextTime = min( (int)(10000/player_online), 100)*60 + (unsigned long)nowTime;
#ifdef _ANGEL_TIME
AngelNextTime = min( (int)(getAngelPlayerTime()/player_online), 100)*60 + (unsigned long)nowTime;
#else
AngelNextTime = min( (int)(5000/player_online), 100)*60 + (unsigned long)nowTime;
#endif
temptime = localtime( &AngelNextTime );
sprintf( msg, "\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٻ<EFBFBD>:<3A><><EFBFBD><EFBFBD>һλȱ<CEBB><C8B1> <20>´β<C2B4><CEB2><EFBFBD>ʱ<EFBFBD><CAB1>=(%d/%d %d:%d) Ŀǰ<C4BF><C7B0><EFBFBD><EFBFBD>=%d\n",
temptime->tm_mon+1, temptime->tm_mday, temptime->tm_hour, temptime->tm_min, player_online );
print( msg);
//LogAngel( msg);
}
#endif