2007-02-25 23:16:26 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* Copyright (C) 2007 by Lothar May *
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <net/netpacket.h>
|
2007-03-13 02:23:12 +00:00
|
|
|
#include <net/netexception.h>
|
|
|
|
|
#include <net/socket_msg.h>
|
2007-02-25 23:16:26 +00:00
|
|
|
|
|
|
|
|
NetPacket::~NetPacket()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 02:20:50 +00:00
|
|
|
const NetPacketInit *
|
|
|
|
|
NetPacket::ToNetPacketInit() const
|
2007-03-13 02:23:12 +00:00
|
|
|
{
|
2007-03-20 02:20:50 +00:00
|
|
|
return NULL;
|
2007-03-13 02:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
2007-03-20 02:20:50 +00:00
|
|
|
const NetPacketInitAck *
|
|
|
|
|
NetPacket::ToNetPacketInitAck() const
|
2007-02-25 23:16:26 +00:00
|
|
|
{
|
2007-03-20 02:20:50 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketGameStart *
|
|
|
|
|
NetPacket::ToNetPacketGameStart() const
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
NetPacketInit::NetPacketInit()
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetPacketInit::NetPacketInit(u_int32_t value)
|
|
|
|
|
{
|
|
|
|
|
Init();
|
2007-03-13 02:23:12 +00:00
|
|
|
m_data.test = htonl(value);
|
2007-02-25 23:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
2007-03-20 02:20:50 +00:00
|
|
|
NetPacketInit::~NetPacketInit()
|
2007-02-25 23:16:26 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-13 02:23:12 +00:00
|
|
|
void
|
2007-03-20 02:20:50 +00:00
|
|
|
NetPacketInit::Init()
|
|
|
|
|
{
|
|
|
|
|
m_data.head.type = htons(NET_TYPE_INIT);
|
|
|
|
|
m_data.head.length = htons(sizeof(m_data));
|
|
|
|
|
m_data.test = htonl(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketHeader *
|
|
|
|
|
NetPacketInit::GetData() const
|
|
|
|
|
{
|
|
|
|
|
return (const NetPacketHeader *)&m_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketInit::SetData(const NetPacketHeader *p)
|
2007-03-13 02:23:12 +00:00
|
|
|
{
|
|
|
|
|
u_int16_t tmpLen = ntohs(p->length);
|
|
|
|
|
if (tmpLen != sizeof(m_data)
|
2007-03-20 02:20:50 +00:00
|
|
|
|| ntohs(p->type) != NET_TYPE_INIT)
|
2007-03-13 02:23:12 +00:00
|
|
|
{
|
|
|
|
|
throw NetException(ERR_SOCK_INTERNAL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(&m_data, p, tmpLen);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 02:20:50 +00:00
|
|
|
const NetPacketInit *
|
|
|
|
|
NetPacketInit::ToNetPacketInit() const
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
NetPacketInitAck::NetPacketInitAck()
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetPacketInitAck::NetPacketInitAck(u_int32_t value)
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
m_data.test = htonl(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetPacketInitAck::~NetPacketInitAck()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketInitAck::Init()
|
|
|
|
|
{
|
|
|
|
|
m_data.head.type = htons(NET_TYPE_INIT_ACK);
|
|
|
|
|
m_data.head.length = htons(sizeof(m_data));
|
|
|
|
|
m_data.test = htonl(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketHeader *
|
|
|
|
|
NetPacketInitAck::GetData() const
|
|
|
|
|
{
|
|
|
|
|
return (const NetPacketHeader *)&m_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketInitAck::SetData(const NetPacketHeader *p)
|
|
|
|
|
{
|
|
|
|
|
u_int16_t tmpLen = ntohs(p->length);
|
|
|
|
|
if (tmpLen != sizeof(m_data)
|
|
|
|
|
|| ntohs(p->type) != NET_TYPE_INIT_ACK)
|
|
|
|
|
{
|
|
|
|
|
throw NetException(ERR_SOCK_INTERNAL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(&m_data, p, tmpLen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketInitAck *
|
|
|
|
|
NetPacketInitAck::ToNetPacketInitAck() const
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
NetPacketGameStart::NetPacketGameStart()
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetPacketGameStart::NetPacketGameStart(u_int32_t value)
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
m_data.test = htonl(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetPacketGameStart::~NetPacketGameStart()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketGameStart::Init()
|
|
|
|
|
{
|
|
|
|
|
m_data.head.type = htons(NET_TYPE_GAME_START);
|
|
|
|
|
m_data.head.length = htons(sizeof(m_data));
|
|
|
|
|
m_data.test = htonl(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketHeader *
|
|
|
|
|
NetPacketGameStart::GetData() const
|
|
|
|
|
{
|
|
|
|
|
return (NetPacketHeader *)&m_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketGameStart::SetData(const NetPacketHeader *p)
|
|
|
|
|
{
|
|
|
|
|
u_int16_t tmpLen = ntohs(p->length);
|
|
|
|
|
if (tmpLen != sizeof(m_data)
|
|
|
|
|
|| ntohs(p->type) != NET_TYPE_GAME_START)
|
|
|
|
|
{
|
|
|
|
|
throw NetException(ERR_SOCK_INTERNAL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(&m_data, p, tmpLen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketGameStart *
|
|
|
|
|
NetPacketGameStart::ToNetPacketGameStart() const
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|