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

📄 serversystem.cpp

📁 墨香最新私服
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		m_MapChange[n].MoveMapNum = file.GetWord();
		m_MapChange[n].CurPoint.x = file.GetFloat();
		m_MapChange[n].CurPoint.y = 0;
		m_MapChange[n].CurPoint.z = file.GetFloat();
		m_MapChange[n].MovePoint.x = file.GetFloat();
		m_MapChange[n].MovePoint.y = 0;
		m_MapChange[n].MovePoint.z = file.GetFloat();
		m_MapChange[n].chx_num = file.GetWord();
		
		++n;
	}
}

MAPCHANGE_INFO* CServerSystem::GetMapChangeInfo(DWORD Index)
{
	for(int i=0; i<MAX_MAP_NUM; i++)
	{
		if(m_MapChange[i].Kind == Index)
			return &m_MapChange[i];
	}

	return NULL;
}

//甘辑滚 促款矫 促款等 甘俊 乐绰 蜡历俊霸 甘促款阑 舅覆
void CServerSystem::SendMsgMapServerDown( WORD wServerNum )
{
	USERINFO* pInfo;
	g_pUserTable->SetPositionUserHead();

	while( pInfo = g_pUserTable->GetUserData() )
	{
		if( pInfo->wUserMapNum == wServerNum )
		{
//			MSGBASE msg;
//			msg.Category = MP_USERCONN;
//			msg.Protocol = MP_USERCONN_MAPSERVERDOWN_NOTIFY;
									
			//立加 辆丰甫 舅覆//唱吝俊 甘辑滚 促款登绢档 敲饭捞 啊瓷矫俊
//			g_Network.Send2User( pinfo->dwConnectionIndex, (char*)&msg, sizeof(msg) );

			//agent俊辑 谗绰促.
//			DisconnectUser(pInfo->dwConnectionIndex);
			DisconnectUser(pInfo->dwConnectionIndex, 2);
			
		}
	}
}



DWORD CServerSystem::MakeAuthKey()
{
	//return ICAllocIndex(m_IdxCreater) + 1;
	static DWORD ID = 1;//GetTickCount()*GetTickCount();
	if(ID == 0)
		++ID;
	return ID++;
}
void CServerSystem::ReleaseAuthKey(DWORD key)
{
	//ICFreeIndex(m_IdxCreater,key-1);
}















// global function

void OnConnectServerSuccess(DWORD dwConnectionIndex, void* pVoid)
{
	SERVERINFO* info = (SERVERINFO*)pVoid;
	info->dwConnectionIndex = dwConnectionIndex;
	if(info->wServerKind == MONITOR_SERVER)
	{
		BOOTMNGR->NotifyBootUpToMS(&g_Network);
		g_Console.LOG(4, "Connected to the MS : %s, %d, (%d)", info->szIPForServer, info->wPortForServer, dwConnectionIndex);
	}
	else
	{
		BOOTMNGR->SendConnectSynMsg(&g_Network, dwConnectionIndex, g_pServerTable);
		g_Console.LOG(4, "Connected to the Server : %s, %d, (%d)", info->szIPForServer, info->wPortForServer, dwConnectionIndex);
	}

/*
	SERVERINFO* info = (SERVERINFO*)pVoid;
	if(!dwConnectionIndex) return;

	char strr[255];
	wsprintf(strr, "%d 锅 辑滚肺 立加己傍 ", dwConnectionIndex);//pjslocal
	g_Console.LOG(4, strr);
	

	info->dwConnectionIndex = dwConnectionIndex;					// 捞霸 力措肺 悼累窍唱? 眉农
	MSG_WORD msg;
	msg.Category = MP_SERVER;
	msg.Protocol = MP_SERVER_PWRUP;
	msg.wData = g_pServerTable->GetSelfServer()->wPortForServer;
	g_Network.Send2Server(dwConnectionIndex, (char*)&msg, sizeof(msg));*/


	
	//YH2DO 林籍贸府 登绢乐带 巴阑 瘤框
	if(g_pServerTable->GetMaxServerConnectionIndex() < dwConnectionIndex)			//??????
		g_pServerTable->SetMaxServerConnectionIndex(dwConnectionIndex);	
}

