本文整理汇总了C++中PACKET函数的典型用法代码示例。如果您正苦于以下问题:C++ PACKET函数的具体用法?C++ PACKET怎么用?C++ PACKET使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PACKET函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PACKET
void g1_server_class::start_game()
{
PACKET(packet,r);
r.write_8(G1_PK_WE_ARE_STARTING);
r.write_32(4);
send_to_all(packet,&r);
send_to_all(packet,&r);
state=LOADING;
};
示例2: PACKET
void AppServer::sendTest(std::string msg)
{
PACKET(PacketTest, PACKET_TEST);
#ifdef PACKET_WITH_JSON
std::string data = "{\"msg\":" + msg + "}";
packet->setData(data, 0, false);
#else
packet->msg = msg;
#endif
SEND_PACKET(packet)
}
示例3: switch
int g1_client_class::prepare_command(int command)
{
g1_global_id.poll();
switch (state)
{
case SYNCING:
case LOADING:
{
state=SYNCING;
PACKET(sp,r);
r.write_8(G1_PK_LOADING_DONE);
i4_warning("We are ready to start.");
send_server(sp,&r);
}
return NE_ERROR_NOTREADY;
case RUNNING:
{
if (!network_file)
{
network_file=new i4_temp_file_class(2000,2000);
}
switch (command)
{
case G1_PK_GAME_DATA:
{
network_file->clear();
network_file->write_8(command);
network_file->write_32(0); //placeholder for length
network_file->write_32(g1_tick_counter);
}
break;
case G1_PK_PROCESS:
{
send_server(network_file->get_buffer(),network_file);
network_file->clear();
network_file->write_8(G1_PK_GAME_DATA);
network_file->write_32(0);
network_file->write_32(g1_tick_counter);
}
break;
}
}
break;
}
if (!g1_global_id.is_ready())
{
return NE_ERROR_NOTREADY;
}
return NE_ERROR_OK;
}
示例4: PACKET
CNpc::CNpc(uint8_t *pData, uint32_t size)
{
PACKET(Packets::SSpawnNPCPacket::SPacket, pData, packet);
m_Object.dir = TO_FLOAT_DIR(packet.dir);
m_Object.id = packet.id;
m_Object.type = packet.type;
m_Object.x = packet.x;
m_Object.y = packet.y;
m_Object.z = packet.z;
m_Object.dead = false;
}
示例5: crt_image_findfile
static int crt_image_findfile(crt_image *image, const char *fname)
{
int nr=0;
char name[6];
int i=sizeof(crt_header);
while (i<image->size) {
sprintf(name, "%d",nr);
if (!strcmp(fname, name) ) return i;
i+=GET_ULONG( PACKET(image, i)->packet_length );
nr++;
}
return 0;
}
示例6: crt_image_readfile
static int crt_image_readfile(imgtool_image *img, const char *fname, imgtool_stream *destf)
{
crt_image *image=(crt_image*)img;
int size;
int pos;
if (!(pos=crt_image_findfile(image, fname)) )
return IMGTOOLERR_MODULENOTFOUND;
size=GET_UWORD( PACKET(image, pos)->length );
if (stream_write(destf, image->data+pos+sizeof(crt_packet), size)!=size) {
return IMGTOOLERR_WRITEERROR;
}
return 0;
}
示例7: down_stack_app
// app data -> SSL -> protocol encapsulation -> reliability layer -> network
void down_stack_app()
{
if (ssl_started_)
{
// push app-layer cleartext through SSL object
while (!app_write_queue.empty())
{
BufferPtr& buf = app_write_queue.front();
try {
const ssize_t size = ssl_->write_cleartext_unbuffered(buf->data(), buf->size());
if (size == SSLContext::SSL::SHOULD_RETRY)
break;
}
catch (...)
{
if (stats)
stats->error(Error::SSL_ERROR);
invalidate(Error::SSL_ERROR);
throw;
}
app_write_queue.pop_front();
}
// encapsulate SSL ciphertext packets
while (ssl_->read_ciphertext_ready() && rel_send.ready())
{
typename ReliableSend::Message& m = rel_send.send(*now);
m.packet = PACKET(ssl_->read_ciphertext());
// encapsulate packet
try {
encapsulate(m.id(), m.packet);
}
catch (...)
{
if (stats)
stats->error(Error::ENCAPSULATION_ERROR);
invalidate(Error::ENCAPSULATION_ERROR);
throw;
}
// transmit it
net_send(m.packet, NET_SEND_SSL);
}
}
}
示例8: crt_image_deletefile
static int crt_image_deletefile(imgtool_image *img, const char *fname)
{
crt_image *image=(crt_image*)img;
int size;
int pos;
if (!(pos=crt_image_findfile(image, fname)) ) {
return IMGTOOLERR_MODULENOTFOUND;
}
size=GET_ULONG(PACKET(image, pos)->packet_length);
if (image->size-pos-size>0)
memmove(image->data+pos, image->data+pos+size, image->size-pos-size);
image->size-=size;
image->modified=1;
return 0;
}
示例9: crt_image_writefile
static int crt_image_writefile(imgtool_image *img, const char *fname, imgtool_stream *sourcef,
const ResolvedOption *_options)
{
crt_image *image=(crt_image*)img;
int size;
int pos;
size=stream_size(sourcef);
if (!(pos=crt_image_findfile(image, fname)) ) {
// appending
pos=image->size;
if (!(image->data=realloc(image->data, image->size+size+sizeof(crt_packet))) )
return IMGTOOLERR_OUTOFMEMORY;
image->size+=size+sizeof(crt_packet);
} else {
int oldsize=GET_ULONG(PACKET(image,pos)->packet_length);
// overwritting
if (!(image->data=realloc(image->data, image->size+size+sizeof(crt_packet)-oldsize) ) )
return IMGTOOLERR_OUTOFMEMORY;
if (image->size-pos-oldsize!=0) {
memmove(image->data+pos+size+sizeof(crt_packet), image->data+pos+oldsize,
image->size-pos-oldsize);
}
image->size+=size+sizeof(crt_packet)-oldsize;
}
if (stream_read(sourcef, image->data+pos+sizeof(crt_packet), size)!=size) {
return IMGTOOLERR_READERROR;
}
memset(image->data+pos, 0, sizeof(crt_packet));
memcpy(PACKET(image,pos)->id,"CHIP",4);
SET_ULONG( PACKET(image, pos)->packet_length, size+sizeof(crt_packet));
SET_UWORD(PACKET(image, pos)->chip_type, _options[C64CRT_FILEOPTION_FTYPE].i);
SET_UWORD( PACKET(image, pos)->address, _options[C64CRT_FILEOPTION_FADDR].i);
SET_UWORD( PACKET(image, pos)->bank, _options[C64CRT_FILEOPTION_FBANK].i);
SET_UWORD( PACKET(image, pos)->length, size);
image->modified=1;
return 0;
}
示例10: crt_image_nextenum
static int crt_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent)
{
crt_iterator *iter=(crt_iterator*)enumeration;
ent->corrupt=0;
if (!(ent->eof=(iter->pos>=iter->image->size))) {
sprintf(ent->fname,"%d", iter->number);
ent->filesize=GET_UWORD( PACKET(iter->image, iter->pos)->length );
if (ent->attr) {
unsigned crc=crc32(0, iter->image->data+iter->pos+sizeof(crt_packet), ent->filesize);
sprintf(ent->attr,"%-4s %s bank:%-2d addr:%.4x crc:%8x",
(char*)PACKET(iter->image, iter->pos),
chip_types[GET_UWORD(PACKET(iter->image,iter->pos)->chip_type)],
GET_UWORD( PACKET(iter->image,iter->pos)->bank),
GET_UWORD( PACKET(iter->image,iter->pos)->address),
crc);
}
iter->number++;
iter->pos+=GET_ULONG( PACKET(iter->image, iter->pos)->packet_length );
}
return 0;
}
示例11: r
void g1_server_class::process_client_packet(w8 * packet,
int packet_length,
int client_num)
{
clients[client_num].last_data.get();
i4_ram_file_class r(packet, packet_length);
w8 msg=r.read_8();
switch (msg)
{
case G1_PK_I_WANNA_JOIN:
{
r.read_16(); // skip use port
delete clients[client_num].username;
clients[client_num].username=r.read_counted_str();
send_player_joined(client_num);
}
break;
case G1_PK_LOADING_DONE:
{
clients[client_num].flags|=READY;
i4_bool ok=i4_T;
for (int i=0; i<G1_MAX_PLAYERS; i++)
{
if (clients[i].addr && !(clients[i].flags&READY))
{
ok=i4_F; //at least one is not yet ready;
}
}
if (ok&&state==SYNCING)
{
int rem_players,player,k,k2;
rem_players=0;
player=1; //zero is always neutral,
//1 is usually local (server) player
if (player==local_player_num)
{
player++;
}
for(k=0; k<G1_MAX_PLAYERS; k++)
{
if (clients[k].addr!=0)
{
rem_players++;
clients[k].remote_player_num=player;
player++;
if (player==local_player_num)
{
player++;
}
}
}
for (player=0; player<G1_MAX_PLAYERS; player++)
{
if (clients[player].addr)
{
PACKET(sp,s);
s.write_8(G1_PK_GAME_START);
s.write_32(G1_MAX_PLAYERS); //So many ai's are going to follow
for (k=0; k<G1_MAX_PLAYERS; k++)
{
s.write_32(k);
g1_player_info_class * pl=g1_player_man.get(k);
i4_bool found=i4_F;
if (k==0) //the neutral player
{
s.write_counted_str(*(pl->get_ai()->ai_name()));
found=i4_T;
}
else if (k==local_player_num)
{
s.write_counted_str("remote_player");
found=i4_T;
}
else
{
for (k2=0; k2<G1_MAX_PLAYERS; k2++)
{
if (clients[k2].addr && clients[k2].remote_player_num==k)
{
//this automatically indicates
//that it is the remote local player
//(only one player can be human at a time on
//a particular machine)
s.write_counted_str("human");
found=i4_T;
break;
}
}
}
if (!found) //this player will stay the same as originally defined on the map
{
s.write_counted_str(*(pl->get_ai()->ai_name()));
found=i4_T;
}
}
send_to(sp,&s,player);
send_to(sp,&s,player); //its important!
//.........这里部分代码省略.........
示例12: i4_message_box
i4_bool g1_client_class::poll() // returns false if server is not responding
{
if (!listen || !send)
{
return 0;
}
if (state==JOIN_START)
{
i4_time_class now;
if (now.milli_diff(last_responce_time)>40000) // if it's been 40 secs assume server dead
{
i4_message_box("Server not responding","The server is not responding any more. ",MSG_OK);
return i4_F;
}
w8 packet[512];
i4_ram_file_class r(packet, sizeof(packet));
r.write_8(G1_PK_I_WANNA_JOIN);
r.write_16(use_port);
r.write_counted_str(*g1_resources.username);
if (!send->write(packet, r.tell()))
{
return i4_F;
}
}
if (state==SYNCING) //set from the main loop as soon as the map is loaded
{
PACKET(pack,fp); //we just resend this message till we get the matching reply
fp.write_8(G1_PK_LOADING_DONE);
send_server(pack,&fp);
}
int noloops=0;
while (listen->ready_to_read() && noloops<10)
{
w8 packet[MAX_PACKET_SIZE];
i4_net_address * a;
int s=listen->read_from(packet, sizeof(packet), a);
if (a->equals(server_address))
{
i4_ram_file_class r(packet, sizeof(packet));
w8 new_message=r.read_8();
switch (new_message)
{
case G1_PK_YOU_HAVE_JOINED:
{
player_num=(w8)r.read_16();
if (map_name)
{
delete map_name;
}
map_name=r.read_counted_str();
i4_warning("We were accepted by the server to join");
state=CONNECTING;
last_responce_time.get();
}
break;
case G1_PK_WE_ARE_STARTING:
{
num_players=r.read_32();
if (state==CONNECTING)
{
i4_warning("Loading game data");
//don't do this twice.
//i4_user_message_event_class u(G1_START_NEW_GAME);
i4_file_open_message_class u(G1_SAVEGAME_LOAD_OK, new i4_str (* map_name));
i4_kernel.send_event(i4_current_app, &u);
state=LOADING;
}
//li_call("hide_main_menu");
}
break;
case G1_PK_GAME_START:
{
//from now on, it's the main loops task to know that
//this is a net game
if (state!=RUNNING)
{
int num_ais=r.read_32();
if (num_ais>G1_MAX_PLAYERS)
{
i4_error("ERROR: Local Golgotha version supports fewer players than this game needs. Check your version.");
num_ais=G1_MAX_PLAYERS;
}
i4_str * ainame=0;
g1_team_api_class * newai=0;
for (int ais=0; ais<num_ais; ais++)
{
//the player the next ai is for
w32 aifor=r.read_32();
ainame=r.read_counted_str();
char buf[100];
//.........这里部分代码省略.........
示例13: ProcessUDP
void ProcessUDP(Socket *s, socket_t client, void *buf, size_t len)
{
if (len > 512)
{
printf("WARNING: Invalid packet size: %ld, rejecting packet.\n", len);
return;
}
#ifdef _DEBUG
printf("============= PACKET DATA ==========\n");
fwrite(buf, 1, len, stdout);
printf("\nHex:\n");
for (size_t i = 0, j = 0; i < len; ++i, j++)
{
j %= 11;
printf("%-3X%c", ((uint8_t*)buf)[i], j == 10 ? '\n' : '\0');
}
tfm::printf("\nPacket Type: %s", PACKET(*(uint8_t*)buf));
printf("\n============= END PACKET DATA ==========\n");
#endif
for (auto it = clients.begin(), it_end = clients.end(); it != it_end;)
{
printf("Iterating client!\n");
whatever_t *w = *it;
if (w->c.in.sin_port == client.in.sin_port)
{
printf("Found client!\n");
packet_t pak;
memset(&pak, 0, sizeof(packet_t));
// Copy the packet.
memcpy(&pak, buf, len);
#ifdef _DEBUG
tfm::printf("RAW: packet %d (%.8X), packetno: %d (%.8X)\n", pak.packet, pak.packet, pak.packetno, pak.packetno);
tfm::printf("RAW ENDIAN: packet %d (%.8X), packetno: %d (%.8X)\n", pak.packet, pak.packet, htonl(pak.packetno), htonl(pak.packetno));
tfm::printf("Received packet %d (%s)\n", pak.packet, PACKET(pak.packet));
#endif
// So it isnt a burst, but are we bursting?
if (!w->bursting)
{
tfm::printf("Received packet %d (%s) but we're not bursting?? ignoring packet.\n", pak.packet, PACKET(pak.packet));
return;
}
/*
* Description:
* So basically the way this works is that we have 5 types of UDP packets.
* The first packet type is a "DATABURST" packet, signalling that the client wants to initiate a databurst.
* The second packet consists of a timeout value which is uint32_t bytes long, this is the time the client expects to reply.
* The third packet type is the number of packet chunks that will be sent (number of datablocks to expect).
* The forth packet type is the actual data info from the client which is MessagePack data.
* The fifth packet type signals the end of the databurst and to terminate the connection.
*/
switch (pak.packet)
{
case TIMEOUT:
// unfuck ntohl.
w->timeout = pak.packetno;//ntohl(pak.packetno);
return;
case INFOPACKS:
w->totalpackets = pak.packetno;//ntohl(pak.packetno);
return;
case INFO:
{
// TODO: Prevent buffer-overrun attack?
size_t datalen = len - sizeof(uint8_t) - sizeof(uint32_t);
uint8_t *typeddata = reinterpret_cast<uint8_t*>(pak.data);
w->data.insert(w->data.end(), typeddata, typeddata + datalen);
w->receivedpackets++;
return;
}
case ENDBURST:
{
if (w->receivedpackets == w->totalpackets)
{
printf("Processing client.");
break; // continue running the function.
}
else
{
// Just delete the received packets and continue until next response.
printf("Received invalid number of data packets: %ld (expected %ld)\n", w->receivedpackets, w->totalpackets);
clients.erase(it);
delete w;
return;
}
}
default:
printf("Invalid packet %d, rejecting...\n", pak.packet);
return;
}
printf("Received data burst! Unserializing the data...\n");
// Unserialize the packet data, then process.
information_t *info = UnserializeData(w->data);
// Process the info structure, this submits it to the database among other things.
//.........这里部分代码省略.........
示例14: fprintf
{
uint32_t *handles = cl + offset;
fprintf(stderr, "0x%08x 0x%08x: handle 0: %d, handle 1: %d\n",
offset, hw_offset, handles[0], handles[1]);
}
#define PACKET_DUMP(name) [name] = { #name, name ## _SIZE, dump_##name }
#define PACKET(name) [name] = { #name, name ## _SIZE, NULL }
static const struct packet_info {
const char *name;
uint8_t size;
void (*dump_func)(void *cl, uint32_t offset, uint32_t hw_offset);
} packet_info[] = {
PACKET(VC4_PACKET_HALT),
PACKET(VC4_PACKET_NOP),
PACKET(VC4_PACKET_FLUSH),
PACKET(VC4_PACKET_FLUSH_ALL),
PACKET(VC4_PACKET_START_TILE_BINNING),
PACKET(VC4_PACKET_INCREMENT_SEMAPHORE),
PACKET(VC4_PACKET_WAIT_ON_SEMAPHORE),
PACKET(VC4_PACKET_BRANCH),
PACKET_DUMP(VC4_PACKET_BRANCH_TO_SUB_LIST),
PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER),
PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF),
PACKET_DUMP(VC4_PACKET_STORE_FULL_RES_TILE_BUFFER),
PACKET_DUMP(VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER),
示例15: PACKET
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "util/u_math.h"
#include "util/macros.h"
#include "vc4_context.h"
#define PACKET(name, size) [name] = { #name, size }
static const struct packet_info {
const char *name;
uint8_t size;
} packet_info[] = {
PACKET(VC4_PACKET_HALT, 1),
PACKET(VC4_PACKET_NOP, 1),
PACKET(VC4_PACKET_FLUSH, 1),
PACKET(VC4_PACKET_FLUSH_ALL, 1),
PACKET(VC4_PACKET_START_TILE_BINNING, 1),
PACKET(VC4_PACKET_INCREMENT_SEMAPHORE, 1),
PACKET(VC4_PACKET_WAIT_ON_SEMAPHORE, 1),
PACKET(VC4_PACKET_BRANCH, 5),
PACKET(VC4_PACKET_BRANCH_TO_SUB_LIST, 5),
PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER, 1),
PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF, 1),
PACKET(VC4_PACKET_STORE_FULL_RES_TILE_BUFFER, 5),
PACKET(VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER, 5),