SA-MP/saco/net/netgame.cpp

142 lines
3.4 KiB
C++
Raw Normal View History

2023-11-23 23:56:11 +08:00
#include "../main.h"
#include "../../raknet/SocketDataEncryptor.h"
extern CGame *pGame;
2024-01-31 23:57:40 +08:00
extern CChatWindow *pChatWindow;
//----------------------------------------------------
2024-08-24 23:28:14 +08:00
BYTE __stdcall GetPacketID(Packet *p)
{
if (p==0) return 255;
if ((unsigned char)p->data[0] == ID_TIMESTAMP) {
assert(p->length > sizeof(unsigned char) + sizeof(unsigned long));
return (unsigned char) p->data[sizeof(unsigned char) + sizeof(unsigned long)];
}
else {
return (unsigned char) p->data[0];
}
}
//----------------------------------------------------
2024-08-24 23:28:40 +08:00
bool __stdcall HasTimestamps(Packet *p)
{
if (p==0) return 0;
if ((unsigned char)p->data[0] == ID_TIMESTAMP)
return true;
return false;
}
//----------------------------------------------------
2023-11-23 23:56:11 +08:00
CNetGame::CNetGame(PCHAR szHostOrIp, int iPort,
PCHAR szPlayerName, PCHAR szPass)
{
2023-11-23 23:56:11 +08:00
field_3D5 = (struc_41*)calloc(1,sizeof(struc_41));
memset(m_szHostName,0,256);
memset(m_szHostOrIp,0,256);
strcpy(m_szHostName, "SA-MP");
strncpy(m_szHostOrIp, szHostOrIp, sizeof(m_szHostOrIp));
m_iPort = iPort;
2024-01-31 23:57:40 +08:00
m_pRakClient = RakNetworkFactory::GetRakClientInterface();
2024-02-06 22:01:20 +08:00
InitPools();
SocketDataEncryptor::SetKey(iPort);
2024-02-16 22:32:43 +08:00
RegisterRPCs(m_pRakClient);
RegisterScriptRPCs(m_pRakClient); // Register server-side scripting RPCs.
2024-01-31 23:57:40 +08:00
2023-11-23 23:56:11 +08:00
m_iGameState = GAMESTATE_WAIT_CONNECT;
2024-01-31 23:57:40 +08:00
if(pChatWindow) pChatWindow->AddDebugMessage("{FFFFFF}SA-MP {B9C9BF}0.3.7-R5 {FFFFFF}Started");
// TODO: CNetGame::CNetGame(...) .text:1000B930
}
2024-01-06 23:39:04 +08:00
2024-02-06 22:01:20 +08:00
//----------------------------------------------------
void CNetGame::Process()
{
UpdateNetwork();
// TODO: CNetGame::Process()
}
//----------------------------------------------------
// UPDATE NETWORK
//----------------------------------------------------
void CNetGame::UpdateNetwork()
{
/* Packet* pkt=NULL;
unsigned char packetIdentifier;
while((pkt = m_pRakClient->Receive()))
{
}*/
// TODO: CNetGame::UpdateNetwork()
}
2024-02-06 22:01:20 +08:00
void CNetGame::InitPools()
{
m_pPools = (NETGAME_POOLS *)calloc(1, sizeof(NETGAME_POOLS));
2024-02-06 22:08:24 +08:00
2024-02-12 20:10:26 +08:00
m_pPools->pObjectPool = new CObjectPool();
2024-02-12 20:22:51 +08:00
m_pPools->pMenuPool = new CMenuPool();
2024-02-12 20:16:37 +08:00
m_pPools->pLabelPool = new CLabelPool();
m_pPools->pTextDrawPool = new CTextDrawPool();
2024-02-18 21:21:09 +08:00
m_pPools->pGangZonePool = new CGangZonePool();
2024-02-06 22:20:05 +08:00
m_pPools->pPlayerPool = new CPlayerPool();
2024-02-06 22:08:24 +08:00
m_pPools->pVehiclePool = new CVehiclePool();
m_pPools->pPickupPool = new CPickupPool();
2024-02-12 20:12:15 +08:00
m_pPools->pActorPool = new CActorPool();
2024-02-06 22:01:20 +08:00
}
2024-01-06 23:39:04 +08:00
DWORD CNetGame::GetTime()
{
return (DWORD)RakNet::GetTime();
}
//-----------------------------------------------------------
// Puts a personal marker using any of the radar icons on the map
void CNetGame::SetMapIcon(BYTE byteIndex, float fX, float fY, float fZ, BYTE byteIcon, DWORD dwColor, int iStyle)
{
if (byteIndex >= 100) return;
if (m_dwMapIcon[byteIndex] != NULL) DisableMapIcon(byteIndex);
//ScriptCommand(&create_radar_marker_without_sphere, fX, fY, fZ, byteIcon, &m_dwMapIcon);
m_dwMapIcon[byteIndex] = pGame->CreateRadarMarkerIcon(byteIcon, fX, fY, fZ, dwColor, iStyle);
}
//-----------------------------------------------------------
// Removes the Map Icon
void CNetGame::DisableMapIcon(BYTE byteIndex)
{
if (byteIndex >= 100) return;
ScriptCommand(&disable_marker, m_dwMapIcon[byteIndex]);
m_dwMapIcon[byteIndex] = NULL;
}
//----------------------------------------------------
void CNetGame::ResetMapIcons()
{
BYTE i;
for (i = 0; i < 100; i++)
{
if (m_dwMapIcon[i] != NULL) DisableMapIcon(i);
}
}
//----------------------------------------------------