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

📄 main.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "stdafx.h"
#include <mmsystem.h>
#include <direct.h>
#include "LowerLayers\monitor.h"
#include "LowerLayers\GameTimer.h"
#include "mapserver.h"
#include "HigherLayers\DefaultHeader.h"
#include "HigherLayers\Rajasystem.h"
#include "LowerLayers\mylog.h"
#include "HigherLayers\Npclist.h"
#include "HigherLayers\MenuServer.h"
#include "HigherLayers\Winzs.h"
#include "HigherLayers\Scrp_int.h"
#include "HigherLayers\WeatherControl.h"
#include "HigherLayers\Op_Magic.h"
#include "HigherLayers\SealStone.h" // 001209 KHS 
#include "HigherLayers\AREA.h"		// 010205 KHS
#include "LowerLayers\servertable.h"	// 001215 KHS
#include "HigherLayers\TeamBattle.h"		// 010205 KHS
#include "HigherLayers\ChrLog.h"
#include "HigherLayers\UserManager.h"
#include "HigherLayers\SymbolItemMgr.h"//soto-030512
#include "HigherLayers\EventTreasureBoxMgr.h"//soto-030711

extern CSymbolItemMgr g_CSymbolMgr;//soto-030512
extern void InitLimitedTimeAndAge(); // 030929 kyo
// 011130 YGI
int DRAGON_MAX_CONNECTIONS;

static unsigned int random_next;
inline int ran()
{
	random_next = random_next * 1103515245 + 12345;
	return (random_next / 65536);
}

void sran( DWORD cnt )
{
	random_next = cnt;
}

// 020707 YGI
int srand_()
{
	sran( (unsigned)time( NULL ) );
	return 1;
}

int rand_()
{
	static a = srand_();
	return ran();
}

// ----------------------------------------------------------------------------------------------
// Global Variables Begin
// ----------------------------------------------------------------------------------------------
int g_year				= 0;
int g_mon				= 0;	// 0 - 11
int g_day				= 0;
int g_yday				= 0;
int g_wday				= 0;
int g_hour				= 0;
int g_min				= 0;
int g_sec				= 0;

int g_count_ok;

DWORD global_time		= 0;	// 1ms 窜困..
DWORD g_alive_time		= 0;
DWORD g_curr_time		= 0;	// 1檬窜困..
DWORD g_curr_time_with_out_year = 0;		// 岿, 朝, 矫埃阑 檬窜困肺 函券, 斥 篮 器窃登瘤 臼绰促.	// 031009 CI YGI
int   g_weatherflag		= 0;	// 1 捞搁 朝揪俊 包秦辑 BroadCast窍瘤 臼蠢促. 


char bbsString[ MAX_PATH];
int  BBSBroadcast; 

int	 DRAGON_PORT	= 0;

HANDLE hIn;
// ----------------------------------------------------------------------------------------------
// Global Variables End
// ----------------------------------------------------------------------------------------------


// ----------------------------------------------------------------------------------------------
// Externs Begin
// ----------------------------------------------------------------------------------------------
// for Item Init
extern struct CItem_List Item_Ref ;
extern short int nNPC_Type ;


int LoadSkillLevelTable(void); // skill.cpp
int initItem(void) ;
int initNPCTable(void) ;
int InitEffectTbl();
int InitMagicTbl();
void CleanUpConnectionList(void);

// 010904 LTS
extern bool InitNationSystem();
extern bool InitLocalWarSystem();		// LTS LOCALWAR
extern bool InitEventLocalWarSystem();		// 020115 LTS
extern int InitMapServerConfigINI();		// LTS NEW LOCALWAR
extern int  LoadGeneration();			// LTS AI2
extern int	InitAIData();				// LTS AI2

// 020430 YGI acer 2
extern int InitChrLogDB( int port );

//021011 KYO 
extern int InitLoadQuestTable();		//涅胶飘包访 抛捞喉 肺靛


