Beispiel #1
0
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);
}
Beispiel #2
0
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();
  }
}
Beispiel #3
0
void XETP::send_command(OutStreamP out,
                        const IntelId &iId,ITcommand command) {
  u_int len = 
    Identifier::get_write_length() + // intelId
    sizeof(char);                     // command
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }
  
  send_header(out,COMMAND,len);
  iId.write(out);
  assert(command <= UCHAR_MAX);
  out->write_char((u_char)command);
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Beispiel #4
0
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();
  }
}
Beispiel #5
0
void XETP::send_rooms_known(OutStreamP out,const Rooms &rooms,
                            int worldVersion,Boolean *map) {
  int mapSize = rooms.acrossMax * rooms.downMax;

  u_int len = sizeof(int) +             // version
    Rooms::get_write_length() +       // rooms
    sizeof(char) * mapSize;           // map
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }

  send_header(out,ROOMS_KNOWN,len);
  out->write_int(worldVersion);
  rooms.write(out);
  for (int n = 0; n < mapSize; n++) {
    out->write_char((u_char)map[n]);
  }
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Beispiel #6
0
void ViewportInfo::write(OutStreamP out) const {
  out->write_char((char)smoothScroll);
  logicalSize.write_32(out);
  extraSize.write(out);
  out->write_int(radius);
}