Example #1
0
void Picturecontrol::sendFilename(int cid, int myId, int pid, Net &net, Client &client)
{
  // boundary checks for from and to already done in net.cpp
  // pid is checked against piclen but not against files

  if (pid > -1 && pid < (int) files.size()) {
    *out << VERBOSE_QUIET << "sending filename...\n";

    Unit unit;

    unit.picfetch.flag = UNIT_PICFETCH;
    unit.picfetch.from = myId;
    unit.picfetch.to = cid;
    unit.picfetch.pid = pid;

    // don't get rid of path cos when client requests file I need to know where it is!
    /*std::string name;
    size_t found = files[pid].find_last_of('/');
    if (found != std::string::npos) name = files[pid].substr(found+1);
    else name = files[pid];*/

    if (files[pid].size() > MAX_FILENAME_SIZE - 1) {
      *out << VERBOSE_LOUD << "Filename too long: " << files[pid] << '\n';
    }else{

      std::strncpy(unit.picfetch.filename, files[pid].c_str(), MAX_FILENAME_SIZE);
      net.addUnit(unit, client);
    }
  }else{
    *out << VERBOSE_LOUD << "Error, pid out of range for files.size: " << (int) files.size() << '\n';
  }
}
Example #2
0
void Picturecontrol::fetch(int myId, Net &net, Client &client)
{
  // deal with fetching
  Unit unit;

  for (int c = 0; c < MAX_CLIENTS; c++) {
    for (int i = 0; i < piclen[c]; i++) {
      // if not active then fetch them
      if (!pic[c][i].getActive() && !pic[c][i].getRequested()) {
        pic[c][i].setRequested(true);
        unit.picfetch.flag = UNIT_PICFETCH;
        unit.picfetch.from = myId;
        unit.picfetch.to = c;
        unit.picfetch.pid = i;
        unit.picfetch.filename[0] = '\0';
        net.addUnit(unit, client);
        *out << VERBOSE_QUIET << "Requesting picture: " << unit.picfetch.pid << '\n';
      }
    }
  }
}
Example #3
0
void Picturecontrol::load(int myId, Net &net, Client &client)
// if we are given a path, then load and transmit which pics are active
// if path is an empty string then we expect either pictures aren't being used or we're receving them
{
  if (readPath != "") {
    *out << VERBOSE_LOUD << "Loading pics...\n";
    files = dir.getPics(readPath);

    // error checks done in allocate, but left to segfault below!
    // (error messages from allocate() should help track down problem!)
    allocate(myId, files.size()); // this also calls incrementLoaded

    for (int i = 0; i < piclen[myId]; i++) {
      pic[myId][i].load(readPath+files[i]);
      pic[myId][i].setActive(true);
    }

    *out << VERBOSE_LOUD << "Loaded\n";

    // tell server number of pics
    Unit unit;

    unit.picalloc.flag = UNIT_PICALLOC;
    unit.picalloc.id = myId;
    unit.picalloc.total = piclen[myId];
    net.addUnit(unit, client);

    // set to plausible picnum and transmit picselect,
    // note that client who has pictures may not be client 0
    if (picnum > piclen[clientnum] - 1) {

      bool found = false;

      for (int c = clientnum + 1; c < MAX_CLIENTS; c++) {
        if (piclen[c] > 0) {
          clientnum = c;
          found = true;
          break;
        }
      }

      if (!found) {
        for (int c = 0; c < clientnum; c++) {
          if (piclen[c] > 0) {
            clientnum = c;
            found = true;
            break;
          }
        }
      }

      if (!found) *out << VERBOSE_LOUD << "Error: not found any plausible clientnum in Picturecontrol::load()\n";

      picnum = 0;
    }

    // transmit picnum
    unit.picselect.flag = UNIT_PICSELECT;
    unit.picselect.clientnum = clientnum;
    unit.picselect.picnum = picnum;
    unit.picselect.direction = 1;

    net.addUnit(unit, client);
    // this transmission will bounce back and setPicnum will be called to set up positions
    //setPicnum(clientnum, picnum); // sets up positions

    *out << VERBOSE_LOUD << "Picselect clientnum: " << unit.picselect.clientnum << ", picnum: " << unit.picselect.picnum
    << ", direction: " << unit.picselect.direction << '\n';
  }
}