void OnDisconnectServer(DWORD dwConnectionIndex)
{
	char strr[255];
	
	SERVERINFO* serverinfo = g_pServerTable->FindServerForConnectionIndex(dwConnectionIndex);

	wsprintf(strr, "%d 锅 connectionIndex 辑滚 立加 谗辫", dwConnectionIndex);//pjslocal
	g_Console.LOG(4, strr);

	// 咯扁促 呈滴 蹬唱??------------------------------------------------------------------------
//	if( serverinfo )
//	if( serverinfo->wServerKind == AGENT_SERVER )	//Agent辑滚牢版快
//	{
		//促矫立加...
//		SERVERINFO Info;
//		g_Network->ConnectToServer( serverinfo->szIPForServer, serverinfo->wPortForServer, (void*)&Info );
//		return;
//	}
	//-------------------------------------------------------------------------------------------

	if(serverinfo)
	if( serverinfo->wServerKind == 3 )	//map辑滚牢版快
	{
		//甘辑滚俊 楷搬等 蜡历俊霸 甘辑滚 促款阑 舅覆
		g_pServerSystem->SendMsgMapServerDown(serverinfo->wServerNum);
	}

	SERVERINFO * delInfo = g_pServerTable->RemoveServer(dwConnectionIndex);
	if(!delInfo)
	{
		ASSERT(0);
	}
	delete delInfo;
}


void OnConnectServerFail(void* pVoid)
{
	SERVERINFO* info = (SERVERINFO*)pVoid;
	if(info->wServerKind == MONITOR_SERVER)
	{
		BOOTMNGR->AddBootListINI(AGENT_SERVER, g_pServerSystem->GetServerNum(), g_pServerTable);
		BOOTMNGR->BactchConnectToMap(&g_Network, g_pServerTable);
		g_Console.LOG(4, "Failed to Connect to the MS : %s, %d", info->szIPForServer, info->wPortForServer);
	}
	else
	{
		g_Console.LOG(4, "Failed to Connect to the Server : %s, %d", info->szIPForServer, info->wPortForServer);
		BOOTMNGR->RemoveBootList(g_pServerTable, info->wPortForServer);
	}	
		
}
void OnAcceptServer(DWORD dwConnectionIndex)
{
	g_Console.LOG(4, "Server Connected : ConnectionIndex %d", dwConnectionIndex );
}

void OnAcceptUser(DWORD dwConnectionIndex)
{
	if(g_bReady == FALSE)
		return;
	
	++g_dwAcceptUser;

	MSGBASE send;
	send.Category = MP_USERCONN;
	send.Protocol = MP_USERCONN_AGENT_CONNECTSUCCESS;
	g_Network.Send2User(dwConnectionIndex, (char*)&send, sizeof(send));

/*
	BYTE CS = rand() % 256;

	memset(info, 0, sizeof(USERINFO));
	info->dwConnectionIndex = dwConnectionIndex;
	info->CheckSum = CS;
	g_pUserTable->AddUser(info,dwConnectionIndex);
	
	// crypt system on
	info->crypto.Create();										// key 积己

	MSGCRYPTDATA send;
	send.CheckSum = CS;
	send.Category = MP_USERCONN;
	send.Protocol = MP_USERCONN_AGENT_CONNECTSUCCESS;
#ifdef _CRYPTCHECK_
	send.eninit = *info->crypto.GetEnKey();
	send.deinit = *info->crypto.GetDeKey();
#endif
	g_Network.Send2User(dwConnectionIndex, (char*)&send, sizeof(send));
  
	// init on
	info->crypto.SetInit( TRUE );
	*/

	
//	g_Console.LOG(4, "User Connected : ConnectionIndex %d", dwConnectionIndex);

	

	//user count 拌魂==============================================================================
	SERVERINFO * myInfo = g_pServerTable->GetSelfServer();
	++myInfo->wAgentUserCnt;

	MSG_WORD2 msg2;
	msg2.Category = MP_SERVER;
	msg2.Protocol = MP_SERVER_USERCNT;
	msg2.wData1 = myInfo->wPortForServer;
	msg2.wData2 = myInfo->wAgentUserCnt;
	
	g_pServerTable->SetPositionHead();
	SERVERINFO* pOtherAgentInfo = NULL;
	while(pOtherAgentInfo = g_pServerTable->GetNextDistServer())
	{
		if(myInfo == pOtherAgentInfo)
			continue;

		g_Network.Send2Server(pOtherAgentInfo->dwConnectionIndex, (char *)&msg2, sizeof(msg2));
	}
	//user count 拌魂==============================================================================
	
	

	//俊捞怜飘 辑滚捞搁 蜡历 墨款磐甫 刘啊矫挪促.
	DWORD CurUserCount = g_pUserTable->GetUserCount();
	g_pUserTable->SetCalcMaxCount(CurUserCount);
	DWORD MaxUserCount = g_pUserTable->GetUserMaxCount();
	SetUserCurAndMaxCount(CurUserCount, MaxUserCount);
	
	

}

