Skip to content

Commit cf74682

Browse files
committed
LocationMsg framework
1 parent fb36fa7 commit cf74682

5 files changed

Lines changed: 106 additions & 8 deletions

File tree

src/Net/IMessage.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ class IMessage {
1414
* @brief Command type
1515
*/
1616
enum EKind {
17-
EKind_Connect,
18-
EKind_Disconnect,
19-
EKind_Print,
20-
EKind_Item,
17+
EKind_Connect, // 0
18+
EKind_Disconnect, // 1
19+
EKind_Print, // 2
20+
EKind_Item, // 3
21+
EKind_Location, // 4
2122
};
2223

2324
public:

src/Net/NetworkMgr.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Net/msg/DisconnectMsg.h"
77
#include "Net/msg/ItemMsg.h"
88
#include "Net/msg/PrintMsg.h"
9+
#include "Net/msg/LocationMsg.h"
910

1011
#include <libkiwi.h>
1112

@@ -90,6 +91,7 @@ void NetworkMgr::PacketCallback(kiwi::PacketBase* pPacket, void* pArg) {
9091
HANDLE_PACKET(Disconnect);
9192
HANDLE_PACKET(Print);
9293
HANDLE_PACKET(Item);
94+
HANDLE_PACKET(Location);
9395

9496
default: {
9597
ASSERT_EX(false, "Unknown packet type: %d", kind);
@@ -114,13 +116,19 @@ void NetworkMgr::PacketCallback(kiwi::PacketBase* pPacket, void* pArg) {
114116
(*it)->OnMessage(pMessage);
115117
}
116118

117-
delete pMessage;
118-
119119
// TODO(kiwi) Move this somewhere else
120120
if (r.mPeerAddr.IsValid()) {
121-
u8 ack = 0xAA;
122-
r.mpServer->Send(ack, &r.mPeerAddr);
121+
if (pMessage->GetKind() == IMessage::EKind_Location) {
122+
LocationMsg locMsg(contentStrm);
123+
kiwi::TVector<u32> command = locMsg.GetLocationMsg();
124+
r.mpServer->Send(command.Data(), command.Size() * sizeof(u32), &r.mPeerAddr);
125+
} else {
126+
u8 ack = 0xAA;
127+
r.mpServer->Send(ack, &r.mPeerAddr);
128+
}
123129
}
130+
131+
delete pMessage;
124132
}
125133

126134
} // namespace Net

src/Net/msg/LocationMsg.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "Net/msg/LocationMsg.h"
2+
#include "Net/NetworkMgr.h"
3+
#include "Cmn/CheckMgr.h"
4+
#include "checks.h"
5+
6+
#include <libkiwi.h>
7+
8+
namespace AP {
9+
namespace Net {
10+
11+
/**
12+
* @brief Constructor
13+
*
14+
* @param rStrm Stream to packet content
15+
*/
16+
LocationMsg::LocationMsg(kiwi::MemStream& rStrm) {
17+
// mData.Clear();
18+
}
19+
20+
kiwi::TVector<u32> LocationMsg::GetLocationMsg() {
21+
22+
#define X(ID, IDENTIFIER, STR) \
23+
if (Cmn::CheckMgr::GetInstance().GetCheckState((CheckID) ID)) { \
24+
mData.PushBack(static_cast<u32>(ID)); \
25+
}
26+
27+
AP_CHECKS_X_MACRO
28+
29+
#undef X
30+
31+
for (int i = 0; i < mData.Size(); i++) {
32+
kiwi::cout << mData[i];
33+
}
34+
35+
kiwi::cout << kiwi::endl;
36+
37+
return mData;
38+
}
39+
40+
}
41+
}

src/Net/msg/LocationMsg.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef APCLIENT_NET_MSG_LOCATION_MSG_H
2+
#define APCLIENT_NET_MSG_LOCATION_MSG_H
3+
#include <types.h>
4+
5+
#include "Net/IMessage.h"
6+
#include "Net/NetworkMgr.h"
7+
8+
#include <libkiwi.h>
9+
10+
namespace AP {
11+
namespace Net {
12+
13+
/**
14+
* @brief Location message
15+
*/
16+
class LocationMsg : public IMessage {
17+
public:
18+
/**
19+
* @brief Constructor
20+
*
21+
* @param rStrm Stream to packet content
22+
*/
23+
LocationMsg(kiwi::MemStream& rStrm);
24+
25+
/**
26+
* @brief returns MemStream of all location data
27+
*/
28+
kiwi::TVector<u32> GetLocationMsg();
29+
30+
/**
31+
* @brief Gets the type of this command
32+
*/
33+
virtual EKind GetKind() const {
34+
return EKind_Location;
35+
}
36+
private:
37+
kiwi::TVector<u32> mData;
38+
};
39+
40+
} // namespace Net
41+
} // namespace AP
42+
43+
#endif

src/packets.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ struct DisconnectPacket : CommonPacket {};
3636
*/
3737
struct ItemPacket : CommonPacket {};
3838

39+
/**
40+
* @brief Location packet (LocationMsg)
41+
*/
42+
struct LocationPacket : CommonPacket {};
43+
3944
} // namespace AP
4045

4146
#pragma pack(pop)

0 commit comments

Comments
 (0)