Exemple #1
0
void fs_logger(const char *msg) {
	FsMsg *ptr = newmsg();
	ptr->msg = strdup(msg);
	if (!ptr->msg)
		errExit("strdup");
	insertmsg(ptr);
}
void msgfrm::init()
{
	lbluser->setText(username);
	
	treeindex->hideColumn(1);
	treeindex->hideColumn(2);
	treeindex->hideColumn(3);
    treeindex->header()->setClickable(FALSE);
    treeindex->header()->setResizeMode(QHeaderView::Fixed);	
	
	connect(btnclose, SIGNAL(released()), this, SLOT(close()));
	connect(treeindex, SIGNAL(itemClicked(QTreeWidgetItem* , int)), this, SLOT(loadmsg()));
	connect(btnnew, SIGNAL(released()), this, SLOT(newmsg()));
	connect(btnedit, SIGNAL(released()), this, SLOT(editmsg()));
	connect(btndelete, SIGNAL(released()), this, SLOT(deletemsg()));
	connect(btnprint, SIGNAL(released()), this, SLOT(print()));
	connect(btncomplete, SIGNAL(released()), this, SLOT(completeitems()));
	connect(treemain, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contmenu()));
	
    vars v;
    QStringList sgeo = v.loadgeo(this->objectName());
    if(sgeo.size() > 0	)
    {
        if(sgeo[0] == "1")
			this->setWindowState(this->windowState() ^ Qt::WindowMaximized);
	    this->setGeometry(sgeo[1].toInt(), sgeo[2].toInt(), sgeo[3].toInt(), sgeo[4].toInt());
   	}
   	
   	loadmsgcfg();
   	treeindex->setCurrentItem(treeindex->topLevelItem(0));
	loadmsg();
}
Exemple #3
0
void fs_logger3(const char *msg1, const char *msg2, const char *msg3) {
	FsMsg *ptr = newmsg();
	char *str;
	if (asprintf(&str, "%s %s %s", msg1, msg2, msg3) == -1)
		errExit("asprintf");
	ptr->msg = str;
	insertmsg(ptr);
}
Exemple #4
0
void fs_logger2int(const char *msg1, int d) {
	FsMsg *ptr = newmsg();
	char *str;
	if (asprintf(&str, "%s %d", msg1, d) == -1)
		errExit("asprintf");
	ptr->msg = str;
	insertmsg(ptr);
}
Exemple #5
0
void startTest(){
  int rc;
  int rankMessage = 0;
  pthread_t thread;

  rc = sem_init(&semWaitEnoughMembers, 0, 0);
  if (rc)
    ERROR_AT_LINE(rc, errno, __FILE__, __LINE__, "sem_init()");

  // We initialize the trains protocol
  if (gettimeofday(&timeTrInitBegin, NULL ) < 0)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "gettimeofday");
  rc = trInit(trainsNumber, alternateMaxWagonLen, 0, 0, callbackCircuitChange, callbackODeliver, reqOrder);
  if (rc < 0) {
    trError_at_line(rc, trErrno, __FILE__, __LINE__, "tr_init()");
    exit(EXIT_FAILURE);
  }
  if (gettimeofday(&timeTrInitEnd, NULL ) < 0)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "gettimeofday");

  // We wait until there are enough members
  do {
    rc = sem_wait(&semWaitEnoughMembers);
  } while ((rc < 0) && (errno == EINTR));
  if (rc)
    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__, "sem_wait()");

  // We start the warm-up phase
  rc = pthread_create(&thread, NULL, timeKeeper, NULL );
  if (rc < 0)
    ERROR_AT_LINE(EXIT_FAILURE, rc, __FILE__, __LINE__, "pthread_create");
  rc = pthread_detach(thread);
  if (rc < 0)
    ERROR_AT_LINE(EXIT_FAILURE, rc, __FILE__, __LINE__, "pthread_detach");

  // We check if process should be a broadcasting process
  if (rank < broadcasters) {
    // It is the case
    do {
      message *mp = newmsg(size);
      if (mp == NULL ) {
        trError_at_line(rc, trErrno, __FILE__, __LINE__, "newmsg()");
        exit(EXIT_FAILURE);
      }
      rankMessage++;
      *((int*) (mp->payload)) = rankMessage;
      if (oBroadcast(TEST_MESSAGE, mp) < 0) {
        trError_at_line(rc, trErrno, __FILE__, __LINE__, "oBroadcast()");
        exit(EXIT_FAILURE);
      }
    } while (1);
  } else {
    // Sleep enough time to be sure that this thread does not exist
    // before all other jobs are done
    sleep(warmup + measurement + cooldown + 1);
  }
}
Exemple #6
0
int main(int argc, char *argv[]){

  int i, j;
  int rc;
  int msgCounter;
  int wagonSizes[] = { 1024, 2048, 4096, 8192, 16384, 32768, 65536 };
  int payloadSizes[] = { 10, 100, 200, 500, 1000, 2000, 5000, 10000, 15000,
      20000 };
  struct timeval debut, fin, duree;
  struct rusage debutCPU, finCPU, dureeCPU;
  long elapsedTime, cpuTime;

  MUTEX_LOCK(stateMachineMutex);
  automatonState = SEVERAL;
  MUTEX_UNLOCK(stateMachineMutex);

  printf("Début de l'experience\n");

  for (i = 0; i < 7; i++) {
    for (j = 0; j < 10; j++) {
      // initialisation du wagon
      wagonMaxLen = wagonSizes[i];
      wagonToSend = newWiw();
      msgCounter = 0;

// start timers
      printf("Début du remplissage...\n");
      getrusage(RUSAGE_SELF, &debutCPU);
      gettimeofday(&debut, NULL );

// remplissage du wagon

      while (wagonToSend->p_wagon->header.len + payloadSizes[j]
          + sizeof(messageHeader) < wagonMaxLen) {
        message *mp = newmsg(payloadSizes[j]);
        if (mp == NULL ) {
          trError_at_line(rc, trErrno, __FILE__, __LINE__, "newmsg()");
          exit(EXIT_FAILURE);
        }
        if (utoBroadcast(mp) < 0) {
          trError_at_line(rc, trErrno, __FILE__, __LINE__, "utoBroadcast()");
          exit(EXIT_FAILURE);
        }
        msgCounter++;
      }

// stop timers
      gettimeofday(&fin, NULL );
      getrusage(RUSAGE_SELF, &finCPU);
      printf("Remplissage terminé\n");

// calculs
      timersub(&(finCPU.ru_utime), &(debutCPU.ru_utime), &(dureeCPU.ru_utime));
      timersub(&(finCPU.ru_stime), &(debutCPU.ru_stime), &(dureeCPU.ru_stime));
      timersub(&fin, &debut, &duree);

      elapsedTime = (1000000 * duree.tv_sec + duree.tv_usec);
      cpuTime = ((1000000
          * (dureeCPU.ru_utime.tv_sec + dureeCPU.ru_stime.tv_sec))
          + dureeCPU.ru_utime.tv_usec + dureeCPU.ru_stime.tv_usec);

      printf("********************************\n"
          "*********************************\n"
          "Messages de %d octets dans un wagon de %d octets\n", payloadSizes[j],
          wagonSizes[i]);
      printf("%d messages écrits\n", msgCounter);
      if (msgCounter > 0) {
        printf(
            "Temps absolu écoulé :          %9ld usec par message (%9ld au total)\n",
            elapsedTime / msgCounter, elapsedTime);
        printf(
            "Temps CPU (user+sys) écoulé :  %9ld usec par message (%9ld au total)\n",
            cpuTime / msgCounter, cpuTime);
      }
      printf("**************************\n");

      // free ressources
      freeWiw(wagonToSend);

    }
  }

  return EXIT_SUCCESS;
}
Exemple #7
0
void Bot::handleMessage( const Message& stanza, MessageSession* session ) 
{
	cout << "Received message (function handleMessage): " << stanza << endl;
	int inMsgType=0;
	string inMsg=stanza.body();
	if ((inMsg.length()>0) && (stanza.subtype()!=2))
	{
		if (inMsg[0]=='C')
		{
			inMsgType=1;
		}
		if (inMsg[0]=='T')
		{
			inMsgType=2;
		}
		if (inMsg[0]=='R')
		{
			inMsgType=3;
		}
	}
	if (inMsgType==1)
	{
		//openedwindows.initialize();
		//MyFunc();
		cout<<"win_num = "<<openedwindows.win_num<<endl;
		for (int i=0;i<openedwindows.win_num;i++)
		{
			Message newmsg(Message::Chat,stanza.from(),'T'+to_string(i)+": "+openedwindows.content[i]);
			cout<<"Message sent: "<<'T'+to_string(i)+": "+openedwindows.content[i]<<endl;
			client->send(newmsg);
		}
		Message msg(Message::Chat,stanza.from(),"R");
		client->send(msg);
	}
	if (inMsgType==2)
	{
		int inNum=inMsg[1]-'0';
		cout<<"Buddy is telling me something with inNum = "<<inNum<<endl;
		int buddyid=mybuddylist.inList(stanza.from().bare());
		cout<<"Which buddy is this? "<<buddyid<<endl;
		buddyswindows.addwindow_ind(inMsg,inNum);
		mybuddylist.addWindow_BuddyID(buddyid,inMsg,inNum);
	}
	if (inMsgType==3)
	{
		string uishow;
		uishow=uishow+"----------\n";
		if (mybuddylist.head!=mybuddylist.rear)
		{
			BuddyNode* p=mybuddylist.head;
			while (1)
			{
				uishow=uishow+(p->buddyJID)+'\n';
				for (int i=0;i<p->onebuddywindowlist.win_num;i++)
				{
					uishow=uishow+(p->onebuddywindowlist.content[i])+'\n';
				}
				if (!p->next)
				{
					break;
				}
				else
				{
					p=p->next;
				}
				uishow=uishow+"----------\n";
			}
		}
		uishow=uishow+"----------\n";
		const char *uishowchar = uishow.c_str();
		displaywidget->text(uishowchar);
	}
}
Exemple #8
0
void SpellManager::HandleAssembler(MsgEntry* me, Client* client)
{
    psGlyphAssembleMessage mesg;
    mesg.FromClient(me);

    csArray<psItemStats*> assembler;
    for(size_t i = 0; i < GLYPH_ASSEMBLER_SLOTS; i++)
    {
        if(mesg.glyphs[i] != 0)
        {
            psItemStats* stats = cacheManager->GetBasicItemStatsByID(mesg.glyphs[i]);
            if(stats)
                assembler.Push(stats);
        }
    }

    if(assembler.GetSize() == 0)
    {
        psserver->SendSystemError(client->GetClientNum(), "There are no glyphs in the research slots.");
        return;
    }

    if(!client->GetCharacterData()->Inventory().HasPurifiedGlyphs(assembler))
    {
        Error2("Client %i tried to research spell with glyphs he actually doesn't have", client->GetClientNum());
        SendGlyphs(NULL,client);
        return;
    }

    // Is the Glyph Sequence a Valid one?
    psSpell* spell = FindSpell(client, assembler);

    csString description("Your research didn't result in a valid spell.");
    if(spell)
    {
        // Is this spell already in our spellbook?
        psSpell* knownSpell = client->GetCharacterData()->GetSpellByName(spell->GetName());
        if(knownSpell)
        {
            if(mesg.info)
            {
                psGlyphAssembleMessage newmsginfo(client->GetClientNum(), knownSpell->GetName(), knownSpell->GetImage(), knownSpell->GetDescription());
                newmsginfo.SendMessage();
            }
            else
            {
                psserver->SendSystemInfo(client->GetClientNum(), "You know this spell already.");
            }
            return;
        }
        description = "A spell materializes for a second, but you then lose focus. Try again or increase your magic knowledge.";
    }
    if(mesg.info)
        return;

    csString name(" ");
    csString image(" ");

    const bool success = spell && psserver->GetRandom() * 100.0 < spell->ChanceOfResearchSuccess(client->GetCharacterData());
    ProgressionScript* outcome = psserver->GetProgressionManager()->FindScript(success ? "ResearchSpellSuccess" : "ResearchSpellFailure");
    if(outcome)
    {
        MathEnvironment env;
        env.Define("Actor", client->GetActor());
        outcome->Run(&env);
    }

    if(success)
    {
        description = spell->GetDescription();
        name = spell->GetName();
        image = spell->GetImage();
        SaveSpell(client, name);
    }

    // Clear the description, if this is not valid glyph sequence for our player:
    psGlyphAssembleMessage newmsg(client->GetClientNum(), name, image, description);
    newmsg.SendMessage();
}
Exemple #9
0
void IdPage::updatePage() {
    QString newmsg("finger " + idform->login_label->text().replace(QRegExp("<[^>]*>"),"").stripWhiteSpace());
    browser->clear();
    getMaster()->send(newmsg);
}
bool PendingInvite::CheckForSpam(Client *inviter, psQuestionMessage::questionType_t type)
{
    csTicks now = csGetTicks();
    csTicks then = inviter->GetLastInviteTime();

    // If the inviter has a security level then don't count it as spam
    if (inviter->GetSecurityLevel() > 0)
        return false;

    if (then && now > then + INVITESPAMBANTIME[inviter->GetSpamPoints()]*60*1000)
    {
        // If the player hasn't invited anyone in a while, expire a spamPoint
        // (LastInviteTime is set at the end of the invite, restarting this timer)
        inviter->DecrementSpamPoints();
    }

    csTicks ban = INVITESPAMBANTIME[inviter->GetSpamPoints()-1]*60*1000;

    if (inviter->GetSpamPoints() && !inviter->GetLastInviteResult() && now < then + ban)
    {
        // Warn the player, if not done already this session
        if (inviter->GetSpamPoints() >= 2 && !inviter->HasBeenWarned())
        {
            psserver->SendSystemError(inviter->GetClientNum(), "Invite spamming will be penalized.");
            inviter->SetWarned();
        }

        // Award penalties if due (one penalty per decline)
        else if (inviter->GetSpamPoints() >= 3 && !inviter->HasBeenPenalized())
        {
            inviter->SetPenalized(true);

            bool three = (inviter->GetSpamPoints() == 3);

            int fine = (three)?FIRST_SPAM_FINE:SECOND_SPAM_FINE;

            inviter->IncrementAdvisorPoints( -fine );

            psSystemMessage newmsg(inviter->GetClientNum(), MSG_INFO,
                                   "The nuisance known as %s was %s by %s!\n"
                                   "Let this be a lesson to all...",
                                   inviter->GetName(),
                                   (three)?"struck down":"banished to another realm",
                                   inviter->GetCharacterData()->GetLocation().loc_sector->god_name.GetData() );
            newmsg.Multicast(inviter->GetActor()->GetMulticastClients(), 0, PROX_LIST_ANY_RANGE);

            inviter->GetActor()->Kill(NULL);

            // A fourth offense gets a kick
            if (!three)
            {
                psserver->RemovePlayer(inviter->GetClientNum(),
                                       "You were automatically kicked from the server for invite spamming.");
                return true;
            }
        }

        // Display time remaining in the ban
        int minutes = (then-now+ban)/(60*1000);
        int seconds = (then-now+ban)/1000 - minutes*60;
        csString message;
        if (minutes)
            message.Format("You need to wait %d minutes and %d seconds before inviting again.", minutes, seconds);
        else
            message.Format("You need to wait %d seconds before inviting again.", seconds);
        psserver->SendSystemError(inviter->GetClientNum(), message.GetData() );

        return true; // This invite is spam: cancel message
    }
    else return false;
}
Exemple #11
0
int main(int argc, char *argv[]){

#ifdef INSERTION_TEST

  int rc;
  int rankMessage = 0;
  pthread_t timeKeeperThread;

  if (argc != 7) {
    printf("%s wagonMaxLen size interval participantNumber trainsNumber position\n", argv[0]);
    printf("\t- wagonMaxLen is the maximum size of wagons\n");
    printf("\t- size is the size of messages (should be more than %lu)\n", sizeof(int));
    printf("\t- interval is the time (in seconds) between each event during the experience\n");
    printf("\t- participantNumber is the number of participant during the experience\n");
    printf("\t- trainsNumber is the number of trains during the experience\n");
    printf("\t- position is the position of the participant during the experience (first one has position number 1, NOT 0)\n");
    return EXIT_FAILURE;
  }

  // We initialize the different variables which will be used
  wagonMaxLen = atoi(argv[1]);
  size = atoi(argv[2]);
  if (size < sizeof(int)){
    printf("size should be more than sizeof(int) = %zu\n", sizeof(int));
  }
  interval = atoi(argv[3]);
  participantNumber = atoi(argv[4]);
  trainsNumber = atoi(argv[5]);
  position = atoi(argv[6]);

  /* We wait a number of sec between insertion */
  int delay = (position - 1) * interval;
  if (delay > 0) {
    printf("%d sec before insertion\n", delay);
    usleep(delay * 1000000);
  }

  // We create the timeKeeper thread
  rc = pthread_create(&timeKeeperThread, NULL, timeKeeper, NULL );
  if (rc < 0)
    ERROR_AT_LINE(EXIT_FAILURE, rc, __FILE__, __LINE__, "pthread_create");
  rc = pthread_detach(timeKeeperThread);
  if (rc < 0)
    ERROR_AT_LINE(EXIT_FAILURE, rc, __FILE__, __LINE__, "pthread_detach");

  // We initialize the trains protocol
  rc = trInit(trainsNumber, wagonMaxLen, 0, 0, callbackCircuitChange, callbackODeliver, UNIFORM_TOTAL_ORDER);
  if (rc < 0) {
    trError_at_line(rc, trErrno, __FILE__, __LINE__, "trInit()");
    return EXIT_FAILURE;
  }

  // Process sends messages
  while (!terminate) {
    message *mp = newmsg(size);
    if (mp == NULL ) {
      trError_at_line(rc, trErrno, __FILE__, __LINE__, "newmsg()");
      return EXIT_FAILURE;
    }
    rankMessage++;
    *((int*) (mp->payload)) = rankMessage;
    if (oBroadcast(TEST_MESSAGE, mp) < 0) {
      trError_at_line(rc, trErrno, __FILE__, __LINE__, "oBroadcast()");
      return EXIT_FAILURE;
    }
  }

  rc = trTerminate();
  if (rc < 0) {
    trError_at_line(rc, trErrno, __FILE__, __LINE__, "trInit()");
    return EXIT_FAILURE;
  }

#else /* INSERTION_TEST */

  printf("To run insertion duration tests, you have to compile with the tests target\n");

#endif /* INSERTION_TEST */

  return EXIT_SUCCESS;
}