예제 #1
0
파일: man.c 프로젝트: 1andyn/virtualnetwork
void manSetNetAddr(managerLink * manLink)
{
int netaddr;
char command[1000];
char addr[1000]; 

/* Ask user for the network address */
while(1) {
   printf("Enter network address: ");
   scanf("%d",&netaddr);
   if (netaddr <0)
      printf("Address must be postive. Try again\n");
   else if (netaddr > 10000)
      printf("The address is too big. Try again\n");
   else break;
}

/* Create the command message */
command[0] = '\0';
appendWithSpace(command, "SetNetAddr");
int2Ascii(addr,netaddr);
appendWithSpace(command, addr);

/* Send the message to the host */
manCommandSend(manLink, command);
}
예제 #2
0
파일: man.c 프로젝트: 1andyn/virtualnetwork
int manTransmitPacket(managerLink * manLink)
{
char command[1000];
char word[1000];
int netaddr;

/* As the user to enter the destination address */
printf("Enter the destination's network address: ");
scanf("%d", &netaddr);
if (netaddr < 0) {
   printf("Aborted: address should be positive\n");
   return -1;
}
else if (netaddr > 10000) {
   printf("The address too big.  Try again.\n");
   return -1;
}

/* Create the command message */
command[0] = '\0';                         /* Empty command string */
appendWithSpace(command, "TransmitPacket"); 

int2Ascii(word, netaddr);    /* Add destination address */
appendWithSpace(command, word);  

/* Send command */
manCommandSend(manLink, command);  
return 0;
}
예제 #3
0
파일: host.c 프로젝트: raegand/Lab8
/* 
 * hostReplySend is called after the host executes a command 
 * from the manager. It sends a reply
 * message to the manager in the format " Replytype <reply[]>".
 * - Replytype can be
 *    o "DISPLAY" which means the rest of the message should be 
 *      displayed on the user's console
 *    o "GetHostStateACK" which means the rest of the message is the
 *      host's state
 */ 
void hostReplySend(managerLink * manLink, char replytype[], char replymsg[])
{
char reply[1000];

reply[0] = '\0';
appendWithSpace(reply, replytype);
appendWithSpace(reply, replymsg);
hostToManSend(manLink, reply);
}
예제 #4
0
파일: item.cpp 프로젝트: miki151/keeperrl
string Item::getSuffix() const {
  string artStr;
  if (!attributes->prefixes.empty())
    artStr += "of " + attributes->prefixes.back();
  if (attributes->artifactName)
    appendWithSpace(artStr, "named " + *attributes->artifactName);
  if (fire->isBurning())
    appendWithSpace(artStr, "(burning)");
  return artStr;
}
 util::String baseSpecToString (BaseSpecPtr const & base_spec)
 {
   String str;
   if (base_spec->isVirtual ())
   {
     str = "virtual";
   }
   appendWithSpace (str, accessToString (base_spec->getAccess ()));
   appendWithSpace (str, nameToString (base_spec->getBaseName ()));
   return str;
 }
예제 #6
0
파일: host.c 프로젝트: raegand/Lab8
/*
 * Get the host's state  
 * - host's physical ID
 * - host's main directory
 * - host's network address
 * - host's neighbor address
 * - host's receive flag
 * and create a message that has all this information to be sent
 * to the manager
 */
void hostGetHostState(hostState * hstate, managerLink * manLink, char replymsg[])
{
char word[1000];
char empty[7] = "Empty";

/* Create reply message */

replymsg[0] = '\0';  /* Clear reply message */

int2Ascii(word, hstate->physid);
appendWithSpace(replymsg, word);

if (hstate->maindirvalid==0) appendWithSpace(replymsg, empty);
else appendWithSpace(replymsg, hstate->maindir);

if (hstate->netaddr == EMPTY_ADDR) appendWithSpace(replymsg, empty);
else {
   int2Ascii(word, hstate->netaddr);
   appendWithSpace(replymsg, word);
}

if (hstate->nbraddr == EMPTY_ADDR) appendWithSpace(replymsg, empty);
else {
   int2Ascii(word, hstate->nbraddr);
   appendWithSpace(replymsg, word);
}

int2Ascii(word, hstate->rcvflag);
appendWithSpace(replymsg, word);

}
예제 #7
0
파일: man.c 프로젝트: 1andyn/virtualnetwork
/*
 * It tells the host to upload a file.  It asks the user to type in
 * the file name.  Then it sends the following message to
 * the host:  "UploadPacket <filename>"  
 */
