void WhatsAppProto::onGroupCreated(const std::string &gjid, const std::string &subject) { WAChatInfo *pInfo = InitChat(gjid, subject); pInfo->tszOwner = str2t(m_szJid); // also set new subject if it's present if (!subject.empty()) onGroupNewSubject(gjid, "Server", subject, 0); }
void WhatsAppProto::onGroupInfo(const std::string &jid, const std::string &owner, const std::string &subject, const std::string &subject_owner, int time_subject, int time_created) { WAChatInfo *pInfo = SafeGetChat(jid); if (pInfo == NULL) { pInfo = InitChat(jid, subject); pInfo->bActive = true; time_subject = 0; } else { GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_CONTROL }; GCEVENT gce = { sizeof(gce), &gcd }; CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce); } if (!subject.empty()) { pInfo->tszOwner = str2t(owner); onGroupNewSubject(jid, subject_owner, subject, time_subject); } }
void WhatsAppProto::onGroupMessage(const FMessage &pMsg) { // we need to add a contact, so there's no difference at all if (pMsg.media_wa_type == FMessage::WA_TYPE_CONTACT) { onMessageForMe(pMsg); return; } WAChatInfo *pInfo = SafeGetChat(pMsg.key.remote_jid); if (pInfo == NULL) { pInfo = InitChat(pMsg.key.remote_jid, ""); pInfo->bActive = true; } std::string msg(pMsg.data); if (!pMsg.media_url.empty()) { if (!msg.empty()) msg.append("\n"); msg += pMsg.media_url; } ptrT tszText(str2t(msg)); ptrT tszUID(str2t(pMsg.remote_resource)); ptrT tszNick(GetChatUserNick(pMsg.remote_resource)); GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_MESSAGE }; GCEVENT gce = { sizeof(gce), &gcd }; gce.dwFlags = GCEF_ADDTOLOG; gce.ptszUID = tszUID; gce.ptszNick = tszNick; gce.time = pMsg.timestamp; gce.ptszText = tszText; gce.bIsMe = m_szJid == pMsg.remote_resource; CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce); if (isOnline()) m_pConnection->sendMessageReceived(pMsg); }
MainForm::MainForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainForm) { ui->setupUi(this); InitChat(ui->textBrowser); QList<int> sizes; sizes.push_back(512); sizes.push_back(256); ui->splitter->setSizes(sizes); setWindowTitle("Griefly"); left_column = ui->leftColumn->width(); right_column = ui->rightColumn->width(); ui->widget->hide(); SetMainWidget(this); connect(&Network2::GetInstance(), &Network2::connectionSuccess, this, &MainForm::startGameLoop); connect(&Network2::GetInstance(), &Network2::connectionFailed, this, &MainForm::connectionFailed); connect(this, &MainForm::autoConnect, this, &MainForm::on_lineEdit_returnPressed); connect(ui->widget, &QtOpenGL::enterPressed, this, &MainForm::setFocusOnLineEdit); connect(ui->lineEdit, &GamingLineEdit::keyToPass, ui->widget, &QtOpenGL::handlePassedKey); if (GetParamsHolder().GetParamBool("-auto_connect")) { activeTimer = new QTimer(this); activeTimer->setInterval(1 * 1000); activeTimer->setSingleShot(true); connect(activeTimer, &QTimer::timeout, this, &MainForm::helperAutoConnect); activeTimer->start(); } }
/** * OuvrirChat * @Param[in] le descripteur de fichier du minitel * @Param[in] le pipe d'ecriture, bouche vers serveur * @Param[in] le pipe de lecture, oreille sur serveur * @Param[in] le philosophe * @Return : */ int OuvrirChat (int iFdMinitel, int* fdPipeOut, int* fdPipeIn, const unsigned char* strPhilosophe) { int STOP; int k; unsigned char LigneEnCours = 1; int iLignesTexteMinitel = 0; int iLongueurPhilosophe, iLongueurPrefixe; int iNbCaracteresRecus, iCalculLignes; char bufMinitel[CRATYLE_TEXTMAX]; // char bufOreille[CRATYLE_TEXTMAX]; iLongueurPhilosophe = strlen((const char*)strPhilosophe); iLongueurPrefixe = strlen (PREFIXE_AUTEUR); STOP = FALSE; printf("ouvrir chat %i \n", iFdMinitel); AfficherAttenteCratyle(iFdMinitel); unsigned char strServeur[CRATYLE_TEXTMAX]; int iLnMessage = 0; /* save fd flags*/ int flags = fcntl(iFdMinitel, F_GETFL, 0); /* on tourne tant que l'on reste : CRATYLE_ESCAPE_SENTENCE */ while (STOP == FALSE) { /* ici traitement de l'oreille minitel */ #ifdef DEBUG_CRATYLE printf (" Attente lecture M : %i\n",iFdMinitel ); #endif /* set NONBLOCK flag afin que la lecture soit non bloquante*/ fcntl (iFdMinitel, F_SETFL, flags | O_NONBLOCK); iNbCaracteresRecus = read(iFdMinitel,bufMinitel,CRATYLE_TEXTMAX); /* restore fd flags*/ fcntl (iFdMinitel, F_SETFL, flags); if (iNbCaracteresRecus == -1 && errno == EAGAIN) { #ifdef DEBUG_CRATYLE printf ("Rien a lire sur le minitel\n"); #endif usleep(25000); } else { MINITELEnvoyerCaractere(iFdMinitel, MINITEL_CURSEUR_DESACTIVE); if(((iNbCaracteresRecus == 2) && (bufMinitel[0] != 0x20)) || ((iNbCaracteresRecus >= 3) && (bufMinitel[0] >= 0x20))) { // caractere de chaine pour printf&co bufMinitel[iNbCaracteresRecus] = '\0'; //calcul nombre de ligne du texte iLignesTexteMinitel = 1; iCalculLignes = iNbCaracteresRecus-1 + iLongueurPhilosophe; while(iCalculLignes-MINITEL_TAILLE_X >= 0) { iCalculLignes = MINITEL_TAILLE_X - iCalculLignes; printf("LOCAL:CalculLignes : %d\n", iCalculLignes); iLignesTexteMinitel++; } printf("LOCAL:LignesTexteMinitel : %d -- CalculLignes %d\n", iLignesTexteMinitel, iCalculLignes); MINITELCurseurXY(iFdMinitel, MISEENPAGE_PIED_DE_CHAT_INFO, 3); MINITELEnvoyerTexte(iFdMinitel, (const unsigned char*)"Envoi... "); /* for(k = 7; k < iNbCaracteresRecus; k++) { MINITELEnvoyerCaractere(iFdMinitel, ' '); } */ //test du bas de la piece du chat LigneEnCours++; if(LigneEnCours > MISEENPAGE_HAUTEUR_DE_CHAT) { LigneEnCours = 2; } MINITELCurseurXY(iFdMinitel, (LigneEnCours + 2), 1); //affichage du philosophe MINITELEnvoyerTexte(iFdMinitel, strPhilosophe); //MINITELEnvoyerCaractere(iFdMinitel, ' '); // On affiche le texte saisie dans la piece du chat MINITELChangerAttribut(iFdMinitel, MINITEL_CARACTERE_VERT); printf("LigneEnCours : %d\n", LigneEnCours) ; for(k = 0; k < (iNbCaracteresRecus - 1); k++) { //le texte saisie fait deux lignes, retour en haut a la fin de la premiere if(iLignesTexteMinitel >= 2 && LigneEnCours+2 >= MISEENPAGE_HAUTEUR_DE_CHAT && k+iLongueurPhilosophe == MINITEL_TAILLE_X) { LigneEnCours = 2; MINITELCurseurXY(iFdMinitel, (LigneEnCours + 2), 1); MINITELChangerAttribut(iFdMinitel, MINITEL_CARACTERE_VERT); iLignesTexteMinitel = 1; } if(bufMinitel[k] >= 0x20) { MINITELEnvoyerCaractere(iFdMinitel, bufMinitel[k]); } else { MINITELChangerAttribut(iFdMinitel, MINITEL_CARACTERE_ROUGE); MINITELEnvoyerCaractere(iFdMinitel, '!'); MINITELChangerAttribut(iFdMinitel, MINITEL_CARACTERE_VERT); } } MINITELChangerAttribut(iFdMinitel, MINITEL_CARACTERE_BLANC); //On efface la fin de la ligne for(k = 0 ; k < MINITEL_TAILLE_X+iCalculLignes ; k++) MINITELEnvoyerCaractere(iFdMinitel, ' '); // if(iNbCaracteresRecus >= 32) // { // LigneEnCours++; // } // On efface la ligne suivante pour separer le nouveau texte de l'ancien (si pas en bas) LigneEnCours += iLignesTexteMinitel-1; if(LigneEnCours+3 < MISEENPAGE_HAUTEUR_DE_CHAT) { MINITELCurseurXY(iFdMinitel, (LigneEnCours + 3), 1); for(k = 0; k < MINITEL_TAILLE_X; k++) { MINITELEnvoyerCaractere(iFdMinitel, ' '); } } AfficherAttenteCratyle(iFdMinitel); printf("bufMinitel:%s:%d\n", bufMinitel, iNbCaracteresRecus); //Test sur phrase specials et envoi dans le tuyau // todo plus propre : swicth ou variable envoi_message if (strncmp (bufMinitel, CRATYLE_CLEAR_SENTENCE, strlen(CRATYLE_CLEAR_SENTENCE)) == 0) // { //Petit clean de l'interface printf ("CRATYLE_CLEAR_SENTENCE \n"); MINITELCurseurXY(iFdMinitel, 2, 1); MINITELChangerAttribut(iFdMinitel, MINITEL_DOUBLE_LARGEUR_DOUBLE_HAUTEUR); MINITELEnvoyerTexte(iFdMinitel, (unsigned char*)CRATYLE_VERSION_TEXTE); MINITELChangerAttribut(iFdMinitel, MINITEL_TAILLE_NORMALE); MINITELCurseurXY(iFdMinitel, 3, 1); for(k = 0; k < MINITEL_TAILLE_X; k++) { MINITELEnvoyerCaractere(iFdMinitel, '_'); } AfficherAttenteCratyle(iFdMinitel); } else { if (strncmp (bufMinitel, CRATYLE_PROPRE_SENTENCE, strlen(CRATYLE_PROPRE_SENTENCE)) == 0) { //Gros nettoyage du chat InitChat(iFdMinitel); AfficherAttenteCratyle(iFdMinitel); LigneEnCours = 1; } else { write (fdPipeOut[1], bufMinitel, iNbCaracteresRecus); } } if (strncmp (bufMinitel, CRATYLE_ESCAPE_SENTENCE, strlen(CRATYLE_ESCAPE_SENTENCE)) == 0) { //Message de aurevoir printf ("CRATYLE_ESCAPE_SENTENCE \n"); AfficherAurevoirCratyle(iFdMinitel); STOP = TRUE; } memset(bufMinitel, '\0', sizeof(bufMinitel)); } } /* oreille sur le serveur */ char buffer[1]; iNbCaracteresRecus = read(fdPipeIn[0],buffer,1); if (iNbCaracteresRecus == -1 && errno == EAGAIN) { #ifdef DEBUG_CRATYLE printf ("Rien a lire sur le serveur\n"); #endif if(iLnMessage != 0) { // caractere de chaine pour printf&co strServeur[iLnMessage] = '\0'; printf("MinitelxDansRien : strServeur %s \n", strServeur); /* restore fd flags*/ fcntl (iFdMinitel, F_SETFL, flags); // if(memcmp(strServeur,CRATYLE_ESCAPE_SENTENCE,iLnMessage) == 0) // if (strcmp ((const char*)strServeur, CRATYLE_ESCAPE_SENTENCE) == 0) { //Petit message de aurevoir printf ("On me dit aurevoir dans l'oreille....\n"); AfficherAurevoirCratyle(iFdMinitel); STOP = TRUE; } else { //calcul nombre de ligne du texte iLignesTexteMinitel = 1; iCalculLignes = iLnMessage-1 + iLongueurPrefixe; while(iCalculLignes-MINITEL_TAILLE_X >= 0) { iCalculLignes = MINITEL_TAILLE_X - iCalculLignes; printf("DISTANT:CalculLignes : %d\n", iCalculLignes); iLignesTexteMinitel++; } printf("LOCAL:LignesTexteMinitel : %d -- CalculLignes %d\n", iLignesTexteMinitel, iCalculLignes); LigneEnCours++; //test du bas de la piece du chat if(LigneEnCours > MISEENPAGE_HAUTEUR_DE_CHAT) { LigneEnCours = 2; } MINITELCurseurXY(iFdMinitel, (LigneEnCours + 2), 1); MINITELEnvoyerTexte(iFdMinitel, (const unsigned char*)PREFIXE_AUTEUR); //MINITELEnvoyerCaractere(iFdMinitel, ' '); MINITELChangerAttribut(iFdMinitel, MINITEL_CARACTERE_VERT); for(k = 0; k < iLnMessage; k++) { //le texte saisie fait deux lignes, retour en haut a la fin de la premiere if(iLignesTexteMinitel >= 2 && LigneEnCours+2 >= MISEENPAGE_HAUTEUR_DE_CHAT && k+iLongueurPrefixe == MINITEL_TAILLE_X) { LigneEnCours = 2; MINITELCurseurXY(iFdMinitel, (LigneEnCours + 2), 1); MINITELChangerAttribut(iFdMinitel, MINITEL_CARACTERE_VERT); iLignesTexteMinitel = 1; } MINITELEnvoyerCaractere(iFdMinitel, strServeur[k]); } MINITELChangerAttribut(iFdMinitel, MINITEL_CARACTERE_BLANC); //On efface la fin de la ligne for(k = 0 ; k < MINITEL_TAILLE_X+iCalculLignes ; k++) MINITELEnvoyerCaractere(iFdMinitel, ' '); /* if(iLnMessage >= 36) { for(k = 0 ; k < (iLnMessage % 36) ; k++) MINITELEnvoyerCaractere(iFdMinitel, ' '); LigneEnCours++; } else { for(k = 0 ; k+iLnMessage < 36 ; k++) MINITELEnvoyerCaractere(iFdMinitel, ' '); } */ // On efface la ligne suivante pour separer le nouveau texte de l'ancien (si pas en bas) LigneEnCours += iLignesTexteMinitel-1; if(LigneEnCours+3 < MISEENPAGE_HAUTEUR_DE_CHAT) { MINITELCurseurXY(iFdMinitel, (LigneEnCours + 3), 1); for(k = 0; k < MINITEL_TAILLE_X; k++) { MINITELEnvoyerCaractere(iFdMinitel, ' '); } } /* MINITELCurseurXY(iFdMinitel, (LigneEnCours + 3), 1); for(k = 0; k < MINITEL_TAILLE_X; k++) { MINITELEnvoyerCaractere(iFdMinitel, ' '); } */ AfficherAttenteCratyle(iFdMinitel); } iLnMessage = 0; } // ici usleep(250000); } else { #ifdef CRATYLE_DEBUG_BUFFER printf("Minitelx : buffer[0] %c \n", buffer[0]); #endif strServeur[iLnMessage++] = buffer[0]; /* if(buffer[0] == '\0') { printf("Minitelx : strServeur %s \n", strServeur); fcntl (iFdMinitel, F_SETFL, flags); MINITELEnvoyerTexte(iFdMinitel, strServeur); iLnMessage = 0; } */ } } return ERROR_NO; }