Example #1
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_world_room(OutStreamP out,WorldP world,
                           const RoomIndex &idx,int worldVersion) {
  u_int len = sizeof(int) +             // version
    Rooms::get_write_length() +       // rooms
    RoomIndex::get_write_length() +   // roomIndex
    Dim::get_write_length() +         // dim
    world->get_write_length(idx);     // world room data

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }

  send_header(out,WORLD_ROOM,len);
  out->write_int(worldVersion);
  Rooms rooms = world->get_rooms();
  rooms.write(out);
  idx.write(out);
  Dim dim = world->get_dim();
  dim.write(out);
  world->write(out,idx); // write one room

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #2
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_objects(OutStreamP out,const PtrList &physicals,
                        Turn turn,const PtrList &tickTypes) {
  assert(physicals.length() == tickTypes.length());
  u_int totalLen = 0;
  int n;
  for (n = 0; n < physicals.length(); n++) {
    totalLen += 
      XETP::add_header(compute_object_length((PhysicalP)physicals.get(n)));
  }

  // length passed into UDP prepare_packet is bigger than the lengths 
  // passed into each XETP packet.
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(totalLen);
  }
  
  // Send each object in turn.
  for (n = 0; n < physicals.length(); n++) {
    PhysicalP p = (PhysicalP)physicals.get(n);
    // computing object_length twice, but who cares.
    _send_object(out,p,turn,(TickType)(size_t)tickTypes.get(n),
                 compute_object_length(p));
  }
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }      
}
Example #3
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_object(OutStreamP out,PhysicalP p,Turn turn,TickType tt) {
  u_int len = compute_object_length(p);

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }
  
  _send_object(out,p,turn,tt,len);
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }    
}
Example #4
0
File: id.cpp Project: toppk/xevil
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);
}
Example #5
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_sound_request(OutStreamP out,const SoundRequest &request) {
  u_int len = 
    SoundRequest::get_write_length();
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }
  
  send_header(out,SOUND_REQUEST,len);
  request.write(out);

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #6
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_delete_object(OutStreamP out,const Id &id) {
  u_int len = 
    Identifier::get_write_length();  // Id
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }
  
  send_header(out,DELETE_OBJECT,len);
  id.write(out);
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #7
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_new_world(OutStreamP out,WorldP world,int worldVersion) {
  u_int len = sizeof(int) +       // version
    world->get_write_length();  // world data
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }

  send_header(out,NEW_WORLD,len);
  out->write_int(worldVersion);
  world->write(out);

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #8
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_timer_pong(OutStreamP out,Turn pingTurn,Turn localTurn) {
  u_int len = 
    2 * sizeof(Turn);
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }
  
  send_header(out,TIMER_PONG,len);
  out->write_int((int)pingTurn);
  out->write_int((int)localTurn);
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #9
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_message(OutStreamP out,char *msg) {
  assert(msg);
  u_int len = strlen(msg);
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }

  send_header(out,MESSAGE,len);
  // signed/unsigned shouldn't matter here, ASCII only.
  out->write((u_char *)msg,len);
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #10
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_arena_message(OutStreamP out,int time,char *msg) {
  assert(msg);
  u_int len = sizeof(int) +  // time
    strlen(msg);             // string body
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }

  send_header(out,ARENA_MESSAGE,len);
  out->write_int(time);
  // signed/unsigned shouldn't matter here.
  out->write(msg,len - sizeof(int));
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #11
0
File: xetp.cpp Project: toppk/xevil
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);
}
Example #12
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_chat_request(OutStreamP out,const char* receiver,
                             const char* message) {
  u_int len = 
    Utils::get_string_write_length(receiver) +    // receiverName
    Utils::get_string_write_length(message);      // message
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }
  
  send_header(out,CHAT_REQUEST,len);
  Utils::string_write(out,receiver);
  Utils::string_write(out,message);

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #13
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_human(OutStreamP out,HumanP human) {
  u_int len = 
    Identifier::get_write_length() + // intelId
    human->get_write_length();       // human data
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }
  
  send_header(out,HUMAN,len);
  IntelId intelId = human->get_intel_id();
  intelId.write(out);
  human->write(out);

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #14
0
File: xetp.cpp Project: toppk/xevil
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();
  }
}
Example #15
0
File: xetp.cpp Project: toppk/xevil
void XETP::send_chat(OutStreamP out,const char* sender,
                     const IntelId& senderId,const char* message) {
  u_int len = 
    Utils::get_string_write_length(sender) +      // sender
    IntelId::get_write_length() +                 // senderId
    Utils::get_string_write_length(message);      // message
  
  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }
  
  send_header(out,CHAT,len);
  Utils::string_write(out,sender);
  senderId.write(out);
  Utils::string_write(out,message);

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
Example #16
0
File: xetp.cpp Project: toppk/xevil
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();
  }
}
Example #17
0
File: xetp.cpp Project: toppk/xevil
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();
  }
}
Example #18
0
File: xetp.cpp Project: toppk/xevil
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();
  }
}
Example #19
0
void ViewportInfo::write(OutStreamP out) const {
  out->write_char((char)smoothScroll);
  logicalSize.write_32(out);
  extraSize.write(out);
  out->write_int(radius);
}