예제 #1
0
int CTradeBase::DoTrade(SAConnection *saConn, void * pNode)
{
    if(saConn == NULL || pNode == NULL)
    {
        trace_log(ERR, "Parameter error.");
        return RET_SYSEXP;
    }

    TRADEDATA *pData=(TRADEDATA *)pNode;

	if( COperateDB::GetReference(saConn, pData->cReference) )
	{
		trace_log(ERR, "GetReference() fail.");
		return RET_SYSEXP;
	}
    /**< 插入交易记录 */
    if(0 != COperateDB::MyBeforeInsertDB(saConn, pData))
    {
        trace_log(ERR, "DoInsert fail.");
        return RET_SYSEXP;
    }

	char cType=pData->TransData.HeadData.RTradeType;
	
	trace_log(DBG, "POS_UNCONSUME==g_Cfg.ChongZhengFlag:%d,cType:%d-%d",g_Cfg.ChongZhengFlag,cType,POS_UNCONSUME);
	if(cType == POS_UNCONSUME) 
	{ //冲正交易
		memcpy(pData->TransData.HeadData.RspCode,"00",2);
		if (g_Cfg.ChongZhengFlag == 2) 
		{ //不向渠道发冲正
			if(0 != COperateDB::MyAfterUpdateDB(saConn, pData, (char)ST_SUCCESS,"00", "交易成功PC"))
			{
				trace_log(ERR, "Call DoUpdate fail!");
				return RET_SYSEXP;
			}
			
			return RET_SUCCESS;
		}
	}
     /**< 组请求包 */
    unsigned char SndBuf[PACK_MAXLEN]={0};
    unsigned iSndLen = sizeof(SndBuf);
    if(RET_SUCCESS != DoPack(saConn, pNode, SndBuf, iSndLen))
    {
        if( strcmp(pData->TransData.HeadData.RspCode, "25")==0 )
        {
            return -1;
        }
        if( 0==strlen(pData->TransData.HeadData.RspCode)) memcpy(pData->TransData.HeadData.RspCode,"96",2);
        if(0 != COperateDB::MyAfterUpdateDB(saConn, (TRADEDATA *)pNode, (char)ST_FAILURE,pData->TransData.HeadData.RspCode, ""))
        {
            trace_log(ERR, "Call MyUpdateDB fail!");
        }
        return RET_PACK;
    }

     /**< 设置报文头 */
    SetMsgHead(SndBuf, iSndLen, pData);
    /**< 写冲正表 */
    //char cType=pData->TransData.HeadData.RTradeType;
    if(cType==POS_CONSUME||cType==POS_REPEAL||cType==POS_PREAUTH||cType==POS_PREAUTHREVE||
        cType==POS_PREAUTHCPLREQ||cType==POS_PREAUTHCPLREVE)
    {

        if(0 != COperateDB::BuildResetData(saConn, pData,&sndObj))
        {
            trace_log(ERR, "DoIstRstRcd fail.");
            if( 0==strlen(pData->TransData.HeadData.RspCode)) memcpy(pData->TransData.HeadData.RspCode,"96",2);
            if(0 != COperateDB::MyAfterUpdateDB(saConn, pData, (char)ST_FAILURE,pData->TransData.HeadData.RspCode, ""))
            {
                trace_log(ERR, "Call DoUpdate fail!");
            }
            return RET_SYSEXP;
        }
    }

    /**<  发送请求包并接收响应包 */
    unsigned char RcvBuf[PACK_MAXLEN]={0};
    unsigned iRcvLen = sizeof(RcvBuf);
    char errDesc[248]={0};
    int iRet = DoSendAndRcv(SndBuf, iSndLen, RcvBuf, (int*)&iRcvLen, g_Cfg.nSendTimeOut,errDesc);
    if(0 !=iRet)
    {
        int nRET;
        char cErr[512];
        sprintf(cErr, "Channel[%d]:%s",iRet,errDesc);
        if(2==iRet)
        {
            memcpy(pData->TransData.HeadData.RspCode,TIMEOUT_FLAG,2);/**< 第三方响应超时 */
            nRET=RET_RECV;
        }else {
            if( 0==strlen(pData->TransData.HeadData.RspCode)) memcpy(pData->TransData.HeadData.RspCode,"96",2);
            nRET=RET_SYSEXP;
        }

        if(0 != COperateDB::MyAfterUpdateDB(saConn, pData, (char)ST_FAILURE,pData->TransData.HeadData.RspCode, cErr))
        {
            trace_log(ERR, "Call MyUpdateDB fail!");
        }
        return nRET;
    }
    /**<  处理响应包 */
    return DoUnpack(saConn, pNode, RcvBuf, iRcvLen);
}
예제 #2
0
gint main_unpack(gchar *game_dir, gint race)
{
  gint argc = 2;
  gchar *argv[2];

  FILE *init, *ctrl;
  gchar *rstname, *player;
  gint i;

  argv[1] = game_dir;

  if (argc == 2) {
    gamedir = malloc(strlen(argv[1]) + 1 + 1); /* trailing '/' and '\0' */
    if (argv[1][strlen(argv[1]) - 1] != '/') {
      sprintf(gamedir, "%s%c", argv[1], '/');
    } else {
      sprintf(gamedir, "%s", argv[1]);
    }
#ifdef test
    fprintf(stderr, "Game directory is %s\n", gamedir);
#endif
    ctrlremember = malloc(6002);
    for (i = 0; i < 6002; i++) ctrlremember[i] = 'K';

    i = race;
    player = malloc(3); /* max 2 digits + '\0' */
    sprintf(player, "%d", i);
#ifdef test
    fprintf(stderr, "Player number is %s\n", player);
#endif
    rstname = malloc(strlen(gamedir) + strlen(player) + 11);
    sprintf(rstname, "%splayer%s.rst", gamedir, player);
#ifdef test
    fprintf(stderr, "%s\n", rstname);
#endif
    rst = fopen(rstname, "rb");
    if (rst != NULL) {
      DoUnpack(rst, player, i);
    } else {
      sprintf(rstname, "%sPLAYER%s.RST", gamedir, player);
#ifdef test
      fprintf(stderr, "%s\n", rstname);
#endif
      rst = fopen(rstname, "rb");
      if (rst != NULL) {
	DoUnpack(rst, player, i);
      } else {
#ifdef test
	fprintf(stderr, "No player %s in game %s\n", player, gamedir);
#endif
      }
    }
    free(rstname);
    free(player);

    if (found) {
      init = OpenPlayerFile("init", "", "tmp");
      fwrite(&inittmp, 2, 11, init);
      fclose(init);
      ctrl = OpenPlayerFile("control", "", "dat");
      fwrite(ctrlremember, 6002, 1, ctrl);
      fclose(ctrl);
    } else {
      fprintf(stderr, "Nothing to unpack!\n\n");
    }
    free(gamedir);
    free(ctrlremember);
  } else {
    fprintf(stderr, "Usage: kunpack <gamedir> \n\n");
    return(1);
  }
#ifdef test
  fprintf(stderr, "Really done now.\n");
#endif
  return(0);
} /* main */