Exemplo n.º 1
0
void process_macro(const char *line) {
	const char *p = strchr(line, ' ');
	char inst[32];
	char param[32];
	memset(&inst,0,sizeof(inst));
	memset(&param,0,sizeof(param));
	int end = strlen(line);
	if(p) {
		end = p - line;
	}
	strncpy(inst, line, end);
	int uv_mode;
	ETextureSampleType sample_mode;
	EPreProcessorType token = find_preprocessor_token_by_name(&inst[1]);
	switch(token) {
		case EPreProcessor_UVLength:
			find_nth((char *)line, 1, param, sizeof(param));
			uv_mode = atoi(param);
			g_asmState.UVMode = uv_mode;
			//printf("Setting UV Mode to: %d\n",uv_mode);
			break;
		case EPreProcessor_TexSamplerType:
			find_nth((char *)line, 1, param, sizeof(param));
			uv_mode = atoi(param);
			memset(&param, 0, sizeof(param));
			find_nth((char *)line, 2, param, sizeof(param));
			//printf("Selected Tex: %d %s\n",uv_mode, line);
			sample_mode = find_texture_sampler_by_name(param);
			g_asmState.tex_types[uv_mode] = sample_mode;
			break;
		case EPreProcessor_Marker:
			break;
	}
}
Exemplo n.º 2
0
//void
//int prio;
//float ratio;
void upgrade_process_prio(int prio,float ratio)
{
    int count;
    int n;
    Ele *proc;
    List *src_queue, *dest_queue;

    if (prio >= MAXPRIO)
    {
        return;
    }
    src_queue = prio_queue[prio];
    dest_queue = prio_queue[prio+1];
    count = src_queue->mem_count;

    if (count > 0)
    {
        n = (int) (count*ratio + 1);
        proc = find_nth(src_queue, n);
        if (proc)
        {
            src_queue = del_ele(src_queue, proc);
            /* append to appropriate prio queue */
            proc->priority = prio;
            dest_queue = append_ele(dest_queue, proc);
        }
    }
}
Exemplo n.º 3
0
void parse_result_modifiers(char *line, InstructionModifiers *modifiers) {
	char *p = strchr(line, '|');
	int i = 0;
	char param[128];
	char func[64];
	char args[64];
	memset(&param,0,sizeof(param));
	if(p != NULL) {
		*p = 0;
		p++;
		while(true) {
			find_nth(p, i++, param, sizeof(param));
			memset(&func,0,sizeof(func));
			memset(&args,0,sizeof(args));
			if(strlen(param) == 0) break;
			char *x = strchr(param, '(');
			if(x == NULL) break;
			char *x1 = strchr(x,')');
			strncpy(func,param,x-param);
			strncpy(args,x+1,x1-x-1);
			get_modifiers((char *)&func, (char *)&args, modifiers);
			//printf("%s %s\n",func, args);
		}		
	}
}
Exemplo n.º 4
0
int main(int argc,char *argv[])
{
	node *ans;
	lst=NULL;
	generic_data(argv[2]);
	print_list(lst);

	ans=find_nth(lst,atoi(argv[1]));
	printf("the nth element is:%c\n",ans->element);
	return 0;
}
Exemplo n.º 5
0
void Sample::updateName() {
    if (_name.length() > 0) {
        if (_name[0] != '/') {
            _name.insert(_name.begin(), '/');
        }
        
        if (count(_name.begin(), _name.end(), ':') == 2) {
            
            int one = find_nth(_name, 0, ":", 0);
            int two = find_nth(_name, 0, ":", 1);
            
            min = stof(_name.substr(one + 1, two - one - 1));
            max = stof(_name.substr(two + 1));
            
            cout << "min: " << min << " max: " << max << endl;
            
            _name = _name.substr(0, one);
        }

        setEnabled(true);
    }
}
Exemplo n.º 6
0
int main(int argc, char **argv) {
    long type;
    long value;
    int length = 0;
    List *ll;

    //If more than 1 arguments are put in, changes the filestream to 
    //be the specified filename at argv[1]
    FILE * out;
    if (argc > 1)
    {
        out = fopen(argv[1], "w");
    }

    //If only 1 argument is put in, the filestream is
    //stdout
    else
    {
        out = stdout;
    }

    int i;
    for(i = 0; i < MAX_VAL; i++) {
        double prob = (double)random() / RAND_MAX;
        if(prob < PROB_PRINT) {
            type = 3;
            fprintf(out, "%ld\n", type);
        }
        if(prob < PROB_PRINT + PROB_ADD) {
            type = 1;
            value = random() % MAX_VAL;
            ll = add_node(ll, value);
            length++;
            fprintf(out, "%ld %ld\n", type, value);
        } else {
            type = 2;
            if(length > 0) {
                // choose a node that is in the list to delete
                int index = random() % length;
                value = find_nth(ll, index);
                ll = remove_node(ll, value);
                length--;
                fprintf(out, "%ld %ld\n", type, value);
            } 
        }
    }
    return 0;
}
Exemplo n.º 7
0
void unblock_process(float ratio) {
  int count;
  int n;
  Ele *proc;
  int prio;

  if (block_queue) {
    count = block_queue->mem_count;
    n = (int) (count*ratio + 1);
    proc = find_nth(block_queue, n);
    if (proc) {
      block_queue = del_ele(block_queue, proc);
      prio = proc->priority;
      prio_queue[prio] = append_ele(prio_queue[prio], proc);
    }
  }
}
Exemplo n.º 8
0
void process_instruction(char *line) {
	const char *p = strchr(line, ' ');
	char inst[32];
	char param[32];
	memset(&inst,0,sizeof(inst));
	memset(&param,0,sizeof(param));
	int end = strlen(line);
	if(p) {
		end = p - line;
	}
	strncpy(inst, line, end);
	EShaderInstruction instruction =  find_instruction_by_name(inst);
	EOperandInfo oper;
	memset(&oper,0,sizeof(oper));

	printf("Inst: %s\n", inst);

	char operandtxt[128];
	int idx = 1;

	EOperandInfo operand;
	memset(&operand,0,sizeof(operand));

	InstructionModifiers modifiers;
	memset(&modifiers, 0, sizeof(modifiers));

	parse_result_modifiers(line, &modifiers);
	while(true) {
		memset(&operandtxt,0,sizeof(operand));
		find_nth((char *)line, idx++, operandtxt, sizeof(operand));
		if(strlen(operandtxt) < 1 || idx-1 > MAX_OPERANDS) break;
		parse_operand(operandtxt, &operand, idx-2, instruction);
		printf("oper: %s\n", operandtxt);
	}
	write_instruction(instruction, &operand, &modifiers);
	
}
Exemplo n.º 9
0
TEST(pointer, FIND_NTH_1) {
  double x[5], *y;
  y = find_nth(&x[3], 1);
  EXPECT_EQ(&x[4], y);
}
Exemplo n.º 10
0
TEST(pointer, FIND_NTH_7) {
  double x[5], *y;
  y = find_nth(&x[1], 3);
  EXPECT_EQ(&x[4], y);
}
Exemplo n.º 11
0
TEST(pointer, FIND_NTH_6) {
  double x[5], *y;
  y = find_nth(&x[0], 4);
  EXPECT_EQ(&x[4], y);
}
Exemplo n.º 12
0
TEST(pointer, FIND_NTH_5) {
  double x[5], *y;
  y = find_nth(&x[0], 2);
  EXPECT_EQ(&x[2], y);
}
Exemplo n.º 13
0
TEST(pointer, FIND_NTH_4) {
  double x[5], *y;
  y = find_nth(&x[1], 1);
  EXPECT_EQ(&x[2], y);
}
Exemplo n.º 14
0
/** This class constructor sets up Nedges_ instances of channels 
 * of type channeltype_, connected together according to conns_.
 * Destructor is kind of involved because the class does possibly shady things with vectors of pointers to classes (which of course contain arrays). There are many creatures born with "new".
 * \param[in] Nnodes_ the number of nodes, which are presumed to be numbered [0,1, ...Nnodes]. 
 * \param[in] conns_ an array of length 2*Nedges. Layout: [leftend0, rightend0, leftend1, rightend1,...]
 *		Describes the network connectivity. pipe 0 goes from leftend0 to rightend 0, etc. 
 *		So if an element of conns has an (odd/even) index, it corresponds to a (left/right) end.
 *		The edge corresponding to the ith row of conns is stored in the ith element of channels.
 * \param[in] Nedges_ is the number of edges in the network (Nedges_= length(conns)/2.) 
 * \param[in] Ns  an array of length Nedges with number of grid points for each edge
 * \param[in] ws  an array of length Nedges with widths/diameters for each edge (m)
 * \param[in] Ls  an array of length Nedges with lengths of each edge (m)
 * \param[in] S0s an array of length Nedges with channel slopes for each edge 
 * \param[in] Mrs an array of length Nedges with Manning roughness coeffs for each edge
 * \param[in] a0s a vector with constant initial cross-sectional area values for each edge (m^2)
 * \param[in] q0s a vector with constant initial discharge values for each edge (m^3/s)
 * \param[in] M_  number of time steps
 * \param[in] channeltype_ is which model to use (Preissman slot or uniform)
 * \param[in] a wavespeed in pressurized pipe (m/s)
*/
Network::Network(int Nnodes_, std::vector<int> conns_, int Nedges_, std::vector<int> Ns, std::vector<double> ws, std::vector<double> Ls, 
		std::vector<double> S0s, std::vector<double> Mrs, std::vector<double> a0s, std::vector<double> q0s, int M_,  int channeltype_, double a):
	        Nnodes(Nnodes_), Nedges(Nedges_), M(M_), channeltype(channeltype_)
{
	
	//start with time =0	
	nn = 0; 
	//initialize internal array of connectivity data 
	for(int k = 0; k<Nedges*2; k++)
	{
		conns.push_back(conns_[k]);
	}
	//figure out the type of each node (is it connected to 1, 2 or 3 pipes)
	for (int k=0; k<2*Nedges; k++){nodeTypes.push_back(0.);}
	for(int k=0; k<2*Nedges; k++)
	{
		nodeTypes[conns[k]]+=1;
	}
	//fill channels with data from Ns, ws, Ls, etc
	for(int i = 0; i<Nedges; i++)
	{	
		if(channeltype==0){channels.push_back(new Cuniform(Ns[i], ws[i], Ls[i],M,a));}
		else{channels.push_back(new Cpreiss(Ns[i], ws[i], Ls[i],M,a));}
		channels[i]->setq(a0s[i],q0s[i]);
		channels[i]->setq0(a0s[i], q0s[i]);
		channels[i]->Mr = Mrs[i];
		channels[i]->S0 = S0s[i];
	//	channels[i]->showGeom();
	}

	//now can assign channels to the correct junctions
	for(int j=0; j<Nnodes; j++)
	{
	//	printf("node %d gets a junction%d\n", j,nodeTypes[j]);
		if(nodeTypes[j] ==1)
		{
			int idx =find_nth(conns, j, 1, 2*Nedges);
	//		printf(" index is %d, row is %d, column is %d\n", idx, idx/2, idx%2);
			printf("\njunction1!!!\n edge is %d and whichend is %d\n ", idx/2, idx%2); 
		        junction1s.push_back(new Junction1(*channels[idx/2], idx%2 ,0.,1)); //row in conns corresponds to edge; column corresponds to left or right end.
		}
		else if(nodeTypes[j] ==2)
		{
			int idx1 =find_nth(conns, j, 1, 2*Nedges);
			int idx2 =find_nth(conns, j, 2, 2*Nedges);
			printf("\njunction2!!! edge0 is %d, which0 is edge 1 is %d, which1 is %d %d\n", idx1/2, idx1/2, idx1%2, idx2/2, idx2%2);
		//	printf(" index2 is %d, edge1 is %d, which1 is %d\n", idx2, idx2/2, idx2%2);
			junction2s.push_back(new Junction2(*channels[idx1/2], *channels[idx2/2], idx1%2, idx2%2, 1.0));
		}

		else if(nodeTypes[j] ==3)
		{
			int idx1 =find_nth(conns, j, 1, 2*Nedges);
			int idx2 =find_nth(conns, j, 2, 2*Nedges);
			int idx3 =find_nth(conns, j, 3, 2*Nedges);
			printf("\njunction3!!!\n index1 is %d, row is %d, column is %d\n", idx1, idx1/2, idx1%2);
			printf(" index2 is %d, row is %d, column is %d\n", idx2, idx2/2, idx2%2);	
			printf(" index3 is %d, row is %d, column is %d\n", idx3, idx3/2, idx3%2);
			//set it up so that either you have [end0, end1, end2] = [1,0,0] or = [0,1,1];
			//[0,1,1] case
			if(idx1%2+idx2%2+idx3%2 ==2){
				if (idx1%2 == 0){junction3s.push_back(new Junction3(*channels[idx1/2], *channels[idx2/2], *channels[idx3/2], idx1%2, idx2%2, idx3%2));
				printf("(A) ch0 is %d ch1 is %d ch2 is %d", idx1/2, idx2/2, idx3/2 );
				printf("whichends are [%d %d %d]\n", idx1%2, idx2%2, idx3%2 );
				}
				else if(idx2%2 == 0){junction3s.push_back(new Junction3(*channels[idx2/2], *channels[idx1/2], *channels[idx3/2], idx2%2, idx1%2, idx3%2));
				printf("(B) ch0 is %d ch1 is %d ch2 is %d", idx2/2, idx1/2, idx3/2 );
				printf("whichends are [%d %d %d]\n", idx2%2, idx1%2, idx3%2 );
			}
				else {junction3s.push_back(new Junction3(*channels[idx3/2], *channels[idx2/2], *channels[idx1/2], idx3%2, idx2%2, idx1%2));
				printf("(C) ch0 is %d ch1 is %d ch2 is %d", idx3/2, idx2/2, idx1/2 );
				printf("whichends are [%d %d %d]\n", idx3%2, idx2%2, idx1%2 );
			}

			}
			//[1,0,0] case
			else if(idx1%2+idx2%2+idx3%2 ==1){
				if(idx1%2 ==1){junction3s.push_back(new Junction3(*channels[idx1/2], *channels[idx2/2], *channels[idx3/2], idx1%2, idx2%2, idx3%2));
				printf("(D) ch0 is %d ch1 is %d ch2 is %d", idx1/2, idx2/2, idx3/2 );
				printf("whichends are [%d %d %d]\n", idx1%2, idx2%2, idx3%2 );
				}
				else if(idx2%2 ==1){junction3s.push_back(new Junction3(*channels[idx2/2], *channels[idx1/2], *channels[idx3/2], idx2%2, idx1%2, idx3%2));
				printf("(E) ch0 is %d ch1 is %d ch2 is %d", idx2/2, idx1/2, idx3/2 );
				printf("whichends are [%d %d %d]\n", idx2%2, idx1%2, idx3%2 );
				}
				else {junction3s.push_back(new Junction3(*channels[idx3/2], *channels[idx2/2], *channels[idx1/2], idx3%2, idx2%2, idx1%2));
				printf("(F)ch0 is %d ch1 is %d ch2 is %d", idx3/2, idx2/2, idx1/2 );
				printf("whichends are [%d %d %d]\n", idx3%2, idx2%2, idx1%2 );
				}
			}
			else {
				cout<<"Ruh-roh, boundary conditions not implemented for this configuration yet. Your simulation is fairly certainily going to suck.\n";
			}
			
			
		}			
		else {printf("Well, then I have no idea. Too many nodes!  (nodetypes[j] = %d)\n", nodeTypes[j]);
			for (int k = 0; k<Nedges; k++)cout<<conns[2*k]<<" "<<conns[2*k+1]<<endl;
		}

	}
}
Exemplo n.º 15
0
//copy constructor from pointer to an old network...
Network::Network(Network *N_old):Nnodes(N_old->Nnodes), Nedges(N_old->Nedges), M(N_old->M)
	      {
	nn = 0;
	double a = N_old->channels[0]->a;
	channeltype = N_old->channeltype;
//copy nodes and connectivity info
	for( int i =0; i<Nedges*2; i++){conns.push_back(N_old->conns[i]);}
	for(int i =0; i<Nedges*2; i++){nodeTypes.push_back(N_old->nodeTypes[i]);}
//copy channels, their values and their parameters N, w, L, M, a, M, S0
	for(int i = 0; i<Nedges; i++)
	{	
		int Ni = N_old->channels[i]->N;
		if(N_old->channeltype ==0){channels.push_back(new Cuniform(Ni, N_old->channels[i]->w, N_old->channels[i]->L,M,a));}
		else{channels.push_back(new Cpreiss(Ni, N_old->channels[i]->w, N_old->channels[i]->L,M,a));}
		for(int k=0; k<2*Ni; k++){
			channels[i]->q[k] = N_old->channels[i]->q[k];
			channels[i]->q0[k] = N_old->channels[i]->q0[k];
		}
		channels[i]->Mr = N_old->channels[i]->Mr;
		channels[i]->S0 = N_old->channels[i]->S0;
	}
//now assign channels to the correct junctions
	for(int j=0; j<Nnodes; j++)
	{
		if(nodeTypes[j] ==1)
		{
			int idx =find_nth(conns, j, 1, 2*Nedges);
		    junction1s.push_back(new Junction1(*channels[idx/2], idx%2 ,0.,1)); //row in conns corresponds to edge; column corresponds to left or right end.
		}
		else if(nodeTypes[j] ==2)
		{
			int idx1 =find_nth(conns, j, 1, 2*Nedges);
			int idx2 =find_nth(conns, j, 2, 2*Nedges);
			junction2s.push_back(new Junction2(*channels[idx1/2], *channels[idx2/2], idx1%2, idx2%2, 1.0));
		}

		else if(nodeTypes[j] ==3)
		{
			int idx1 =find_nth(conns, j, 1, 2*Nedges);
			int idx2 =find_nth(conns, j, 2, 2*Nedges);
			int idx3 =find_nth(conns, j, 3, 2*Nedges);

//set it up so that either you have [end0, end1, end2] = [1,0,0] or = [0,1,1];
//[0,1,1] case
			if(idx1%2+idx2%2+idx3%2 ==2){
				if (idx1%2 == 0){junction3s.push_back(new Junction3(*channels[idx1/2], *channels[idx2/2], *channels[idx3/2], idx1%2, idx2%2, idx3%2));
                    printf("junction3! incoming channels= [%d %d %d]\n",idx1/2, idx2/2, idx3/2);
				}
				else if(idx2%2 == 0){junction3s.push_back(new Junction3(*channels[idx2/2], *channels[idx1/2], *channels[idx3/2], idx2%2, idx1%2, idx3%2));
                    printf("junction3! incoming channels= [%d %d %d]\n",idx2/2, idx1/2, idx3/2);

				}
				else {junction3s.push_back(new Junction3(*channels[idx3/2], *channels[idx2/2], *channels[idx1/2], idx3%2, idx2%2, idx1%2));
                     printf("junction3! incoming channels= [%d %d %d]\n",idx3/2, idx1/2, idx1/2);

				}

			}
//[1,0,0] case
			else if(idx1%2+idx2%2+idx3%2 ==1){
				if(idx1%2 ==1){junction3s.push_back(new Junction3(*channels[idx1/2], *channels[idx2/2], *channels[idx3/2], idx1%2, idx2%2, idx3%2));
                     printf("junction3! incoming channels= [%d %d %d]\n",idx1/2, idx2/2, idx3/2);

				}
				else if(idx2%2 ==1){junction3s.push_back(new Junction3(*channels[idx2/2], *channels[idx1/2], *channels[idx3/2], idx2%2, idx1%2, idx3%2));
                    printf("junction3! incoming channels= [%d %d %d]\n",idx2/2, idx1/2, idx3/2);

				}
				else {junction3s.push_back(new Junction3(*channels[idx3/2], *channels[idx2/2], *channels[idx1/2], idx3%2, idx2%2, idx1%2));
				 printf("junction3! incoming channels= [%d %d %d]\n",idx3/2, idx2/2, idx1/2);

                }
			}
			else {
				cout<<"Oops! boundary conditions not implemented for this configuration yet. Your simulation is fairly certainily going to suck.\n";
			}
			
			
		}			
		else {printf("Well, then I have no idea. Too many nodes!  (nodetypes[j] = %d)\n", nodeTypes[j]);
			for (int k = 0; k<Nedges; k++)cout<<conns[2*k]<<" "<<conns[2*k+1]<<endl;
		}

	}
	//copy other junction info
	for(int k = 0; k<junction1s.size(); k++)
	{
		junction1s[k]->bvaltype = N_old->junction1s[k]->bvaltype;
		junction1s[k]->setbVal(N_old->junction1s[k]->bval);
		junction1s[k]->reflect = N_old->junction1s[k]->reflect;
	}
	for(int k = 0; k<junction2s.size(); k++)
	{
		junction2s[k]->offset = N_old->junction2s[k]->offset;
		junction2s[k]->valveopen = N_old->junction2s[k]->valveopen;
		junction2s[k]->setValveTimes(N_old->junction2s[k]->valvetimes);
	}
	
	for(int k = 0; k<junction3s.size(); k++)
	{
		junction3s[k]->j2_01.offset = N_old->junction3s[k]->j2_01.offset; 
		junction3s[k]->j2_20.offset = N_old->junction3s[k]->j2_20.offset;
		junction3s[k]->j2_12.offset = N_old->junction3s[k]->j2_12.offset;
		junction3s[k]->j2_21.offset = N_old->junction3s[k]->j2_21.offset;
	}


}
Exemplo n.º 16
0
void Channel::setModes(Client *setter, char *modestr) {
	chanClient *info;
	chanClient tinfo;
	bool set=true;
	char tbuff[64];
	int modep=0;
	bool canVoice;
	char oldMode = this->auditorium;
	char *p=strchr(modestr,' ');
	if(p != NULL) *p++ = 0;
	memset(&tinfo,0,sizeof(tinfo));
	bool operoverride=false;
	char *tbuffptr;
	if(setter->getRights()&OPERPRIVS_OPEROVERRIDE) operoverride=true;
	//if(setter->getRights()&OPERPRIVS_GLOBALOWNER)  operoverride=true;
	info = getUserInfo(setter);
	if(info == NULL) info = &tinfo;
	if(info->owner) info->op = true;
	if(info->op) info->halfop = true;
	for(int i=0;i<strlen(modestr);i++) {
		switch(modestr[i]) {
		case '-':
			set = false;
			break;
		case '+':
			set = true;
			break;
		case 'e':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->mode_ops_obey_channel_limit == set) break;
				this->mode_ops_obey_channel_limit = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+e":"-e");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'm':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->moderated == set) break;
				this->moderated = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+m":"-m");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'n':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->nooutsidemsgs == set) break;
				this->nooutsidemsgs = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+n":"-n");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'i':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->inviteonly == set) break;
				this->inviteonly = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+i":"-i");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'l': //set channel limit
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
			int len = 0;
			if(set) {
				if(p == NULL) {
					info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
					return;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				len = atoi(tbuff);
				if(len < 1) return;
			}
			if(set) {
				sendMessage(false,false,setter,"MODE %s +l %d",getName(),len);
			} else {
				sendMessage(false,false,setter,"MODE %s -l",getName());
			}
			this->limit = len;
			} else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'k': //set channel key
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
			if(set) {
				if(p == NULL) {
					info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
					return;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				sendMessage(false,false,setter,"MODE %s +k %s",getName(),tbuff);
				strcpy(key,tbuff);
			} else {
				sendMessage(false,false,setter,"MODE %s -k",getName());
				memset(key,0,sizeof(key));
			}
			} else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 't':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->topic_protect == set) break;
				this->topic_protect = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+t":"-t");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'p':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->secret && set) {
					this->secret = false;
					sendMessage(false,false,setter,"MODE %s -s",getName());
				}
				if(this->priv == set) break;
				this->priv = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+p":"-p");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 's':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(this->priv && set) {
					this->priv = false;
					sendMessage(false,false,setter,"MODE %s -p",getName());
				}
				if(this->secret == set) break;
				this->secret = set;
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+s":"-s");
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'q':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(set && this->auditorium == 2) {
					sendMessage(false,false,setter,"MODE %s %s",getName(),!set?"+u":"-u");	
				}
				if((set && this->auditorium == 1) || (!set && this->auditorium != 1)) break;
				this->auditorium = (set==true?1:0);
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+q":"-q");
				auditoriumUpdate(oldMode);
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'u':
			if(info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				if(set && this->auditorium == 1) {
					sendMessage(false,false,setter,"MODE %s %s",getName(),!set?"+q":"-q");	
				}
				if((set && this->auditorium == 2) || (!set && this->auditorium != 2)) break;
				this->auditorium = (set==true?2:0);
				sendMessage(false,false,setter,"MODE %s %s",getName(),set?"+u":"-u");
				auditoriumUpdate(oldMode);
			}
			else sendNotEnoughPrivs(ENotEnough_HALFOP,setter,set?"set mode":"remove mode");
			break;
		case 'o': //op someone
			if(info->owner || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
			chanClient *tclient;
			Client *opclient;
			if(p == NULL) {
				info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
				return;
			}
			find_nth(p,modep++,tbuff,sizeof(tbuff));
			if(strlen(tbuff)<1) return;
			opclient = find_user(tbuff);

			if(opclient != NULL) {
				tclient = this->getUserInfo(opclient);
				if(tclient != NULL) {
					if(tclient->op == set) break;
					sendMessage(false,false,setter,"MODE %s %s %s",getName(),set?"+o":"-o",tbuff);
					if(set == false) tclient->owner = set;
					tclient->op=set;
					tclient->halfop = set;
				} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
				sendNotEnoughPrivs(ENotEnough_OWNER,setter,"change ops");
			}
			break;
		case 'v': //voice someone
			//checking isn't instant because you could be devoicing yourself
			chanClient *tclient;
			Client *opclient;
			if(p == NULL) {
				info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
				return;
			}
			canVoice = info->halfop || info->op || info->owner || operoverride && (this->onlyowner != 1 || info->owner);
			find_nth(p,modep++,tbuff,sizeof(tbuff));
			if(strlen(tbuff)<1) return;
			opclient = find_user(tbuff);
			if(opclient != NULL) {
				tclient = this->getUserInfo(opclient);
				if(tclient != NULL) {
					if(!canVoice && (tclient->client != setter || set == true)) {
						sendNotEnoughPrivs(ENotEnough_HALFOP,setter,"change voice");
						break;
					}
					if(tclient->voice == set) break;
					sendMessage(false,false,setter,"MODE %s %s %s",getName(),set?"+v":"-v",tbuff);
					tclient->voice=set;
				} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
			}
			break;
		case 'h': //halfop someone
			if(info->op || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
			chanClient *tclient;
			Client *opclient;
			if(p == NULL) {
				info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
				return;
			}
			find_nth(p,modep++,tbuff,sizeof(tbuff));
			if(strlen(tbuff)<1) return;
			opclient = find_user(tbuff);
			if(opclient != NULL) {
				tclient = this->getUserInfo(opclient);
				if(tclient != NULL) {
					if(tclient->halfop == set) break;
					if(tclient->op == true || tclient->owner == true && info->owner == false) break;
						sendMessage(false,false,setter,"MODE %s %s %s",getName(),set?"+o":"-o",tbuff);
						tclient->halfop = set;
				} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
				sendNotEnoughPrivs(ENotEnough_OP,setter,"set halfop");
			}
			break;
		case 'O': //owner someone
			if(info->owner || operoverride && !(this->onlyowner == 1 && info->owner == false)) {
				chanClient *tclient;
				Client *opclient;
				if(p == NULL) {
					info->client->send_numeric(461, "%c :Not enough parameters",modestr[i]);
					return;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				opclient = find_user(tbuff);
			if(opclient != NULL) {
				tclient = this->getUserInfo(opclient);
				if(tclient != NULL) {
					if(tclient->owner == set) break;
					sendMessage(false,false,setter,"MODE %s %s %s",getName(),set?"+o":"-o",tbuff);
					tclient->owner = set;
					tclient->op = set;
					tclient->halfop = set;
				} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
					setter->send_numeric(401,"%s :No such nick/channel",tbuff);
					break;
				}
			} else {
				sendNotEnoughPrivs(ENotEnough_OWNER,setter,"change owner");
			}
			break;
		case 'b': //ban/unban someone
			if((info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) || p == NULL) {
				if(p == NULL) { //list bans
					std::list<userMode *>::iterator iterator=server.usermodes_list.begin();
					userMode *um;
					char *nick;
					info->client->getUserInfo(&nick,NULL,NULL,NULL);
					while(iterator != server.usermodes_list.end()) {
						um=*iterator;
							if(match(um->chanmask,getName()) == 0) {
								if(um->hostmask[0] != 0 && um->modeflags & EModeFlags_Ban)
									info->client->send_numeric(367,"%s *!*@%s %s@%s %d",getName(), um->hostmask, um->setbynick[0] == 0?"SERVER":um->setbynick,um->setbyhost[0] == 0||info->halfop==false?"*":um->setbyhost,um->setondate);
							}
						iterator++;
					}
					info->client->send_numeric(368,"%s :End of channel ban list",getName());
					break;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				char setstr[128];
				memset(&setstr,0, sizeof(setstr));
				tbuffptr = (char *)&tbuff;
				if(strchr(tbuffptr,'@') != NULL) tbuffptr = strchr(tbuffptr,'@')+1;
				sprintf(setstr,"\\hostmask\\%s\\modeflags\\b\\comment\\Banned by MODE command (Persist)",tbuffptr);
				if(set) {
					addUserMode(info->client,this->getName(),setstr);
				} else {
					userMode *usermode = findRemoveableUsermode(getName(),tbuff,EModeFlags_Ban,setter->getRights()&OPERPRIVS_GLOBALOWNER);
					if(usermode != NULL) {
						removeUsermode(usermode);
					}
				}
				//tbuff = ban name
			} else {
				sendNotEnoughPrivs(ENotEnough_HALFOP,setter,"set mode");
			}
			break;
		case 'I': //invite/uninvite someone
			if((info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) || p == NULL) {
				if(p == NULL) { //list bans
					std::list<userMode *>::iterator iterator=server.usermodes_list.begin();
					userMode *um;
					char *nick;
					info->client->getUserInfo(&nick,NULL,NULL,NULL);
					while(iterator != server.usermodes_list.end()) {
						um=*iterator;
							if(match(um->chanmask,getName())) {
								if(um->hostmask[0] != 0 && um->modeflags & EModeFlags_Invited)
									info->client->send_numeric(367,"%s *!*@%s %s@%s %d",getName(), um->hostmask, um->setbynick[0] == 0?"SERVER":um->setbynick,um->setbyhost[0] == 0||info->halfop==false?"*":um->setbyhost,um->setondate);
							}
						iterator++;
					}
					info->client->send_numeric(368,"%s :End of channel invite list",getName());
					break;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				char setstr[128];
				memset(&setstr,0, sizeof(setstr));
				tbuffptr = (char *)&tbuff;
				if(strchr(tbuffptr,'@') != NULL) tbuffptr = strchr(tbuffptr,'@')+1;
				sprintf(setstr,"\\hostmask\\%s\\modeflags\\I\\comment\\Invited by MODE command (Persist)",tbuffptr);
				if(set) {
					addUserMode(info->client,this->getName(),setstr);
				} else {
					userMode *usermode = findRemoveableUsermode(getName(),tbuff,EModeFlags_Invited,setter->getRights()&OPERPRIVS_GLOBALOWNER);
					if(usermode != NULL) {
						removeUsermode(usermode);
					}
				}
				//tbuff = ban name
			} else {
				sendNotEnoughPrivs(ENotEnough_HALFOP,setter,"set mode");
			}
			break;
		case 'E': //excempt/unexcempt someone
			if((info->halfop || operoverride && !(this->onlyowner == 1 && info->owner == false)) || p == NULL) {
				if(p == NULL) { //list bans
					std::list<userMode *>::iterator iterator=server.usermodes_list.begin();
					userMode *um;
					char *nick;
					info->client->getUserInfo(&nick,NULL,NULL,NULL);
					while(iterator != server.usermodes_list.end()) {
						um=*iterator;
							if(match(um->chanmask,getName())) {
								if(um->hostmask[0] != 0 && um->modeflags & EModeFlags_BanExcempt)
									info->client->send_numeric(367,"%s *!*@%s %s@%s %d",getName(), um->hostmask, um->setbynick[0] == 0?"SERVER":um->setbynick,um->setbyhost[0] == 0||info->halfop==false?"*":um->setbyhost,um->setondate);
							}
						iterator++;
					}
					info->client->send_numeric(368,"%s :End of channel exempt list",getName());
					break;
				}
				find_nth(p,modep++,tbuff,sizeof(tbuff));
				if(strlen(tbuff)<1) return;
				char setstr[128];
				memset(&setstr,0, sizeof(setstr));
				tbuffptr = (char *)&tbuff;
				if(strchr(tbuffptr,'@') != NULL) tbuffptr = strchr(tbuffptr,'@')+1;
				sprintf(setstr,"\\hostmask\\%s\\modeflags\\E\\comment\\Exempt by MODE command (Persist)",tbuffptr);
				if(set) {
					addUserMode(info->client,this->getName(),setstr);
				} else {
					userMode *usermode = findRemoveableUsermode(getName(),tbuff,EModeFlags_BanExcempt,setter->getRights()&OPERPRIVS_GLOBALOWNER);
					if(usermode != NULL) {
						removeUsermode(usermode);
					}
				}
			} else {
				sendNotEnoughPrivs(ENotEnough_HALFOP,setter,"set mode");
			}
			break;
		default:
			setter->send_numeric(472,"%c :is unknown mode to me for %s",modestr[i],getName());
			break;
		}
	}
	return;
}