コード例 #1
0
ファイル: christmas_sock.c プロジェクト: Zhanyin/taomee
//2011圣诞活动
int hang_christmas_sock_cmd(sprite_t* p, uint8_t* body, int len)
{
	CHECK_BODY_LEN(len, 4);
	uint32_t friend_id = 0;
	int i = 0;
	UNPKG_UINT32(body, friend_id, i);
	CHECK_VALID_ID(friend_id);

#ifndef TW_VER
	if (get_today() >= 20111225)
#else
	if (get_today() > 20111231)
#endif
	{
		return send_to_self_error(p, p->waitcmd, -ERR_invalid_session, 1);
	}

	if (friend_id == p->id) {
		return send_to_self_error(p, p->waitcmd, -ERR_invalid_session, 1);
	}

	*(uint32_t*)p->session = friend_id;
	//去好友家检查自己送了几次,并查看好友收到多少袜子
	return send_request_to_db(SVR_PROTO_CHECK_CHRISTMAS_SOCK_CNT, p, sizeof(p->id), &(p->id), friend_id);
}
コード例 #2
0
ファイル: xhx_server.c プロジェクト: Zhanyin/taomee
/*
 * @brief 小花仙增加物品 4112
 */
int xhx_add_items_cmd(sprite_t* p, const uint8_t* body, int len)
{
	uint32_t value;
	int i = 0;
	UNPKG_UINT32(body, value, i);
	*(uint32_t*)(p->session) = value;
	uint32_t day_limit;
#ifndef TW_VER
	day_limit = 20111114;
#else
	day_limit = 20111121;
#endif
	if (get_today() >= day_limit || !(get_now_tm()->tm_hour >= 19 && get_now_tm()->tm_hour < 21)) {
		DEBUG_LOG("xhx can not add item: id[%u] count[%u]", p->id, value);
		return send_to_self_error(p, p->waitcmd, -ERR_invalid_session, 1);
	}
	if (value == 1) {	//value=1时,通知小花仙获得拉姆花种子,1天只能1次
		return db_set_sth_done(p, 50006, 1, p->id);
	} else if (value == 2) {	//花宝猪吃小仙果
		uint32_t db_buf[]={1, 0, 0, 0, 99, 1351127, 1};
		send_request_to_db(SVR_PROTO_EXCHG_ITEM, NULL, sizeof(db_buf), db_buf, p->id);
		
		return xhx_add_one_item(p, 0);
	} else if (value == 3) {	//获得小花仙神奇水珠,1天只能1次
		return db_set_sth_done(p, 50007, 1, p->id);
	}

	return send_to_self_error(p, p->waitcmd, ERR_invalid_item_id, 1);
}
コード例 #3
0
ファイル: skipwin.c プロジェクト: SeaPea/GentleWake
static void update_date_display() {
  time_t skip_utc = s_skip_until - get_UTC_offset(NULL);
  struct tm *t = localtime(&skip_utc);
  strftime(s_date, LEN_DATE, "%a, %b %d", t);
  s_show_noskip = (s_skip_until <= get_today());
  layer_mark_dirty(s_info_layer);
}
コード例 #4
0
ファイル: xhx_server.c プロジェクト: Zhanyin/taomee
/*
 * @brief 查询用户是否来自小花仙 4111
 */