void manUploadPacket(managerLink * manLink)
{
char fname[MAXBUFFER]; /* File name. */
char command[1000]; 

printf("Enter the name of the file in the host's directory: ");
scanf("%s",fname);

/* Create a command to the host */
command[0] = '\0'; /* Clear the command stringn */
appendWithSpace(command, "UploadPacket");
appendWithSpace(command, fname);

/* Send command to host */
manCommandSend(manLink, command);
} 
예제 #8
0
파일: item.cpp 프로젝트: miki151/keeperrl
string Item::getModifiers(bool shorten) const {
  EnumSet<AttrType> printAttr;
  if (!shorten) {
    for (auto attr : ENUM_ALL(AttrType))
      if (attributes->modifiers[attr] != 0)
        printAttr.insert(attr);
  } else
    switch (getClass()) {
      case ItemClass::RANGED_WEAPON:
        printAttr.insert(getRangedWeapon()->getDamageAttr());
        break;
      case ItemClass::WEAPON:
        printAttr.insert(getWeaponInfo().meleeAttackAttr);
        break;
      case ItemClass::ARMOR:
        printAttr.insert(AttrType::DEFENSE);
        break;
      default: break;
    }
  vector<string> attrStrings;
  for (auto attr : printAttr)
    attrStrings.push_back(withSign(attributes->modifiers[attr]) + (shorten ? "" : " " + ::getName(attr)));
  if (attributes->damageReduction > 0)
    attrStrings.push_back(toString(int(attributes->damageReduction * 100)) + "%");
  string attrString = combine(attrStrings, true);
  if (!attrString.empty())
    attrString = "(" + attrString + ")";
  if (attributes->uses > -1 && attributes->displayUses) 
    appendWithSpace(attrString, "(" + toString(attributes->uses) + " uses left)");
  return attrString;
}
예제 #9
0
파일: man.c 프로젝트: 1andyn/virtualnetwork
void manClearRcvFlg(managerLink * manLink)
{
char command[100];

command[0] = '\0';    /* Empty the command string */
appendWithSpace(command, "ClearRcvFlg"); /* Create command */
manCommandSend(manLink, command); /* Send command to the host */
}
예제 #10
0
파일: item.cpp 프로젝트: miki151/keeperrl
string Item::getShortName(const Creature* owner, bool plural) const {
  PROFILE;
  if (owner && owner->isAffected(LastingEffect::BLIND) && attributes->blindName)
    return getBlindName(plural);
  if (attributes->artifactName)
    return *attributes->artifactName + " " + getModifiers(true);
  string name;
  if (!attributes->prefixes.empty())
    name = attributes->prefixes.back();
  else if (attributes->shortName) {
    name = *attributes->shortName;
    appendWithSpace(name, getSuffix());
  } else
    name = getVisibleName(plural);
  appendWithSpace(name, getModifiers(true));
  return name;
}
예제 #11
0
파일: man.c 프로젝트: 1andyn/virtualnetwork
/*
 * It tells the host to set its main directory.  First, it
 * asks the user to enter the directory name.  Then it creates
 * the command message "SetMainDir <directory name>".  Then it
 * sends the message to the host.
 */
