Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified server/build/libenet.a
Binary file not shown.
Binary file modified server/build/libinicpp.a
Binary file not shown.
2 changes: 2 additions & 0 deletions server/core/CControllerState.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <cstdint>

#pragma once

#ifndef _CCONTROLLERSTATE_H_
Expand Down
2 changes: 2 additions & 0 deletions server/core/CNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ class CNetwork

};

char* strncpy_linux(char* dest, unsigned long destSize, const char* src, unsigned long srcSize);

#endif
5 changes: 2 additions & 3 deletions server/core/CPedManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CPedPackets

for (int i = 0; i < 52; i++)
{
if (_strnicmp(packet->specialModelName, CPedManager::ms_aszAllowedSpecialActors[i], strlen(CPedManager::ms_aszAllowedSpecialActors[i])))
if (strncasecmp(packet->specialModelName, CPedManager::ms_aszAllowedSpecialActors[i], strlen(CPedManager::ms_aszAllowedSpecialActors[i])))
{
isSpecialModelValid = true;
break;
Expand All @@ -83,8 +83,7 @@ class CPedPackets
CNetwork::SendPacketToAll(CPacketsID::PED_SPAWN, packet, sizeof * packet, ENET_PACKET_FLAG_RELIABLE, peer);

CPed* ped = new CPed(packet->pedid, player, packet->modelId, packet->pedType, packet->pos, packet->createdBy);
strncpy_s(ped->m_szSpecialModelName, packet->specialModelName, 7);
CPedManager::Add(ped);
strncpy_linux(ped->m_szSpecialModelName, sizeof(ped->m_szSpecialModelName), packet->specialModelName, 7); CPedManager::Add(ped);

// send it back to the syncer of the ped so that he knows the id
CPedPackets::PedConfirm pedConfirmPacket{};
Expand Down
20 changes: 16 additions & 4 deletions server/src/CNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cstring>

#include "../core/CPacketListener.h"
#include "../core/CPacket.h"
Expand All @@ -13,7 +14,7 @@
#include "../core/CVehicleManager.h"
#include "../core/CPedManager.h"

#include "../shared/semver.h"
#include "../../shared/semver.h"


std::unordered_map<unsigned short, CPacketListener*> CNetwork::m_packetListeners;
Expand Down Expand Up @@ -319,8 +320,7 @@ void CNetwork::HandlePlayerConnected(ENetEvent& event)
packet.pos = i->m_vecPos;
packet.pedType = i->m_nPedType;
packet.createdBy = i->m_nCreatedBy;
strncpy_s(packet.specialModelName, i->m_szSpecialModelName, strlen(i->m_szSpecialModelName));
CNetwork::SendPacket(event.peer, CPacketsID::PED_SPAWN, &packet, sizeof packet, ENET_PACKET_FLAG_RELIABLE);
strncpy_linux(packet.specialModelName, sizeof(packet.specialModelName), i->m_szSpecialModelName, strlen(i->m_szSpecialModelName)); CNetwork::SendPacket(event.peer, CPacketsID::PED_SPAWN, &packet, sizeof packet, ENET_PACKET_FLAG_RELIABLE);
}

if (CPlayerPackets::EnExSync::ms_pLastPlayerOwner)
Expand Down Expand Up @@ -407,4 +407,16 @@ void CNetwork::AddListener(unsigned short id, void(*callback)(ENetPeer*, void*,
{
CPacketListener* listener = new CPacketListener(id, callback);
m_packetListeners.insert({ id, listener });
}
}

char* strncpy_linux(char* dest, size_t destsz, const char* src, size_t count) {
if (dest == nullptr || src == nullptr || destsz == 0) {
// Handle error conditions as needed (e.g., return nullptr, throw exception)
return nullptr; // Or throw an exception.
}

size_t copy_len = std::min(count, destsz - 1); // Ensure we don't write past the buffer
std::memcpy(dest, src, copy_len);
dest[copy_len] = '\0'; // Null-terminate the destination string
return dest;
}