int xhx_check_user_cmd(sprite_t* p, const uint8_t* body, int len)
{
	CHECK_BODY_LEN(len, 0);

	uint32_t day_limit;
#ifndef TW_VER
	day_limit = 20111114;
#else
	day_limit = 20111121;
#endif
	if (get_today() >= day_limit || !(get_now_tm()->tm_hour >= 19 && get_now_tm()->tm_hour < 21)) {
		int l = sizeof(protocol_t);
		PKG_UINT32(msg, 0, l);
		init_proto_head(msg, p->waitcmd, l);
		return send_to_self(p, msg, l, 1);
	}

	uint8_t db_buf[1024] = {0};
	int l = 0;
	PKG_H_UINT32(db_buf, 99, l);
	PKG_H_UINT32(db_buf, 1351128, l);
	PKG_H_UINT32(db_buf, 1351129, l);
	PKG_H_UINT8(db_buf, 0, l);
	return send_request_to_db(SVR_PROTO_CHK_ITEM, p, l, db_buf, p->id);
}
コード例 #5
0
ファイル: main.c プロジェクト: klassenpeter/pebble_tomato
static void save_persistent_data() {
    uint32_t today = get_today();
    persist_write_int(DATE_SAVE, today);
    persist_write_int(CANCELED_COUNT, rounds_canceled);
    persist_write_int(COMPLETED_COUNT, rounds_done);
    
}
コード例 #6
0
ファイル: skipwin.c プロジェクト: lenkawamoto/GentleWake
static void update_date_display() {
  struct tm *t;
  time_t skip_utc = s_skip_until - get_UTC_offset(NULL);
  t = localtime(&skip_utc);
  strftime(s_date, sizeof(s_date), "%a, %b %d", t);
  text_layer_set_text(s_textlayer_date, s_date);
  layer_set_hidden(text_layer_get_layer(s_textlayer_status), s_skip_until > get_today());
}
コード例 #7
0
ファイル: main.c プロジェクト: klassenpeter/pebble_tomato
static void load_persistent_data(){
    uint32_t data_from = persist_exists(DATE_SAVE) ? (uint32_t)persist_read_int(DATE_SAVE) : get_today();
    
    if (data_from == get_today()){
        rounds_done = persist_exists(COMPLETED_COUNT) ? persist_read_int(COMPLETED_COUNT) : 0;
        rounds_canceled = persist_exists(CANCELED_COUNT) ? persist_read_int(CANCELED_COUNT) : 0;
    }
}
コード例 #8
0
ファイル: skipwin.c プロジェクト: lenkawamoto/GentleWake
static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
  time_t today = get_today();
  
  if (day_diff(today, s_skip_until) >= 28)
    // If the skip date is already set to 4 weeks from today, wrap around to today
    s_skip_until = today;
  else
    // Set the date to the next date
    s_skip_until += (24 * 60 * 60);
  
  update_date_display();
}
コード例 #9
0
ファイル: skipwin.c プロジェクト: lenkawamoto/GentleWake
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
  time_t today = get_today();
  
  if (s_skip_until <= today)
      // If the skip date was already set to today, wrap around to 4 weeks from now
      s_skip_until = today + (28 * 24 * 60 * 60);
  else
      // Set the date to the previous date
      s_skip_until -= (24 * 60 * 60);
  
  update_date_display();
}
コード例 #10
0
ファイル: jnl_feed_aux.c プロジェクト: huilang22/Projects
/***********************************************************************
 *
 * Name :       process_run_date()
 *
 * Description: Retrieves the system date and time and formats
 *              it to the user specification which will be inserted
 *              later into the feed record.
 *
 * Inputs  :    None
 * Outputs :    None
 * Returns :    None 
 *
 **********************************************************************/
void
process_run_date(tiny size,
                 tiny trim,
                 tiny format,
                 char *value)
{
  struct tm     *s_loctime;


  s_loctime = get_today();

  process_jnl_field_date(NULL, s_loctime, format, value);
  process_jnl_field_trim(trim, value, size);
  return;
}
コード例 #11
0
ファイル: score.c プロジェクト: OS2World/APP-INTERNET-Slrn
int slrn_read_score_file (char *file)
{
   Score_Context_Type sc;
   int status;

   if (Group_Score_Root != NULL)
     {
	free_group_scores ();
     }
   free_group_chain ();
   while (Scorefile_Names != NULL)
     {
	Scorefile_Name_Type *next = Scorefile_Names->next;
	slrn_free ((char *) Scorefile_Names->filename);
	slrn_free ((char *) Scorefile_Names);
	Scorefile_Names = next;
     }

   sc.today = get_today ();
   sc.score = 0;
   sc.start_new_group = 1;
   sc.gnt_not_flag = 0;
   sc.start_new_score = 0;
   sc.score_has_expired = 0;
   sc.pscore_flags = 0;
   sc.pst = NULL;
   sc.group[0] = '*';
   sc.group[1] = 0;

   (void) SLprep_open_prep (&sc.pt);
   status = read_score_file_internal (file, &sc);
   SLprep_close_prep (&sc.pt);
   
   if (status == -1)
     Slrn_Apply_Score = 0;
   else
     Slrn_Apply_Score = 1;

   return status;
}
コード例 #12
0
ファイル: xhx_server.c プロジェクト: Zhanyin/taomee
/*
 * @brief 小花仙联运活动接取 4110
 */
