summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/NetPacket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'StarsEx/NetPacket.cpp')
-rw-r--r--StarsEx/NetPacket.cpp83
1 files changed, 41 insertions, 42 deletions
diff --git a/StarsEx/NetPacket.cpp b/StarsEx/NetPacket.cpp
index e8964c2..96d61a6 100644
--- a/StarsEx/NetPacket.cpp
+++ b/StarsEx/NetPacket.cpp
@@ -12,12 +12,14 @@
*/
#include "NetPacket.h"
+
+#include <cstdint>
+
+#include "Game.h"
#include "NetLink.h"
#include "NetMsg.h"
#include "Ship.h"
-#include "Game.h"
-
// +--------------------------------------------------------------------+
const int PING_SIZE = 8;
@@ -32,7 +34,7 @@ NetPacket::NetPacket(NetMsg* g)
: msg(g)
{ }
-NetPacket::NetPacket(DWORD netid, BYTE type)
+NetPacket::NetPacket(std::uint32_t netid, std::uint8_t type)
{
int len = 0;
char buf[256];
@@ -72,7 +74,7 @@ NetPacket::Send(NetLink& link)
// +--------------------------------------------------------------------+
-DWORD
+std::uint32_t
NetPacket::NetID() const
{
if (msg)
@@ -81,7 +83,7 @@ NetPacket::NetID() const
return 0;
}
-BYTE
+std::uint8_t
NetPacket::Type() const
{
if (msg)
@@ -92,11 +94,11 @@ NetPacket::Type() const
// +--------------------------------------------------------------------+
-DWORD
+std::uint32_t
NetPacket::GetPingSequence()
{
if (msg && msg->Length() >= PING_SIZE) {
- DWORD* data = (DWORD*) (msg->Data()+4);
+ auto* data = reinterpret_cast<std::uint32_t*>(msg->Data() + 4);
return *data;
}
@@ -104,21 +106,21 @@ NetPacket::GetPingSequence()
}
void
-NetPacket::SetPingSequence(DWORD seq)
+NetPacket::SetPingSequence(std::uint32_t seq)
{
if (msg && msg->Length() >= PING_SIZE) {
- DWORD* data = (DWORD*) (msg->Data()+4);
+ auto* data = reinterpret_cast<std::uint32_t*>(msg->Data() + 4);
*data = seq;
}
}
// +--------------------------------------------------------------------+
-DWORD
+std::uint32_t
NetPacket::GetNetID()
{
if (msg && msg->Length() >= PING_SIZE) {
- DWORD* data = (DWORD*) (msg->Data()+4);
+ auto* data = reinterpret_cast<std::uint32_t*>(msg->Data() + 4);
return *data;
}
@@ -126,10 +128,10 @@ NetPacket::GetNetID()
}
void
-NetPacket::SetNetID(DWORD id)
+NetPacket::SetNetID(std::uint32_t id)
{
if (msg && msg->Length() >= PING_SIZE) {
- DWORD* data = (DWORD*) (msg->Data()+4);
+ auto* data = reinterpret_cast<std::uint32_t*>(msg->Data() + 4);
*data = id;
}
}
@@ -140,7 +142,7 @@ Point
NetPacket::GetShipLocation()
{
if (msg && msg->Length() >= SHIP_LOC_SIZE) {
- long* data = (long*) (msg->Data()+8);
+ auto* data = reinterpret_cast<long*>(msg->Data() + 8);
long x = *(data + 0);
long y = *(data + 1);
long z = *(data + 2);
@@ -159,7 +161,7 @@ NetPacket::SetShipLocation(const Point& loc)
long y = (long) (loc.y * 100);
long z = (long) (loc.z * 100);
- long* data = (long*) (msg->Data()+8);
+ auto* data = reinterpret_cast<long*>(msg->Data() + 8);
*(data + 0) = x;
*(data + 1) = y;
@@ -173,7 +175,7 @@ Point
NetPacket::GetShipVelocity()
{
if (msg && msg->Length() >= SHIP_LOC_SIZE) {
- short* data = (short*) (msg->Data()+20);
+ auto* data = reinterpret_cast<short*>(msg->Data() + 20);
short dx = *(data + 0);
short dy = *(data + 1);
@@ -189,7 +191,7 @@ void
NetPacket::SetShipVelocity(const Point& vel)
{
if (msg && msg->Length() >= SHIP_LOC_SIZE) {
- short* data = (short*) (msg->Data()+20);
+ auto* data = reinterpret_cast<short*>(msg->Data() + 20);
*(data + 0) = (short) vel.x;
*(data + 1) = (short) vel.y;
@@ -203,7 +205,7 @@ Point
NetPacket::GetShipOrientation()
{
if (msg && msg->Length() >= SHIP_LOC_SIZE) {
- short* data = (short*) (msg->Data()+26);
+ auto* data = reinterpret_cast<short*>(msg->Data() + 26);
short r = *(data + 0);
short p = *(data + 1);
@@ -219,7 +221,7 @@ void
NetPacket::SetShipOrientation(const Point& rpy)
{
if (msg && msg->Length() >= SHIP_LOC_SIZE) {
- short* data = (short*) (msg->Data()+26);
+ auto* data = reinterpret_cast<short*>(msg->Data() + 26);
*(data + 0) = (short) (32767*rpy.x/(2*PI));
*(data + 1) = (short) (32767*rpy.y/(2*PI));
@@ -233,9 +235,9 @@ double
NetPacket::GetThrottle()
{
if (msg && msg->Length() >= SHIP_LOC_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+32;
+ auto* data = reinterpret_cast<std::uint8_t*>(msg->Data() + 32);
- return (double) *data;
+ return static_cast<double>(*data);
}
return 0;
@@ -245,9 +247,9 @@ void
NetPacket::SetThrottle(double t)
{
if (msg && msg->Length() >= SHIP_LOC_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+32;
+ auto* data = reinterpret_cast<std::uint8_t*>(msg->Data() + 32);
- *data = (BYTE) t;
+ *data = static_cast<std::uint8_t>(t);
}
}
@@ -257,9 +259,9 @@ bool
NetPacket::GetTrigger(int i)
{
if (i >= 0 && i < 8 && msg && msg->Length() >= SHIP_LOC_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+33;
+ auto* data = reinterpret_cast<std::uint8_t*>(msg->Data() + 33);
- BYTE select = 1 << i;
+ std::uint8_t select = 1 << i;
return (*data & select)?true:false;
}
@@ -270,9 +272,9 @@ void
NetPacket::SetTrigger(int i, bool trigger)
{
if (i >= 0 && i < 8 && msg && msg->Length() >= SHIP_LOC_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+33;
+ auto* data = reinterpret_cast<std::uint8_t*>(msg->Data() + 33);
- BYTE select = 1 << i;
+ std::uint8_t select = 1 << i;
if (trigger)
*data = *data | select;
@@ -287,9 +289,9 @@ const char*
NetPacket::GetName()
{
if (msg && msg->Length() >= JOIN_REQ_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+20;
+ auto* data = reinterpret_cast<const char*>(msg->Data() + 20);
- return (const char*) data;
+ return data;
}
return 0;
@@ -299,8 +301,8 @@ void
NetPacket::SetName(const char* name)
{
if (msg && msg->Length() >= JOIN_REQ_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+20;
- strncpy((char*) data, name, 32);
+ auto* data = reinterpret_cast<char*>(msg->Data() + 20);
+ strncpy(data, name, 32);
}
}
@@ -310,9 +312,9 @@ const char*
NetPacket::GetDesign()
{
if (msg && msg->Length() >= JOIN_REQ_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+52;
+ auto* data = reinterpret_cast<const char*>(msg->Data() + 52);
- return (const char*) data;
+ return data;
}
return 0;
@@ -322,8 +324,8 @@ void
NetPacket::SetDesign(const char* design)
{
if (msg && msg->Length() >= JOIN_REQ_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+52;
- strncpy((char*) data, design, 32);
+ auto* data = reinterpret_cast<char*>(msg->Data() + 52);
+ strncpy(data, design, 32);
}
}
@@ -333,9 +335,9 @@ const char*
NetPacket::GetRegion()
{
if (msg && msg->Length() >= JOIN_REQ_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+84;
+ auto* data = reinterpret_cast<const char*>(msg->Data() + 84);
- return (const char*) data;
+ return data;
}
return 0;
@@ -345,10 +347,7 @@ void
NetPacket::SetRegion(const char* rgn_name)
{
if (msg && msg->Length() >= JOIN_REQ_SIZE) {
- BYTE* data = (BYTE*) msg->Data()+84;
- strncpy((char*) data, rgn_name, 32);
+ auto* data = reinterpret_cast<char*>(msg->Data() + 84);
+ strncpy(data, rgn_name, 32);
}
}
-
-// +--------------------------------------------------------------------+
-