Пример #1
0
/* The c++ function for: printif(self:any) [NEW_ALLOC+BAG_UPDATE+SLOT_UPDATE] */
void  printif_any(OID self)
{ (Core.pretty->index = (Core.pretty->index+3));
  if (Core.pretty->pbreak == CTRUE)
   { int  b_index = buffer_length_void();
    int  _Zl = Core.pretty->index;
    (Core.pretty->pbreak = CFALSE);
    { ClaireHandler c_handle = ClaireHandler();
      if ERROR_IN 
      { print_any(self);
        ClEnv->cHandle--;} 
      else if (belong_to(_oid_(ClEnv->exception_I),_oid_(Core._much_too_far)) == CTRUE)
      { c_handle.catchIt();;} 
      else PREVIOUS_HANDLER;} 
Пример #2
0
void CubeCreature::avoid_collision(){
	if(cur_move_state()->get_move_state()==MS_AVOID_COLLISION)return;
	if(colli_state()==C_STATE_COLLI_OFF)return;
	if(get_v()<0.00001)return;
	std::vector<CubeCreature*>*creature_v;
	CubeCreature* avoid_creature;
	int x=in_x(),y=in_y(),z=in_z();
	for(int i=-1;i<=1;i++){
		for(int j=-1;j<=1;j++){
			for(int k=-1;k<=1;k++){
				creature_v=map->creature_map->get_creature_map(x+i,y+j,z+k);
				for(unsigned i=0;i<creature_v->size();i++){
					avoid_creature=creature_v->at(i);
					if(avoid_creature!=this&&avoid_creature->colli_state()!=C_STATE_COLLI_OFF
							&&avoid_creature->belong_to()==belong_to())
					if(pre_collide(creature_v->at(i))){
						creature_v->at(i)->avoid_collision(this);
					}
				}
			}
		}
	}
}
Пример #3
0
int main(int argc, char *argv[])
{
  if (argc != 3)
    {
      fprintf(stderr,"usage: <hostname> <PORT>\n");
      exit(1);
    } else {
    HOSTNAME = argv[1];
    PORT = atoi(argv[2]);
  }

  if ((he=gethostbyname(argv[1])) == NULL) /* get the host info */
    {
      herror("gethostbyname");
      exit(1);
    }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    {
      perror("socket");
      exit(1);
    }
  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(PORT);
  their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  bzero(&(their_addr.sin_zero), 8);
  if (connect(sockfd,(struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1)
    {
      perror("connect");
      exit(1);
    }
  

  if ((nb=recv(sockfd, buf, 100, 0)) == -1){
    perror("Recieve 1"); exit(1);
  }

  buf[nb] = '\0';
  str = ""; str.append(buf);
  if(str != "+OK")
    {
      printf("Connection cannot be established");
      exit(0);
    }
  printf("\n\tConnected to Server : \n");
    
  while(1) {
    printf("\n\tEnter Choice : \n");
    printf("\t\t1. Login\n");
    printf("\t\t2. Register\n");
    printf("\t\t3. Change Password\n");
    printf("\t\t_________________________________________\nChoice : ");
    scanf("%d", &choice);
    
    switch(choice) {

    case 1: 
      str = "LOGI";
      if (send (sockfd, str.c_str(), strlen(str.c_str()), 0) == -1) {
	perror("send:"); exit(0);
      }
      if((nb=recv(sockfd, buf, 100, 0)) == -1){
	perror("Recieve 2"); exit(1);
      } 
      buf[nb] = '\0'; str = ""; str.append(buf);
      if(str != "+OK"){
	printf("<LOGI> Login request cannot be completed");
	continue;
      }
	
      printf("Username : "******"%s", user);
      printf("Password : "******"%s", pass);
      if (send (sockfd, user, strlen(user), 0) == -1){
	perror("send:"); exit(0);
      }
      if ((nb=recv(sockfd, buf, 100, 0)) == -1){
	perror("Recieve 3"); exit(1);
      }
      buf[nb] = '\0'; str = ""; str.append(buf);
      if(str != "PASS") {
	cout << "The login failed" <<endl ;
	continue;
      }
      if (send (sockfd, pass, strlen(pass), 0) == -1){
	perror("send:"); exit(0);
      }
      if ((nb=recv(sockfd, buf, 100, 0)) == -1){
	perror("Recieve 3"); exit(1);
      }
      buf[nb] = '\0'; str = ""; str.append(buf);
      if(str != "AUTH"){
	cout<< "Login failed" << endl;
	continue;
      }
      
      pthread_create(&pth,NULL,recvthread,(void *)sockfd);
      cout <<  "\n\t\tLogin Successful" << endl;
      cout <<  "\t\t(Type  /help  to get list of commands)" << endl;
      getline(cin, str);

      while(1){

	usleep(usec);

	if(prompt_flag == 1)
	  prompt();
	prompt_flag=0;

	getline(cin, str);

	if(str[0] == '/') {
	  command = str.substr(1, str.find(' ')-1);
	  message = str.substr(str.find(' ')+1);
	}
	else if(str == "") {
	  continue;
	}
	else if(request_flag == 1){
	  if(str == "y" or str == "Y")
	    { str = "ACPT"; 
	      sprintf(temp, " %d ", conf_id);
	      str.append(temp);
	      str.append("YES");	      
	      request_flag = 0;
	    }
	  // Guess we don't need to send a NO Notification :-//
	  if(str == "n" or str == "N")
	    {
	      str = "ACPT"; 
	      sprintf(temp, " %d ", conf_id);
	      str.append(temp);
	      str.append("NO");	      
	      request_flag = 0;
	    }
	  if(request_flag == 0) { //means it was either of Y and N.
	    if (send (sockfd, str.c_str(), strlen(str.c_str()), 0) == -1) {
	      perror("send:"); exit(0);
	    }
	    //prompt_flag = 1;
	  }
	  else cout << "Try again (y/n)?"; 
	  continue;
	}
	else {
	  command = "data";
	  message = str;
	}

	if(belong_to(command) == 0) {
	  cout << "invalid command : " << command << endl;
	  prompt_flag = 1;
	  continue;
	}

	//{"start", "topic", "list", "invite", "data", "kick", "leave", "end"};
	if(command == "start") {
	  str = "STAT";
	  str.append(" ");
	  str.append(message);
	}

	if(command == "topic") {
	  str = "TOPI";
	  str.append(" ");
	  str.append(message);
	}

	if(command == "users") {
	  str = "USER";
	}

	if(command == "info") {
	  str = "INFO";
	}

	if(command == "invite") {
	  str = "INVI";
	  str.append(" ");
	  str.append(message);
	}

	if(command == "data") {
	  str = "DATA";
	  str.append(" ");
	  str.append(message);
	  prompt_flag = 1;
	}

	if(command == "members") {
	  str = "MEMB";
	}

	if(command == "kick") {
	  str = "KICK";
	  str.append(" ");
	  str.append(message);
	}

	if(command == "leave") {
	  str = "LEAV";
	}

	if(command == "end") {
	  str = "ENDC";
	}

	if(command == "print") {
	  str = "PRIN";
	}

	if(command == "help") {
	  str = "HELP";
	}

	if(command == "logout") {
	  str = "LOGO";
	}

	if (send (sockfd, str.c_str(), strlen(str.c_str()), 0) == -1) {
	  perror("send:"); exit(0);
	}
	
      }//END OF Inner while(1) <in case 1:>


      break;
	
    case 2: 
      str = "REGR";
      if (send (sockfd, str.c_str(), strlen(str.c_str()), 0) == -1) {
	perror("send:"); exit(0);
      }
      if ((nb=recv(sockfd, buf, 100, 0)) == -1){
	perror("Recieve 2"); exit(1);
      } 
      buf[nb] = '\0'; str = ""; str.append(buf);
      if(str != "+OK") {
	  printf("<REGR> Register request cannot be completed");
	  continue;
      }
      cout << endl;
      cout << "<Username and Password should contain only alphabetical characters not more than 10>" << endl;
      printf("Username : "******"%s", user);
      if (send (sockfd, user, strlen(user), 0) == -1){
	perror("send:"); exit(0);
      }
      if ((nb=recv(sockfd, buf, 100, 0)) == -1){
	perror("Recieve 3"); exit(1);
      } 
      buf[nb] = '\0'; str = ""; str.append(buf);
      if(str == "ERR") {
	cout << endl << user <<" : already exists. Registration failed\n";
	continue;
      }
      if(str == "PASS") {
	printf("Password : "******"%s", pass);
	fflush(stdin);
	temp_flag = 0;
	do {
	  printf("Are you a designated user(y/n) : ");
	  scanf("%s", designated);
	  if(strcmp(designated, "y") == 0) {
	    printf("Enter passphrase : ");
	    scanf("%s", temp);
	    if(strcmp(temp, PASSPHRASE) == 0)
	      temp_flag = 1;
	    else {
	      cout << "Wrong Passphrase" << endl;
	    }
	  }
	  else if(strcmp(designated, "n") == 0) {
	    temp_flag = 1;
	  }
	}while(!temp_flag);
	
	//	cout << designated;
	str = "";
	str.append(pass);
	str.append(designated);
	//	cout << "str : " << str;
	if (send (sockfd, str.c_str(), strlen(str.c_str()), 0) == -1) {
	  perror("send:"); exit(0);
	}
      }
      break;
      
    case 3: 
      str = "CHPS";
      if (send (sockfd, str.c_str(), strlen(str.c_str()), 0) == -1) {
	perror("send:"); exit(0);
      }
      break;
      
    default: printf("Wrong Choice again");
      exit(0);
    }//END OF switch-case
  }//END OF while(1)
}//END OF main()
Пример #4
0
/* The c++ function for: main(lp:list[string]) [NEW_ALLOC+BAG_UPDATE+SLOT_UPDATE+STRING_UPDATE] */
void  main_list(list *lp)
{ GC_BIND;
  { ClaireBoolean * rCode = CTRUE;
    char * _Zcm = copy_string("");
    char * _Zcf = copy_string("");
    int  dblevel = 1;
    char * _Zout = copy_string("");
    char * _Zcj = copy_string("");
    int  slevel = 0;
    int  clevel = 1;
    ClaireBoolean * _Zinit_ask = CTRUE;
    int  vlevel = 2;
    list * l = ((list *) copy_bag(lp));
    { ClaireHandler c_handle = ClaireHandler();
      if ERROR_IN 
      { { (Reader._starfs_star->value= _string_(copy_string("\\")));
          (OBJECT(Generate_producer,Generate.PRODUCER->value)->extension = copy_string(".cpp"));
          update_property(Optimize.libraries_dir,
            Optimize.compiler,
            17,
            Kernel._object,
            _oid_(list::alloc(Kernel._any,3,_string_(copy_string("c:\\claire\\v3.3\\bin\\public\\ntv")),
              _string_(copy_string("c:\\claire\\v3.3\\bin\\debug\\ntv")),
              _string_(copy_string("c:\\claire\\v3.3\\bin\\public\\ntv")))));
          (Optimize.compiler->headers_dir = copy_string("c:\\claire\\v3.3\\bin\\include"));
          update_property(Optimize.options,
            Optimize.compiler,
            19,
            Kernel._object,
            _oid_(list::alloc(Kernel._any,3,_string_(copy_string("-c /O2 /Oi")),
              _string_(copy_string("-c /Zi")),
              _string_(copy_string("-c /Zi")))));
          (Optimize.compiler->env = copy_string("ntv"));
          (Optimize.claire_lib->value= _string_(copy_string("")));
          { while ((l->length != 0))
            { if ((equal((*(l))[1],_string_(copy_string("?"))) == CTRUE) || 
                  (equal((*(l))[1],_string_(copy_string("-help"))) == CTRUE))
               printHelp_void();
              else if (equal((*(l))[1],_string_(copy_string("-s"))) == CTRUE)
               { if (3 <= l->length)
                 l= skip_list(l,3);
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -s <s1> <s2>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-f"))) == CTRUE)
               { if (2 <= l->length)
                 { load_string(string_v((*(l))[2]));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -f <filename>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-env"))) == CTRUE)
               { if (2 <= l->length)
                 { (Optimize.compiler->env = string_v((*(l))[2]));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -env <OS name>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-m"))) == CTRUE)
               { if (2 <= l->length)
                 { if (_Zinit_ask == CTRUE)
                   { load_string(copy_string("init"));
                    _Zinit_ask= CFALSE;
                    } 
                  { module * m = string2module_string(string_v((*(l))[2]));
                    load_module(m);
                    begin_module(m);
                    l= skip_list(l,2);
                    (Optimize.claire_modules->value= _oid_(OBJECT(list,Optimize.claire_modules->value)->addFast(_oid_(m))));
                    } 
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -m <module>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-v"))) == CTRUE)
               { if (2 <= l->length)
                 { vlevel= (vlevel+integer_I_string(string_v((*(l))[2])));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -v <integer>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-ld"))) == CTRUE)
               { if (2 <= l->length)
                 { (Optimize.claire_lib->value= (*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -od <directory>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-od"))) == CTRUE)
               { if (2 <= l->length)
                 { (Optimize.compiler->source = string_v((*(l))[2]));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -od <directory>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-os"))) == CTRUE)
               { if (2 <= l->length)
                 { slevel= integer_I_string(string_v((*(l))[2]));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -ol <int>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-S"))) == CTRUE)
               { if (2 <= l->length)
                 { (CLREAD(global_variable,new_class2(Core._global_variable,symbol_I_string2(string_v((*(l))[2]))),value) = Kernel.ctrue);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -S <FLAG>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-o"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zout= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -o <name>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-p"))) == CTRUE)
               { (Optimize.OPT->profile_ask = CTRUE);
                dblevel= ((dblevel <= 1) ?
                  1 :
                  dblevel );
                l= skip_list(l,1);
                } 
              else if (equal((*(l))[1],_string_(copy_string("-D"))) == CTRUE)
               { dblevel= 0;
                l= skip_list(l,1);
                } 
              else if (equal((*(l))[1],_string_(copy_string("-safe"))) == CTRUE)
               { (Optimize.compiler->safety = ((dblevel == 0) ?
                  0 :
                  1 ));
                (Optimize.claire_lib->value= (*(Optimize.compiler->libraries_dir))[2]);
                (Optimize.claire_options->value= (*(Optimize.compiler->options))[2]);
                l= skip_list(l,1);
                } 
              else if (equal((*(l))[1],_string_(copy_string("-O"))) == CTRUE)
               { (Optimize.compiler->optimize_ask = CTRUE);
                dblevel= 2;
                l= skip_list(l,1);
                } 
              else if (equal((*(l))[1],_string_(copy_string("-l"))) == CTRUE)
               { if (2 <= l->length)
                 { Optimize.compiler->libraries->addFast((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -l <library>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-cl"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zcm= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -cm <module>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-cc"))) == CTRUE)
               { if (2 <= l->length)
                 { clevel= 0;
                  _Zcm= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -cc <module>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-cm"))) == CTRUE)
               { if (2 <= l->length)
                 { clevel= 2;
                  _Zcm= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -cl <module>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-cj"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zcj= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                } 
              else if (equal((*(l))[1],_string_(copy_string("-cjx"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zcj= string_v((*(l))[2]);
                  clevel= 0;
                  l= skip_list(l,2);
                  } 
                } 
              else if (equal((*(l))[1],_string_(copy_string("-cx"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zcf= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  clevel= 2;
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -cx <filename>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-n"))) == CTRUE)
               { _Zinit_ask= CFALSE;
                l= skip_list(l,1);
                } 
              else { if (string_v((*(l))[1])[1 - 1] == '-')
                   { print_any((*(l))[1]);
                    princ_string(copy_string(" is an unvalid option\n"));
                    printHelp_void();
                    } 
                  rCode= CFALSE;
                  l= list::empty(Kernel._string);
                  } 
                } 
            } 
          if (equal_string(_Zout,copy_string("")) == CTRUE)
           { if (equal_string(_Zcm,copy_string("")) != CTRUE)
             _Zout= _Zcm;
            else if (equal_string(_Zcf,copy_string("")) != CTRUE)
             _Zout= _Zcf;
            } 
          if (_Zinit_ask == CTRUE)
           load_string(copy_string("init"));
          (Optimize.claire_options->value= (*(Optimize.compiler->options))[((dblevel == 0) ?
            2 :
            ((dblevel == 2) ?
              1 :
              3 ) )]);
          if (equal(Optimize.claire_lib->value,_string_(copy_string(""))) == CTRUE)
           (Optimize.claire_lib->value= (*(Optimize.compiler->libraries_dir))[((dblevel == 0) ?
            2 :
            ((dblevel == 2) ?
              1 :
              3 ) )]);
          (ClEnv->verbose = vlevel);
          if (slevel > 0)
           (Optimize.compiler->safety = slevel);
          if (equal_string(_Zcm,copy_string("")) != CTRUE)
           { module * m = string2module_string(_Zcm);
            (Optimize.compiler->active_ask = CTRUE);
            if (equal(_oid_(m->uses),_oid_(list::alloc(1,GC_OID((*(OBJECT(bag,Optimize.claire_modules->value)))[2])))) == CTRUE)
             { (Optimize.claire_modules->value= _oid_(shrink_list(OBJECT(bag,Optimize.claire_modules->value),2)));
              tformat_string(copy_string("=== Light Module ~S:~S -> use ~S=== "),0,list::alloc(3,_oid_(m),
                GC_OID(_oid_(m->uses)),
                GC_OID(Optimize.claire_modules->value)));
              } 
            (Optimize.claire_modules->value= _oid_(OBJECT(list,Optimize.claire_modules->value)->addFast(_oid_(m))));
            (*Reader.load)(value_string(copy_string("Compile")));
            if (equal_string(_Zout,copy_string("")) != CTRUE)
             (m->external = _Zout);
            load_module(m);
            if (dblevel < 1)
             { (Optimize.compiler->safety = ((Optimize.compiler->safety <= 4) ?
                Optimize.compiler->safety :
                4 ));
              Optimize.compiler->debug_ask->addFast(_oid_(m));
              } 
            compile_module(m);
            if (clevel == 1)
             { if (equal_string(_Zout,copy_string("")) != CTRUE)
               (m->external = _Zout);
              cmakefile_any(_oid_(m),copy_string(""));
              } 
            else if (clevel == 2)
             cmakefile_any(_oid_(m),_Zout);
            CL_exit(0);
            } 
          else if (equal_string(_Zcj,copy_string("")) != CTRUE)
           (*Core.call)(value_string(copy_string("jcmakefile")),
            _oid_(string2module_string(_Zcj)),
            _string_(_Zout),
            _oid_(equal(clevel,0)));
          else if (equal_string(_Zcf,copy_string("")) != CTRUE)
           { (Optimize.compiler->active_ask = CTRUE);
            (*Reader.load)(value_string(copy_string("Compile")));
            load_string(_Zcf);
            function_compile_string(_Zcf,_Zcf);
            cmakefile_any(_string_(_Zcf),_Zout);
            CL_exit(0);
            } 
          } 
        ClEnv->cHandle--;} 
      else if (belong_to(_oid_(ClEnv->exception_I),_oid_(Kernel._any)) == CTRUE)
      { c_handle.catchIt();{ restore_state_meta_reader(Reader.reader);
          debug_if_possible_void();
          } 
        } 
      else PREVIOUS_HANDLER;} 
    }