int xhx_get_tast_cmd(sprite_t* p, const uint8_t* body, int len)
{
	CHECK_BODY_LEN(len, 4);
	uint32_t flag = 0;
	int i = 0;
	UNPKG_UINT32(body, flag, i);
	*(uint32_t*)p->session = flag;
	if (flag > 2 ) {
		return send_to_self_error(p, p->waitcmd, -ERR_invalid_session, 1);
	}
	uint32_t day_limit;
#ifndef TW_VER
	day_limit = 20111114;
#else
	day_limit = 20111121;
#endif
	if (flag == 2 && (get_today() >= day_limit)) {
		return send_to_self_error(p, p->waitcmd, -ERR_invalid_session, 1);
	}
	
	return send_request_to_db(SVR_PROTO_XHX_GET_TASK, p, 4, &flag, p->id);
}
コード例 #13
0
ファイル: validate.cpp プロジェクト: gsteelman/mst
///////////////////////////////////////////////////////////////////////////////
/// @fn bool validateLeave( string startDate, string endDate, rulesSystem &rules )
/// @brief checks a leave range of dates against the rules in the passed rules
///   and then returns whether or not the range follows the rules
/// @param string startDate is the start date for the requested vacation 
/// @param string endDate is the end date for the requested vacation
/// @param rulesSystem &rules is rules system to check the dates against for
///   verification of leave time
/// @return false if the request is denied for any reason
/// @return true if the request is accepted
/// @note the parameters startDate and endDate must be in "MM/DD" where MM is 
///   the month number and DD is the day number
///////////////////////////////////////////////////////////////////////////////
bool validate::validateLeave( string uID, string request ) {

  vector<string> request_vec = parse_request(request);

  string startDate    = request_vec[1];
  string endDate      = request_vec[2];
  string requestType  = request_vec[3];

  //First make sure both the start and end dates are valid dates
  if ( validateDate( startDate ) == false ) {
    
    return false;
  
  }

  if ( validateDate( endDate ) == false ) {
    
    return false;
  
  }

  // Number of days requesting off.
  int request_days = num_days( startDate, endDate );
  int days_to_start = num_days( get_today(), startDate ) - 1;

  // TEST 0
  // If they don't have enough time available in the leave type
  // of their request, they fail.
  if (requestType == SICK_LEAVE) {

    int time_available = str_to_int( DATABASE.get_entry(uID, SICK_LEAVE_BALANCE) );

    // Not enough time.
    if (time_available < request_days) {

      return false;

    }

  } else if (requestType == VACATION_LEAVE) {

    int time_available = str_to_int( DATABASE.get_entry(uID, VACATION_LEAVE_BALANCE) );

    // Not enough time.
    if (time_available < request_days) {

      return false;

    }

  } else {

    // Not a valid leave type.
    return false;

  }

  //TEST 1
  //If the number of days notice is fewer than the rules allow, fail
  //leave time validation
  if ( ( days_to_start ) < m_rules->getDaysNotice() ) {
    
    return false;
  
  }

  //TEST 2
  //Now we're going to make sure we're not requesting too much time off in a row
  //This will just check the size of the leaveRequestDates against the rule for
  //amount of time off in a row
  if ( request_days > m_rules->getDaysConsecutive() ) {
    
    return false;
  
  }

  //TEST 3
  //And now we need to make sure that we're not going to leave the company
  //Trying to run itself with no employees left
  //This I'm not sure how we're going to implement yet, but I'll figure it out
  //I think I've got this part figured out. There's a field in the scope uID
  //in the database that is called ON_VACATION that will store a 1 or a 0
  //to represent if that user is on vacation. This item will be edited somewhere
  //that isn't here.
  //We'll just get all the entries in all scopes in that field and count the
  //number of 1s >_>

  //THIS NEEDS TO BE CHANGED TO JUST CHECK THE CURRENT DATE VS THE DATES OF
  //PEOPLE WHO ARE ON VACATION, lolk
  
  double usersOnVacation = 0;

  vector<string> users = DATABASE.get_scopes();
  vector<string> leaveRequest;

  //We'll run through each user
  for ( int x = 0; x < users.size(); x++ ) {
   
    //Gets all of the approved requests for the user
    leaveRequest = DATABASE.get_entries( users.at( x ), APPROVED_REQUESTS );

    // Hax the vector from the request list into the last
    // approved request in the list.
    leaveRequest = parse_request(leaveRequest.back());

    if (leaveRequest[0] != DEFAULT_ENTRY) {

      // Pull out the start/end of the most recent approved request.
      string request_start = leaveRequest[1];
      string request_end = leaveRequest[2];

      // Calculate the length of the request.
      int request_length = num_days(request_start, request_end);

      // And the number of days from the start of the request to today.
      int start_to_today = num_days(request_start, get_today());

      // If today is between the start and end of the request...
      if (start_to_today > 0 && start_to_today <= request_length) {

        // They're on vacation.
        usersOnVacation++;

      }

    } /* if (leave_request[0] != DEFAULT_ENTRY) */
   
  }
  
  if ( usersOnVacation >= m_rules->getMaxPeopleOff() ) {
  
    return false;
  
  }

  // Vector to store the blackout days.
  vector<string> blackout = m_rules->getBlackoutList();
  
  //TEST 4
  //And finally now we're going to make sure that we're not trying to leave on 
  //A blackout date. This should run through all of the blackoutlist for each
  //date in the request list, not efficient, but the easiest way
  for ( int j = 0; j < blackout.size(); j++ ) {

    int days_to_blackout = num_days(startDate, blackout[j]);

    //And if the date in the request list matches any in the blackout list
    //We return false because employees can't take a vacation on a 
    //blackout date
    if ( days_to_blackout > 0 &&  // A day in the past doesn't matter to us.
         days_to_blackout <= request_days ) {

      return false;

    }
    
  } //end for loop

  return true;

}
コード例 #14
0
ファイル: validate.cpp プロジェクト: gsteelman/mst
///////////////////////////////////////////////////////////////////////////////
/// @fn bool managerApproval( string uID, bool approved )
/// @brief approves or disapproves the user with uID based on the approved bool
/// @param string uID is the user ID to approve or disapprove
/// @param bool approved
///   true = user approved
///   false = user denied
/// @pre the user uID must have made a request 
/// @return true if the approval process went alright
/// @return false if the user had not previously made a request
///////////////////////////////////////////////////////////////////////////////
bool validate::managerApproval( string uID, bool approved ) {

  //Storage of requests, one at a time
  vector<string> vacationRequest;

  string approvedRequest = "";
  string deniedRequest = "";

  vector<string> users;

  // If uID is blank, get all users. Otherwise, just the one passed in.
  if (uID == "") {

    users = DATABASE.get_scopes();

  } else {

    users.push_back( uID );

  }
  
  //This will approve requests.
  if ( approved ) {
  
    //We'll run through each user
    for ( int x = 0; x < users.size(); x++ ) {
      
      //get the entries for the current username and put them into a temp vector
      vacationRequest = DATABASE.get_entries( users.at( x ), PENDING_APPROVAL );
      
      if ( vacationRequest.at( 0 ) == DEFAULT_ENTRY ) {
      
        //Do nothing because this employee has no pending requests
      
      } else {
      
        //Since each user may have more than 1 request at a time, we're going 
        //to run through each request the current iteration's user has
        while ( vacationRequest.empty() == false ) {

          string request = vacationRequest[0];

          vector<string> request_vec = parse_request(request);

          // Rules are overridden if validation comes back false.
          bool rules_overridden = !validateLeave(uID, request);
        
          //This gets us a string in the form of RR/RR|SS/SS|EE/EE|T|AA/AA
          approvedRequest = request + "|" + get_today();

          // If the manager overrides the rules, it needs to be logged.
          if (rules_overridden) {

            approvedRequest += "|" + RULES_OVERRIDDEN;

          }

          //Get the number of days the request is
          int vacaLen = num_days( request_vec[1], request_vec[2] );
          
          //Add the current pending request to the approved requests field
          DATABASE.add_entry( users.at( x ), APPROVED_REQUESTS, approvedRequest );

          //Now update the user's vacation balance with vacaLen
          if ( request_vec[3] == SICK_LEAVE ) {

            //This means it is a sick leave request
            //Multiply the vacation length by -1 to make it a subtraction
            addSickLeave( users.at( x ), ( vacaLen * -1 ) );

          } else if ( request_vec[3] == VACATION_LEAVE ) {

            //This means it is a vacation leave request
            //Multiply the vacation length by -1 to make it a subtraction
            addVacationLeave( users.at( x ), vacaLen * -1 );

          }

          //Now remove the request from the pending requests section
          DATABASE.delete_entry(users.at( x ), PENDING_APPROVAL );
          
          //And now clear the request from the temp vector
          vacationRequest.erase( vacationRequest.begin() );
        
        }//end while
      
      }//end else
      
    }//end for
  
  // Deny requests.
  } else if ( !approved ) {
  
    //We'll run through each user
    for ( int x = 0; x < users.size(); x++ ) {
      
      //get the entries for the current username and put them into a temp vector
      vacationRequest = DATABASE.get_entries( users.at( x ), PENDING_APPROVAL );
      
      if ( vacationRequest.at( 0 ) == DEFAULT_ENTRY ) {
      
        //Do nothing because this employee has no pending requests
      
      } else {
      
        //Since each user may have more than 1 request at a time, we're going 
        //to run through each request the current iteration's user has
        while ( vacationRequest.empty() == false ) {
        
          //This gets us a string in the form of RR/RR|SS/SS|EE/EE|T|DD/DD
          approvedRequest = vacationRequest.at( 0 ) + "|" + get_today();
          
          //Add the current pending request to the disapproved requests field
          DATABASE.add_entry( users.at( x ), DISAPPROVED_REQUESTS, approvedRequest );

          //Now remove the request from the pending requests section
          DATABASE.delete_entry( users.at( x ), PENDING_APPROVAL );
          
          //And now clear the request from the temp vector
          vacationRequest.erase( vacationRequest.begin() );
        
        }//end while
      
      }//end else
      
    }//end for
  
  }//end else if

  // SAVE CHANGES.
  DATABASE.save_file();

  return true;

}//end managerApproval()
コード例 #15
0
ファイル: skipwin.c プロジェクト: lenkawamoto/GentleWake
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  // Close this screen
  hide_skipwin();
  // Pass skip date back (skip date of today or earlier disables skip)
  s_set_event((s_skip_until <= get_today()) ? 0 : s_skip_until);
}
コード例 #16
0
ファイル: skipwin.c プロジェクト: lenkawamoto/GentleWake
  window_single_repeating_click_subscribe(BUTTON_ID_DOWN, 50, down_click_handler);
}