// ----------------------------------------------------------------------------------------------
// Externs End
// ----------------------------------------------------------------------------------------------




// ----------------------------------------------------------------------------------------------
// Functions Begin
// ----------------------------------------------------------------------------------------------
int InitialScript( void )
{	
	int ret;
	
	InitTextScript();
	ret = LoadScript( MapName );
	
	if( !ret )
	{
		MyLog( LOG_NORMAL, " *** Error : Script Syntax " );
	}
	
	Script( 0 );
	MyLog( LOG_NORMAL, "   Script(0) Executed !");
	
	return ret;
};
// ----------------------------------------------------------------------------------------------
void RecvBBSLogin( char *msg )
{
	strcpy( bbsString, msg );
	
	BBSBroadcast = 30; 
}
// ----------------------------------------------------------------------------------------------
void StartingBBS( void )
{
	static DWORD time;
	char temp[ MAX_PATH];
	char *s;
	
	FILE *fp;
	
	wsprintf( temp, "%s/data/靛贰帮扼磊傍瘤荤亲.txt", GameServerDataPath );
	
	fp = fopen( temp, "rt" );
	if( fp == NULL ) return;
	
	fgets( temp, MAX_PATH-1, fp );
	s = EatRearWhiteChar( temp );
	strcpy( bbsString, s );
	fclose(fp);
	
	BBSBroadcast = 30; 
}

void BroadCastBBS_Sub( char *msg, int len )
{	//< CSD-031213
	if (msg == NULL)
	{
		return;
	}

	if (len == 0)
	{
		return;
	}

	t_packet p;
	p.h.header.type = CMD_BBS;
	p.h.header.size = sizeof(t_server_bbs) - MAX_PATH + len;
	strcpy(p.u.server_bbs.bbs, msg);
	g_pUserManager->SendPacket(&p);
}	//> CSD-031213

void RecvTotalMapConnections( int cn )
{
	t_packet p;
	int no;
	no = PC_COUNT;
	if( no < 0 ) no = 0;
	p.h.header.type = CMD_TOTAL_MAP_CONNECTIONS;
	p.u.total_map_connections.no = no;
	p.h.header.size = sizeof( t_total_map_connections );
	QueuePacket( connections, cn, &p, 1 );
}

void RecvTotalConnections(int cn)
{
	int no = TotalConnections();
	
	if (no < 0) 
	{
		no = 0;
	}

	t_packet p;
	p.h.header.type = CMD_TOTAL_CONNECTIONS;
	p.h.header.size = sizeof(t_total_connections);
	p.u.total_connections.no = no;
	QueuePacket(connections, cn, &p, 1);
}

void RecvAbsLogOut2GameServer(char* id)
{	//< CSD-HK-030829
	for (int i = DRAGON_CONNECTIONS_START; i < DRAGON_MAX_CONNECTIONS; ++i)
	{
		if (connections[i].dwAgentConnectionIndex)
		{
			if (strcmp(connections[i].id, id) == 0)
			{
				closeconnection(connections, i, -203);
				break;
			}
		}
	}
}	//> CSD-HK-030829

void prepare(t_connection c[])
{
	global_time = ::timeGetTime();
	
	time_t lTime = {0,};
	time(&lTime);
	struct tm *today = localtime(&lTime);
	
	g_year = today->tm_year + 1900;
	g_mon  = today->tm_mon;
	g_yday = today->tm_yday;
	g_wday = today->tm_wday;
	g_day  = today->tm_mday;
	g_hour = today->tm_hour;
	g_min  = today->tm_min;
	g_sec  = today->tm_sec;
	
	// 031009 CI YGI
	g_curr_time_with_out_year = 
		(g_yday* 86400) 
		+ (g_hour* 3600) 
		+ (g_min * 60) 
		+ g_sec;
	
	g_curr_time = ( (g_year-1999 ) * 31536000) + g_curr_time_with_out_year;
}

