Skip to content

Commit

Permalink
Update how packets are sent to player
Browse files Browse the repository at this point in the history
  • Loading branch information
xx-shitai-xx committed Feb 19, 2023
1 parent 2fc6e6a commit 6f8fe31
Show file tree
Hide file tree
Showing 20 changed files with 2,415 additions and 2,417 deletions.
23 changes: 16 additions & 7 deletions server/include/TPlayer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TPLAYER_H
#define TPLAYER_H

#include <time.h>
#include <ctime>
#include <map>
#include <set>
#include <unordered_set>
Expand All @@ -15,8 +15,6 @@

#ifdef V8NPCSERVER
#include "ScriptBindings.h"
#include "TPacket.h"

#endif

class TLevel;
Expand Down Expand Up @@ -106,10 +104,17 @@ class TPlayer : public TAccount, public CSocketStub

// Socket-Functions
bool doMain();
template <class T>
void sendPacket(const TPacket<T>& packet, bool sendNow = false, bool appendNL = true) { sendPacket((unsigned char)packet.Id, packet.Data, sendNow, appendNL); };
void sendPacket(unsigned char packetId, const CString& pPacket, bool sendNow = false, bool appendNL = true);
void sendPacketOld(CString pPacket, bool appendNL = true);
void sendPacket(const PlayerOutPacket& packet, bool sendNow = false, bool appendNL = true) {
if (newProtocol)
{
sendPacketNewProtocol((unsigned char)packet.Id, packet.Data, sendNow, appendNL);
}
else
{
sendPacketOldProtocol(CString() >> (char)packet.Id << packet.Data, appendNL);
}
};

bool sendFile(const CString& pFile);
bool sendFile(const CString& pPath, const CString& pFile);

Expand Down Expand Up @@ -309,6 +314,10 @@ class TPlayer : public TAccount, public CSocketStub

bool newProtocol;
private:
// SendPacket functions.
void sendPacketNewProtocol(unsigned char packetId, const CString& pPacket, bool sendNow = false, bool appendNL = true);
void sendPacketOldProtocol(CString pPacket, bool appendNL = true);

// Login functions.
bool sendLoginClient();
bool sendLoginNC();
Expand Down
16 changes: 8 additions & 8 deletions server/include/TServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ class TServer : public CSocketStub
// Packet sending.
using PlayerPredicate = std::function<bool(const TPlayer *)>;

void sendPacketToAll(char packetId, CString pPacket, TPlayer *pSender) const;
void sendPacketToLevel(char packetId, CString pPacket, TLevel* pLevel, TPlayer* pPlayer = 0) const;
void sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TLevel* pLevel, TPlayer* pPlayer = 0, bool onlyGmap = false) const;
void sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf = false, bool onlyGmap = false) const;
void sendPacketToLevel(PlayerPredicate predicate, char packetId, CString pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf = false, bool onlyGmap = false) const;
void sendPacketTo(char packetId, int who, CString pPacket, TPlayer* pPlayer = 0) const;
void sendPacketToAll(PlayerOutPacket pPacket, TPlayer *pSender) const;
void sendPacketToLevel(PlayerOutPacket pPacket, TLevel* pLevel, TPlayer* pPlayer = 0) const;
void sendPacketToLevel(PlayerOutPacket pPacket, TMap* pMap, TLevel* pLevel, TPlayer* pPlayer = 0, bool onlyGmap = false) const;
void sendPacketToLevel(PlayerOutPacket pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf = false, bool onlyGmap = false) const;
void sendPacketToLevel(PlayerPredicate predicate, PlayerOutPacket pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf = false, bool onlyGmap = false) const;
void sendPacketTo(int who, PlayerOutPacket pPacket, TPlayer* pPlayer = 0) const;

// Player Management
unsigned int getFreePlayerId();
Expand Down Expand Up @@ -347,7 +347,7 @@ inline void TServer::sendToRC(const CString& pMessage, TPlayer *pSender) const
if (len == -1)
len = pMessage.length();

sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << pMessage.subString(0, len), pSender);
sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << pMessage.subString(0, len)}, pSender);
}

inline void TServer::sendToNC(const CString& pMessage, TPlayer *pSender) const
Expand All @@ -356,7 +356,7 @@ inline void TServer::sendToNC(const CString& pMessage, TPlayer *pSender) const
if (len == -1)
len = pMessage.length();

sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYNC, CString() << pMessage.subString(0, len), pSender);
sendPacketTo(PLTYPE_ANYNC, {PLO_RC_CHAT, CString() << pMessage.subString(0, len)}, pSender);
}

#endif
Loading

0 comments on commit 6f8fe31

Please sign in to comment.