void show_skipwin(time_t skip_until, SkipSetCallBack set_event) {
  initialise_ui();
  window_set_window_handlers(s_window, (WindowHandlers) {
    .unload = handle_window_unload,
  });
  
  // Store pointer to callback function
  s_set_event = set_event;
  
  // Trap action bar clicks
  window_set_click_config_provider(s_window, click_config_provider);
  
  time_t today = get_today();
  
  // Validate and store current skip date
  if (skip_until == 0)
    s_skip_until = today;
  else if (skip_until < today)
    s_skip_until = today;
  else
    s_skip_until = strip_time(skip_until);
  
  update_date_display();
  
  window_stack_push(s_window, true);
}

void hide_skipwin(void) {
コード例 #17
0
int main(int argc,char **argv)
{
    int n;
    int curr_arg;
    bool bDebug;
    bool bRuntot;
    int retval;
    time_t today;
    time_t date1;
    time_t date2;
    char *cpt;
    int weekday_counts[NUM_WEEKDAYS];
    int weekday;
    int total_days;

    if ((argc < 3) || (argc > 5)) {
        printf(usage);
        return 1;
    }

    bDebug = false;
    bRuntot= false;

    for (curr_arg = 1; curr_arg < argc; curr_arg++) {
        if (!strcmp(argv[curr_arg],"-debug"))
            bDebug = true;
        else if (!strcmp(argv[curr_arg],"-runtot"))
            bRuntot = true;
        else
            break;
    }

    if (argc - curr_arg != 2) {
        printf(usage);
        return 2;
    }

    retval = get_today(&today);

    if (retval) {
        printf("get_today() failed: %d\n",retval);
        return 3;
    }

    if (!strcmp(argv[curr_arg],"today"))
        date1 = today;
    else
        date1 = cvt_date(argv[curr_arg]);

    if (date1 == -1L) {
        printf("%s: invalid date\n",argv[curr_arg]);
        return 4;
    }

    if (!strcmp(argv[curr_arg+1],"today"))
        date2 = today;
    else
        date2 = cvt_date(argv[curr_arg+1]);

    if (date2 == -1L) {
        printf("%s: invalid date\n",argv[curr_arg+1]);
        return 5;
    }

    if (bDebug) {
        cpt = ctime(&date1);
        cpt[strlen(cpt)-1] = 0;
        printf("date1: %s\n",cpt);
        cpt = ctime(&date2);
        cpt[strlen(cpt)-1] = 0;
        printf("date2: %s\n",cpt);
    }

    if (date1 >= date2) {
        printf("date1 must be less than date2\n");
        return 6;
    }

    for (n = 0; n < NUM_WEEKDAYS; n++)
        weekday_counts[n] = 0;

    for ( ; date1 < date2; date1 += SECS_PER_DAY) {
        cpt = ctime(&date1);

        retval = get_weekday(&cpt[0],&weekday);

        if (retval) {
            printf("get_weekday_failed: %d\n",retval);
            return 7;
        }

        weekday_counts[weekday]++;
    }

    total_days = 0;

    for (n = 0; n < NUM_WEEKDAYS; n++) {
        total_days += weekday_counts[n];

        if (!bRuntot)
            printf("%7d %s\n",weekday_counts[n],weekdays[n]);
        else
            printf("%7d %s %7d\n",weekday_counts[n],weekdays[n],total_days);
    }

    if (!bRuntot)
        printf("\n%7d\n",total_days);

    return 0;
}