void OnDisconnectUser(DWORD dwConnectionIndex)
{
	if(g_bReady == FALSE)
		return;

//	g_Console.LOG(4, "  User Disconnected : ConnectionIndex %d", dwConnectionIndex);
	if(g_pUserTable->FindUser(dwConnectionIndex))
		g_pUserTable->OnDisconnectUser(dwConnectionIndex);
//	g_Console.LOG(4, "UserCount %d   %d   %d",
//		g_pUserTableForUserID->GetUserCount(),
//		g_pUserTable->GetUserCount(),
//		g_pUserTableForObjectID->GetUserCount());

}

void ProcessDBMessage()
{
	g_DB.ProcessingDBMessage();
}

void ReceivedMsgFromServer(DWORD dwConnectionIndex,char* pMsg,DWORD dwLength)
{
	MSGROOT* pTempMsg = reinterpret_cast<MSGROOT*>(pMsg);
	ASSERT(g_pServerMsgParser[pTempMsg->Category] != NULL);
	if(g_pServerMsgParser[pTempMsg->Category])
	{
#ifdef _NETWORKTEST
		RecvServerMsgAmount[pTempMsg->Category] += dwLength;
#endif

		g_pServerMsgParser[pTempMsg->Category](dwConnectionIndex, pMsg, dwLength);
	}
}

void ReceivedMsgFromUser(DWORD dwConnectionIndex,char* pMsg,DWORD dwLength)
{
	MSGROOT* pTempMsg = reinterpret_cast<MSGROOT*>(pMsg);

/*
	if(pInfo->CheckCorrectCheckSum(pTempMsg->CheckSum) == FALSE)
	{
		MSGBASE msg;
		msg.Category = MP_USERCONN;
		msg.Protocol = MP_USERCONN_CHECKSUMERROR;
		g_Network.Send2User(dwConnectionIndex,(char*)&msg,sizeof(msg));
		return;
	}
*/
/*
#ifdef _CRYPTCHECK_ 

	int headerSize = sizeof( MSGROOT );
	USERINFO* pInfo = g_pUserTable->FindUser(dwConnectionIndex);
	if( !pInfo->crypto.Decrypt( ( char * )pTempMsg +  headerSize, dwLength - headerSize ) )
	{
		ASSERTMSG(0,"Decrypt Error");
		return;
	}
	char aaa = pInfo->crypto.GetDeCRCConvertChar();
	if( pTempMsg->Code !=  aaa )
	{
		ASSERTMSG(0,"Decrypt CRC Error");
		return;
	}
#endif	
*/
	USERINFO* pInfo = g_pUserTable->FindUser(dwConnectionIndex);

	if( pInfo )
	if( g_pServerSystem->IsEnableCrypt() )
	{
		int headerSize = sizeof( MSGROOT );

		if( !pInfo->crypto.Decrypt( ( char * )pTempMsg +  headerSize, dwLength - headerSize ) )
		{
			ASSERTMSG(0,"Decrypt Error");
			return;
		}
		char aaa = pInfo->crypto.GetDeCRCConvertChar();
		if( pTempMsg->Code !=  aaa )
		{
			ASSERTMSG(0,"Decrypt CRC Error");
			return;
		}
	}

	ASSERT(g_pServerMsgParser[pTempMsg->Category] != NULL);
	ASSERT(pTempMsg->Category < MP_MAX);
	ASSERT(pTempMsg->Category != 0);
	if( g_pServerMsgParser[pTempMsg->Category] == NULL ||
		pTempMsg->Category >= MP_MAX ||
		pTempMsg->Category == 0)
		return;

#ifdef _NETWORKTEST
	RecvUserMsgAmount[pTempMsg->Category] += dwLength;
	if(pInfo)
		pInfo->AddPacketForUser(pTempMsg->Category, dwLength);
	//pInfo->dwTrafficForUserSend[pTempMsg->Category] += dwLength;
#endif

	//eTraffic_User_To_Agent
	if( pTempMsg->Category == MP_MOVE )
	{
		TRAFFIC->AddReceiveMovePacket( ((MSGBASE*)pTempMsg)->dwObjectID, pTempMsg->Protocol, dwLength );
	}
	TRAFFIC->AddReceivePacket( pTempMsg->Category, dwLength );

	g_pUserMsgParser[pTempMsg->Category](dwConnectionIndex, pMsg, dwLength);
}

void GameProcess()
{
	g_pServerSystem->Process();
}

void fConnectionCheck()
{
	g_pServerSystem->ConnectionCheck();
}


// console interface function
void ButtonProc1()
{
/*	g_bAssertMsgBox = !g_bAssertMsgBox;
	if(g_bAssertMsgBox)
		g_Console.LOG(4,"Assert MsgBox is On");
	else
		g_Console.LOG(4,"Assert MsgBox is Off");
*/	

	int servercount = g_pServerTable->GetDataNum();
	g_Console.LOG(4, "Connected Server Count : %d", servercount);

	char temp[128] = {0,};
	SERVERINFO* pInfo = NULL;
	g_pServerTable->SetPositionHead();
	while( pInfo = g_pServerTable->GetNextServer() )
	{
		switch( pInfo->wServerKind )
		{
		case DISTRIBUTE_SERVER:	sprintf( temp, "DistributeServer" ); break;
		case AGENT_SERVER:		sprintf( temp, "AgentServer" );	break;
		case MAP_SERVER:		sprintf( temp, "MapServer" );	break;		
		}
		g_Console.LOG(4, "%s : IP = %s, Port = %d", temp, pInfo->szIPForServer, pInfo->wPortForServer );
	}
}

void ButtonProc2()
{
	g_Console.LOG(4, "UserCount %d %d %d, AcceptUser %d %d [ USERIDX[%d, %d] UT[%d, %d] OBJECTIDX[%d, %d]]",
		g_pUserTableForUserID->GetUserCount(),
		g_pUserTable->GetUserCount(),
		g_pUserTableForObjectID->GetUserCount(), g_dwAcceptUser, g_dwAcceptUser2, 
		g_pUserTableForUserID->GetAddCount(), 
		g_pUserTableForUserID->GetRemoveCount(), 
		g_pUserTable->GetAddCount(), 
		g_pUserTable->GetRemoveCount(),
		g_pUserTableForObjectID->GetAddCount(), 
		g_pUserTableForObjectID->GetRemoveCount() );
}

void ButtonProc3()
{
}

void OnCommand(char* szCommand)
{
	strupr(szCommand);
	char Header[256] = {0,};	
	sscanf(szCommand,"%s",Header);
	START_STRING_COMPARE(Header)
		COMPARE("FINDUSER")
			DWORD UserID;
			sscanf(szCommand,"%s %d",Header,&UserID);
			USERINFO* pInfo = g_pUserTableForUserID->FindUser(UserID);
			if(pInfo == NULL)
				g_Console.Log(eLogDisplay,4,"No User (%d)",UserID);
			else
			{
				g_Console.Log(eLogDisplay,4,"UserID:%d  ConIdx:%d  DistAuthKey:%d  AgentAuthKey:%d",
					UserID,pInfo->dwConnectionIndex,pInfo->DistAuthKey,pInfo->dwUniqueConnectIdx);
			}
	END_COMPARE

}



⌨️ 快捷键说明

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