Pol  Revision:cb584c9
ufunc2.cpp
Go to the documentation of this file.
1 
10 #include "../clib/rawtypes.h"
11 #include "containr.h"
12 #include "item/item.h"
13 #include "menu.h"
14 #include "mobile/charactr.h"
15 #include "network/client.h"
16 #include "network/packethelper.h"
17 #include "network/packets.h"
18 #include "tooltips.h"
19 #include "ufunc.h"
20 
21 
22 namespace Pol
23 {
24 namespace Core
25 {
26 using namespace Network;
27 
28 bool send_menu( Client* client, Menu* menu )
29 {
30  // build up the message so it gets sent as a unit.
31  if ( menu->menuitems_.size() > 255 )
32  return false;
33 
35  msg->offset += 2;
36  msg->offset += 4; // used_item_serial
37  msg->WriteFlipped<u16>( menu->menu_id );
38  size_t stringlen = strlen( menu->title );
39  if ( stringlen > 80 )
40  stringlen = 80;
41  msg->Write<u8>( stringlen ); // NOTE null-term not included!
42  msg->Write( menu->title, static_cast<u16>( stringlen ), false );
43  msg->Write<u8>( menu->menuitems_.size() );
44 
45  for ( unsigned idx = 0; idx < menu->menuitems_.size(); idx++ )
46  {
47  if ( msg->offset + 85 > static_cast<u16>( sizeof msg->buffer ) )
48  {
49  return false;
50  }
51  MenuItem* mi = &menu->menuitems_[idx];
52  msg->WriteFlipped<u16>( mi->graphic_ );
53  msg->WriteFlipped<u16>( mi->color_ );
54  stringlen = strlen( mi->title );
55  if ( stringlen > 80 )
56  stringlen = 80;
57  msg->Write<u8>( stringlen ); // NOTE null-term not included!
58  msg->Write( mi->title, static_cast<u16>( stringlen ), false );
59  }
60  u16 len = msg->offset;
61  msg->offset = 1;
62  msg->WriteFlipped<u16>( len );
63  msg.Send( client, len );
64  return true;
65 }
66 
67 void send_open_gump( Client* client, const UContainer& cont )
68 {
70  msg->Write<u32>( cont.serial_ext );
71  msg->WriteFlipped<u16>( cont.gump() );
72  if ( client->ClientType & CLIENTTYPE_7090 )
73  msg->WriteFlipped<u16>( 0x7Du );
74  msg.Send( client );
75 }
76 
77 // dave changed 11/9/3, don't send invis items to those who can't see invis
78 void send_container_contents( Client* client, const UContainer& cont )
79 {
81  msg->offset += 4; // msglen+count
82  u16 count = 0;
83  for ( UContainer::const_iterator itr = cont.begin(), itrend = cont.end(); itr != itrend; ++itr )
84  {
85  const Items::Item* item = GET_ITEM_PTR( itr );
86  if ( !item->invisible() || client->chr->can_seeinvisitems() )
87  {
88  msg->Write<u32>( item->serial_ext );
89  msg->WriteFlipped<u16>( item->graphic );
90  msg->offset++; // unk6
91  msg->WriteFlipped<u16>( item->get_senditem_amount() );
92  msg->WriteFlipped<u16>( item->x );
93  msg->WriteFlipped<u16>( item->y );
94  if ( client->ClientType & CLIENTTYPE_6017 )
95  msg->Write<u8>( item->slot_index() );
96  msg->Write<u32>( cont.serial_ext );
97  msg->WriteFlipped<u16>( item->color ); // color
98  ++count;
99  }
100  else
101  {
103  client, item ); // TODO: Doesn't this send a list of invisible items on the corpse?
104  }
105  }
106  u16 len = msg->offset;
107  msg->offset = 1;
108  msg->WriteFlipped<u16>( len );
109  msg->WriteFlipped<u16>( count );
110  msg.Send( client, len );
111 
112  if ( client->UOExpansionFlag & AOS )
113  {
114  // 07/11/09 Turley: moved to bottom first the client needs to know the item then we can send
115  // revision
116  for ( UContainer::const_iterator itr = cont.begin(), itrend = cont.end(); itr != itrend; ++itr )
117  {
118  const Items::Item* item = GET_ITEM_PTR( itr );
119  if ( !item->invisible() || client->chr->can_seeinvisitems() )
120  {
121  send_object_cache( client, item );
122  }
123  }
124  }
125 }
126 }
127 }
Contents::const_iterator const_iterator
Definition: containr.h:115
unsigned char u8
Definition: rawtypes.h:25
char title[80]
Definition: menu.h:37
void send_open_gump(Network::Client *client, const UContainer &cont)
Definition: ufunc2.cpp:67
bool can_seeinvisitems() const
Definition: charactr.h:1032
Mobile::Character * chr
Definition: client.h:182
virtual u16 get_senditem_amount() const
Definition: item.cpp:552
std::vector< MenuItem > menuitems_
Definition: menu.h:57
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
const u16 AOS
Definition: client.h:75
void send_remove_object(Client *client, const UObject *object)
Definition: ufunc.cpp:420
void Send(Client *client, int len=-1) const
Definition: packethelper.h:69
bool send_menu(Network::Client *client, Menu *menu)
Definition: ufunc2.cpp:28
unsigned short menu_id
Definition: menu.h:53
#define GET_ITEM_PTR(itr)
Definition: containr.h:38
u8 slot_index() const
Definition: item.h:358
bool invisible() const
Definition: item.h:324
void send_container_contents(Network::Client *client, const UContainer &cont)
Definition: ufunc2.cpp:78
void send_object_cache(Network::Client *client, const UObject *obj)
Definition: tooltips.cpp:68
u16 gump() const
Definition: containr.cpp:707
Definition: berror.cpp:12
char title[80]
Definition: menu.h:55