// ----------------------------------------------------------------------------------------------
// 020808 YGI 
struct ID_PASS
{
	char m_szID1[30];
	char m_szPASS1[30];
	char m_szID2[30];
	char m_szPASS2[30];
	char m_szID3[30];
	char m_szPASS3[30];
	
	ID_PASS()
	{
		m_szID1[0] = 0;
		m_szPASS1[0] = 0;
		m_szID2[0] = 0;
		m_szPASS2[0] = 0;
		m_szID3[0] = 0;
		m_szPASS3[0] = 0;
	}
};

bool DecoadFile( char *filename, void *pData, int size )
{
	CHSEL_STREAM m_hsel;
	FILE *fp = fopen( filename, "rb" );
	if( !fp ) return false;
	
	int nVersion = 0;
	fread( (void*)(&nVersion), sizeof(int), 1, fp ); 
	if (m_hsel.GetVersion() != nVersion)  return false;
	HselInit deinit;
	fread( (void*)(&deinit), sizeof(HselInit), 1, fp );
	if (!m_hsel.Initial(deinit))  return false;
	fread( pData, 1, size, fp );
	m_hsel.Decrypt((char *)pData, size);
	fclose( fp );
	return true;
}
bool IncordFile( char *filename, void *pData, int size )
{
	CHSEL_STREAM m_hsel;
	FILE *fp = fopen( filename, "wb" );
	if( !fp ) return false;
	
	HselInit eninit;
	eninit.iEncryptType	=	HSEL_ENCRYPTTYPE_RAND;
	eninit.iDesCount	=	HSEL_DES_TRIPLE;
	eninit.iCustomize	=	HSEL_KEY_TYPE_DEFAULT;
	eninit.iSwapFlag	=	HSEL_SWAP_FLAG_ON;
	
	if (!m_hsel.Initial(eninit)) 
	{
		return false;
	}
	
	HselInit deinit;
	deinit = m_hsel.GetHSELCustomizeOption();
	const int nVersion = m_hsel.GetVersion();
	fwrite((void *)(&nVersion), sizeof(nVersion), 1, fp ); 
	fwrite((void *)(&deinit), sizeof(HselInit), 1, fp ); 
	m_hsel.Encrypt((char*)pData, size);
	fwrite( pData, 1, size, fp );
	fclose( fp );
	return true;
}

void MakeServerNeedFolder()
{	//< CSD-TW-030622
	::mkdir("./Output");
}	//> CSD-TW-030622

