void Identifier::write(OutStreamP out) const { u_short val; if (index == INVALID) { val = 0xffff; } else { assert(index < USHRT_MAX); // strictly less than to avoid 0xffff val = (u_short)index; } out->write_short(val); out->write_int(unique); }
void XETP::_send_object(OutStreamP out,PhysicalP p,Turn turn, TickType tt,u_int len) { // len does not include the XETP header. const PhysicalContext *cx = p->get_context(); // Only send objects that can be read back in. assert(cx->create_from_stream); Id id = p->get_id(); send_header(out,OBJECT,len); assert(p->get_class_id() <= USHRT_MAX); out->write_short((u_short)p->get_class_id()); id.write(out); out->write_int((int)turn); assert(tt <= UCHAR_MAX); out->write_char((char)tt); p->write(out); }
void XETP::send_server_pong(OutStreamP out,GameStyleType gameStyle, int enemiesNum,int humansNum, const char* version, const char* names[],const char* clientNames[], int humanKills[], int enemyKills[],const Id ids[]) { u_int len = sizeof(u_char) + // gameStyle sizeof(u_int) + // enemiesNum sizeof(u_short) + // humansNum Utils::get_string_write_length(version); // version int n; for (n = 0; n < humansNum; n++) { len += Utils::get_string_write_length(names[n]); // name len += Utils::get_string_write_length(clientNames[n]); // name len += sizeof(u_int); // humanKills len += sizeof(u_int); // enemyKills len += Id::get_write_length(); // Id } if (out->get_protocol() == GenericStream::UDP) { ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len)); } assert(gameStyle < 256 && enemiesNum >= 0 && humansNum >= 0 && (((u_int)humansNum & 0xffff0000) == 0)); send_header(out,SERVER_PONG,len); out->write_char((u_char)gameStyle); out->write_int((u_int)enemiesNum); out->write_short((u_short)humansNum); Utils::string_write(out,version); // Write out data for each human. for (n = 0; n < humansNum; n++) { Utils::string_write(out,names[n]); Utils::string_write(out,clientNames[n]); out->write_int((u_int)humanKills[n]); out->write_int((u_int)enemyKills[n]); ids[n].write(out); } if (out->get_protocol() == GenericStream::UDP) { ((UDPOutStreamP)out)->done_packet(); } }
void XETP::send_tcp_connect(OutStreamP out,u_short udpPort,char *humanName, const ViewportInfo &vInfo,int skip,Boolean wantSounds) { assert(humanName); // can still be "". u_int len = sizeof(u_short) + // udpPort Utils::get_string_write_length(humanName) + // humanName ViewportInfo::get_write_length(); // vInfo if (out->get_protocol() == GenericStream::UDP) { ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len)); } send_header(out,TCP_CONNECT,len); out->write_short(udpPort); Utils::string_write(out,humanName); vInfo.write(out); out->write_int(skip); out->write_char((char)wantSounds); if (out->get_protocol() == GenericStream::UDP) { ((UDPOutStreamP)out)->done_packet(); } }