Beispiel #1
0
TEST(Alloc, GCSync)
{
  register void **stack asm ("ebp");
  alloc allocator(stack);
  std::atomic<int> joined (0);

  auto thread_main = [&](int dummy) {
    allocator.gc_barrier.add_thread();
    if (allocator.gc_barrier.trigger ())
      {
	allocator.gc_barrier.finish ();
      }

    joined++;
    allocator.gc_barrier.remove_thread();
  };
  
  auto other_thread = std::thread (thread_main, 42);
  thread_main (43);

  other_thread.join();

  ASSERT_EQ (joined, 2);
}
Beispiel #2
0
void play()
{
	char str[256],str2[256],log[81],done,doub,dh,split_card,suggestion
		,*YouWereDealt="\1n\1k\0015 You \1n\1m were dealt: %s\r\n"
		,*UserWasDealt="\1n\1m\1h%s\1n\1m was dealt: %s\r\n"
		,*YourHand="\1n\1k\0015 You \1n\1m                     (%2d) %s"
		,*UserHand="\1n\1m\1h%-25s \1n\1m(%2d) %s"
		,*DealerHand="\1n\1hDealer                    \1n\1m(%2d) "
		,*Bust="\1n\1r\1hBust\1n\r\n"
		,*Natural="\1g\1h\1iNatural "
		,*Three7s="\1r\1h\1iThree 7's "
		,*Blackjack="\1n\0011\1k Blackjack! \1n\r\n"
		,*TwentyOne="\1n\0012\1k Twenty-one \1n\r\n";
	int h,i,j,file;
	uint max;
	long val;
	time_t start,now;
	struct tm* tm;

sprintf(str,"MESSAGE.%d",node_num);         /* remove message if waiting */
if(fexist(str))
    remove(str);

getgamedat(0);
if(node[node_num-1]) {
	getgamedat(1);
	node[node_num-1]=0;
	putgamedat();
	getgamedat(0); }

if(total_players && misc&INPLAY) {
	bputs("\r\n\1hWaiting for end of hand (^A to abort)...\1n");
	start=now=time(NULL);
	getgamedat(0);
	while(total_players && misc&INPLAY) {
		if((i=inkey(0))!=0) {	 /* if key was hit */
			if(i==1) {		 /* if ctrl-a */
				bputs("\r\n");
				return; } }  /* return */
		mswait(100);
		getgamedat(0);
		now=time(NULL);
		if(now-start>300) { /* only wait up to 5 minutes */
			bputs("\r\ntimeout\r\n");
			return; } }
	bputs("\r\n"); }

getgamedat(1);
node[node_num-1]=user_number;
putgamedat();

if(!total_players)
    shuffle();
else
	listplayers();

sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,joined());
putallnodemsg(str);

