📄 dragonserver.cpp
字号:
#include "..\stdafx.h"
#include <mmsystem.h>
#include "DefaultHeader.h"
#include "Scrp_int.h"
#include "Scrp_Exe.h"
#include "NPC_Pattern.h"
#include "map.h"
#include "OP_Magic.h"
#include "CItem.h"
#include "WeatherControl.h"
#include "Map.h"
#include "Chatting.h"
#include "RajaSystem.h"
#include "SealStoneGameServer.h"
#include "SealStone.h"
#include "..\LowerLayers\mylog.h"
#include "..\LowerLayers\packed.h"
#include "..\LowerLayers\servertable.h"
#include "dr_network.h"
#include "ChrLog.h"
#include "teambattle.h" // 010406 YGI
#include "skill_lsw.h"
#include "RareEffectMgr.h" //020214 lsw
#include "op_battle.h"
#include "LTSSupport.h" // LTS DRAGONLORDWAR
#include "dungeon.h" // 020701 YGI
#include "eventmgr.h"
#include "UserManager.h"
#include "BattleManager.h"
#include "DualManager.h"
#include "SymbolItemMgr.h" // soto-1.02
#include "BASEARENA.h"
#include "EventTreasureBoxMgr.h"//soto-030711
// 030329 kyo << //just using in thailand
#include "..\HigherLayers\QuestFunction.h"
extern void CheckLimitedAge();
int g_nLimitedStartTime=0;
int g_nLimitedEndTime=0;
int g_nLimitedAge =0;
char g_szLimitedUser_Message[MAX_PATH];
// 030929 kyo >>
extern void ResetAbility(CHARLIST *ch); //020214 lsw
extern void RecvCMD_SKILL_RARE_UPGRADE(int cn, t_packet *p);
extern int HandleCommand2( t_packet *p, t_connection c[], int cn );
extern int g_LocalWarBegin; // 011215 LTS
#define MELEE 0 // 窜芭府.
#define RANGE_BOW 1 // 厘芭府..
#define RANGE_HURL 2 // 吝芭府.
#define RANGE_DEFAULT 3 // 窜芭府..
#define MAGIC 4 // 付过.
t_connection connections[ DRAGON_MAX_CONNECTIONS_+1];
extern bool isLevelUp(CHARLIST *);
extern int updateCharacterStatus(t_connection [], int) ;
extern int CheckHandleByKein( t_packet *p, t_connection c[], int cn );
extern int CheckHandleByNationWar( t_packet *p, t_connection c[], const int cn ); // 010904 LTS//020903 lsw
extern void RecvSkillGauge( int cn, t_client_skill_gauge *p );
extern void RecvDebugReqCharInfo( int cn, int target ); // OP_Battle.cpp
extern void RecvCMD_MAGIC_RESULT( int caster_id, int target_id, int magic_no, int x, int y, int hunter_target );
extern void RecvCMD_CLIENT_CHARACTER_DEMAND( int cn, t_client_character_demand *p );
extern void Recv_CMD_PLEASE_GIVE_LIFE( int cn, int type, int alive_word_type = 0 ); // 010502 YGI
extern void RecvBBSLogin( char *msg );
extern void RecvAbsLogOut2GameServer( char *id );// main.cpp
extern int initItem(void);
extern void Recv_fight_stone(int cn, t_packet packet);
//this msg1 lsw
extern bool CheckFailedMagic(CHARLIST *caster, CHARLIST *target, int magic_no, int cn);//010604 lsw
extern void Recv_CMD_SERVER_NPC_ACCESS_TABLE_RELOAD( int cn, t_packet *p );
extern void BroadCastBBS_Sub( char *msg, int len ); // main.cpp
extern void SendNK( int id, int nk );
extern void SendNK( int id, int nk3, int nk4, int nk6 );
// 1010 CSB
extern int SearchItemByInv( int item_no, CHARLIST *ch );
extern int HandleCommand3( t_packet *p, t_connection c[], const int cn ); // 021028 kyo
void CleanUpConnection(short idServer)
{ //< CSD-HK-030829
memset(&connections[idServer], 0, sizeof(t_connection));
memset(var[idServer], 0, SIZE_OF_SCRIPT_VAR);
} //> CSD-HK-030829
void CleanUpConnectionList()
{
for (DWORD i = 0; i <= DRAGON_MAX_CONNECTIONS; ++i)
{
connections[i].dwAgentConnectionIndex = 0;
connections[i].dwIDForAgent = 0;
}
}
// 2000/11/06, chan78 :: New QueuePacket()
static char szMsg[MAX_PACKET_SIZE+5];
//int QueuePacket( t_connection c[], int cn, t_packet *packet, int type, char *file = __FILE__, int line = __LINE__ )
int QueuePacket_( t_connection c[], int cn, t_packet *packet, int type, char *file, int line )
{
CPackedMsg packedMsg;
if(cn < 0 || cn >= DRAGON_MAX_CONNECTIONS)
{
MyLog(LOG_IGNORE, "ERROR : cn:%d > DRAGON_MAX_CONNECTIONS:%d cmd:%d type:%d ", cn, DRAGON_MAX_CONNECTIONS, packet->h.header.type, type);
FILE *fp = fopen( "./OutPut/InvalidPacketLog.txt", "at+" );
if(fp )
{
if( file )
fprintf( fp, "%02d.%02d:%02d cn:%5d header:%5d type:%d, %s:%d \n", g_day, g_hour, g_min, cn, packet->h.header.type, type, file, line );
fclose(fp);
}
return 0;
}
if( (cn == DB_DEMON) || (cn == 0) )
{ // To DB Demon
DWORD dummy = 0;
szMsg[0] = (BYTE)PTCL_MAP_TO_DB;
memcpy( szMsg+1, (char*)&dummy, 4);
memcpy( szMsg+1+4, (char*)packet, sizeof(t_header)+packet->h.header.size );
if( g_pServerTable
&& !g_pServerTable->SendToDBDemon( szMsg, (sizeof(t_header)+packet->h.header.size)+5 ) )
{
if( g_pServerTable->GetOwnDBDemonData() ) // 031021 kyo
{
MyLog( LOG_FATAL, "Can't Write to DB Demon(%d) :: ServerTable()", g_pServerTable->GetOwnDBDemonData()->dwConnectionIndex );
}
else
MyLog( LOG_FATAL, "Can't Write to DB Demon :: ServerTable");
}
}
else
{ // To Agent
if( connections[cn].dwAgentConnectionIndex == NULL)
{
// MyLog(LOG_FATAL, "c[%d].dwAgentConnectionIndex is NULL", cn);
return 0;
}
// Message Packing
packedMsg.SetMsg( (char *)packet, (sizeof(t_header)+packet->h.header.size) );
packedMsg.AddUser( connections[cn].dwIDForAgent );
packedMsg.SetAgentServerIndex( connections[cn].dwAgentConnectionIndex );
// Send it.
if( g_pServerTable
&& !g_pServerTable->Send( connections[cn].dwAgentConnectionIndex, (char *)&packedMsg, packedMsg.GetPacketSize() ) )
{
MyLog( LOG_IMPORTANT, "QueuePacket() Failed To Send Packet to Agent Server(%d)", connections[cn].dwAgentConnectionIndex );
}
}
return true;
}
int DequeuePacket(t_connection c[], int cn, t_packet *packet, int type)
{
return 1;
}
void SendAliveCheckRoutine(t_connection c[])
{ //< CSD-CN-31213
if ((global_time - g_alive_time) > 6000)
{
t_packet packet;
packet.h.header.type = CMD_NONE;
packet.h.header.size = 0;
g_pUserManager->SendPacket(&packet);
g_alive_time = global_time;
}
} //> CSD-CN-31213
extern short int getWeatherCorrection( void );
void updateCharacterStatusToLoginServer( t_connection c[], int char_id);
void updateBinaryDataToLoaginServer( t_connection c[], int id );
// Marked by chan78
void UpdateCharacterData(t_connection c[], int cn, bool bDirect)
{ //< CSD-HK-030829
if (g_pServerTable == NULL)
{
goto SAVE_MAP;
}
if (!g_pServerTable->GetOwnDBDemonData() || !g_pServerTable->GetOwnDBDemonData()->dwConnectionIndex)
{
goto SAVE_MAP;
}
if (bDirect)
{
goto SAVE_MAP;
}
updateCharacterStatusToLoginServer(connections, cn);
updateBinaryDataToLoaginServer(c, cn);
SendLoginServerForCharUpdate(cn); // 眠啊 某腐磐 沥焊 历厘
UpdateLadderScore(&c[cn].chrlst); // 贰歹 珐欧俊 历厘
return;
SAVE_MAP:
updateCharacterStatus(connections, cn);
UpdateCharStatusByKein(c, cn); // 眠啊 某腐磐 沥焊 历厘
} //> CSD-HK-030829
extern void DeleteSquadMember(const int cn); // 010904 LTS // 惫啊傈 何措沥焊甫 昏力茄促.//020903 lsw
extern void DecLocalWarfieldMemberCount(const int cn); // LTS LOCALWAR//020903 lsw
extern cDragonLordWar g_pDragonLordWar; // LTS DRAGONLORD
//---------------------------------------------------------------------------------
// Re-Wrote by chan78 at 2000/11/09 :: New closeconnection()
// 函版荤亲: socket阑 流立 促风瘤 臼绰促. Server埃 目池记篮 捞 窃荐甫 荤侩窍瘤 臼绰促.
//<! BBD 040110 牢磊 眠啊
//void closeconnection(t_connection c[], int cn, int errnum)
void closeconnection(t_connection c[], int cn, int errnum, bool bUseDemon)
//> BBD 040110 牢磊 眠啊
{
if (cn < DRAGON_CONNECTIONS_START || cn >= DRAGON_MAX_CONNECTIONS)
{ //< CSD-030322
return;
} //> CSD-030322
CHARLIST *ch = &connections[cn].chrlst;
if (cn != ch->GetServerID())
{ //< CSD-HK-030829
g_pServerTable->SetNumOfUsers(g_pServerTable->GetNumOfUsers() - 1, 100, cn, errnum, connections[cn].name);
CleanUpConnection(cn);
MyLog(LOG_FATAL, "closeconnection : cn(%d), server_id(%d)", cn, ch->GetServerID());
return;
} //> CSD-HK-030829
t_packet packet;
QTickData[cn].Func = 0;
if (ch->IsPlayer())
{ // 家券等 阁胶磐啊 乐促搁 傈何 力芭
ch->m_xSummon.Remove(KillMonster);
if (ch->DragonLordWarTeam>0) // LTS DRAGONLORDWAR
{
g_pDragonLordWar.FindAndDeleteMember(cn);
}
}
SendExitGameWho(cn); // 颇萍盔俊霸 唱 唱埃促绊 舅赴促. // 0116 YGI
SetArea(REMOVE_PC_AREA, cn);
ResetManToManItemWhenCloseConnect(ch); // 0911 YGI
if( ch->reporter_mode ) // 扁磊窜 葛靛捞搁
{
ch->Hp = ch->HpMax * 20 / 100;
ch->Hungry = ch->HungryMax * 30 / 100;
ch->Mana = 0;//020214 lsw
aliveCharacter( ch );
}
if( ch->handheld.item_no )
{
MoveEmptyInv( &ch->handheld, ch );
POS pos;
SetItemPos( HAND, &pos );
SendServerEachItem( &pos, &ch->handheld, cn );
}
if( ch->fight_flag )
{
CHARLIST *win = CheckServerId( ch->fight_id );
if( win )
{
EndManToManFight( win, ch );
}
}
if( g_pDungeonMap )
{
g_pDungeonMap->CloseConnect( cn ); // 020701 YGI
}
::SetTileOccupied(ch->MoveSx,ch->MoveSy,false);
for( int i = 0 ; i < MAX_PC_CONTROL_NPC ; i ++) // LTS AI BUG
{
if( ch->ctrlnpc[i] != -1 )
{
NPCList[ ch->ctrlnpc[i]].ctrlpc = -1;
SetArea(ADD_NPC_AREA, ch->ctrlnpc[i]);
}
}
if( connections[cn].state >= CONNECT_JOIN ) // 楷搬窍磊付磊 场绢脸促绊 佬瘤档 臼绰 Data甫 盎脚且荐绰 绝促.
{
packet.h.header.type = CMD_USER_REMOVE;
packet.u.server_user_remove.server_id = cn;
packet.h.header.size = sizeof(t_server_user_remove);
QueuePacket(connections, cn, &packet, 1);
}
DeleteSquadMember(cn); // Remove From Warfield Squad Hash; // 010904 LTS
DecLocalWarfieldMemberCount(cn); // LTS LOCALWAR
// 011210 YGI
// DB俊霸 唱 唱埃促绊 舅赴促.
SendPacketDefault( CMD_SERVER_EXIT_GAME , ch->Name, strlen( ch->Name), DB_DEMON );
//<! BBD 040110 敲贰弊甫 捞侩
// UpdateCharacterData(c, cn, false);
UpdateCharacterData(c, cn, bUseDemon);
//> BBD 040110
SendLog2ChrLogDB( c, cn, CHR_LOG_LOGOUT_ );
// Modified by chan78 at 2000/12/17
// 立加辆丰 夸备 皋矫瘤甫 焊辰促.
char szMsg[32];
// Connected User Counter
// Added by chan78 at 2000/12/17
if( connections[cn].dwAgentConnectionIndex && connections[cn].dwIDForAgent )
{
szMsg[0] = (BYTE)PTCL_MAP_TO_AGENT_REQUEST_DISCONNECT_USER;
memcpy(szMsg+1,&connections[cn].dwIDForAgent,4);
if( !g_pServerTable->Send(connections[cn].dwAgentConnectionIndex, szMsg, 1+4) )
{
MyLog( LOG_FATAL, "closeconnection_core() :: Failed to Send PTCL_USER_LOST_CONNECTION(cn:%d/dwCI%d/ID:%d)", cn, connections[cn].dwAgentConnectionIndex, connections[cn].dwIDForAgent );
}
}
switch( errnum )
{
case -208 : // Accelator User...
{
MyLog( LOG_NORMAL, "Forced Disconnect ! (Accelator): %s:%s( %s )", connections[cn].id, connections[cn].name, connections[cn].ip_address );
break;
}
case -206 : // Filter User...
{
MyLog( LOG_NORMAL, "Forced Disconnect ! (Filter): %s:%s( %s )", connections[cn].id, connections[cn].name, connections[cn].ip_address );
break;
}
case -203: // CMD_CLOSE_LOGIN_ID
case -220: // Death Connections
case -205: // 努扼捞攫飘俊辑 柯 沥惑辆丰.
case -33 : // 款康磊俊 狼茄 碍力辆丰.
case -204: // 农贰欧矫档俊 狼茄 辆丰 (努扼捞攫飘俊辑 朝酒柯)
{
MyLog( LOG_NORMAL, "Forced Disconnect ! (%d): %s:%s( %s )", errnum, connections[cn].id, connections[cn].name, connections[cn].ip_address );
break;
}
}
g_pServerTable->SetNumOfUsers(g_pServerTable->GetNumOfUsers()-1,100, cn,errnum, connections[cn].name);
//< CSD-HK-030829
CleanUpConnection(cn);
} //> CSD-HK-030829
//-------------------------------------------------------------------------
int SettingMoveData_( int j, CHARLIST *c, t_packet *p )
{
t_server_move *t = &(p->u.server_move);
t->length = (unsigned char)( c->MoveLength - c->MovePathCount );
if( j >= 10000 && t->length <= 0 ) return 0;
if( t->length < 0 ) return 0;
t->targetid = c->targetid;
t->server_id = j;
t->length = (unsigned char)( c->MoveLength - c->MovePathCount );
if( c->MovePathCount % 2 ) t->length += 1000; // 父距 1000焊促 奴荐啊 啊搁 刚历 1官捞飘狼 窍困4Bit甫 捞侩茄促.
t->sx = (short int)c->MoveSx;
t->sy = (short int)c->MoveSy;
t->gox = (short int)c->MoveGox;
t->goy = (short int)c->MoveGoy;
memcpy(t->dir_tbl, c->MoveDirTbl + c->MovePathCount / 2, ( c->MoveLength - c->MovePathCount+1 )/2 );
t->desttime = ReturnDestTime( c );
t->movetype = c->MoveType;
p->h.header.size = sizeof(t_server_move) - MAX_DIR_TABLE + (( c->MoveLength - c->MovePathCount+1 )/2 );
return 1;
}
int move_count = 0;
//-----------------------------------------------------------------
// Send Environment Info
//-----------------------------------------------------------------
void SendEnvironment( t_connection c[], int cn)
{
t_packet packet;
t_server_envir_info *tp = &packet.u.server_envir_info;
packet.h.header.type = CMD_ENVIR_INFO;
{
tp->weather_count = global_time;
tp->currtime_count = g_curr_time;
tp->rainstart = today_rainstart[ today_weathercount];
tp->rainend = today_rainend[ today_weathercount];
tp->amount = today_rainamount[ today_weathercount];
tp->temperature = getWeatherCorrection(); // 泅犁 岿, 老, 矫埃阑 焊郴霖促.
memcpy(tp->mapname, MapName, NM_LENGTH);
}
packet.h.header.size = sizeof(t_server_envir_info);
QueuePacket(connections, cn, &packet, 1);
}
extern void RecvNewDay( t_packet *packet );
int HandleCommand( int cn, t_packet *packet)
{
if ((cn < 0 || cn > DRAGON_MAX_CONNECTIONS) && cn != CN_FROM_OTHER_MAPSERVER_MSG)
{
return -80;
}
switch (packet->h.header.type)
{
case CMD_NONE:
{
break;
}
case CMD_PROXY_TO_MAP_CHANGE_DATE:
{
RecvNewDay(packet);
break;
}
case CMD_CHANGE_MAP_DETECTED:
{
closeconnection_kein( connections, cn, 1 );
break;
}
case CMD_HEXAEDITING:
{
RecvHexaEditing(cn, &packet->u.angra.client_editing_table);
break;
}
case CMD_PING:
{
packet->h.header.type = CMD_PING;
packet->h.header.size = 0;
QueuePacket(connections, cn, packet, 1);
break;
}
case CMD_LOST_CONNECTION:
{
closeconnection(connections, cn, -51);
break;
}
case CMD_ACCESS_JOIN:
{ //< CSD-HK-030829
if (!CheckServerIndex(cn))
{
break;
}
ACCESSJOIN *pAJ = &packet->u.AccessJoin;
if (g_pUserManager->IsExist(pAJ->name))
{
break;
}
// initializing user // THAI kein
const DWORD idUniq = connections[cn].dwIDForAgent;
const DWORD dwConnectionIndex = connections[cn].dwAgentConnectionIndex;
CleanUpConnection(cn);
connections[cn].dwIDForAgent = idUniq;
connections[cn].dwAgentConnectionIndex = dwConnectionIndex;
connections[cn].state = CONNECT_LOGIN;
strcpy(connections[cn].id, pAJ->id);
strcpy(connections[cn].pw, pAJ->pw);
strcpy(connections[cn].name, pAJ->name);
strcpy(connections[cn].ip_address, pAJ->ip);
connections[cn].chrlst.SetServerID(cn);
connections[cn].chrlst.startposition = pAJ->startposition;
if(LocalMgr.IsAbleNation(KOREA))
{
connections[cn].chrlst.SetBillingType(pAJ->nBillingType);
}
else
{
connections[cn].chrlst.SetBillingType(BT_COMMERCIAL_IP);
}
//DB俊霸 罐酒档 亮篮瘤 夸没茄促. 肚绰 Map捞悼秦档 亮篮瘤 夸没茄促.
// Mapserver->DBDemon
t_packet tp;
tp.h.header.type = CMD_REQ_INSERT_USERID;
tp.h.header.size = sizeof(t_gs_req_insert_userid);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -