Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*PALACHAT v0.1
- *
- * Developed by Wistaro
- *
- * This sofware will listen the chat of Minecraft/Paladium and send desktop notifications in case of mentions or PM.
- * More details on paladium-pvp.fr/forum
- *
- * Help and feedback on my Discord: Wistaro#9308
- */
- /*
- /* Copyright 2018 Wistaro
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.<br />
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- */
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- #include <string.h>
- #include "SDL2/SDL.h"
- #include "SDL2/SDL_mixer.h"
- using namespace std;
- static const char *NotifSong = "notif.wav";
- int main(int argc, char **argv) {
- /*Window initialisation*/
- printf("~ PalaChat v0.1 ~ \n Made by Wistaro\n\n");
- SDL_Window* fenetre(0);
- // Initialisation de la SDL
- printf("Initializing files...\n");
- if(SDL_Init(SDL_INIT_VIDEO) < 0)
- {
- cout << "Failed to load SDL : " << SDL_GetError() << endl << endl;
- SDL_Quit();
- system("pause");
- return -1;
- }
- /*Mixer init*/
- int result = 0;
- int flags = MIX_INIT_OGG;
- if (SDL_Init(SDL_INIT_AUDIO) < 0) {
- printf("Failed to init SDL\n \n");
- system("pause");
- return 0;
- }
- Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 640);
- Mix_Music *music = Mix_LoadMUS(NotifSong);
- /*Loading logfile*/
- int nbLignes, cpt, i, j, k;
- int notif = 0;
- i = 0;
- size_t pos_chat;
- string ligne, lastligne,lastlignebuff,chatOnly,psdMp, mpMsg, logPath, ligneBuff, psdUser;
- string detectIsMe;
- string wordDetected, mpMessageNotif;
- string lowerCaseString;
- const char * lastligneConst;
- char flagNotif = 0;
- psdMp = "x";
- /*Import datas from config file*/
- ifstream configfile("config.txt" , ios::in);
- if(configfile.good()){
- while(getline( configfile, ligneBuff)){
- i++;
- if(i == 1) logPath = ligneBuff;
- if(i == 2) psdUser = ligneBuff;
- if(i == 3) wordDetected = ligneBuff;
- }
- }else{
- printf("Impossible de lire le fichier de configuration de Palachat!\n \n");
- system("pause");
- return 0;
- }
- /*Avoid non-detection issues*/
- transform(psdUser .begin(), psdUser .end(), psdUser .begin(), ::tolower);
- transform(wordDetected .begin(), wordDetected .end(), wordDetected .begin(), ::tolower);
- cout << "Loading data from " << logPath << endl;
- cout << "Detected username: " << psdUser << endl;
- cout << "Additionnal word detected: " << wordDetected << endl << endl;
- while(1){
- nbLignes = 0;
- cpt = 0;
- ifstream logfile(logPath+"/latest.log" , ios::in);
- if(!logfile.good()){
- printf("\nImpossible de lire le fichier de log de Paladium!\n \n");
- system("pause");
- return 0;
- }
- while(std::getline( logfile, ligne))
- {
- nbLignes++;
- }
- logfile.clear();
- logfile.seekg(0, ios::beg);
- while(logfile)
- {
- getline(logfile, ligne);
- cpt++;
- if (cpt == nbLignes)
- lastligne = ligne;
- }
- lastligneConst = lastligne.c_str();
- if(lastlignebuff != lastligne && strstr( lastligneConst, "[CHAT]") != NULL){
- pos_chat = lastligne.find('CHAT')+3;
- chatOnly = lastligne.substr (pos_chat);
- if(strstr( chatOnly.c_str() , "-> moi") != NULL){
- notif = 1; //mp notif
- psdMp = chatOnly.substr(1, (chatOnly.find("->")-2));
- mpMsg = chatOnly.substr(chatOnly.find("-> moi")+8);
- cout << "MP de " << psdMp << ">> " << mpMsg << endl;
- }else if(strstr( chatOnly.c_str() , ">") != NULL){
- cout << "CHAT >> "<< chatOnly << endl;
- }else {
- cout << "LOG >> "<< chatOnly << endl;
- }
- lowerCaseString = lastligne;
- transform(lowerCaseString.begin(), lowerCaseString.end(), lowerCaseString.begin(), ::tolower);
- if(strstr(lowerCaseString.c_str(), wordDetected.c_str()) != NULL || strstr(lowerCaseString.c_str(),psdUser.c_str()) != NULL){
- //if I'm talking, don't send me notifications :p
- detectIsMe = lastligne.substr(1, lastligne.find(">"));
- transform(detectIsMe.begin(), detectIsMe.end(), detectIsMe.begin(), ::tolower);
- if(strstr( detectIsMe.c_str() ,psdUser.c_str() ) != NULL){
- notif = 0;
- }else{
- notif =1;
- }
- }
- }
- lastlignebuff = lastligne;
- if(notif == 1 && psdMp != "x"){
- //notification de MP
- mpMessageNotif = "Vous avez recu un message privé de "+psdMp+" sur Paladium!\n"+mpMsg;
- Mix_PlayMusic(music, 1);
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION,
- "Message privé reçu",
- mpMessageNotif.c_str(),
- fenetre);
- notif = 0;
- psdMp = "x";
- }else if(notif == 1){
- //Autre notification
- Mix_PlayMusic(music, 1);
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION,
- "Notification",
- "Vous avez recu une notification sur Paladium!.",
- fenetre);
- notif = 0;
- }
- }
- /*Exiting programm*/
- while (!SDL_QuitRequested()) {
- SDL_Delay(250);
- }
- Mix_FreeMusic(music);
- SDL_Quit();
- return 0;
- }
Add Comment
Please, Sign In to add comment