while(1) {
	aborted=0;
	#if DEBUG
	debugline("top of loop");
	#endif
	if(autoplay)
		lncntr=0;
	bprintf(ShoeStatus,cur_card,total_decks*52);
	if(cur_card>(total_decks*52)-(total_players*10)-10 && lastplayer())
		shuffle();
	getgamedat(1);
	misc&=~INPLAY;
	status[node_num-1]=BET;
	node[node_num-1]=user_number;
	putgamedat();

	bprintf("\r\n\1n\1cYou have \1h%s\1n\1ck credits\r\n"
		,ultoac(credits/1024L,str));
	if(credits<min_bet/1024) {
		bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet);
		bputs("\1n\1r\1hCome back when you have more credits.\r\n");
        break; }
	if(credits/1024L>(ulong)max_bet)
		max=max_bet;
	else
		max=credits/1024L;
	sprintf(str,"\r\nBet amount (in kilobytes) or ~Quit [%u]: "
		,ibet<credits/1024L ? ibet : credits/1024L);
	chat();
	mnemonics(str);
	if(autoplay && keyhit())
		autoplay=0;
	if(autoplay)
		i=ibet;
	else
		i=getnum(max);
	if(i==-1)	/* if user hit ^C or 'Q' */
		break;
	bputs("\r\n");
	if(i)		/* if user entered a value */
		bet[0]=i;
	else		/* if user hit enter */
		bet[0]=ibet<credits/1024L ? ibet : credits/1024L;
	if(bet[0]<min_bet) {
		bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet);
		bputs("\1n\1r\1hCome back when you're ready to bet more.\r\n");
		break; }
	ibet=bet[0];
	getgamedat(0);	/* to get all new arrivals */
	sprintf(str,"\1m\1h%s\1n\1m bet \1n\1h%u\1n\1mk\r\n",user_name,bet[0]);
	putallnodemsg(str);

	pc[0]=2;						/* init player's 1st hand to 2 cards */
	for(i=1;i<MAX_HANDS;i++)		/* init player's other hands to 0 cards */
		pc[i]=0;
	hands=1;						/* init total player's hands to 1 */

	getgamedat(1);					/* first come first serve to be the */
	for(i=0;i<total_nodes;i++)		/* dealer in control of sync */
		if(node[i] && status[i]==SYNC_D)
			break;
	if(i==total_nodes) {
		#if DEBUG
		debugline("syncdealer");
		#endif
		syncdealer();  }			/* all players meet here */
	else {							/* first player is current after here */
		#if DEBUG
		debugline("syncplayer");
		#endif
		syncplayer(); } 			/* game is closed (INPLAY) at this point */

	#if DEBUG
	debugline("waitturn 1");
	#endif
    waitturn();
	getnodemsg();
										/* Initial deal card #1 */
	getcarddat();
	player[0][0]=card[cur_card++];
	putcarddat();
	sprintf(str,YouWereDealt,cardstr(card[cur_card-1]));
	if(!symbols)
		strip_symbols(str);
    bputs(str);
	sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1]));
    putallnodemsg(str);
	
	if(lastplayer()) {
		getcarddat();
		dealer[0]=card[cur_card++];
		dc=1;
		putcarddat(); }
	nextplayer();
	#if DEBUG
	debugline("waitturn 2");
	#endif
	waitturn();
	getnodemsg();

	getcarddat();					   /* Initial deal card #2 */
	player[0][1]=card[cur_card++];
	putcarddat();
	sprintf(str,YouWereDealt,cardstr(card[cur_card-1]));
	if(!symbols)
		strip_symbols(str);
	bputs(str);
	sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1]));
    putallnodemsg(str);
	
	if(lastplayer()) {
		getcarddat();
		dealer[1]=card[cur_card++];
		dc=2;
		putcarddat(); }
	nextplayer();
	#if DEBUG
	debugline("waitturn 3");
	#endif
	waitturn();
	getnodemsg();
	getcarddat();

	for(i=0;i<hands;i++) {
		if(autoplay)
			lncntr=0;
		done=doub=0;
		while(!done && pc[i]<MAX_CARDS && cur_card<total_decks*52) {
			h=hand(player[i],pc[i]);
			str[0]=0;
			for(j=0;j<pc[i];j++) {
				strcat(str,cardstr(player[i][j]));
				strcat(str," "); }
			j=bstrlen(str);
			while(j++<19)
				strcat(str," ");
			if(h>21) {
				strcat(str,Bust);
				sprintf(str2,YourHand,h,str);
				if(!symbols)
					strip_symbols(str2);
				bputs(str2);
				sprintf(str2,UserHand,user_name,h,str);
				putallnodemsg(str2);
				break; }
			if(h==21) {
				if(pc[i]==2) {	/* blackjack */
					if(player[i][0].suit==player[i][1].suit)
						strcat(str,Natural);
					strcat(str,Blackjack); }
				else {
					if(player[i][0].value==7
						&& player[i][1].value==7
						&& player[i][2].value==7)
						strcat(str,Three7s);
					strcat(str,TwentyOne); }
				sprintf(str2,YourHand,h,str);
				if(!symbols)
					strip_symbols(str2);
				bputs(str2);
				sprintf(str2,UserHand,user_name,h,str);
                putallnodemsg(str2);
				// fdelay(500);
				break; }
			strcat(str,"\r\n");
			sprintf(str2,YourHand,h,str);
			if(!symbols)
				strip_symbols(str2);
			bputs(str2);
			sprintf(str2,UserHand,user_name,h,str);
			putallnodemsg(str2);
			if(doub)
				break;
			sprintf(str,"\1n\1hDealer\1n\1m card up: %s\r\n"
				,cardstr(dealer[1]));
			if(!symbols)
				strip_symbols(str);
			bputs(str);

			if(tutor) {
				if(pc[i]==2)
					split_card=pair(player[i],pc[i]);
				else
					split_card=0;
                if(split_card==A
					|| (split_card==9 && (dealer[1].value<7
						|| (dealer[1].value>7 && dealer[1].value<10)))
                    || split_card==8
					|| (split_card==7 && dealer[1].value<9)
					|| (split_card==6 && dealer[1].value<7)
					|| (split_card==4 && dealer[1].value==5)
					|| (split_card && split_card<4 && dealer[1].value<8))
					suggestion='P';
                else if(soft(player[i],pc[i])) {
                    if(h>18)
						suggestion='S';
					else if(pc[i]==2
						&& ((h==18
							&& dealer[1].value>3 && dealer[1].value<7)
                        || (h==17
							&& dealer[1].value>2 && dealer[1].value<7)
                        || (h>13
							&& dealer[1].value>3 && dealer[1].value<7)
                        || (h==12
							&& dealer[1].value>4 && dealer[1].value<7)))
						suggestion='D';
                    else
						suggestion='H'; }
                else { /* hard */
					if(h>16 || (h>13 && dealer[1].value<7)
						|| (h==12 && dealer[1].value>3 && dealer[1].value<7))
						suggestion='S';
					else if(pc[i]==2
						&& (h==11 || (h==10 && dealer[1].value<10)
						|| (h==9 && dealer[1].value<7)))
						suggestion='D';
                    else
						suggestion='H'; } }

			if(tutor==1)
				suggest(suggestion);
			strcpy(str,"\r\n~Hit");
			strcpy(tmp,"H\r");
			if(bet[i]+ibet<=credits/1024L && pc[i]==2) {
				strcat(str,", ~Double");
				strcat(tmp,"D"); }
			if(bet[i]+ibet<=credits/1024L && pc[i]==2 && hands<MAX_HANDS
				&& player[i][0].value==player[i][1].value) {
				strcat(str,", ~Split");
				strcat(tmp,"S"); }
			strcat(str,", or [Stand]: ");
			chat();
			mnemonics(str);
			if(autoplay && keyhit())
				autoplay=0;


			if(autoplay) {
				lncntr=0;
				bputs("\r\n");
				strcpy(str,stand());
				bputs(str);
				putallnodemsg(str);
				done=1; }
			else
			switch(getkeys(tmp,0)) {
				case 'H':     /* hit */
					if(tutor==2 && suggestion!='H')
						wrong(suggestion);
					strcpy(str,hit());
					bputs(str);
					putallnodemsg(str);
					getcarddat();
					player[i][pc[i]++]=card[cur_card++];
					putcarddat();
					break;
				case 'D':   /* double down */
					if(tutor==2 && suggestion!='D')
                        wrong(suggestion);
					strcpy(str,doubit());
					bputs(str);
					putallnodemsg(str);
					getcarddat();
					player[i][pc[i]++]=card[cur_card++];
					putcarddat();
					doub=1;
					bet[i]+=ibet;
					break;
				case 'S':   /* split */
					if(tutor==2 && suggestion!='P')
                        wrong(suggestion);
					strcpy(str,split());
					bputs(str);
					putallnodemsg(str);
					player[hands][0]=player[i][1];
					getcarddat();
					player[i][1]=card[cur_card++];
					player[hands][1]=card[cur_card++];
					putcarddat();
					pc[hands]=2;
					bet[hands]=ibet;
					hands++;
					break;
				case CR:
					if(tutor==2 && suggestion!='S')
                        wrong(suggestion);
					strcpy(str,stand());
					bputs(str);
					putallnodemsg(str);
					done=1;
					break; } } }

	if(lastplayer()) {	/* last player plays the dealer's hand */
		getcarddat();
		while(hand(dealer,dc)<17 && dc<MAX_CARDS && cur_card<total_decks*52)
			dealer[dc++]=card[cur_card++];
		putcarddat(); }

	nextplayer();
	#if DEBUG
	debugline("waitturn 4");
	#endif
	waitturn();
	getnodemsg();

	if(firstplayer()==node_num) {
		strcpy(str,"\1n\0014\1h Final \1n\r\n");
		bputs(str);
		putallnodemsg(str); }
	getcarddat();
	dh=hand(dealer,dc); 					/* display dealer's hand */
	sprintf(str,DealerHand,dh);
	for(i=0;i<dc;i++) {
		strcat(str,cardstr(dealer[i]));
		strcat(str," "); }
	i=bstrlen(str);
	while(i++<50)				/* was 50 */
		strcat(str," ");
	if(dh>21) {
		strcat(str,Bust);
		if(!symbols)
			strip_symbols(str);
		bputs(str); }
	else if(dh==21) {
		if(dc==2) { 	/* blackjack */
			if(dealer[0].suit==dealer[1].suit)
				strcat(str,Natural);
			strcat(str,Blackjack); }
		else {			/* twenty-one */
			if(dc==3 && dealer[0].value==7 && dealer[1].value==7
				&& dealer[2].value==7)
				strcat(str,Three7s);
			strcat(str,TwentyOne); }
		if(!symbols)
            strip_symbols(str);
		bputs(str); }
	else {
		if(!symbols)
            strip_symbols(str);
		bprintf("%s\r\n",str); }

	for(i=0;i<hands;i++) {						/* display player's hand(s) */
		h=hand(player[i],pc[i]);
		str[0]=0;
		for(j=0;j<pc[i];j++) {
			strcat(str,cardstr(player[i][j]));
			strcat(str," "); }
		j=bstrlen(str);
		while(j++<19)
			strcat(str," ");
		if(logit) {
			now=time(NULL);
			tm=localtime(&now);
			sprintf(log,"%02d%02d%02d.log"                  /* log winnings */
				,tm->tm_mon+1,tm->tm_mday,tm->tm_year%100);
			if((file=nopen(log,O_RDONLY))!=-1) {
				read(file,tmp,filelength(file));
				tmp[filelength(file)]=0;
				val=atol(tmp);
				close(file); }
			else
				val=0L;
			if((file=nopen(log,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
				bprintf("error opening %s\r\n",log);
				return; } }
		if(h<22 && (h>dh || dh>21	/* player won */
			|| (h==21 && pc[i]==2 && dh==21 && dh>2))) {	/* blackjack */
			j=bet[i];								  /* and dealer got 21 */
			if(h==21 && 	/* natural blackjack or three 7's */
				((player[i][0].value==7 && player[i][1].value==7
				&& player[i][2].value==7)
				|| (pc[i]==2 && player[i][0].suit==player[i][1].suit)))
				j*=2;
			else if(h==21 && pc[i]==2)	/* regular blackjack */
				j*=1.5; /* blackjack pays 1 1/2 to 1 */
			sprintf(tmp,"\1n\1h\1m\1iWon!\1n\1h %u\1n\1mk",j);
			strcat(str,tmp);
			credits+=j*1024L;
			val-=j*1024L;
			moduserdat(); }
		else if(h<22 && h==dh)
			strcat(str,"\1n\1hPush");
		else {
			strcat(str,"\1nLost");
			credits-=bet[i]*1024L;
			val+=bet[i]*1024L;
			moduserdat(); }
		if(logit) {
			sprintf(tmp,"%ld",val);
			write(file,tmp,strlen(tmp));
			close(file); }					/* close winning log */
		strcat(str,"\1n\r\n");
		sprintf(str2,YourHand,h,str);
		if(!symbols)
			strip_symbols(str2);
		bputs(str2);
		sprintf(str2,UserHand,user_name,h,str);
		putallnodemsg(str2); }

	nextplayer();
	if(!lastplayer()) {
		#if DEBUG
		debugline("lastplayer waitturn");
		#endif
		waitturn();
		nextplayer(); }
	#if DEBUG
	debugline("end of loop");
	#endif
	getnodemsg(); }

getgamedat(1);
node[node_num-1]=0;
putgamedat();
sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,left());
putallnodemsg(str);
}
// read a line of irc and process it.
void IRCLobby::processMessage()
{
    assert(irc_server_socket != 0);
    
    char buf[1024];
    char *host, *mess, *host_end, *user_end, *code,*irc_user,*real_user,
        *buf_start;

    readIRCLine(buf, sizeof(buf));
#ifndef WITHOUT_NETPANZER
    LOGGER.debug("recv irc:%s",buf);
#endif
    
    buf_start=buf;
    if(buf[0]==':')  { buf_start++; }

    real_user=irc_user=buf_start;
    if(strncmp(real_user,nickname_prefix,sizeof(nickname_prefix)-1)==0) {
        real_user+=sizeof(nickname_prefix)-1;
    }

    code=irc_user;
    // skip 1 word and spaces behind it
    while(*code && !isspace(*code)) { code++; }
    while(*code && isspace(*code)) { code++; }

    if((mess=strchr(code,':'))==NULL) {
        return;
    }
    mess++;

    char *code_end=code;
    while(*code_end && !isspace(*code_end)) code_end++;
    *code_end=0;
    int code_i=atoi(code);


    if(code_i == 433) {
        // wrong user name, change the number at the end
        char newplayer[256];
        char *p;
        strncpy(newplayer,nickname.c_str(),sizeof(newplayer)-2);
        newplayer[sizeof(newplayer)-2]=0;
        p=strchr(newplayer,0);
        if(isdigit(p[-1])) {
            p--;
            while(isdigit(*p) && p>newplayer) p--;
            p++;
        }
        snprintf(p,(newplayer+sizeof(newplayer))-p,"%i",atoi(p)+1);
        changeNickName(newplayer);
        return;
    }
    if(code_i==1) {
        sendLoginInfo();
        return;
    }
    if(code_i>=400 && code_i<500) {
        addChatMessage("Error",mess);
        LOG(("IRC:%s",buf));
        return;
    }
    if(strcmp(code,"NOTICE")==0) {
        addChatMessage("Lobby",mess);
        return;
    }
    if(code_i==353) {
        char user_list[1024];
        char *u=user_list;
        char *m=mess;
        while(*m) {
            if(strncmp(m,nickname_prefix,sizeof(nickname_prefix)-1)==0) {
                m+=sizeof(nickname_prefix)-1;
            }
            *u++=*m++;
        }
        *u=0;
        addChatMessage("Lobby",user_list);
        return;
    }
    if(strcmp(code,"PONG")==0) {
        expected_ping=0;
        return;
    }
    if(strcmp(code,"PING")==0 || strncmp(buf,"PING",4)==0) {
        std::stringstream pong;  
        pong << "PONG " <<mess;
        sendIRCLine(pong.str());
        return;
    }

    // get remote user/host
    if(
        (host=strchr(buf,'@'))==0
        || (user_end=strchr(buf,'!'))==0
    ) {
        return;
    }
    *host++=0;
    *user_end++=0;

    if(strcmp(code,"JOIN")==0) {
        std::string joined(real_user);
        joined+=" has arrived in lobby";
        addChatMessage("",joined);
        return;
    }
    if(strcmp(code,"PART")==0 || strcmp(code,"QUIT")==0) {
        std::string leave(real_user);
        leave+=" has left the lobby";
        addChatMessage("",leave);
        return;
    }


    if((host_end=strchr(host,' '))==0) {
        return;
    }
    *host_end++=0;
    while(isspace(*host_end)) host_end++;
    if(strcmp(code,"PRIVMSG")!=0) {
        return;
    }

    if(mess[0]=='#') {
        // this is a chat message
        addChatMessage(real_user, mess+1);

        return;
    }
    if(mess[0]=='-') {
        // this is an internal message

        if(strcmp(mess+1, ask_server_running_mess)==0) {
            // reply with server details
            sendServerInfo(irc_user);
        }
        else 
        if(strncmp(mess+1,server_running_mess,sizeof(server_running_mess)-1)==0) {
            // add a server to the list
            const char *p=mess+strlen(server_running_mess)+1;
            const char *map;
            int players=atoi(p);
            if((p=strchr(p,'/'))==0) {
                LOG(("bad server description: %s\n",mess));
                return;
            }
            int max_players=atoi(++p);
            int port=_NETPANZER_DEFAULT_PORT_TCP;
            char *port_str;
            if((port_str=strstr(p,"port:"))!=0) {
                port=atoi(port_str+5);
            }
            if((map=strstr(p,"map:"))==0) {
                LOG(("no map name: %s\n",mess));
                return;
            }
            map+=4;

            GameServer *server
                = game_servers->find(host, port);
            if(server==0) {
                SDL_mutexP(game_servers_mutex);
                game_servers->push_back(
                        GameServer(host, port,
                            irc_user,real_user,map, players, max_players));
                SDL_mutexV(game_servers_mutex);
            }
            else {
                server->irc_user = irc_user;
                server->real_user = real_user;
                server->map = map;
                server->playercount = players;
                server->max_players = max_players;
            }
        }
        else if(strncmp(mess+1,leaving_mess,sizeof(leaving_mess)-1)==0) {
            addChatMessage(real_user,mess);
        }
    }
}
Beispiel #4
0
void
av::NetNode::join(const std::string& groupName)
{
#ifdef AVANGO_DEBUG
  logger.debug() << "av::NetNode::NetNode: joining group: " << groupName;
#endif

#ifdef ZMQ_DISTRIBUTION_SUPPORT
  bool isServer;
  std::string hostName;
  std::string port;
  uint64_t serverHWM = 2;
  {
    // from http://stackoverflow.com/questions/541561/using-boost-tokenizer-escaped-list-separator-with-different-parameters
    std::string gn(groupName);
    
    typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
    boost::escaped_list_separator<char> Separator( ' ', '|' );
    Tokenizer tok( gn, Separator );
    unsigned numTokens = 0;
    for (Tokenizer::iterator iter = tok.begin(); iter != tok.end(); ++iter) {
      ++numTokens;
    }
    if (3 == numTokens) {
      Tokenizer::iterator iter = tok.begin();
      isServer = ("AVSERVER" == *iter);
      ++iter;
      hostName = *iter;
      ++iter;
      port = *iter;
    } else if (4 == numTokens) {
      Tokenizer::iterator iter = tok.begin();
      isServer = ("AVSERVER" == *iter);
      ++iter;
      hostName = *iter;
      ++iter;
      port = *iter;
      serverHWM = atoi((*iter).c_str());
    } else {
      std::stringstream msg;
      msg << "ERROR in av::NetNode::join(const std::string& groupName), could not join - invalid CONFIG";
      throw (std::runtime_error(msg.str()));
    }

  }
  
  if (isServer) {
    gServer = new NetNodeServer(hostName,port, this, gClientEndpoint, gServerEndpoint, serverHWM);
    joined(gServerEndpoint);

    av::Msg av_msg;
    getStateFragment(gServerEndpoint,av_msg);
    setStateFragment(gClientEndpoint,av_msg);
  } else {
    gClient = new NetNodeClient(hostName,port, this, gClientEndpoint, gServerEndpoint);
    joined(gClientEndpoint);
    gClient->start();
  }
  //handleNetworkSends();
  //handleNetworkReceives();

  mIdCounter = 0;

#else
  leave();

  Maestro_CSX_Options ops;

  // heartbeat is once per second
  ops.heartbeatRate = 1000;
  ops.groupName = (char*) groupName.c_str();
  ops.transports = "DEERING";
  ops.properties = "Gmp:Sync:Heal:Switch:Frag:Suspect:Flow:Total";
  ops.params = "suspect_max_idle=3:int;suspect_sweep=1.000:time";
  ops.mbrshipType = MAESTRO_SERVER;
  ops.xferType = MAESTRO_ATOMIC_XFER;

  // get the command-line options from the database
  ops.argv = getEnsOptionsArgv();

  // check for usage of a groupd and set the corresponding maestro flag
  std::string dummy_value;
  if (getEnsOption("-groupd", dummy_value))
    ops.groupdFlag = true;

  if (getEnsOption("-properties", dummy_value))
    ops.properties = const_cast<char*> (dummy_value.c_str());

  if (getEnsOption("-verbose", dummy_value)) {
    if (getEnsOption("-modes", dummy_value))
      std::cout << " modes       : " << dummy_value << std::endl;
    if (getEnsOption("-deering_port", dummy_value))
      std::cout << " deering_port: " << dummy_value << std::endl;
    if (getEnsOption("-gossip_port", dummy_value))
      std::cout << " gossip_port : " << dummy_value << std::endl;
    if (getEnsOption("-gossip_hosts", dummy_value))
      std::cout << " gossip_hosts: " << dummy_value << std::endl;
    if (getEnsOption("-properties", dummy_value))
      std::cout << " properties  : " << dummy_value << std::endl;
    if (getEnsOption("-multiread", dummy_value))
      std::cout << " multiread   : " << (dummy_value.empty () ? "on" : dummy_value) << std::endl;
  }

  mMember = new NetGroup(this, ops);
  mMember->join();
  mEID =  mMember->eid().getHotEndpt().name;
  joined(mEID);

  handleNetworkSends();
  handleNetworkReceives();

#ifdef AVANGO_DEBUG
  logger.debug() << "av::NetNode::NetNode: "
            << "joined group '"
            << groupName.c_str()
            << "', my eid: "
            << netEID();
#endif

  mIdCounter = 0;

#ifdef AVANGO_DEBUG
  logger.debug() << "av::NetNode::join: was called from: " << "  pid: " << getpid();
  logger.debug() << "av::NetNode::join: completed.";
#endif

#endif // #ifdef ZMQ_DISTRIBUTION_SUPPORT
}
Beispiel #5
0
void IrcLayer::parseCmd(QString cmd, QHash<QString, QString> data)
{
//	qDebug() << "Command=" << cmd << ", cmd=" << cmd;
	if(prRegexes["privmsg"].exactMatch(cmd))
	{
		bool isAction=false;
		data["target"]=prRegexes["privmsg"].cap(1); // target
		data["text"]=prRegexes["privmsg"].cap(2); // text
		if(prRegexes["action"].exactMatch(data["text"]))
		{
			data["text"]=prRegexes["action"].cap(1);
			isAction = true;
		}
		if((!QString::compare(data["target"], target(), Qt::CaseInsensitive) && targetMode()==ChannelMode) || (!QString::compare(data["target"], nick(), Qt::CaseInsensitive) && targetMode()==PrivateMode))
		{
			isAction ? emit gotAction(data) : emit gotChannelMsg(data);
		}
		else	emit gotPrivAction(data);
	} else
	if(prRegexes["notice"].exactMatch(cmd))
	{
		data["target"]=prRegexes["notice"].cap(1); // target
		data["text"]=prRegexes["notice"].cap(2); // text
		if((!QString::compare(data["target"], nick(), Qt::CaseInsensitive)) || (!QString::compare(data["target"], target(), Qt::CaseInsensitive)))
			emit gotNotice(data);
	} else
	if(prRegexes["part"].exactMatch(cmd))
	{
		data["target"]=prRegexes["part"].cap(1); // target
		data["text"]=prRegexes["part"].cap(2); // text
		if((!QString::compare(data["target"], target(), Qt::CaseInsensitive))&&(!QString::compare(data["nick"], nick(), Qt::CaseInsensitive)))
			setJoined(0);
		if(!QString::compare(data["target"], target(), Qt::CaseInsensitive))
		{
			if(int i=m_users.indexOf(data["nick"]) != -1) m_users.removeAt(i);
			emit gotPart(data);
		}
	} else
	if(prRegexes["topic"].exactMatch(cmd))
	{
		if(!QString::compare(prRegexes["topic"].cap(1), target(), Qt::CaseInsensitive))
		{
			data["target"]=prRegexes["topic"].cap(1);
			data["text"]=prRegexes["topic"].cap(2);
			m_topic=data["text"];
			emit gotTopic(data);
		}
	}
	else
	if(prRegexes["quit"].exactMatch(cmd))
	{
		data["text"]=prRegexes["quit"].cap(1); // text
		if (m_users.contains(data["nick"]) || !QString::compare(data["nick"], nick(), Qt::CaseInsensitive))
		{
			if(int i=m_users.indexOf(data["nick"]) != -1) m_users.removeAt(i);
			emit gotQuit(data);
		}
	} else
	if(prRegexes["join"].exactMatch(cmd))
	{
		data["target"]=prRegexes["join"].cap(1); // target
		// if it's about me
		if((!QString::compare(data["nick"], nick(), Qt::CaseInsensitive)) && (!QString::compare(data["target"],target(),Qt::CaseInsensitive)) && !joined())
		{
			setTarget(data["target"]);
			setJoined(1);
		}
		if(!QString::compare(data["target"], target(), Qt::CaseInsensitive))
		{
			m_users << data["nick"];
			emit gotJoin(data);
		}
	} else
	if(prRegexes["kick"].exactMatch(cmd))
	{
		data["target"]=prRegexes["kick"].cap(1); // target
		data["subject"]=prRegexes["kick"].cap(2); // whom
		data["text"]=prRegexes["kick"].cap(3); // reason
		if(!QString::compare(data["target"], target(), Qt::CaseInsensitive))
		{
			if(int i=m_users.indexOf(data["nick"]) != -1) m_users.removeAt(i);
			emit gotKick(data);
		}
	} else
	if(prRegexes["mode"].exactMatch(cmd))
	{
		data["target"]=prRegexes["mode"].cap(1); // target
		data["text"]=prRegexes["mode"].cap(2); // modecmd
		data["subject"]=prRegexes["mode"].cap(3); // subject
		if(!QString::compare(data["target"], target(), Qt::CaseInsensitive))
			emit gotMode(data);
	} else
	if(prRegexes["nick"].exactMatch(cmd))
	{
		data["target"]=prRegexes["nick"].cap(1); // target
		qDebug() << data;
		if(m_users.contains(data["nick"]) || !QString::compare(data["target"],nick(),Qt::CaseInsensitive))
		{
			if(int i=m_users.indexOf(data["nick"]) != -1) m_users.removeAt(i);
			m_users << data["target"];
			emit gotNick(data);
		}
	}
}
Beispiel #6
0
bool CFrmGroupChat::Join(const QString &jid)
{
    if(jid.isEmpty())
        return false;

    QList<QXmppMucRoom*> rooms = CGlobal::Instance()->GetXmppClient()->m_MucManager.rooms();
    QXmppMucRoom* r;
    foreach(r, rooms)
    {
        if(r->jid() == jid)
        {
            LOG_MODEL_DEBUG("Group chat", "had joined room[%s]", qPrintable(jid));
            return false;
        }
    }

    m_pRoom = CGlobal::Instance()->GetXmppClient()->m_MucManager.addRoom(jid);
    if(m_pRoom)
    {
        bool check = connect(m_pRoom, SIGNAL(joined()),
                             SLOT(slotJoined()));
        Q_ASSERT(check);
        
        check = connect(m_pRoom, SIGNAL(left()),
                        SLOT(slotLeft()));
        Q_ASSERT(check);
        
        check = connect(m_pRoom, SIGNAL(nameChanged(QString)), 
                        SLOT(slotNameChanged(QString)));
        Q_ASSERT(check);
        
        check = connect(m_pRoom, SIGNAL(error(QXmppStanza::Error)),
                        SLOT(slotError(QXmppStanza::Error)));
        Q_ASSERT(check);
        
        check = connect(m_pRoom, SIGNAL(subjectChanged(QString)),
                        SLOT(slotSubjectChanged(QString)));
        Q_ASSERT(check);
        
        check = connect(m_pRoom, SIGNAL(messageReceived(QXmppMessage)),
                        SLOT(slotMessageReceived(QXmppMessage)));
        Q_ASSERT(check);
        
        check = connect(m_pRoom, SIGNAL(participantAdded(QString)),
                        SLOT(slotParticipantAdded(QString)));
        Q_ASSERT(check);
        
        check = connect(m_pRoom, SIGNAL(participantChanged(QString)),
                        SLOT(slotParticipantChanged(QString)));
        Q_ASSERT(check);
        
        check = connect(m_pRoom, SIGNAL(participantRemoved(QString)),
                        SLOT(slotParticipantRemoved(QString)));
        Q_ASSERT(check);
        
        check = connect(m_pRoom, SIGNAL(permissionsReceived(QList<QXmppMucItem>)),
                        SLOT(slotPermissionsReceived(QList<QXmppMucItem>)));
        Q_ASSERT(check);
 
        check = connect(m_pRoom, SIGNAL(configurationReceived(QXmppDataForm)),
                        SLOT(slotConfigurationReceived(QXmppDataForm)));
        Q_ASSERT(check);

        //设置昵称  
        m_pRoom->setNickName(CGlobal::Instance()->GetRoster()->Name());
        //加入房间  
        return m_pRoom->join();
    }
    return false;
}
Beispiel #7
0
 std::string desc() const {
   return "[" + stringify(joined(matchers_, [](const auto &matcher) {
     return matcher.desc();
   })) + "]";
 }
TEST(uri_parser, split_string3) {
  std::string joined("");
  std::list<std::string> parts = {""};
  run_split_test(joined, parts);
  run_join_test(parts, joined);
}
TEST(uri_parser, split_string2) {
  std::string joined("/a/b/c/");
  std::list<std::string> parts = {"", "a", "b", "c", ""};
  run_split_test(joined, parts);
  run_join_test(parts, joined);
}