//魔弹传递
void BackgroundEngine::missilePass(bool rightOrder,int dst,int src,bool* passed,int missilePoint)
{
    int i;
    PlayerEntity* srcPlayer = getPlayerByID(src);
    PlayerEntity* dstPlayer = getPlayerByID(dst);
    PlayerEntity* next = dstPlayer;
    passed[srcPlayer->getSeatNum()] = true;

    for(i = 0;i < this->playerList.size();i++)
    {
        if(!*(passed+i) && (i != dstPlayer->getSeatNum()))
            break;
    }
    if(i == this->playerList.size())
    {
        for(int j = 0;j < this->playerList.size();j++)
            *(passed + j) = false;
    }

    if(rightOrder)
    {   
        while((next->getColor() == dstPlayer->getColor()) || *(passed + next->getSeatNum()))
            next = next->getNext();

        coder.askForMissile(dst,src,missilePoint,next->getID());
    }
    else
    {
        while((next->getColor() == dstPlayer->getColor()) || passed[next->getSeatNum()])
            next = this->getFront(next);

        coder.askForMissile(dst,src,missilePoint,next->getID());
    }
}
//中毒处理
void BackgroundEngine::posionProcess(PlayerEntity* player,CardEntity* card)
{
    Harm harm;
    harm.harmPoint = 1;
    harm.type = MAGIC;
    //coder.magicHurtNotice(player->getID(),1,card->getSrcUser(),"中毒");
    this->timeLine3(harm,getPlayerByID(card->getSrcUser()),player,"中毒");

}
Exemple #3
0
void processLogin(struct sock_ev* ev)
{
    char usr[64];
    memset(usr, 0, 64);
    NET_PACKET_POP_STRING(ev->packet, usr, 64);
    printf("buff=");
    printf(usr);
    updatePlayerSockid(usr, ev->sockid);
    updatePlayerSchedule(usr);
    //int ret = send(ev->sockid, usr, strlen(usr), 0);
    AllPlayer* player = getPlayerByID(usr);
    if (player != 0)
    {
        NET_PACKET_BEGIN(packet, DEFAULT_SIZE);
        NET_PACKET_PUSH_UINT16(packet, MSG_SC_LOGIN_RES);
        NET_PACKET_PUSH_UINT16(packet, 0);
        NET_PACKET_PUSH_UINT16(packet, 0);
        NET_PACKET_PUSH_STRING(packet, "Login success!");
        NET_PACKET_PUSH_STRING(packet, player->usr);
        NET_PACKET_PUSH_STRING(packet, player->nickname);
        NET_PACKET_PUSH_STRING(packet, player->birthday);
        NET_PACKET_UPDATE_LENGTH(packet);
        int ret = send(ev->sockid, packet->m_buffer, packet->m_writePos, 0);
        NET_PACKET_END(packet);
        if (ret < 0)
        {
            printf("[WorldPacket]Error: gmsvproto_sv.c:processLogin()send err!\n");
        }
    }
    else
    {
        //错误处理  没有此ID的角色
        NET_PACKET_BEGIN(packet, DEFAULT_SIZE);
        NET_PACKET_PUSH_UINT16(packet, MSG_SC_LOGIN_RES);
        NET_PACKET_PUSH_UINT16(packet, 0);
        NET_PACKET_PUSH_UINT16(packet, 1);
        NET_PACKET_PUSH_STRING(packet, "Login failed!");
        NET_PACKET_UPDATE_LENGTH(packet);
        int ret = send(ev->sockid, packet->m_buffer, packet->m_writePos, 0);
        NET_PACKET_END(packet);
        if (ret < 0)
        {
            printf("[WorldPacket]Error: gmsvproto_sv.c:processLogin()send err!\n");
        }
    }
    //测试代码
    db_updatePlayerHistory(usr);
}
void BackgroundEngine::timeLine2(CardEntity* harmCard,PlayerEntity* src,PlayerEntity* dst,bool isActiveAttack,int attackType,Harm harm)
{
    coder.askForReBat(attackType,harmCard->getID(),dst->getID(),src->getID());
    //当攻击是必中时,不接受客户端回应
    //emit askForReply(dst->getHandCards(),element,dst->getID());
    BatInfor temp;
    bool checkShield=true;
    if(attackType != NOMISS)
    {
        //战斗信息存储在temp中。若应战,则保存着应战的牌;若抵挡,则保存着圣光或圣盾
        temp = messageBuffer::readBatInfor();
    }
    else
    {
        temp.reply = HIT;
        checkShield=false;
    }

    if(temp.reply == REPLYBATTLE)
    {
        //应战
        //似乎发射信号的时机还要商榷
        CardEntity* usedCard = getCardByID(temp.CardID);
        QList<CardEntity*> use;
        use<<usedCard;
        this->useCard(use,getPlayerByID(temp.srcID),getPlayerByID(temp.dstID));

        coder.hitNotice(BLOCKED,isActiveAttack,dst->getID(),src->getID());
        QList<void*> args;
        args << src;
        args << dst;
        args << &harm;
        args << harmCard;
        args << &isActiveAttack;
        emit timeLine2missedSIG(args);
        this->timeLine1(getCardByID(temp.CardID),getPlayerByID(temp.srcID),getPlayerByID(temp.dstID),false);
    }
    else if(temp.reply == BLOCKED)
    {
        //抵挡
        CardEntity* usedCard = getCardByID(temp.CardID);

        if(usedCard->getPlace() == HAND)
        {
            //圣光
            QList<CardEntity*> use;
            use<<usedCard;
            this->useCard(use,getPlayerByID(temp.srcID));
        }
        coder.hitNotice(BLOCKED,isActiveAttack,dst->getID(),src->getID());
        QList<void*> args;
        args << src;
        args << dst;
        args << &harm;
        args << harmCard;
        args << &isActiveAttack;
        emit timeLine2missedSIG(args);

    }
    else if(temp.reply == HIT)
    {    
        //命中的情况

        QList<void*> args;
        args << src;
        args << dst;
        args << &checkShield;
        emit shieldSIG(args);
        for(int i = 0;i < dst->getBasicEffect().size()&& checkShield;i++)
        {
            //检查是否有圣盾                        
            if(dst->getBasicEffect().at(i)->getMagicName() == SHIELDCARD || dst->getBasicEffect().at(i)->getSpecialityList().contains(tr("天使之墙")))
            {
                coder.shieldNotic(dst->getID());
                dst->removeBasicEffect(dst->getBasicEffect()[i]);

                coder.hitNotice(BLOCKED,isActiveAttack,dst->getID(),src->getID());
                args.clear();
                args << src;
                args << dst;
                args << &harm;
                args << harmCard;
                args << &isActiveAttack;
                emit timeLine2missedSIG(args);
                return;
            }
        }
        //emit timeLine2hitSIG();

        coder.hitNotice(HIT,isActiveAttack,dst->getID(),src->getID());
        args.clear();
        args << src;
        args << dst;
        args << &harm;
        args << harmCard;
        args << &isActiveAttack;
        emit timeLine2hitSIG(args);

        int color = src->getColor();
        //增加星石
        if((teamArea.getCrystal(color) + teamArea.getGem(color)) < 5)
        {
            if(isActiveAttack)
                teamArea.setGem(color,teamArea.getGem(color) + 1);
            else
                teamArea.setCrystal(color,teamArea.getCrystal(color) + 1);
            coder.stoneNotice(color,teamArea.getGem(color),teamArea.getCrystal(color));

        }

        this->timeLine3(harm,src,dst);
    }
}
//行动阶段函数
void BackgroundEngine::actionPhase()
{    
    //这个标记表明是否行动过,如果已经行动过,那么追加的各种行动机会可以放弃
    bool acted = false;
    bool firstTime=true;
    int canGiveUp=0;


    this->checkEffect(this->currentPlayer);
    QList<void*> args;
    args<<currentPlayer;

    while((this->allowAttack()||this->allowMagic()||this->allowSpecial())&&playing)
    {        
        //根据允许的行动类别询问client
        if(firstTime){
            emit actionPhaseSIG(args);
            emit tiaoXinPhaseSIG(currentPlayer,&canGiveUp);
            firstTime=false;
        }
        if(!acted){
            coder.askForAction(currentPlayer->getID(),canGiveUp,acted);
        }
        else
            coder.askForAdditionalAction(currentPlayer->getID());

        //读取client的回复
        BatInfor bat = messageBuffer::readBatInfor();

        //放弃额外行动
        if(bat.reply == FINISH)
            break;
        //无法行动
        if(bat.reply == UNACTIONAL)
        {                        
            //弃牌重摸
            this->reDraw();
            continue;
        }

        if(bat.reply == ATTACK || bat.reply==ATTACKSKILL)
        {
            //使用攻击牌
            CardEntity* usingCard = getCardByID(bat.CardID);
            PlayerEntity* dst = getPlayerByID(bat.dstID);
            PlayerEntity* src = getPlayerByID(bat.srcID);
            QList<CardEntity*> use;
            int realCard=1;
            use << usingCard;
            args.clear();
            args<<&bat;
            args<<&realCard;
            if(bat.reply==ATTACKSKILL)
                emit skillAttack(args);
            this->useCard(use,src,dst,false,realCard);
            this->timeLine1(usingCard,src,dst,true);

            acted = true;
            this->acted(ATTACK);
            args.clear();
            args<< src;
            args << dst;
            emit attackFinishSIG(args);

        }

        else if(bat.reply == MAGIC)
        {
            //使用法术牌
            if(bat.infor1 == COMMONMAGIC)
                this->useMagicCard(bat.CardID,bat.srcID,bat.dstID);
            else
            {
                QList<void*> args;
                args << &bat;
                emit this->skillMagic(args);
            }
            acted = true;
            this->acted(MAGIC);
            PlayerEntity* src = getPlayerByID(bat.srcID);
            args.clear();
            args<< src;
            emit magicFinishSIG(args);
        }
        else if(bat.reply == SPECIAL)
        {
            //特殊行动
            if(bat.CardID == BUY)
            {
                coder.notice("执行【购买】");
                this->drawCards(3,0,this->getCurrentPlayer());
                int color = this->currentPlayer->getColor();
                teamArea.setGem(color,teamArea.getGem(color) + bat.infor1);
                teamArea.setCrystal(color,teamArea.getCrystal(color) + bat.infor2);                
                coder.stoneNotice(color,teamArea.getGem(color),teamArea.getCrystal(color));
            }
            else if(bat.CardID == SYNTHESIZE)
            {
                coder.notice("执行【合成】");
                this->drawCards(3,0,currentPlayer);
                int color = this->currentPlayer->getColor();
                teamArea.setGem(color,teamArea.getGem(color) - bat.infor1);
                teamArea.setCrystal(color,teamArea.getCrystal(color) - bat.infor2);
                teamArea.setCup(color,teamArea.getCup(color) + 1);
                teamArea.setMorale(!color,teamArea.getMorale(!color) - 1);                
                coder.stoneNotice(color,teamArea.getGem(color),teamArea.getCrystal(color));
                coder.cupNotice(color,teamArea.getCup(color));
                coder.moraleNotice(!color,teamArea.getMorale(!color));
                this->checkEnd();
            }
            else if(bat.CardID == EXTRACT)
            {
                coder.notice("执行【提炼】");
                int color = this->currentPlayer->getColor();
                teamArea.setGem(color,teamArea.getGem(color) - bat.infor1);
                teamArea.setCrystal(color,teamArea.getCrystal(color) - bat.infor2);
                currentPlayer->setGem(currentPlayer->getGem()+bat.infor1);
                currentPlayer->setCrystal(currentPlayer->getCrystal()+bat.infor2);                
                coder.stoneNotice(color,teamArea.getGem(color),teamArea.getCrystal(color));
                coder.energyNotice(currentPlayer->getID(),currentPlayer->getGem(),currentPlayer->getCrystal());
            }
            else {
                QList<void*> args;
                args << &bat;
                emit skillSpecial(args);
            }
            acted = true;
            this->acted(SPECIAL);
        }
    }
    emit turnEndPhaseSIG(currentPlayer);
}
//魔弹处理
void BackgroundEngine::missileProcess(CardEntity* card,int src,int dst)
{
    bool rightOrder;
    BatInfor reply;
    PlayerEntity* nextOpponent;

    //确定传递方向
    nextOpponent = this->getCurrentPlayer()->getNext();
    while(nextOpponent->getColor() == this->currentPlayer->getColor())
        nextOpponent = nextOpponent->getNext();
    if(nextOpponent->getID() == dst)
        rightOrder = true;
    else
        rightOrder = false;

    bool passed[6];
    for(int i = 0;i < this->playerList.size();i++)
    {
        passed[i] = false;
    }
    int missilePoint = 2;

    QList<CardEntity*> cards;


    do
    {
        cards.clear();
        //魔弹传递到下家
        missilePass(rightOrder,dst,src,passed,missilePoint);

        //读取用户回复
        reply = messageBuffer::readBatInfor();

        if(reply.reply == 0)
        {
            //继续传递
            src = dst;
            dst = reply.dstID;
            missilePoint++;
            cards << getCardByID(reply.CardID);
            this->useCard(cards,getPlayerByID(src),getPlayerByID(dst),false);
            continue;
        }
        else if(reply.reply == 1)
        {
            //圣光
            cards << getCardByID(reply.CardID);
            this->useCard(cards,getPlayerByID(dst));
            break;
        }
        else if(reply.reply == 2)
        {
            //无应对
            PlayerEntity* dstPlayer = getPlayerByID(dst);
            bool shieldBlocked = false;
            //检查圣盾
            for(int i = 0;i < dstPlayer->getBasicEffect().size();i++)
            {
                if(dstPlayer->getBasicEffect()[i]->getMagicName() == SHIELDCARD||dstPlayer->getBasicEffect().at(i)->getSpecialityList().contains(tr("天使之墙")))
                {
                    coder.shieldNotic(dst);
                    dstPlayer->removeBasicEffect(dstPlayer->getBasicEffect()[i]);
                    shieldBlocked = true;
                    break;
                }
            }
            if(shieldBlocked)
                break;
            Harm missileHurt;
            missileHurt.harmPoint = missilePoint;
            missileHurt.type = MAGIC;
            //无圣盾,造成伤害
            this->timeLine3(missileHurt,getPlayerByID(src),dstPlayer,"魔弹");
            break;
        }
        else if(reply.reply == 802)
        {
            //继续传递
            src = dst;
            dst = reply.dstID;
            missilePoint++;
            cards << getCardByID(reply.CardID);
            useCard(cards,getPlayerByID(src),getPlayerByID(dst));
            coder.notice("魔导师发动【魔弹融合】");
            continue;
        }

    }while(1);

}
Exemple #7
0
int db_updatePlayerHistory(const char* id)
{
	int aID;
	char calTimeStr[64];
	time_t updateTime;
	struct tm updateTimeTM;
	char updateTimeStr[64];
	char updateTimeStr_T[64];
	time_t now;
	struct tm* now_tm;
	char now_str[64];
	char now_str_T[64];
	PlayerHistory* phistory = 0;
	int history_num = 0;
	PlayerHistory* update_his = 0;
	int update_his_num = 0;
	PlayerSchedule* schedule = 0;

	time(&now);
	now_tm = localtime(&now);
	strftime(now_str, sizeof(now_str), "%Y-%m-%d %H:%M:%S", now_tm);
	strftime(now_str_T, sizeof(now_str_T), "%H:%M:%S", now_tm);


	MYSQL_RES* res;
	MYSQL_ROW row;
	int i, rec;
	BOOL cc;
	char string[256];

	//第一步:从数据库中把指定id的角色历史时间读取到内存中
	cc = sendQuery("SELECT * FROM player_history WHERE player_history.ID=%s", id);
	if (!cc) return FALSE;
	res =mysql_store_result(gpMysql);
	if (!res)
	{
		sprintf(string, "[SQL_ERROR]db.c:db_updatePlayerHistory() sql err!\n");
		LogWrite(LT_SYSTEM, string);
		return FALSE;
	}
	rec = mysql_num_rows(res);
	if (rec > 0)
	{
		phistory = (PlayerHistory*)malloc(sizeof(PlayerHistory) * rec);
		history_num = rec;
		for (i = 0; i < rec; i++)
		{
			row = mysql_fetch_row(res);
			strcpy(phistory[i].ID, row[ePLAYER_HISTORY_ID]);
			phistory[i].aID = atoi(row[ePLAYER_HISTORY_AID]);
			phistory[i].total_time = atof(row[ePLAYER_HISTORY_TOTAL_TIME]);
			strcpy(phistory[i].update_time, row[ePLAYER_HISTORY_UPDATE_TIME]);
		}
		memset(updateTimeStr, 0, 64);
		strcpy(updateTimeStr, row[ePLAYER_HISTORY_UPDATE_TIME]); 
	}
	else
	{
		AllPlayer* player = getPlayerByID(id);
		if (player == 0)
		{
			sprintf(string, "[Player]db.c:db_updatePlayerHistory().get playerid=(%s)failed!\n", id);
			LogWrite(LT_SYSTEM, string);
			return -1;
		}
		strcpy(updateTimeStr, player->birthday);
	}
	
	strcpy(calTimeStr, updateTimeStr);
	strptime(updateTimeStr, "%Y-%m-%d %H:%M:%S", &updateTimeTM);
	updateTime = mktime(&updateTimeTM);
	strftime(updateTimeStr_T, sizeof(updateTimeStr_T), "%H:%M:%S", &updateTimeTM);
	printf("now_str_T=(%s),updateTimeStr_T=(%s)\n", now_str_T, updateTimeStr_T);

	mysql_free_result(res);

	//第二步:计算并更新内存数据中角色的最新历史时间
	int elapse = now - updateTime;
	int day = elapse/(60*60*24);
	int min = elapse%(60*60*24);
	schedule = getPlayerScheduleByid(id);
	if (schedule != 0)
	{
		update_his_num = schedule->act_num + history_num;
		update_his = (PlayerHistory*)malloc(sizeof(PlayerHistory)*update_his_num);
		memset(update_his, 0, sizeof(PlayerHistory)*update_his_num);
		memcpy(update_his, phistory, sizeof(PlayerHistory)*history_num);
		//累计整天的部分
		if (day > 0)
		{
			for (i = 0; i < schedule->act_num; i++)
			{
				float ti = 0.0f;
				if (i < schedule->act_num - 1)
					ti = calElapseFromTwoTimeString(schedule->act_time[i], schedule->act_time[i+1]);
				else
				{
					float temp1 = 0.0f;
					float temp2 = 0.0f;
					temp1 = calElapseFromTwoTimeString(schedule->act_time[i], "23:59:59");
					temp2 = calElapseFromTwoTimeString("00:00:00", schedule->act_time[0]);
					ti = temp1 + temp2;
					ti += 1.0f;
				}

				int j;
				for (j = 0; j < history_num; j++)
				{
					//历史记录已经存在。直接累积时间。
					if (schedule->actid[i] == update_his[j].aID)
					{
						update_his[j].total_time += (ti*day);
						strcpy(update_his[j].update_time, now_str);
						break;
					}
				}
				if (j == history_num)
				{
					//历史记录中不存在,添加到历史记录中。
					strcpy(update_his[history_num].ID, id);
					update_his[history_num].aID = schedule->actid[i];
					update_his[history_num].total_time += (ti*day);
					strcpy(update_his[history_num].update_time, now_str);

					history_num++;
				}
			}	
		}
		//累计不足整天的部分
		int haf = strcmp(updateTimeStr_T, now_str_T); 
		if (haf >= 0)
		//if(0)
		{
			float up_i = 0.0f;
			int aID = 0;
			//不足一天计算两端
			for (i = 0; i < schedule->act_num; i++)
			{
				int big = strcmp(now_str_T, schedule->act_time[i]);
				int small = strcmp(schedule->act_time[i], updateTimeStr_T);
				if (big >=0)
				{
					float ti = 0.0f;
					if (i < schedule->act_num - 1)
					{
						if (strcmp(now_str_T, schedule->act_time[i+1]) > 0)
						{
							ti = calElapseFromTwoTimeString(schedule->act_time[i], schedule->act_time[i+1]);
						}
						else
						{
							ti = calElapseFromTwoTimeString(schedule->act_time[i], now_str_T);
						}
					}
					else
					{
						ti = calElapseFromTwoTimeString(schedule->act_time[i], now_str_T);
					}
					int j;
					for (j = 0; j < history_num; j++)
					{
						if (schedule->actid[i] == update_his[j].aID)
						{
							update_his[j].total_time += ti;	
							strcpy(update_his[j].update_time, now_str);
							break;
						}
					}
					if (j == history_num)
					{
						//历史记录中不存在,添加到历史记录中。
						strcpy(update_his[history_num].ID, id);
						update_his[history_num].aID = schedule->actid[i];
						update_his[history_num].total_time += ti;
						strcpy(update_his[history_num].update_time, now_str);
	
						history_num++;
						printf("1---->%d\n", history_num);
					}
					strcpy(calTimeStr, now_str);
				}
				else if (small >= 0)
				{
					float ti = 0.0f;
					if (i > 0)
					{
						if (strcmp(schedule->act_time[i], updateTimeStr_T)>0&&strcmp(schedule->act_time[i-1], updateTimeStr_T)<0)
						{
							up_i = calElapseFromTwoTimeString(updateTimeStr_T, schedule->act_time[i]);
							aID = schedule->actid[i-1];
						}
					}
					else
					{
						
						up_i = calElapseFromTwoTimeString(updateTimeStr_T, schedule->act_time[i]);
						aID = schedule->actid[history_num - 1];
					}
					
					if (i < schedule->act_num - 1)
					{
						ti = calElapseFromTwoTimeString(updateTimeStr_T, schedule->act_time[i+1]);
					}
					else
					{
						ti = calElapseFromTwoTimeString(schedule->act_time[i], "23:59:59");
					}
					int j;
					for (j = 0; j < history_num; j++)
					{
						if (schedule->actid[i] == update_his[j].aID)
						{
							update_his[j].total_time += ti;
							strcpy(update_his[j].update_time, now_str);
							break;
						}
					}
					if (j == history_num)
					{
						//历史记录中不存在,添加到历史记录中。
						strcpy(update_his[history_num].ID, id);
						update_his[history_num].aID = schedule->actid[i];
						update_his[history_num].total_time += ti;
						strcpy(update_his[history_num].update_time, now_str);
	
						history_num++;
						printf("2---->%d\n", history_num);
					}
					strcpy(calTimeStr, now_str);

				}
			}

			//计算update下面一段和now_str上面一段
			int j;
			for (j = 0; j < history_num; j++)
			{
				if (aID == update_his[j].aID)
				{
					update_his[j].total_time += up_i;
					strcpy(update_his[j].update_time, now_str);
					break;
				}
			}
			
			float down_now = 0.0f;
			
			if (strcmp(schedule->act_time[0], now_str_T)>0)
			{
				down_now = calElapseFromTwoTimeString("00:00:00", now_str_T);
				aID = schedule->actid[history_num - 1];
			}
			else
			{
				down_now = calElapseFromTwoTimeString("00:00:00", schedule->act_time[0]);
				aID = schedule->actid[history_num - 1];
			}
			for (j = 0; j < history_num; j++)
			{
				if (aID == update_his[j].aID)
				{
					update_his[j].total_time += down_now;
					strcpy(update_his[j].update_time, now_str);
					break;
				}
			}
	
		}
		else
		{
			//超过一天计算中间
			for (i = 0; i < schedule->act_num; i++)
			{
				int big = strcmp(now_str_T, schedule->act_time[i]);
				int small = strcmp(schedule->act_time[i], updateTimeStr_T);
				if (big >= 0 && small >= 0)
				{	
					float ti = 0.0f;
					//计算update到第一个事件的剩余时间累计到上次事件中
					if (i == 0)
					{
						ti = calElapseFromTwoTimeString(updateTimeStr_T, schedule->act_time[i]);
						aID = schedule->actid[schedule->act_num - 1];
						int j;
						for (j = 0; j < history_num; j++)
						{
							if (aID == update_his[j].aID)
							{
								update_his[j].total_time += ti;
								strcpy(update_his[j].update_time, now_str);
								break;
							}
						}
						if (j == history_num)
						{
							//历史记录中不存在,添加到历史记录中。
							strcpy(update_his[history_num].ID, id);
							update_his[history_num].aID = schedule->actid[i];
							update_his[history_num].total_time += ti;
							strcpy(update_his[history_num].update_time, now_str);
	
							history_num++;
						printf("3---->%d\n", history_num);
						}
					}
					else
					{
						if (strcmp(schedule->act_time[i-1], updateTimeStr_T)<0)
						{
							ti = calElapseFromTwoTimeString(updateTimeStr_T, schedule->act_time[i]);
							aID = schedule->actid[i-1];

							int j;
							for (j = 0; j < history_num; j++)
							{
								if (aID == update_his[j].aID)
								{
									update_his[j].total_time += ti;
									strcpy(update_his[j].update_time, now_str);
									break;
								}
							}
							if (j == history_num)
							{
								//历史记录中不存在,添加到历史记录中。
								strcpy(update_his[history_num].ID, id);
								update_his[history_num].aID = schedule->actid[i];
								update_his[history_num].total_time += ti;
								strcpy(update_his[history_num].update_time, now_str);
	
								history_num++;
								
						printf("4---->%d\n", history_num);
							}
						}
					}

					//计算事件到下次事件的时间
					if (i >= schedule->act_num - 1)
					{
						float ti = 0.0f;
						ti = calElapseFromTwoTimeString(schedule->act_time[i], now_str_T);
						aID = schedule->actid[i];
						int j;
						for (j = 0; j < history_num; j++)
						{
							if (aID == update_his[j].aID)
							{
								update_his[j].total_time += ti;
								strcpy(update_his[j].update_time, now_str);
								break;
							}
						}
						if (j == history_num)
						{
							//历史记录中不存在,添加到历史记录中。
							strcpy(update_his[history_num].ID, id);
							update_his[history_num].aID = schedule->actid[i];
							update_his[history_num].total_time += ti;
							strcpy(update_his[history_num].update_time, now_str);

							history_num++;
						printf("5---->%d\n", history_num);
						}
					}
					else
					{
						float ti = 0.0f;
						if (strcmp(schedule->act_time[i+1], now_str_T)<0)
						{
							ti = calElapseFromTwoTimeString(schedule->act_time[i], schedule->act_time[i+1]);
							aID = schedule->actid[i];
						}
						else
						{
							ti = calElapseFromTwoTimeString(schedule->act_time[i], now_str_T);
							aID = schedule->actid[i];
						}
						int j;
						for (j = 0; j < history_num; j++)
						{
							if (aID == update_his[j].aID)
							{
								update_his[j].total_time += ti;
								strcpy(update_his[j].update_time, now_str);
								break;
							}
						}
						if (j == history_num)
						{
							//历史记录中不存在,添加到历史记录中。
							strcpy(update_his[history_num].ID, id);
							update_his[history_num].aID = schedule->actid[i];
							update_his[history_num].total_time += ti;
							strcpy(update_his[history_num].update_time, now_str);

							history_num++;
						printf("6---->%d\n", history_num);
						}
					}

					strcpy(calTimeStr, now_str);
				}
			}
		}
	}

	//第三步:将内存中的数据更新写入数据库
	for (i = 0; i < history_num; i++)
	{
		char string[1024];
		memset(string, 0, 1024);
		sprintf(string , "REPLACE INTO player_history VALUES('%s',%d,%f,'%s')", update_his[i].ID, update_his[i].aID, update_his[i].total_time, calTimeStr);
		sendQuery(string);
		printf(string);
		printf("\n");
	}


	//第四步:释放临时申请内存空间
	if (phistory != 0)
		free(phistory);
	if (update_his != 0)
		free(update_his);
}