Exemple #1
0
int mailForecast(char* forecastName,
		 char* tag,
		 envelope* anEnvelope,
		 game* aGame,
		 int kind ) {
  int result = FALSE;
  if ( kind == CMD_CHECK_REAL ) {
    plog( LBRIEF, "mailing %s report %s to %s\n",
	  tag, forecastName, anEnvelope->to );
    fprintf( stderr, "mailing %s report %s to %s\n",
	     tag, forecastName, anEnvelope->to );
    result |= eMail( aGame, anEnvelope, forecastName );
  } else {
    /* TODO Create a file copy */
  }
  return result;
}
Exemple #2
0
int CMD_check( int argc, char **argv, int kind ) {
  int result;
  char *logName;
  envelope *anEnvelope;
  char* forecastName;
  char* returnAddress;
  char* raceName;
  char* password;
  char* final_orders;
  game* aGame;
  FILE* forecast;
  player* aPlayer;
  
  int resNumber, theTurnNumber;
  
  result = FALSE;
  
  logName = createString( "%s/log/orders_processed.txt", galaxynghome );
  openLog( logName, "a" );
  free( logName );
  
  plogtime( LBRIEF );
  if ( argc >= 2 ) {
    anEnvelope = createEnvelope(  );
    returnAddress = getReturnAddress( stdin );
    raceName = NULL;
    password = NULL;
    final_orders = NULL;
    aGame = NULL;
    resNumber = areValidOrders( stdin, &aGame, &raceName,
				&password, &final_orders, &theTurnNumber );
    plog( LBRIEF, "game %s\n", aGame->name );
    
    setHeader(anEnvelope, MAILHEADER_FROM, "%s", aGame->serverOptions.SERVERemail);
    
    setHeader( anEnvelope, MAILHEADER_TO, "%s", returnAddress );
    setHeader(anEnvelope, MAILHEADER_REPLYTO, aGame->serverOptions.ReplyTo);
    anEnvelope->from_name = strdup(aGame->serverOptions.SERVERname);
    anEnvelope->from_address = strdup(aGame->serverOptions.SERVERemail);

    if ( resNumber == RES_OK) {
      aPlayer = findElement( player, aGame->players, raceName );
      aPlayer->orders = NULL;
      
      plog( LBRIEF, "Orders from %s\n", returnAddress );
      
      /* produce an XML forecast */
      if ( aPlayer->flags & F_XMLREPORT ) {
	if ( ( theTurnNumber == LG_CURRENT_TURN ) ||
	     ( theTurnNumber == ( aGame->turn ) + 1 ) ) {
	  forecastName = createString( "%s/NG_XML_%d_forecast",
				       tempdir, getpid(  ) );
	  copyOrders( aGame, stdin, raceName, password, final_orders,
		      aGame->turn + 1 );
	  if ( ( forecast =
		 GOS_fopen( forecastName, "w" ) ) == NULL ) {
	    plog( LBRIEF, "Could not open %s for forecasting\n",
		  forecastName );
	    fprintf( stderr,
		     "Could not open %s for forecasting\n",
		     forecastName );
	    return EXIT_FAILURE;
	  }
	  
	  if (final_orders)
	    setHeader( anEnvelope, MAILHEADER_SUBJECT,
		       "[GNG] %s turn %d XML finalorders forecast for %s",
		       aGame->name, ( aGame->turn ) + 1, raceName );
	  else
	    setHeader( anEnvelope, MAILHEADER_SUBJECT,
		       "[GNG] %s turn %d XML forecast for %s",
		       aGame->name, ( aGame->turn ) + 1, raceName );
	  
	  checkOrders( aGame, raceName, forecast, F_XMLREPORT );
	  
	  fclose( forecast );
	  if ( kind == CMD_CHECK_REAL ) {
	    plog( LBRIEF, "mailing XML report %s to %s\n",
		  forecastName, anEnvelope->to );
	    fprintf( stderr, "mailing XML report %s to %s\n",
		     forecastName, anEnvelope->to );
	    result |= eMail( aGame, anEnvelope, forecastName );
	  } else {
	    char *forecastFile;
	    forecastFile =
	      createString( "%s/forecasts/%s/%s_XML",
			    galaxynghome, argv[2],
			    returnAddress );
	    GOS_copy( forecastName, forecastFile );
	  }
	  result |= GOS_delete( forecastName );
	  free( forecastName );
	}
      }
      
      /* produce a text forecast */
      if ( aPlayer->flags & F_TXTREPORT ) {
	if ( ( theTurnNumber == LG_CURRENT_TURN ) ||
	     ( theTurnNumber == ( aGame->turn ) + 1 ) ) {
	  forecastName = createString( "%s/NG_TXT_%d_forecast",
				       tempdir, getpid(  ) );
	  if ( ( forecast =
		 GOS_fopen( forecastName, "w" ) ) == NULL ) {
	    plog( LBRIEF, "Could not open %s for forecasting\n",
		  forecastName );
	    return EXIT_FAILURE;
	  }
	  
	  if ( aPlayer->orders == NULL )
	    copyOrders( aGame, stdin, raceName, password, final_orders,
			aGame->turn + 1 );
	  
	  if (final_orders)
	    setHeader( anEnvelope, MAILHEADER_SUBJECT,
		       "[GNG] %s turn %d text finalorders forecast for %s",
		       aGame->name, ( aGame->turn ) + 1, raceName );
	  else 
	    setHeader( anEnvelope, MAILHEADER_SUBJECT,
		       "[GNG] %s turn %d text forecast for %s",
		       aGame->name, ( aGame->turn ) + 1, raceName );
	  
	  checkOrders( aGame, raceName, forecast, F_TXTREPORT );
	  
	  fclose( forecast );
	  
	  if ( kind == CMD_CHECK_REAL ) {
	    plog( LBRIEF, "mailing TXT report %s to %s\n",
		  forecastName, anEnvelope->to );
	    fprintf( stderr, "mailing TXT report %s to %s\n",
		     forecastName, anEnvelope->to );
	    
	    result |= eMail( aGame, anEnvelope, forecastName );
	  } else {
	    char *forecastFile;
	    forecastFile =
	      createString( "%s/forecasts/%s/%s_TXT",
			    galaxynghome, argv[2],
			    returnAddress );
	    GOS_copy( forecastName, forecastFile );
	  }
	  result |= GOS_delete( forecastName );
	  free( forecastName );
	}
      }
      
    } else {
      forecastName = createString( "%s/NG_TXT_%d_errors",
				   tempdir, getpid(  ) );
      forecast = GOS_fopen( forecastName, "w" );
      setHeader( anEnvelope, MAILHEADER_SUBJECT,
		 "[GNG] Major Trouble" );
      plog( LBRIEF, "Major Trouble %d\n", resNumber );
      
      generateErrorMessage( resNumber, aGame, raceName,
			    theTurnNumber, forecast );
      fclose( forecast );
      
      if ( kind == CMD_CHECK_REAL ) {
	plog( LBRIEF, "mailing error report %s to %s\n", forecastName,
	      anEnvelope->to );
	
	result |= eMail( aGame, anEnvelope, forecastName );
      } else {
	char *forecastFile;
	forecastFile =
	  createString( "%s/forecasts/%s/%s_ERR",
			galaxynghome, argv[2], returnAddress );
	GOS_copy( forecastName, forecastFile );
			}
      result |= GOS_delete( forecastName );
      free( forecastName );
    }
    
    /* code here for advanced orders, we need to see how to determine this */
    if ( theTurnNumber > (aGame->turn+1)) {
      
      if ( aPlayer->orders == NULL )
	copyOrders( aGame, stdin, raceName, password, final_orders,
		    theTurnNumber );
      
      if (final_orders) {
	setHeader( anEnvelope, MAILHEADER_SUBJECT,
		   "[GNG] %s turn %d advance finalorders received for %s.",
		   aGame->name, theTurnNumber, raceName );
	plog( LBRIEF, "%s turn %d advance finalorders received for %s.\n",
	      aGame->name, theTurnNumber, raceName );
      }
      else {
	setHeader( anEnvelope, MAILHEADER_SUBJECT,
		   "[GNG] %s turn %d advance orders received for %s.",
		   aGame->name, theTurnNumber, raceName );
	plog( LBRIEF, "%s turn %d advance orders received for %s.\n",
	      aGame->name, theTurnNumber, raceName );
      }
      
      if ( aPlayer->flags & F_XMLREPORT ) {
	forecastName = createString( "%s/NG_XML_forecast", tempdir );
	forecast = GOS_fopen( forecastName, "w" );
	
	fprintf( forecast,
		 "<galaxy>\n  <variant>GalaxyNG</variant>\n" );
	fprintf( forecast, "  <version>%d.%d.%d</version>\n",
		 GNG_MAJOR, GNG_MINOR, GNG_RELEASE );
	fprintf( forecast, "  <game name=\"%s\">\n", aGame->name );
	fprintf( forecast, "    <turn num=\"%d\">\n", theTurnNumber );
	fprintf( forecast, "      <race name=\"%s\">\n", raceName );
	fprintf( forecast, "        <message>\n" );
	fprintf( forecast, "          <line num=\"1\">"
		 "O wise leader, your orders for turn %d</line>",
		 theTurnNumber );
	fprintf( forecast, "          <line num=\"2\">"
		 "have been received and stored.</line>" );
	fprintf( forecast, "        </message>\n" );
	fprintf( forecast, "      </race>\n" );
	fprintf( forecast, "    </turn>\n" );
	fprintf( forecast, "  </game>\n" );
	fprintf( forecast, "</galaxy>\n" );
	fclose( forecast );
	if ( kind == CMD_CHECK_REAL ) {
	  result |= eMail( aGame, anEnvelope, forecastName );
	} else {
	  char *forecastFile;
	  
	  forecastFile =
	    createString( "%s/forecasts/%s/%s_XML",
			  galaxynghome, argv[2], returnAddress );
	  GOS_copy( forecastName, forecastFile );
	}
	result |= GOS_delete( forecastName );
	free( forecastName );
      }
      
      if ( aPlayer->flags & F_TXTREPORT ) {
	if ( aPlayer->orders == NULL )
	  copyOrders( aGame, stdin, raceName, password, final_orders,
		      theTurnNumber );
	forecastName = createString( "%s/NG_TXT_forecast", tempdir );
	forecast = GOS_fopen( forecastName, "w" );
	fprintf( forecast, "O wise leader your orders for turn %d "
		 "have been received and stored.\n", theTurnNumber );
	fclose( forecast );
	if ( kind == CMD_CHECK_REAL ) {
	  result |= eMail( aGame, anEnvelope, forecastName );
	} else {
	  char *forecastFile;
	  
	  forecastFile =
	    createString( "%s/forecasts/%s/%s_TXT",
			  galaxynghome, argv[2], returnAddress );
	  GOS_copy( forecastName, forecastFile );
	}
	
	result |= GOS_delete( forecastName );
	free( forecastName );
      }
    }
  }
  
  if ( raceName )
    free( raceName );
  if ( password )
    free( password );
  destroyEnvelope( anEnvelope );
  result = ( result ) ? EXIT_FAILURE : EXIT_SUCCESS;
  
  return result;
}
Exemple #3
0
void *NavigatePlugin::processEvent(Event *e)
{
    if (e->type() == EventGoURL){
        string url = (const char*)(e->param());
        string proto;
        if (url.length() == 0)
            return NULL;
        int n = url.find(':');
        if (n < 0){
            proto = "http";
            url = proto + "://" + url;
        }else{
            proto = url.substr(0, n);
            if ((proto != "http") &&
                    (proto != "https") &&
                    (proto != "ftp") &&
                    (proto != "file") &&
                    (proto != "mailto"))
                return NULL;
        }
#ifdef WIN32
        ShellExecuteA(NULL, NULL, url.c_str(), NULL, NULL, SW_SHOWNORMAL);
#else
        ExecParam execParam;
        if (proto == "mailto"){
            execParam.cmd = getMailer();
            url = url.substr(proto.length() + 1);
        }else{
            execParam.cmd = getBrowser();
        }
        execParam.arg = url.c_str();
        Event eExec(EventExec, &execParam);
        eExec.process();
#endif
        return e->param();
    }
    if (e->type() == EventEncodeText){
        QString *text = (QString*)(e->param());
        *text = parseUrl(*text);
        return e->param();
    }
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->id == CmdMail){
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact == NULL)
                return NULL;
            QString mails = contact->getEMails();
            if (mails.length() == 0)
                return NULL;
            int nMails = 0;
            while (mails.length()){
                getToken(mails, ';');
                nMails++;
            }
            cmd->popup_id = (nMails <= 1) ? 0 : MenuMail;
            return e->param();
        }
        if (cmd->id == CmdMailList){
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact == NULL)
                return NULL;
            QString mails = contact->getEMails();
            if (mails.length() == 0)
                return NULL;
            int nMails = 0;
            while (mails.length()){
                getToken(mails, ';');
                nMails++;
            }
            CommandDef *cmds = new CommandDef[nMails + 1];
            unsigned n = 0;
            mails = contact->getEMails();
            while (mails.length()){
                QString mail = getToken(mails, ';', false);
                mail = getToken(mail, '/');
                cmds[n] = *cmd;
                cmds[n].id = CmdMailList + n;
                cmds[n].flags = COMMAND_DEFAULT;
                cmds[n].text_wrk = strdup(mail.utf8());
                n++;
            }
            memset(&cmds[n], 0, sizeof(CommandDef));
            cmd->param = cmds;
            cmd->flags |= COMMAND_RECURSIVE;
            return e->param();
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->id == CmdMail){
            QString mail;
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact)
                mail = contact->getEMails();
            mail = getToken(mail, ';', false);
            mail = getToken(mail, '/');
            if (mail.length()){
                string addr = "mailto:";
                addr += mail.local8Bit();
                Event eMail(EventGoURL, (void*)addr.c_str());
                eMail.process();
            }
            return e->param();
        }
        if (cmd->menu_id == MenuMail){
            unsigned n = cmd->id - CmdMailList;
            QString mails;
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact)
                mails = contact->getEMails();
            while (mails.length()){
                QString mail = getToken(mails, ';', false);
                if (n-- == 0){
                    mail = getToken(mail, '/');
                    if (mail.length()){
                        string addr = "mailto:";
                        addr += mail.local8Bit();
                        Event eMail(EventGoURL, (void*)addr.c_str());
                        eMail.process();
                    }
                    break;
                }
            }
            return e->param();
        }
    }
    return NULL;
}
Exemple #4
0
void *NavigatePlugin::processEvent(Event *e)
{
#ifdef WIN32
    if (e->type() == EventGetURL){
        string *url = (string*)(e->param());
        *url = getCurrentUrl();
        return e->param();
    }
#endif
    if (e->type() == EventGoURL){
        string url = (const char*)(e->param());
        string proto;
        if (url.length() == 0)
            return NULL;
        int n = url.find(':');
        if (n < 0){
            proto = "http";
            url = proto + "://" + url;
        }else{
            proto = url.substr(0, n);
            if ((proto != "http") &&
                    (proto != "https") &&
                    (proto != "ftp") &&
                    (proto != "file") &&
                    (proto != "mailto"))
                return NULL;
        }
#ifdef WIN32
        bool bExec = false;
        if (getNewWindow()){
            string key_name = proto;
            key_name += "\\Shell\\Open";
            RegEntry rp(HKEY_CLASSES_ROOT, key_name.c_str());
            string prg    = rp.value("command");
            string action = rp.value("ddeexec");
            string topic  = rp.value("ddeexec\\Topic");
            string server = rp.value("ddeexec\\Application");
            if (!action.empty()){
                int pos = action.find("%1");
                if (pos >= 0)
                    action = action.substr(0, pos) + url + action.substr(pos + 2);
                pos = prg.find("%1");
                if (pos >= 0)
                    prg = prg.substr(0, pos) + url + prg.substr(pos + 2);
                if (!prg.empty()){
                    STARTUPINFOA si;
                    PROCESS_INFORMATION pi;
                    ZeroMemory(&si, sizeof(si));
                    si.cb = sizeof(si);
                    ZeroMemory(&pi, sizeof(pi));
                    if (CreateProcessA(NULL, (char*)prg.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)){
                        WaitForInputIdle(pi.hProcess, INFINITE);
                        CloseHandle(pi.hProcess);
                        CloseHandle(pi.hThread);
                    }
                }
                DDEbase b;
                DDEconversation conv(server.c_str(), topic.c_str());
                if (conv.Execute(action.c_str()))
                    bExec = true;
            }
        }
        if (!bExec){
            if (proto == "file")
                url = url.substr(5);
            ShellExecuteA(NULL, NULL, url.c_str(), NULL, NULL, SW_SHOWNORMAL);
        }
#else
        ExecParam execParam;
        if (proto == "mailto"){
            execParam.cmd = getMailer();
            url = url.substr(proto.length() + 1);
        }else{
            execParam.cmd = getBrowser();
        }
        execParam.arg = url.c_str();
        Event eExec(EventExec, &execParam);
        eExec.process();
#endif
        return e->param();
    }
    if (e->type() == EventEncodeText){
        QString *text = (QString*)(e->param());
        *text = parseUrl(*text);
        return e->param();
    }
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->id == CmdMail){
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact == NULL)
                return NULL;
            QString mails = contact->getEMails();
            if (mails.length() == 0)
                return NULL;
            int nMails = 0;
            while (mails.length()){
                getToken(mails, ';');
                nMails++;
            }
            cmd->popup_id = (nMails <= 1) ? 0 : MenuMail;
            return e->param();
        }
        if (cmd->id == CmdMailList){
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact == NULL)
                return NULL;
            QString mails = contact->getEMails();
            if (mails.length() == 0)
                return NULL;
            int nMails = 0;
            while (mails.length()){
                getToken(mails, ';');
                nMails++;
            }
            CommandDef *cmds = new CommandDef[nMails + 1];
            unsigned n = 0;
            mails = contact->getEMails();
            while (mails.length()){
                QString mail = getToken(mails, ';', false);
                mail = getToken(mail, '/');
                cmds[n] = *cmd;
                cmds[n].id = CmdMailList + n;
                cmds[n].flags = COMMAND_DEFAULT;
                cmds[n].text_wrk = strdup(mail.utf8());
                n++;
            }
            memset(&cmds[n], 0, sizeof(CommandDef));
            cmd->param = cmds;
            cmd->flags |= COMMAND_RECURSIVE;
            return e->param();
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->id == CmdMail){
            QString mail;
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact)
                mail = contact->getEMails();
            mail = getToken(mail, ';', false);
            mail = getToken(mail, '/');
            if (mail.length()){
                string addr = "mailto:";
                addr += mail.local8Bit();
                Event eMail(EventGoURL, (void*)addr.c_str());
                eMail.process();
            }
            return e->param();
        }
        if (cmd->menu_id == MenuMail){
            unsigned n = cmd->id - CmdMailList;
            QString mails;
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact)
                mails = contact->getEMails();
            while (mails.length()){
                QString mail = getToken(mails, ';', false);
                if (n-- == 0){
                    mail = getToken(mail, '/');
                    if (mail.length()){
                        string addr = "mailto:";
                        addr += mail.local8Bit();
                        Event eMail(EventGoURL, (void*)addr.c_str());
                        eMail.process();
                    }
                    break;
                }
            }
            return e->param();
        }
    }
    return NULL;
}
Exemple #5
0
int CMD_ordersdue(int argc, char** argv) {
  FILE* gmnote;
  FILE* mof_fp;
  
  char* gmbody;
  
  game* aGame;
  player* aplayer;
  envelope* env;
  char* missing_orders_file = NULL;
  char* orders_dir;
  char* orders_file;
  int result;
  int msg_count = 0;
  
  result = EXIT_FAILURE;
  
  if (argc < 3) {
    usage();
  }
  else if ((aGame = loadgame(argv[2], LG_CURRENT_TURN)) != NULL) {
    loadNGConfig( aGame );
    gmbody = createString("%s/orders_due_%s", tempdir, aGame->name);
    gmnote = fopen(gmbody, "w");
    
    orders_dir = createString("%s/orders/%s/", galaxynghome, aGame->name);
    for (aplayer = aGame->players; aplayer; aplayer = aplayer->next) {
      if (aplayer->flags & F_DEAD)
	continue;
      
      orders_file = createString("%s/%s.%d", orders_dir,
				 aplayer->name, aGame->turn+1);
      if (access(orders_file, R_OK) == -1) {
	free(orders_file);
	orders_file = createString("%s/%s_final.%d", orders_dir,
				   aplayer->name, aGame->turn+1);
	if (access(orders_file, R_OK) == -1) {
	  env = createEnvelope();
	  env->to = strdup(aplayer->addr);
	  env->from = strdup(aGame->serverOptions.SERVERemail);
	  env->subject = createString("Turn %d of %s is about to run",
				      aGame->turn+1, argv[2]);
	  setHeader(env, MAILHEADER_REPLYTO,
		    aGame->serverOptions.ReplyTo);
	  env->from_name = strdup(aGame->serverOptions.SERVERname);
	  env->from_address = strdup(aGame->serverOptions.SERVERemail);

	  if (msg_count == 0) {
	    fprintf(gmnote, "The following players have not yet "
		    "submitted orders for turn %d of %s\n",
		    aGame->turn+1, aGame->name);
	    
	    missing_orders_file =
	      createString("%s/data/%s/missing_orders.%d",
			   galaxynghome, aGame->name,
			   aGame->turn+1);
	    mof_fp = fopen(missing_orders_file, "w");
	    fprintf(mof_fp,
		    "Your orders for turn %d for %s have not been "
		    "received.\nOrders are due in %s hours. "
		    "Please send them now.\n"
		    "If you don't plan on sending in orders, please submit a\n"
		    "Quit order (\"Q <racename>\") as it will stop these\n"
		    "annoying emails to you and could help speed up the game\n"
		    "for the other players. Thank you.\n",
		    aGame->turn+1, aGame->name,
		    aGame->serverOptions.due);
	    fclose(mof_fp);
	  }
	  fprintf(gmnote, "%s has not turned in orders.\n",
		  aplayer->name);
	  result |= eMail(aGame, env, missing_orders_file);
	  destroyEnvelope(env);
	  msg_count++;
	}
	free(orders_file);
      }
    }
    free(orders_dir);
  }
  else {
    fprintf(stderr, "Cannot open game %s\n", argv[2]);
  }
  
  if (missing_orders_file) {
    unlink(missing_orders_file);
    free(missing_orders_file);
  }
  
  if (msg_count) {
    fclose(gmnote);
    env = createEnvelope();
    env->to = strdup(aGame->serverOptions.GMemail);
    env->from = strdup(aGame->serverOptions.SERVERemail);
    env->subject = createString("Turn %d of %s is about to run",
				aGame->turn+1, aGame->name);
    setHeader(env, MAILHEADER_REPLYTO, aGame->serverOptions.ReplyTo);
    env->from_name = strdup(aGame->serverOptions.SERVERname);
    env->from_address = strdup(aGame->serverOptions.SERVERemail);

    result |= eMail(aGame, env, gmbody);
    
    destroyEnvelope(env);
  }
  
  return result;
}