extern int InitMapInfo(t_MapInfo T[]); // CSD-030516
// 020808 YGI 林狼荤亲 曼炼
int InitDRMapServerDatas(void)
{
	srand( (unsigned)time( NULL ) );
	
	MakeServerNeedFolder();
	
	prepare(connections);		//021030 YGI
	
	if (InitGameMakeModeSetting( MAP_SERVER_INI_ ) < 0 )
	{
		MyLog( LOG_FATAL, "File '%s' not FOUND",MAP_SERVER_INI_ );
		return (0);
	}
	
	
	char path[MAX_PATH];
	ID_PASS id_password;
	int bIdPassword = 0;		// 沥犬洒 鞠龋甫 佬绢 吭绰啊?
	{
		sprintf( path, "%s/data/IdPassword.bin", GameServerDataPath );
		bIdPassword = DecoadFile( path, (char *)&id_password, sizeof( ID_PASS ) );
	}
	
	ID_PASS IdPassWord;
	::strcpy( IdPassWord.m_szID1,		LocalMgr.GetDBAccount(DRAGON_DB,ID));//030102 lsw
	::strcpy( IdPassWord.m_szPASS1,	LocalMgr.GetDBAccount(DRAGON_DB,PASS) );//030102 lsw
	
	if( bIdPassword )
		IdPassWord = id_password;
	
	if( (Init_SQL("DragonRajaDB", IdPassWord.m_szID1, IdPassWord.m_szPASS1) ) == 0)
	{
		MyLog( LOG_FATAL, "SQL server connect fail !");
		return(0);
	}
	MyLog( LOG_NORMAL, "SQL server connect OK!");
	
	// 020430 YGI acer 2
	if( !InitChrLogDB( GetManagementMapPort( MM_SAVE_LOG_FILE_MAP ) ) ) return 0;
	//< CSD-031229
	/*
	// 031009 CI YGI
	if( !InitItemLimitCountFromDB() )		// 府固飘 锅龋 檬扁拳啊 角菩 沁促.
	{
		JustMsg( "Error!!! Check please ItemLimitMgrTable table" );
		return 0;
	}
	*/
	//> CSD-031229
	InitNPCList();
	if(initNPCTable() < 0) { Error ("  NPC Table Loading Failed.\n");	} 
	else
	{
		MyLog( LOG_NORMAL, "'NPC_NamebyGender' Table initializing  ..........  OK !");
		MyLog( LOG_NORMAL, "'NPC_Lv2Exp'       Table initializing  ..........  OK !");
		MyLog( LOG_NORMAL, "'NPC_Generation_SP'Table initializing  ..........  OK !\n");
	}
	
	g_MapPort = GetOwnPort(); // CSD-030506	
	InitMoveDelayTable();
	
	// 0527 YGI 垮汲鞘磐
	MyLog( LOG_NORMAL, "  Reading './Data/BadWord.TXT'      count = %d ", LoadFilterWord() );
	
	InitItemList();
	
	if(initItem() < 0) 	{	Error ("  Item loading Fail !\n");	return(0);	}
	else MyLog( LOG_NORMAL, "Item Table initializing    ...................... OK !\n");
	
	MakeStoreList();
	MyLog( LOG_NORMAL, "Store Item List  initializing    ................ OK !\n");
	
	if( InitSkillTable( ) < 0 ) 	{	Error ("  'skillmain' loading Fail !\n");	return(0);	}
	MyLog( LOG_NORMAL, "'SkillMain' Table initializing   ................ OK !");
	
	if( InitGmQuest( ) < 0 ) {	Error ("  'GMquest' loading Fail !\n");	return(0);	}
	else MyLog( LOG_NORMAL, "'GMquest' Table initializing    ................. OK !");

	if( InitMapInfo( MapInfo ) < 0 ) { Error( " MapInfo Loading Fail !! \n" ); return(0); }
	else	MyLog( LOG_NORMAL, "'Map_Info' Table loading        ................. OK !");
	if (LoadArenaInfo())
	{	//< CSD-030517
		if (LoadArenaGameInfo())
		{
			MyLog(LOG_NORMAL, "'arean_game_info' Table loading        ........... OK !");
		}

		if (LoadArenaTeamInfo())
		{
			MyLog(LOG_NORMAL, "'arean_Team_info' Table loading        ........... OK !");
		}	

		if (LoadArenaBonusInfo())
		{
			MyLog(LOG_NORMAL, "'arean_bonus_info' Table loading       ........... OK !");
		}	
	}	//> CSD-030517

	if( g_AliveMap.LoadAliveMapZone() < 0 )	Error ("  AliveMapZone Table loading Fail !\n");	// 010502 YGI
	else	MyLog( LOG_NORMAL, "'alive_zone' Table loading        ..............  OK !");
	
	// 010522 YGI
	if( LoadNationInfo(NationInfo ) != 1 )	Error( "  Nation_Info Table loading fail!!!!! \n" );
	else	MyLog( LOG_NORMAL, "'Nation_Info' Table loading         ............  OK !");
	
	if( LoadGuildListForMapServer( ) != 1 )	{ Error( "  Guild_List Table loading fail!!!!! ... new! " ); return(0); }
	else	MyLog( LOG_NORMAL, "'Guild_List' Table loading         ............  OK");
	

⌨️ 快捷键说明

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