2016-01-28 14:52:40 +01:00
|
|
|
/** @file
|
|
|
|
|
*
|
|
|
|
|
* @par History
|
|
|
|
|
* - 2009/07/23 MuadDib: updates for new Enum::Packet Out ID
|
|
|
|
|
*/
|
2016-02-11 22:54:43 +01:00
|
|
|
|
|
|
|
|
|
2018-01-29 21:55:48 +01:00
|
|
|
#include <string>
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../clib/clib_endian.h"
|
|
|
|
|
#include "../clib/rawtypes.h"
|
|
|
|
|
#include "globals/uvars.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
#include "network/packethelper.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "network/packets.h"
|
2018-12-30 21:35:54 +01:00
|
|
|
#include "network/pktdef.h"
|
|
|
|
|
#include "network/pktin.h"
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
namespace Pol
|
|
|
|
|
{
|
|
|
|
|
namespace Core
|
|
|
|
|
{
|
|
|
|
|
bool send_tip( Network::Client* client, const char* tipname, unsigned short tipnum )
|
|
|
|
|
{
|
2021-11-09 09:01:31 +02:00
|
|
|
std::string convertedText = Clib::strUtf8ToCp1252( tipname );
|
|
|
|
|
size_t textlen = convertedText.length() + 1;
|
2016-02-19 19:26:35 +01:00
|
|
|
if ( textlen > 0 && unsigned( textlen ) <= 9999 )
|
|
|
|
|
{
|
|
|
|
|
Network::PktHelper::PacketOut<Network::PktOut_A6> msg;
|
2021-11-09 09:01:31 +02:00
|
|
|
msg->WriteFlipped<u16>( textlen + 10 );
|
2016-02-19 19:26:35 +01:00
|
|
|
msg->Write<u8>( PKTOUT_A6_TYPE_TIP );
|
|
|
|
|
msg->offset += 2; // unk4,5
|
|
|
|
|
msg->WriteFlipped<u16>( tipnum );
|
2021-11-09 09:01:31 +02:00
|
|
|
msg->WriteFlipped<u16>( textlen );
|
|
|
|
|
msg->Write( convertedText.c_str(), static_cast<u16>( textlen ) );
|
2016-02-19 19:26:35 +01:00
|
|
|
msg.Send( client );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
void send_tip( Network::Client* client, const std::string& tiptext )
|
|
|
|
|
{
|
2021-11-09 09:01:31 +02:00
|
|
|
std::string convertedText = Clib::strUtf8ToCp1252(tiptext);
|
|
|
|
|
size_t textlen = convertedText.size() + 1;
|
2016-02-19 19:26:35 +01:00
|
|
|
if ( textlen >= 10000 )
|
|
|
|
|
textlen = 9999;
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
Network::PktHelper::PacketOut<Network::PktOut_A6> msg;
|
2021-11-09 09:01:31 +02:00
|
|
|
msg->WriteFlipped<u16>( textlen + 10 );
|
2016-02-19 19:26:35 +01:00
|
|
|
msg->Write<u8>( PKTOUT_A6_TYPE_TIP );
|
|
|
|
|
msg->offset += 2; // unk4,5
|
|
|
|
|
msg->offset += 2; // tipnum
|
2021-11-09 09:01:31 +02:00
|
|
|
msg->WriteFlipped<u16>( textlen );
|
|
|
|
|
msg->Write( convertedText.c_str(), static_cast<u16>( textlen ) );
|
2016-02-19 19:26:35 +01:00
|
|
|
msg.Send( client );
|
|
|
|
|
}
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
void handle_get_tip( Network::Client* client, PKTIN_A7* msg )
|
|
|
|
|
{
|
|
|
|
|
u16 tipnum = cfBEu16( msg->lasttip );
|
|
|
|
|
if ( !gamestate.tipfilenames.empty() )
|
|
|
|
|
{
|
|
|
|
|
if ( msg->prevnext )
|
|
|
|
|
{
|
|
|
|
|
++tipnum;
|
|
|
|
|
if ( tipnum >= gamestate.tipfilenames.size() )
|
|
|
|
|
tipnum = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
--tipnum;
|
|
|
|
|
if ( tipnum >= gamestate.tipfilenames.size() )
|
|
|
|
|
tipnum = static_cast<u16>( gamestate.tipfilenames.size() ) - 1;
|
|
|
|
|
}
|
2016-02-11 22:54:43 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
send_tip( client, gamestate.tipfilenames[tipnum].c_str(), tipnum );
|
2016-02-11 22:54:43 +01:00
|
|
|
}
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
2018-12-30 21:35:54 +01:00
|
|
|
} // namespace Core
|
|
|
|
|
} // namespace Pol
|