void manSetMainDir(managerLink * manLink)
{
char dirname[1000];
char command[1000];

/* Get the directory name */
printf("Enter new directory: ");
scanf("%s",dirname);

/* Create the command message */
command[0] = '\0'; /* Initialize command to the empty string */
appendWithSpace(command, "SetMainDir");
appendWithSpace(command, dirname);

/* Send the command message */
manCommandSend(manLink, command);
}
예제 #12
0
파일: man.c 프로젝트: 1andyn/virtualnetwork
void manDownloadPacket(managerLink * manLink)
{
char fname[MAXBUFFER]; /* File name. */
char command[1000];

/* Enter file name */
printf("Enter the file name: ");
scanf("%s",fname);

/* Create a command to the host */
command[0] = '\0'; /* Clear the command */
appendWithSpace(command, "DownloadPacket");
appendWithSpace(command, fname);

/* Send command to the host. */
manCommandSend(manLink, command);
}
예제 #13
0
파일: man.c 프로젝트: 1andyn/virtualnetwork
/* 
 *  Tell the host to send its state information.  First, it
 *  creates the command message "GetHostState".  Then it
 *  sends the message to the host.
 */
void manGetHostState(managerLink * manLink)
{
char command[1000];

command[0] = '\0';                         /* Empty command string */
appendWithSpace(command, "GetHostState");  /* Create the command */
manCommandSend(manLink, command);          /* Send the command */
}
예제 #14
0
파일: item.cpp 프로젝트: miki151/keeperrl
string Item::getVisibleName(bool getPlural) const {
  string ret;
  if (!getPlural)
    ret = *attributes->name;
  else {
    if (attributes->plural)
      ret = *attributes->plural;
    else
      ret = *attributes->name + "s";
  }
  appendWithSpace(ret, getSuffix());
  return ret;
}
예제 #15
0
 util::String tmplSpecToArgString (TmplSpecPtr const & tmpl_spec)
 {
   String str;
   ParamPtrVector const & param_set = tmpl_spec->getParamSet ();
   for (ParamPtrVectorConstIter beg = param_set.begin (), end = param_set.end (); beg != end; ++ beg)
   {
     ParamPtr const & param = * beg;
     appendWithSpace (str, nameToString (param->getName ()));
     if (beg + 1 != end)
     {
       str += ',';
     }
   }
   return str;
 }
 util::String PrintClassDecl::declToString (ClassDeclPtr const & class_decl) const
   {
     String str;
     if (is_inst)
     {
       // extern only if dll_api is set
       if (is_inst_extern && conf::isOptionSet (conf::opt_dll_api))
       {
         str = "extern ";
       }
       str += "template";
     }
     else if (is_frnd)
     {
       str =  "friend";
     }
     appendWithSpace (str, classKeyToString (class_decl->getKey ()));
     if (class_decl->isDllApi ())
     {
       appendWithSpace (str, conf::getOptionValue (conf::opt_dll_api));
     }
     appendWithSpace (str, nameToString (class_decl->getName ()));
     return str;
   }
 util::String PrintObjDecl::declToString (ObjPtr const & obj) const
   {
     String str;
     Linkage const & linkage = obj->getLinkage ();
     if (linkage.isSet ())
     {
       appendWithSpace (str, "extern");
       appendWithSpace (str, linkage.getLanguage ().c_str ());
     }
     int flags = obj->getFlags ();
     if (! not_extern)
     {
       if (is_extern || hasFlag (flags, EXTERN_SPEC))
       {
         appendWithSpace (str, "extern");
       }
     }
     if (hasFlag (flags, DLL_API_SPEC))
     {
       appendWithSpace (str, conf::getOptionValue (conf::opt_dll_api));
     }
     if (! not_static && hasFlag (flags, STATIC_SPEC))
     {
       appendWithSpace (str, "static");
     }
     if (hasFlag (flags, MUTABLE_SPEC))
     {
       appendWithSpace (str, "mutable");
     }
     NamePtr name = obj->getName ();
     if (qual_name.isSet ())
     {
       name = createQualName (qual_name, name);
     }
     String dcl_str = nameToString (name);
     appendWithSpace (str, obj->getCvType ().toString (dcl_str));
     return str;
   }
예제 #18
0
파일: item.cpp 프로젝트: miki151/keeperrl
string Item::getNameAndModifiers(bool getPlural, const Creature* owner) const {
  auto ret = getName(getPlural, owner);
  appendWithSpace(ret, getModifiers());
  return ret;
}