Ejemplo n.º 1
0
	// ********************************************************************* //
	void Logger::Initialize( Policy* _policy )
	{
		delete m_policy;
		m_policy = _policy;
		m_policy->Write( GetTimeString() );
		m_policy->Write( " Initialized Logger\n" );
	}
Ejemplo n.º 2
0
cString cEvent::ToDescr(void) const
{
  char vpsbuf[64] = "";
  if (Vps())
     sprintf(vpsbuf, "(VPS: %s) ", *GetVpsString());
  return cString::sprintf("%s %s-%s %s'%s'", *GetDateString(), *GetTimeString(), *GetEndTimeString(), vpsbuf, Title());
}
Ejemplo n.º 3
0
	// ********************************************************************* //
	void Logger::Initialize(Policy* _policy)
	{
		m_policy = _policy;
		m_policy->Write(GetTimeString());
		m_policy->Write(" Initialized Logger\n");

		m_initialized = true;
	}
Ejemplo n.º 4
0
off_t SwitchOutputCallback(void *fp, void *buf, int len)
{
	Pkt *pkt = ((struct pktrec *)buf)->rec;
	int nSize = 0;
	char *p = NULL;

	nSize += fprintf((FILE *)fp, "2;"); //CDR类型

	nSize += fprintf((FILE *)fp, "%s;",
			GetTimeString((time_t)(pkt->u32ReportTimeS)));  //reporttime

	p = GetMSISDN(pkt);
	SD_FPRINTF_JUDGE(nSize, fp, "%s;", p);  //MSISDN, 去掉前缀86

	nSize += fprintf((FILE *)fp, "%u;",
			(pkt->tdata.eventbssap.u8CDRType == 1) ? 0 : 1); // 呼叫类型

	SD_FPRINTF_JUDGE(nSize, fp, "%llu;",
			(unsigned long long)(pkt->tdata.eventbssap.u64IMSI));  //IMSI

	SD_FPRINTF_JUDGE(nSize, fp, "%15llu;",
			(unsigned long long)(pkt->tdata.eventbssap.u64IMEI));  //IMEI

	p = GetToString(pkt->tdata.eventbssap.cPeerNumber);
	SD_FPRINTF_JUDGE(nSize, fp, "%s;", p); //对方号码

	nSize += fprintf((FILE *)fp, "%u;", pkt->tdata.eventbssap.u32Duration / 1000); //通话时长

	nSize += fprintf((FILE *)fp, ";"); //漫游类型, 甲方
	nSize += fprintf((FILE *)fp, ";"); //本方归属地区号, 甲方
	nSize += fprintf((FILE *)fp, ";"); //本方通话地区号, 甲方
	SD_FPRINTF_JUDGE(nSize, fp, "%u;", pkt->tdata.eventbssap.u32ToDPC);//MSC_ID
	SD_FPRINTF_JUDGE(nSize, fp, "%hu;", pkt->tdata.eventbssap.u16FromLAC);//LAC_ID
	if (pkt->u8Subtype == PKTTYPE_EVENT_BSSAP) {
		SD_FPRINTF_JUDGE(nSize, fp, "%hu;", pkt->tdata.eventbssap.u16ToCI);//CELL_ID
	}
	else {
		SD_FPRINTF_JUDGE(nSize, fp, "%hu;", pkt->tdata.eventbssap.u16ToSAC);//CELL_ID
		SD_FPRINTF_JUDGE(nSize, fp, "%hu;",
				pkt->tdata.eventbssap.u16ToSAC ? pkt->tdata.eventbssap.u16ToSAC : pkt->tdata.eventbssap.u16ToCI);//CELL_ID
	}
	nSize += fprintf((FILE *)fp, ";");// 对方归属地区号, 甲方
	nSize += fprintf((FILE *)fp, ";");// 境外类型, 甲方
	nSize += fprintf((FILE *)fp, ";");// 特服标志, 甲方
	nSize += fprintf((FILE *)fp, ";");// 废单标志, 甲方
	nSize += fprintf((FILE *)fp, ";");// 运营商, 甲方
	nSize += fprintf((FILE *)fp, ";");// 文件名, 甲方
	nSize += fprintf((FILE *)fp, ";");// 预留字段1
	nSize += fprintf((FILE *)fp, ";");// 预留字段2
	nSize += fprintf((FILE *)fp, ";");// 预留字段3
	nSize += fprintf((FILE *)fp, ";");// 预留字段4
	nSize += fprintf((FILE *)fp, ";\r\n");// 短信内容

	return nSize;
}
Ejemplo n.º 5
0
void SharedUtil::AddReportLog ( uint uiId, const SString& strText )
{
    SString strPathFilename = PathJoin ( GetMTADataPath (), "report.log" );
    MakeSureDirExists ( strPathFilename );

    SString strMessage ( "%u: %s %s - %s\n", uiId, GetTimeString ( true, false ).c_str (), GetReportLogHeaderText ().c_str (), strText.c_str () );
    FileAppend ( strPathFilename, &strMessage.at ( 0 ), strMessage.length () );
#if MTA_DEBUG
    OutputDebugLine ( SStringX ( "[ReportLog] " ) + strMessage );
#endif
}
Ejemplo n.º 6
0
	// ********************************************************************* //
	Logger::~Logger()
	{
		m_policy->Write( GetTimeString() );
		m_policy->Write( " Closing Logger\n" );

		// If there is some writing do not delete the policy instant.
		m_mutex.lock();
		delete m_policy;
		m_policy = nullptr;
		m_mutex.unlock();
	}
Ejemplo n.º 7
0
/**********************************************
OnSendStatus
    This function is called after a command is
    processed. The command that was processed is
    passed in as well as the name of the file that
    the command was working on, the success state
    of the command and the time it took to perform
    the task
Params
    commandID  - command that was processed
    fileName   - the file that the command processed
    success    - the success state of the command (TRUE/FALSE)
    tickCount  - time it took to perform the command (ms)
Return 
    none
***********************************************/
void CUT_HTTPThread::OnSendStatus(int commandID,LPSTR fileName,int success,long tickCount){
    static char *szCommands[] = {"N/A","GET","HEAD","POST","PUT","PLACE","DELETE"};
    
    tickCount = GetTickCount() - tickCount;
    
    _snprintf(m_szBuf,sizeof(m_szBuf)-1,"%d Time=%-6.6s IP=%-15.15s Duration=%-7.7ld %s=%s",
        success,GetTimeString(),GetClientAddress(),tickCount,
        szCommands[commandID],fileName);
    
    ((CUT_HTTPServer *)m_winsockclass_this)->OnStatus(m_szBuf);
}
Ejemplo n.º 8
0
    static bool HandleInstanceListBindsCommand(ChatHandler* handler, char const* /*args*/)
    {
        Player* player = handler->getSelectedPlayer();
        if (!player)
            player = handler->GetSession()->GetPlayer();

        uint32 counter = 0;
        for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
        {
            Player::BoundInstancesMap &binds = player->GetBoundInstances(Difficulty(i));
            for (Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
            {
                InstanceSave* save = itr->second.save;
                std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
                handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_INFO, itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no",  save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str());
                counter++;
            }
        }
        handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_PLAYER_BINDS, counter);

        counter = 0;
        if (Group* group = player->GetGroup())
        {
            for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
            {
                Group::BoundInstancesMap &binds = group->GetBoundInstances(Difficulty(i));
                for (Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
                {
                    InstanceSave* save = itr->second.save;
                    std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
                    handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_INFO, itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str());
                    counter++;
                }
            }
        }
        handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_GROUP_BINDS, counter);

        return true;
    }
Ejemplo n.º 9
0
    static bool HandleInstanceListBindsCommand(ChatHandler* handler, char const* /*args*/)
    {
        Player* player = handler->getSelectedPlayer();
        if (!player)
            player = handler->GetSession()->GetPlayer();

        uint32 counter = 0;
        for (uint8 i = 0; i < 15; ++i)
        {
            Player::BoundInstancesMap &binds = player->GetBoundInstances(DifficultyID(i));
            for (Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
            {
                InstanceSave* save = itr->second.save;
                std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
                handler->PSendSysMessage("map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no",  save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
                counter++;
            }
        }
        handler->PSendSysMessage("player binds: %d", counter);

        counter = 0;
        if (Group* group = player->GetGroup())
        {
            for (uint8 i = 0; i < 15; ++i)
            {
                Group::BoundInstancesMap &binds = group->GetBoundInstances(DifficultyID(i));
                for (Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
                {
                    InstanceSave* save = itr->second.save;
                    std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
                    handler->PSendSysMessage("map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no",  save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
                    counter++;
                }
            }
        }
        handler->PSendSysMessage("group binds: %d", counter);

        return true;
    }
Ejemplo n.º 10
0
/* Get MP3 File Time */
static PyObject *pspmp3_gettime(PyObject *self, PyObject *args) {

    if (!PyArg_ParseTuple(args, ""))
        return NULL;

    char time[13];
    GetTimeString(time);
	
    return Py_BuildValue("s", time);

    Py_INCREF(Py_None);
    return Py_None;
}
Ejemplo n.º 11
0
//writes message and/or time/date to log file
void CEventLog::LogData(string text, int status=0)
{
  if (log_file.size() <1) SetFilename("log.txt");
  ofstream file(log_file.c_str(), std::ios::app);
  if(file){
    switch(status)
    {
      case LOG_TEXT:
        file << text.c_str() << endl;
        break;
      case LOG_TEXT_TIME:
        file << GetTimeString() << ": " << text.c_str() << endl;
        break;  
      case LOG_TEXT_DATE:
        file << GetDateString() << ": " << text.c_str() << endl;
        break;  
      case LOG_TEXT_DATE_TIME:
        file << GetDateString() << ", " << GetTimeString() << ": "
			 << text.c_str() << endl;
        break;  
    }
  }
}
Ejemplo n.º 12
0
void EventStatDialog::UpdateColumnHeader()
{
	LVCOLUMN lvColumn;
	lvColumn.mask = LVCF_TEXT;
	for (int i = 0; i < sk_numOfColumns; i++)
	{
		char buff[32];
		char headerBuff[64];
		GetTimeString(m_columnsData[i],buff);
		sprintf(headerBuff,"%s", buff);
		lvColumn.pszText = headerBuff;
		m_eventTable.SetColumn(i+1, &lvColumn);
	}

}
Ejemplo n.º 13
0
void MissionUpdateTime(Flight element,C_Mission *mission)
{
    _TCHAR buffer[80];

    mission->Refresh();
    WayPoint wp = element->GetFirstUnitWP();
    if (wp) { // JPO CTD fix
        GetTimeString(wp->GetWPDepartureTime(),buffer);
        mission->SetTakeOff(buffer);
        mission->SetTakeOffTime(wp->GetWPDepartureTime());
    }
    else
        mission->SetTakeOff(_T("Unknown"));
    mission->Refresh();
}
Ejemplo n.º 14
0
    static bool HandleInstanceUnbindCommand(ChatHandler* handler, char const* args)
    {
        if (!*args)
            return false;

        Player* player = handler->getSelectedPlayer();
        if (!player)
            player = handler->GetSession()->GetPlayer();

        char* map = strtok((char*)args, " ");
        char* pDiff = strtok(NULL, " ");
        int8 diff = -1;
        if (pDiff)
            diff = atoi(pDiff);
        uint16 counter = 0;
        uint16 MapId = 0;

        if (strcmp(map, "all"))
        {
            MapId = uint16(atoi(map));
            if (!MapId)
                return false;
        }

        for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
        {
            BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUIDLow(), Difficulty(i));
            for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end();)
            {
                InstanceSave* save = itr->second.save;
                if (itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficulty()))
                {
					uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime();
					uint32 ttr = (resetTime >= time(NULL) ? resetTime - time(NULL) : 0);
                    std::string timeleft = GetTimeString(ttr);
                    handler->PSendSysMessage("unbinding map: %d, inst: %d, perm: %s, diff: %d, canReset: %s, TTR: %s%s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str(), (itr->second.extended ? " (extended)" : ""));
					sInstanceSaveMgr->PlayerUnbindInstance(player->GetGUIDLow(), itr->first, Difficulty(i), true, player);
					itr = m_boundInstances.begin();
                    counter++;
                }
                else
                    ++itr;
            }
        }
        handler->PSendSysMessage("instances unbound: %d", counter);

        return true;
    }
Ejemplo n.º 15
0
/** Draw a clock tray component. */
void DrawClock(ClockType *clk, const TimeType *now)
{

   TrayComponentType *cp;
   const char *timeString;
   int width;
   int rwidth;

   /* Only draw if the time changed. */
   if(now->seconds == clk->lastTime.seconds) {
      return;
   }

   /* Clear the area. */
   cp = clk->cp;
   if(colors[COLOR_CLOCK_BG1] == colors[COLOR_CLOCK_BG2]) {
      JXSetForeground(display, rootGC, colors[COLOR_CLOCK_BG1]);
      JXFillRectangle(display, cp->pixmap, rootGC, 0, 0,
                      cp->width, cp->height);
   } else {
      DrawHorizontalGradient(cp->pixmap, rootGC,
                             colors[COLOR_CLOCK_BG1], colors[COLOR_CLOCK_BG2],
                             0, 0, cp->width, cp->height);
   }

   /* Determine if the clock is the right size. */
   timeString = GetTimeString(clk->format, clk->zone);
   width = GetStringWidth(FONT_CLOCK, timeString);
   rwidth = width + 4;
   if(rwidth == clk->cp->requestedWidth || clk->userWidth) {

      /* Draw the clock. */
      RenderString(cp->pixmap, FONT_CLOCK, COLOR_CLOCK_FG,
                   (cp->width - width) / 2,
                   (cp->height - GetStringHeight(FONT_CLOCK)) / 2,
                   cp->width, timeString);

      UpdateSpecificTray(clk->cp->tray, clk->cp);

   } else {

      /* Wrong size. Resize. */
      clk->cp->requestedWidth = rwidth;
      ResizeTray(clk->cp->tray);

   }

}
Ejemplo n.º 16
0
	// ********************************************************************* //
	void Logger::Shutdown()
	{
		if (m_initialized)
		{
			m_policy->Write(GetTimeString());
			m_policy->Write(" Closing Logger\n");

			// If there is some writing do not delete the policy instant.
			m_mutex.lock();
			delete m_policy;
			m_policy = nullptr;
			m_mutex.unlock();

			m_initialized = false;
		}
	}
Ejemplo n.º 17
0
bool JrnlWrite(char *aMsg)
{
    uint16 journaLength;

    char buffer[64];
    buffer[0]=0;
    GetTimeString(buffer);
    strcat(buffer, aMsg);
    MemGetWords(0x2000, &journaLength, 1);
    if (journaLength + strlen(buffer) / 2 > 0x8000)
        return false;
    MemSetWords(0x2000 + journaLength, (uint16*) buffer, (strlen(buffer)+1) / 2
                + (strlen(buffer)+1) % 2);
    journaLength += (strlen(buffer)+1) / 2 + (strlen(buffer)+1) % 2;
    return MemSetWords(0x2000, &journaLength, 1);
}
Ejemplo n.º 18
0
/** Update a clock tray component. */
void SignalClock(const TimeType *now, int x, int y, Window w, void *data)
{

   ClockType *cp = (ClockType*)data;
   const char *longTime;

   DrawClock(cp, now);
   if(cp->cp->tray->window == w &&
      abs(cp->mousex - x) < settings.doubleClickDelta &&
      abs(cp->mousey - y) < settings.doubleClickDelta) {
      if(GetTimeDifference(now, &cp->mouseTime) >= settings.popupDelay) {
         longTime = GetTimeString("%c", cp->zone);
         ShowPopup(x, y, longTime, POPUP_CLOCK);
      }
   }

}
Ejemplo n.º 19
0
    static bool HandleInstanceUnbindCommand(ChatHandler* handler, char const* args)
    {
        if (!*args)
            return false;

        Player* player = handler->getSelectedPlayer();
        if (!player)
            player = handler->GetSession()->GetPlayer();

        char* map = strtok((char*)args, " ");
        char* pDiff = strtok(NULL, " ");
        int8 diff = -1;
        if (pDiff)
            diff = atoi(pDiff);
        uint16 counter = 0;
        uint16 MapId = 0;

        if (strcmp(map, "all"))
        {
            MapId = uint16(atoi(map));
            if (!MapId)
                return false;
        }

        for (uint8 i = 0; i < 15; ++i)
        {
            Player::BoundInstancesMap &binds = player->GetBoundInstances(DifficultyID(i));
            for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
            {
                InstanceSave* save = itr->second.save;
                if (itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficulty()))
                {
                    std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
                    handler->PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %d canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str());
                    player->UnbindInstance(itr, DifficultyID(i));
                    counter++;
                }
                else
                    ++itr;
            }
        }
        handler->PSendSysMessage("instances unbound: %d", counter);

        return true;
    }
Ejemplo n.º 20
0
/* copy pasta from playercntl as to provide independance*/
bool MailSend(const wstring &wscCharname, const string &scExtension, const wstring &wscMsg)
{
	// Get the target player's message file.
	string scFilePath = GetUserFilePath(wscCharname, scExtension);
	if (scFilePath.length() == 0)
		return false;

	// Move all mail up one slot starting at the end. We automatically
	// discard the oldest messages.
	for (int iMsgSlot = MAX_MAIL_MSGS - 1; iMsgSlot>0; iMsgSlot--)
	{
		wstring wscTmpMsg = IniGetWS(scFilePath, "Msgs", itos(iMsgSlot), L"");
		IniWriteW(scFilePath, "Msgs", itos(iMsgSlot + 1), wscTmpMsg);

		bool bTmpRead = IniGetB(scFilePath, "MsgsRead", itos(iMsgSlot), false);
		IniWrite(scFilePath, "MsgsRead", itos(iMsgSlot + 1), (bTmpRead ? "yes" : "no"));
	}

	// Write message into the slot
	IniWriteW(scFilePath, "Msgs", "1", GetTimeString(set_bLocalTime) + L" " + wscMsg);
	IniWrite(scFilePath, "MsgsRead", "1", "no");
	return true;
}
Ejemplo n.º 21
0
	bool CEventVariableStringMap::GetString(LPCWSTR pszKeyword,String *pString)
	{
		if (::lstrcmpiW(pszKeyword,L"channel-name")==0) {
			*pString=m_EventInfo.Channel.ChannelName;
		} else if (::lstrcmpiW(pszKeyword,L"channel-no")==0) {
			StringUtility::Format(*pString,L"%d",m_EventInfo.Channel.RemoteControlKeyID);
		} else if (::lstrcmpiW(pszKeyword,L"channel-no2")==0) {
			StringUtility::Format(*pString,L"%02d",m_EventInfo.Channel.RemoteControlKeyID);
		} else if (::lstrcmpiW(pszKeyword,L"channel-no3")==0) {
			StringUtility::Format(*pString,L"%03d",m_EventInfo.Channel.RemoteControlKeyID);
		} else if (::lstrcmpiW(pszKeyword,L"event-name")==0) {
			*pString=m_EventInfo.Event.EventName;
		} else if (::lstrcmpiW(pszKeyword,L"event-title")==0) {
			GetEventTitle(m_EventInfo.Event.EventName,pString);
		} else if (::lstrcmpiW(pszKeyword,L"event-id")==0) {
			StringUtility::Format(*pString,L"%04X",m_EventInfo.Event.EventID);
		} else if (::lstrcmpiW(pszKeyword,L"service-id")==0) {
			StringUtility::Format(*pString,L"%04X",m_EventInfo.Channel.ServiceID);
		} else {
			return GetTimeString(pszKeyword,m_CurrentTime,pString);
		}

		return true;
	}
Ejemplo n.º 22
0
    static bool HandleInstanceListBindsCommand(ChatHandler* handler, char const* /*args*/)
    {
        Player* player = handler->getSelectedPlayer();
        if (!player)
            player = handler->GetSession()->GetPlayer();

        uint32 counter = 0;
        for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
        {
			BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUIDLow(), Difficulty(i));
            for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end(); ++itr)
            {
                InstanceSave* save = itr->second.save;
				uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime();
				uint32 ttr = (resetTime >= time(NULL) ? resetTime - time(NULL) : 0);
                std::string timeleft = GetTimeString(ttr);
				handler->PSendSysMessage("map: %d, inst: %d, perm: %s, diff: %d, canReset: %s, TTR: %s%s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no",  save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str(), (itr->second.extended ? " (extended)" : ""));
                counter++;
            }
        }
        handler->PSendSysMessage("player binds: %d", counter);

        return true;
    }
Ejemplo n.º 23
0
void HUD::Update(
	FONT & lcdfont, FONT & sansfont, FONT & sansfont_noshader, float displaywidth, float displayheight,
	float curlap, float lastlap, float bestlap, float stagingtimeleft,
	int curlapnum, int numlaps, int curplace, int numcars,
	float rpm, float redrpm, float maxrpm,
	float speed, float maxspeed, bool mph, float clutch, int newgear,
	const std::string & debug_string1, const std::string & debug_string2,
	const std::string & debug_string3, const std::string & debug_string4,
	bool absenabled, bool absactive, bool tcsenabled, bool tcsactive,
	bool outofgas, bool nosactive, float nosamount,
	bool drifting, float driftscore, float thisdriftscore)
{
	if (!lastvisible)
		return;

	float screenhwratio = displayheight/displaywidth;

	if (debug_hud_info)
	{
		debugtext1.Revise(sansfont, debug_string1);
		debugtext2.Revise(sansfont, debug_string2);
		debugtext3.Revise(sansfont, debug_string3);
		debugtext4.Revise(sansfont, debug_string4);
	}
#ifdef GAUGES
    FONT & gaugefont = sansfont_noshader;

	if (fabs(this->maxrpm - maxrpm) > 1)
	{
		this->maxrpm = maxrpm;
		rpmgauge.Revise(hudroot, gaugefont, 0, maxrpm * 0.001, 1);
	}
	if (fabs(this->maxspeed - maxspeed) > 1 || this->mph != mph)
	{
		this->maxspeed = maxspeed;
		this->mph = mph;
		if (mph)
		{
			speedlabel.Revise(gaugefont, "mph");
			speedscale = 2.23693629;
		}
		else
		{
			speedlabel.Revise(gaugefont, "kph");
			speedscale = 3.6;
		}
		speedgauge.Revise(hudroot, gaugefont, 0, maxspeed * speedscale, 10);
	}
	rpmgauge.Update(hudroot, rpm * 0.001);
	speedgauge.Update(hudroot, fabs(speed) * speedscale);

	// gear
	std::stringstream gearstr;
	if (newgear == -1)
		gearstr << "R";
	else if (newgear == 0)
		gearstr << "N";
	else
		gearstr << newgear;
	geartext.Revise(gaugefont, gearstr.str());

	float geartext_alpha = clutch * 0.5 + 0.5;
	if (newgear == 0) geartext_alpha = 1;
	DRAWABLE & geartextdrawref = hudroot.GetDrawlist().text.get(geartextdraw);
	geartextdrawref.SetColor(1, 1, 1, geartext_alpha);

	// speed
	std::stringstream sstr;
	sstr << std::abs(int(speed * speedscale));
	//float sx = mphtext.GetScale().first;
	//float sy = mphtext.GetScale().second;
	//float w = gaugefont.GetWidth(sstr.str()) * sx;
	//float x = 1 - w;
	//float y = 1 - sy * 0.5;
	mphtext.Revise(gaugefont, sstr.str());//, x, y, fontscalex, fontscaley);
#else
	std::stringstream gearstr;
	if (newgear == -1)
		gearstr << "R";
	else if (newgear == 0)
		gearstr << "N";
	else
		gearstr << newgear;
	geartext.Revise(lcdfont, gearstr.str());

	float geartext_alpha = (newgear == 0) ? 1 : clutch * 0.5 + 0.5;
	DRAWABLE & geartextdrawref = hudroot.GetDrawlist().text.get(geartextdraw);
	geartextdrawref.SetColor(1, 1, 1, geartext_alpha);

	float rpmpercent = std::min(1.0f, rpm / maxrpm);
	float rpmredpoint = redrpm / maxrpm;
	float rpmxstart = 60.0 / displaywidth;
	float rpmwidth = 200.0 / displaywidth;
	float rpmredx = rpmwidth * rpmredpoint + rpmxstart;
	float rpmy = 1.0 - 26.0 / displayheight;
	float rpmheight = 20.0 / displayheight;
	float rpmxend = rpmxstart + rpmwidth * rpmredpoint;
	float rpmrealend = rpmxstart + rpmwidth * rpmpercent;
	if (rpmxend > rpmrealend)
		rpmxend = rpmrealend;
	float rpmredxend = rpmrealend;
	if (rpmrealend < rpmredx)
		rpmredxend = rpmredx;
	rpmbarverts.SetToBillboard(rpmxstart, rpmy, rpmxend, rpmy + rpmheight);
	rpmredbarverts.SetToBillboard(rpmredx, rpmy, rpmredxend, rpmy + rpmheight);
	rpmboxverts.SetToBillboard(rpmxstart, rpmy, rpmxstart + rpmwidth, rpmy + rpmheight);

	std::stringstream speedo;
	if (mph)
		speedo << std::abs((int)(2.23693629 * speed)) << " MPH";
	else
		speedo << std::abs((int)(3.6 * speed)) << " KPH";
	float fontscalex = mphtext.GetScale().first;
	float fontscaley = mphtext.GetScale().second;
	float speedotextwidth = lcdfont.GetWidth(speedo.str()) * fontscalex;
	float x = 1.0 - screenhwratio * 0.02 - speedotextwidth;
	float y = 1 - fontscaley * 0.5;
	mphtext.Revise(lcdfont, speedo.str(), x, y, fontscalex, fontscaley);
#endif
	//update ABS alpha value
	if (!absenabled)
	{
		abs.SetAlpha(hudroot, 0.0);
	}
	else
	{
		if (absactive)
			abs.SetAlpha(hudroot, 1.0);
		else
			abs.SetAlpha(hudroot, 0.2);
	}

	//update TCS alpha value
	if (!tcsenabled)
	{
		tcs.SetAlpha(hudroot, 0.0);
	}
	else
	{
		if (tcsactive)
			tcs.SetAlpha(hudroot, 1.0);
		else
			tcs.SetAlpha(hudroot, 0.2);
	}

	//update GAS indicator
	if (outofgas)
	{
		gas.SetAlpha(hudroot, 1.0);
	}
	else
	{
		gas.SetAlpha(hudroot, 0.0);
	}

	//update NOS indicator
	if (nosamount > 0)
	{
		if (nosactive)
			nos.SetAlpha(hudroot, 1.0);
		else
			nos.SetAlpha(hudroot, 0.2);
	}
	else
	{
		nos.SetAlpha(hudroot, 0.0);
	}

	//update timer info
	{
		std::string tempstr;
		GetTimeString(curlap, tempstr);
		laptime.Revise(tempstr);
		GetTimeString(lastlap, tempstr);
		lastlaptime.Revise(tempstr);
		GetTimeString(bestlap, tempstr);
		bestlaptime.Revise(tempstr);
	}

	//update drift score
	if (numlaps == 0) //this is how we determine practice mode, for now
	{
		std::stringstream scorestream;
		scorestream << "Score " << (int)driftscore;
		if (drifting)
		{
			scorestream << " + " << (int)thisdriftscore;
			driftscoreindicator.SetColor(hudroot, 1,0,0);
		}
		else
		{
			driftscoreindicator.SetColor(hudroot, 1,1,1);
		}
		driftscoreindicator.Revise(scorestream.str());
	}
	else
	{
		driftscoreindicator.SetDrawEnable(hudroot, false);
	}


	if (numlaps > 0)
	{
		//update lap
		std::stringstream lapstream;
		//std::cout << curlapnum << std::endl;
		lapstream << "Lap " << std::max(1, std::min(curlapnum, numlaps)) << "/" << numlaps;
		lapindicator.Revise(lapstream.str());

		//update place
		std::stringstream stream;
		stream << "Place " << curplace << "/" << numcars;
		placeindicator.Revise(stream.str());

		//update race prompt
		std::stringstream t;
		if (stagingtimeleft > 0.5)
		{
			t << ((int)stagingtimeleft)+1;
			raceprompt.SetColor(hudroot, 1,0,0);
			racecomplete = false;
		}
		else if (stagingtimeleft > 0.0)
		{
			t << "Ready";
			raceprompt.SetColor(hudroot, 1,1,0);
		}
		else if (stagingtimeleft < 0.0f && stagingtimeleft > -1.0f) //stagingtimeleft needs to go negative to get the GO message
		{
			t << "GO";
			raceprompt.SetColor(hudroot, 0,1,0);
		}
		else if (curlapnum > numlaps && !racecomplete)
		{
			if (curplace == 1)
			{
				t << "You won!";
				raceprompt.SetColor(hudroot, 0,1,0);
			}
			else
			{
				t << "You lost";
				raceprompt.SetColor(hudroot, 1,0,0);
			}
			raceprompt.Revise(t.str());
			float width = raceprompt.GetWidth();
			raceprompt.SetPosition(0.5-width*0.5,0.5);
			racecomplete = true;
		}

		if (!racecomplete)
		{
			raceprompt.Revise(t.str());
			float width = raceprompt.GetWidth();
			raceprompt.SetPosition(0.5-width*0.5,0.5);
		}
	}
	else
	{
		lapindicator.SetDrawEnable(hudroot, false);
		placeindicator.SetDrawEnable(hudroot, false);
		raceprompt.SetDrawEnable(hudroot, false);
	}
}
Ejemplo n.º 24
0
// This runs once during program startup
void Controller::setup()
{
	// Setup code here
    LGSerial::init();
    LGSerial::put("Hello World!");

	DDRC |= 1 << DDC2;//trigger
	DDRC |= 1 << DDC3;//pc3 pin 26 for output
	DDRC |= 1 << DDC4;
	DDRC |= 1 << DDC5;
	DDRD |= 1 << DDD0;

	PORTD &= ~(1 << PD0);
	PORTC &= ~(1 << PC2);
	PORTC &= ~(1 << PC3);
	_delay_ms(500);

	ClockInit();


	SetSecond(1);
	SetMinute(33);
	SetHour(8);
	SetAmPm(1);///0 for AM, 1 for PM
	SetDay(3);
	SetDate(23);
	SetMonth(4);
	SetYear(13);

	char Time[12];	//hh:mm:ss AM/PM

	while(0)
	{
		//Get the Current Time as a String
		if(!GetTimeString(Time))//modifies time
		{
			/*
			 If return value is false then some error has occured

			 Check
			 ->DS1307 Installed Properly
			 ->DIP Switch 1,2 are in on position
			 */
			while(1);//halt
		}
		_delay_ms(500);
	}

	uint8_t second = GetSecond();
	uint8_t minute = GetMinute();
	uint8_t hour = GetHour();
	uint8_t AmPm = GetAmPm();
	uint8_t day = GetDate();
	uint8_t date = GetDate();
	uint8_t month = GetMonth();
	uint8_t year = GetYear();


	LGSerial::print(second);
	LGSerial::print(minute);
	LGSerial::print(hour);
	LGSerial::print(AmPm);
	LGSerial::print(day);
	LGSerial::print(date);
	LGSerial::print(month);
	LGSerial::print(year);

	_delay_ms(20000);
	second = GetSecond();
	minute = GetMinute();
	LGSerial::print(second);
	LGSerial::print(minute);

	_delay_ms(20000);
	second = GetSecond();
	minute = GetMinute();
	LGSerial::print(second);
	LGSerial::print(minute);



	//uint8_t minute = GetMinute();
//uint8_t minute = 0xAA;
//	bool min[8];
/*
	min[0] = minute & 0x01;
	min[1] = minute & 0x02;
	min[2] = minute & 0x04;
	min[3] = minute & 0x08;
	min[4] = minute & 0x10;
	min[5] = minute & 0x20;
	min[6] = minute & 0x40;
	min[7] = minute & 0x80;
*/

	/*
	 min[0] = 0;
	 min[1] = 1;
	 min[2] = 0;
	 min[3] = 1;
	 min[4] = 0;
	 min[5] = 1;
	 min[6] = 0;
	 min[7] = 1;
	 */

	/*

	int i = 0;

	while(1){
		//make pc2 trigger
		PORTC |= 1 << PC2;
		PORTC &= ~(1 << PC2);

		PORTC |= 1 << PC3;
		PORTC &= ~(1 << PC3);
		PORTC |= 1 << PC3;
		PORTC &= ~(1 << PC3);
		PORTC |= 1 << PC3;
		PORTC &= ~(1 << PC3);

		for (i=0;i<8;i++){
			if (min[i] == 1){	//if that bit of min is 1
				PORTD |= 1 << PD0;
				PORTD &= ~(1 << PD0);
				PORTD |= 1 << PD0;
				PORTD &= ~(1 << PD0);

				PORTC &= ~(1 << PC3);
				PORTC |= 1 << PC3;
				PORTC &= ~(1 << PC3);


			}
			else {//if (min[i] == 0){	//if that bit of min is 0
				PORTD |= 1 << PD0;
				PORTD &= ~(1 << PD0);

				PORTC |= 1 << PC3;
				PORTC &= ~(1 << PC3);
				PORTC |= 1 << PC3;

			}
		}

	}
	*/
}
Ejemplo n.º 25
0
INT cmd_time (LPTSTR param)
{
	LPTSTR *arg;
	INT    argc;
	INT    i;
	INT    nTimeString = -1;

	if (!_tcsncmp (param, _T("/?"), 2))
	{
		ConOutResPaging(TRUE,STRING_TIME_HELP1);
		return 0;
	}

  nErrorLevel = 0;

	/* build parameter array */
	arg = split (param, &argc, FALSE, FALSE);

	/* check for options */
	for (i = 0; i < argc; i++)
	{
		if (_tcsicmp (arg[i], _T("/t")) == 0)
		{
			/* Display current time in short format */
			SYSTEMTIME st;
			TCHAR szTime[20];
			GetLocalTime(&st);
			FormatTime(szTime, &st);
			ConOutPuts(szTime);
			freep(arg);
			return 0;
		}

		if ((*arg[i] != _T('/')) && (nTimeString == -1))
			nTimeString = i;
	}

	if (nTimeString == -1)
	{
		ConOutResPrintf(STRING_LOCALE_HELP1);
		ConOutPrintf(_T(": %s\n"), GetTimeString());
	}

	while (1)
	{
		if (nTimeString == -1)
		{
			TCHAR  s[40];

			ConOutResPuts(STRING_TIME_HELP2);

			ConInString (s, 40);

			TRACE ("\'%s\'\n", debugstr_aw(s));

			while (*s && s[_tcslen (s) - 1] < _T(' '))
				s[_tcslen(s) - 1] = _T('\0');

			if (ParseTime (s))
			{
				freep (arg);
				return 0;
			}
		}
		else
		{
			if (ParseTime (arg[nTimeString]))
			{
				freep (arg);
				return 0;
			}

			/* force input the next time around. */
			nTimeString = -1;
		}

		ConErrResPuts(STRING_TIME_ERROR1);
    nErrorLevel = 1;
	}

	freep (arg);

	return 0;
}
Ejemplo n.º 26
0
/*
 * UpdateStatusWindow - update the status window
 */
void UpdateStatusWindow( void )
{
    char        *str, *ptr;
    char        result[5 * MAX_STR];
    char        *res;
    int         digits;
    long        num;
    bool        use_num;
    int         line;
    char        numstr[12];
    int         format;
    char        c;

    if( BAD_ID( status_window_id ) ||
        EditFlags.DisplayHold ||
        EditFlags.Quiet ||
        !EditFlags.StatusInfo ||
        EditVars.StatusString == NULL ) {
        return;
    }

    res = result;
    line = 1;
    format = FMT_LEFT;
    EditFlags.ModeInStatusLine = false;
    for( str = EditVars.StatusString; (c = *str) != '\0'; ++str ) {
        if( c == '$' ) {
            str++;
            ptr = str;
            while( isdigit( *str ) ) {
                str++;
            }
            if( ptr != str ) {
                digits = strtoul( ptr, NULL, 10 );
            } else {
                digits = 0;
            }
            use_num = false;
            num = 0;
            c = *str;
            if( c == '\0' )
                break;
            switch( c ) {
            case '$':
                *res++ = '$';
                break;
            case 'c':
                *res++ = ',';
                break;
            case 'n':
                *res = 0;
                StatusLine( line, result, format );
                res = result;
                line++;
                break;
            case 'L':
                num = CurrentPos.line;
                use_num = true;
                break;
            case 'C':
                num = VirtualColumnOnCurrentLine( CurrentPos.column );
                use_num = true;
                break;
            case 'D':
#ifdef __WIN__
                GetDateString( res );
#else
                GetDateTimeString( res );
#endif
                res += strlen( res );
                break;
            case 'T':
                GetTimeString( res );
                res += strlen( res );
                break;
            case 'M':
                /* print the desired mode */
                EditFlags.ModeInStatusLine = true;
                GetModeString( res );
                res += strlen( res );
                break;
#ifdef __WIN__
            case 'H':
                GetMenuHelpString( res );
                res += strlen( res );
                break;
            case '[':
                *res++ = STATUS_ESC_CHAR;
                *res++ = STATUS_NEXT_BLOCK;
                break;
            case '|':
                *res++ = STATUS_ESC_CHAR;
                *res++ = STATUS_FORMAT_CENTER;
                break;
            case '>':
                *res++ = STATUS_ESC_CHAR;
                *res++ = STATUS_FORMAT_RIGHT;
                break;
            case '<':
                *res++ = STATUS_ESC_CHAR;
                *res++ = STATUS_FORMAT_LEFT;
                break;
#else
            case '|':
                format = FMT_CENTRE;
                break;
            case '>':
                format = FMT_RIGHT;
                break;
            case '<':
                format = FMT_LEFT;
                break;
#endif
            }
            if( use_num ) {
                ltoa( num, numstr, 10 );
                digits -= strlen( numstr );
                while( digits > 0 ) {
                    *res++ = ' ';
                    digits--;
                }
                ptr = numstr;
                while( *ptr != '\0' ) {
                    *res++ = *ptr++;
                }
            }
        } else {
            *res++ = c;
        }
    }
    *res = 0;
    if( res != result ) {
        StatusLine( line, result, format );
    }

} /* UpdateStatusWindow */
Ejemplo n.º 27
0
	/** Process a draw cash command **/
	bool GiveCash::UserCmd_DrawCash(uint iClientID, const wstring &wscCmd, const wstring &wscParam, const wchar_t *usage) 
	{
		// The last error.
		HK_ERROR err;

		// Get the current character name
		wstring wscCharname = (const wchar_t*) Players.GetActiveCharacterName(iClientID);

		// Get the parameters from the user command.
		wstring wscTargetCharname = GetParam(wscParam, L' ', 0);
		wstring wscCode = GetParam(wscParam, L' ', 1);
		wstring wscCash = GetParam(wscParam, L' ', 2);
		wscCash = ReplaceStr(wscCash, L".", L"");
		wscCash = ReplaceStr(wscCash, L",", L"");
		wscCash = ReplaceStr(wscCash, L"$", L"");
		int cash = ToInt(wscCash);
		if (!wscTargetCharname.length() || !wscCode.length() || cash<=0)
		{
			PrintUserCmdText(iClientID, L"ERR Invalid parameters");
			PrintUserCmdText(iClientID, usage);
			return true;
		}

		CAccount *iTargetAcc=HkGetAccountByCharname(wscTargetCharname);
		if (iTargetAcc==0)
		{
			PrintUserCmdText(iClientID, L"ERR char does not exist");
			return true;	
		}

		int secs = 0;
		HkGetOnLineTime(wscTargetCharname, secs);
		if (secs<set_iMinTime)
		{
			PrintUserCmdText(iClientID, L"ERR insufficient time online");
			return true;
		}

		if (InBlockedSystem(wscCharname) || InBlockedSystem(wscTargetCharname))
		{
			PrintUserCmdText(iClientID, L"ERR cash transfer blocked");
			return true;
		}

		string scFile;
		if (!GetUserFilePath(scFile, wscTargetCharname, "-givecash.ini"))
			return true;

		wstring wscTargetCode = IniGetWS(scFile, "Settings", "Code", L"");
		if (!wscTargetCode.length() || wscTargetCode!=wscCode)
		{
			PrintUserCmdText(iClientID, L"ERR cash account access denied");
			return true;
		}

		if (cash<set_iMinTransfer || cash<0) {
			PrintUserCmdText(iClientID, L"ERR Transfer too small, minimum transfer "+ToMoneyStr(set_iMinTransfer)+L" credits");
			return true;
		}

		int tCash = 0;
		if ((err = HkGetCash(wscTargetCharname, tCash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}
		if (tCash<cash)
		{
			PrintUserCmdText(iClientID, L"ERR Insufficient credits");
			return true;
		}

		// Check the adding this cash to this player will not
		// exceed the maximum ship value.
		float fTargetValue = 0.0f;
		if (HKGetShipValue(wscCharname, fTargetValue) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}
		if ((fTargetValue + cash) > 2000000000.0f)
		{
			PrintUserCmdText(iClientID, L"ERR Transfer will exceed credit limit");
			return true;
		}

		// Calculate the new cash
		int iExpectedCash = 0;
		if ((err = HkGetCash(wscCharname, iExpectedCash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}
		iExpectedCash += cash;

		// Do an anticheat check on the receiving ship first.
		if (HkAntiCheat(iClientID) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR Transfer failed");							
			AddLog("NOTICE: Possible cheating when drawing %s credits from %s (%s) to %s (%s)",
				wstos(ToMoneyStr(cash)).c_str(),
				wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
				wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str());				
			return true;
		}
		HkSaveChar(iClientID);


		uint targetClientId = HkGetClientIdFromCharname(wscTargetCharname);
		if (targetClientId != -1)
		{
			if (ClientInfo[iClientID].iTradePartner || ClientInfo[targetClientId].iTradePartner)
			{
				PrintUserCmdText(iClientID, L"ERR Trade window open");
				AddLog("NOTICE: Trade window open when drawing %s credits from %s (%s) to %s (%s) %u %u",
					wstos(ToMoneyStr(cash)).c_str(),
					wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
					wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
					iClientID, targetClientId);			
				return true;
			}
		}

		// Remove cash from target character
		if ((err = HkAddCash(wscTargetCharname, 0-cash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}

		if (targetClientId!=-1 && !HkIsInCharSelectMenu(targetClientId))
		{		
			if (HkAntiCheat(targetClientId) != HKE_OK)
			{
				PrintUserCmdText(iClientID, L"ERR Transfer failed");						
				AddLog("NOTICE: Possible cheating when drawing %s credits from %s (%s) to %s (%s)",
					wstos(ToMoneyStr(cash)).c_str(),
					wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
					wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str());				
				return true;
			}
			HkSaveChar(targetClientId);
		}

		// Add cash to this player
		if ((err = HkAddCash(wscCharname, cash)) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR "+HkErrGetText(err));
			return true;
		}

		if (HkAntiCheat(iClientID) != HKE_OK)
		{
			PrintUserCmdText(iClientID, L"ERR Transfer failed");			
			AddLog("NOTICE: Possible cheating when drawing %s credits from %s (%s) to %s (%s)",
				wstos(ToMoneyStr(cash)).c_str(),
				wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
				wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str());				
			return true;
		}
		HkSaveChar(iClientID);
		
		// Check that receiving player has the correct ammount of cash.
		int iCurrCash;
		if ((err = HkGetCash(wscCharname, iCurrCash)) != HKE_OK
			|| iCurrCash != iExpectedCash)
		{
			AddLog("ERROR: Cash transfer error when drawing %s credits from %s (%s) to %s (%s) current %s credits expected %s credits ",
					wstos(ToMoneyStr(cash)).c_str(),
					wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
					wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str(),
					wstos(ToMoneyStr(iCurrCash)).c_str(), wstos(ToMoneyStr(iExpectedCash)).c_str());
			PrintUserCmdText(iClientID, L"ERR Transfer failed");
		}

		// If the target player is online then send them a message saying
		// telling them that they've received transfered cash.
		wstring msg = L"You have transferred " + ToMoneyStr(cash) + L" credits to " + wscCharname;
		if (targetClientId!=-1 && !HkIsInCharSelectMenu(targetClientId))
		{
			PrintUserCmdText(targetClientId, L"%s", msg.c_str());
		}
		// Otherwise we assume that the character is offline so we record an entry
		// in the character's givecash.ini. When they come online we inform them
		// of the transfer. The ini is cleared when ever the character logs in.
		else
		{
			LogTransfer(wscTargetCharname, msg);
		}

		AddLog("NOTICE: Draw %s credits from %s (%s) to %s (%s)",
			wstos(ToMoneyStr(cash)).c_str(),
			wstos(wscTargetCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscTargetCharname))).c_str(),
			wstos(wscCharname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(wscCharname))).c_str());

		// A friendly message explaining the transfer.
		msg = GetTimeString(set_bLocalTime) + L": You have drawn " + ToMoneyStr(cash) + L" credits from " + wscTargetCharname;
		PrintUserCmdText(iClientID, L"%s", msg.c_str());
		return true;
	}
Ejemplo n.º 28
0
// This writes stats to a html file (usually run in it's
// own thread to not slow down the client loop)
void *WriteStatsFile(void *pParam){

	int i;
	char *pFileName;
	char QueueName[32];

	// Write current client info to info file
	FILE *StatsFile = fopen(Config.StatsFilename, "w");
	if(StatsFile != NULL){

		// Workout the file name without path
		pFileName = strrchr(Config.StatsFilename, '/');
		if(pFileName == NULL)
			pFileName = Config.StatsFilename;
		else
			pFileName++;

		// Write the header
		fprintf(StatsFile, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n\n<html>\n\n");
		fprintf(StatsFile, "<head>\n<meta http-equiv=\"content-type\" content=\"text-html; charset=utf-8\">\n");
		fprintf(StatsFile, "<meta NAME=\"Description\" CONTENT=\"Frottle stats\">\n<title>Frottle stats</title>\n");
		fprintf(StatsFile, "<meta http-equiv=\"refresh\" content=\"10; URL=%s\">\n</head>\n\n<body>\n\n", pFileName);
		if(Config.Flags & CONFIGFLAGS_SELFCLIENT){
			fprintf(StatsFile, "<h2>Frottle self-client (v%s)</h2>\n", FROTVERSION);
			fprintf(StatsFile, "<p>\nLast updated: %s<br>\nHigh priority ports:", GetTimeString("%d/%m/%Y %H:%M:%S"));
			}
		else{
			fprintf(StatsFile, "<h2>Frottle client (v%s)</h2>\n", FROTVERSION);
			fprintf(StatsFile, "<p>\nLast updated: %s<br>\nMaster: %s:%d (%s)<br>\nPolls/Sec: %ld<br>\nHigh priority ports:",
				GetTimeString("%d/%m/%Y %H:%M:%S"),
				Config.MasterIp, Config.MasterPort, (ClientStatus & CS_CONNECTED) ? "connected" : "not connected",
				ClientStats.Polls/10);
			}
		for(i = 0; i < Config.HiPortsCnt; i++)
			fprintf(StatsFile, " %d", Config.HiPorts[i]);
		fprintf(StatsFile, "\n</p>\n\n");

		// Setup titles
		if(PacketQueues > 0)
			fprintf(StatsFile, "<table>\n<tr bgcolor=\"c0c0c0\"><td>Queue</td><td>Packets sent</td><td>MBytes sent</td><td>Rate kB/s</td></tr>\n");

		// Fill in any queue info
		for(i = 0; i < PacketQueues; i++){

			// This should probably need changing if PacketQueues is changed
			if(i == 0)
				strcpy(QueueName, "High");
			else if(i == 1)
				strcpy(QueueName, "Medium");
			else if(i == 2)
				strcpy(QueueName, "Low");
			else
				sprintf(QueueName, "%d", i+1);

			fprintf(StatsFile, "<tr><td>%s</td><td align=\"right\">%.0f</td><td align=\"right\">%.0f</td><td align=\"right\">%.1f</td></tr>\n",
				QueueName, ClientStats.Packets[i], ClientStats.Bytes[i] / 1048576, ClientStats.BytesAvg[i] / 10240);

			ClientStats.BytesAvg[i] = 0;
		}

		if(PacketQueues > 0)
			fprintf(StatsFile, "</table>\n\n");

		// Link to the home page
		fprintf(StatsFile, "</p><a href=\"http://frottle.sourceforge.net/\">Frottle home page</a></p>\n");

		fprintf(StatsFile, "</body>\n\n</html>\n");

		// Close file
		fclose(StatsFile);
	}

	return NULL;
}
Ejemplo n.º 29
0
void DoToken (char *token, char *brief_string)
	{
	char		*sptr;
	int			i,value;

	// special tokens
	if (strcmp(token,"#EOL")==0)
		{
		_tcscat(brief_string,"\n");
		return;
		}
	else if (strcmp(token,"#SPACE")==0)
		{
		_tcscat(brief_string," ");
		return;
		}
	else if (strncmp(token,"#TAB",4)==0)
		{
		sptr = token+4;
		i = atoi(sptr);
		_tcscat(brief_string," ");
		return;
		}
/*	if (strncmp(token,"#INC",4)==0)
		{
		sptr = token+5;
		if (strcmp(sptr,"PILOT")==0)
			{
			if (mec->curr_pilot)
				mec->curr_pilot = mec->FindPilotDataFromAC(fn, mec->curr_pilot->aircraft_slot+1);
			else
				mec->curr_pilot = mec->FindPilotDataFromAC(fn, 0);
			}
		if (strcmp(sptr,"WEAPON")==0)
			mec->curr_weapon++;
		if (strcmp(sptr,"DATA")==0)
			mec->curr_data++;
		}
*/

	// Text string ids
	if (atoi(token) > 0)
		AddIndexedStringToBrief(atoi(token),brief_string);

	// Add all our script tokens here
	else if (strcmp(token,"FLIGHT_NUM")==0)
		AddNumberToBrief(1234,brief_string);	
	else if (strcmp(token,"FLIGHT_NAME")==0)
		AddIndexedStringToBrief(2000+rand()%150,brief_string);
	else if (strcmp(token,"PLANE_NAME")==0)
		{
		AddIndexedStringToBrief(2000+rand()%150,brief_string);
		AddNumberToBrief(rand()%4,brief_string);
		}
	else if (strcmp(token,"MISSION_NAME")==0)
		{
		value = FindCurrentValue("MISSION_EQ");
		AddIndexedStringToBrief(300+value,brief_string);
		}
	else if (strncmp(token,"MISSION_DESCRIPTION",19)==0)
		{
		value = FindCurrentValue("MISSION_EQ");
		sptr = token + 19;
		i = sptr[0] - '1';
		AddIndexedStringToBrief(400+i*50+value,brief_string);
		}
	else if (strncmp(token,"PACKAGE_MISSION_DESCRIPTION",27)==0)
		{
//		value = FindCurrentValue("PACKAGE_MISSION_EQ");
		value = FindCurrentValue("MISSION_EQ");
		sptr = token + 27;
		i = sptr[0] - '1';
		AddIndexedStringToBrief(900+i*50+value,brief_string);
		}
	else if (strcmp(token,"REQUESTING_UNIT")==0 || strcmp(token,"TARGET_NAME_UNIT")==0)
		{
		AddStringToBrief("BATTALION_NAME_LONG",UnitNameLong,brief_string);
		}
	else if (strcmp(token,"PACKAGE_TARGET_NAME_UNIT")==0)
		{
		AddStringToBrief("DIVISION_NAME",DivisionName,brief_string);
		}
	else if (strncmp(token,"PACKAGE_TARGET_NAME",19)==0)
		{
		i = rand()%6;
		if (!i)
			AddStringToBrief("OBJECTIVE_NAME",AirbaseName,brief_string);
		else if (i == 1)
			AddStringToBrief("OBJECTIVE_NAME",BridgeName,brief_string);
		else if (i == 2)
			AddStringToBrief("OBJECTIVE_NAME",PortName,brief_string);
		else
			AddStringToBrief("OBJECTIVE_NAME",DepotName,brief_string);
		}
	else if (strcmp(token,"ENTITY_NAME")==0)
		{
		i = rand()%2;
		if (i)
			AddStringToBrief("SQUADRON_NAME",SquadronName,brief_string);
		else
			AddStringToBrief("SQUADRON_NAME",UnitNameShort,brief_string);
		}
	else if (strcmp(token,"TARGET_VEHICLE_NAME")==0 || strcmp(token,"REQUESTING_UNIT_VEHICLE")==0 || strcmp(token,"INTERCEPTOR_NAME")==0 || strcmp(token,"AIRCRAFT_TYPE")==0)
		{
		AddStringToBrief("VEHICLE_NAME","F-16", brief_string);
		}
	else if (strcmp(token,"TARGET_OWNER")==0)
		{
		AddIndexedStringToBrief(40+rand()%6+1,brief_string);
		}
	else if (strcmp(token,"PACKAGE_TARGET_BUILDING")==0 || strcmp(token,"TARGET_BUILDING")==0)
		{
		i = rand()%4;
		if (!i)
			AddStringToBrief("FEATURE_NAME",FeatureName[0],brief_string);
		else if (i == 1)
			AddStringToBrief("FEATURE_NAME",FeatureName[1],brief_string);
		else if (i == 2)
			AddStringToBrief("FEATURE_NAME",FeatureName[2],brief_string);
		else
			AddStringToBrief("FEATURE_NAME",FeatureName[3],brief_string);
		}
	else if (strcmp(token,"REQUESTING_UNIT_DEST")==0 || strcmp(token,"TARGET_NAME")==0)
		{
		i = rand()%4;
		if (!i)
			AddStringToBrief("OBJECTIVE_NAME",AirbaseName,brief_string);
		else if (i == 1)
			AddStringToBrief("OBJECTIVE_NAME",BridgeName,brief_string);
		else if (i == 2)
			AddStringToBrief("OBJECTIVE_NAME",PortName,brief_string);
		else
			AddStringToBrief("OBJECTIVE_NAME",DepotName,brief_string);
		}
/*	else if (strcmp(token,"AWACS_NAME")==0)
		{
		mec->curr_data = 1;
		}
	else if (strcmp(token,"JSTAR_NAME")==0)
		{
		mec->curr_data = 1;
		}
	else if (strcmp(token,"TANKER_NAME")==0)
		{
		mec->curr_data = 1;
		}
*/
	else if (strncmp(token,"CONTEXT_STR",11)==0)
		{
		value = FindCurrentValue("CONTEXT_EQ");
		sptr = token + 11;
		i = sptr[0] - '1';
		AddIndexedStringToBrief(700+i*50+value,brief_string);
		}
	else if (strncmp(token,"RESULT_STR",10)==0)
		{
		_TCHAR		temp[128],format[128],t1[80],t2[80],hdr[30];
		int			success = FindCurrentValue("PACKAGE_SUCCESS_EQ");
		char		*sptr;
	
		value = FindCurrentValue("CONTEXT_EQ");

		sptr = strchr(token,' ');
		if (sptr && strchr(sptr,'U'))
			sprintf(t1,"(BATTALION_NAME)%s",UnitNameShort);
		else if (sptr && strchr(sptr,'O'))
			sprintf(t1,"(OBJECTIVE_NAME)%s",BridgeName);
		if (sptr && strchr(sptr,'R'))
			sprintf(t2,"(BATTALION_NAME)%s",UnitNameShort);

		switch (success)
			{
			case 0:
				ReadIndexedString(1200+value,format,127);
				ConstructOrderedSentence(temp,format,t1,t2);
				sprintf(hdr,"%d",1200+value);
				AddStringToBrief(hdr,temp,brief_string);
				break;
			case 1:
				ReadIndexedString(1300+value,format,127);
				ConstructOrderedSentence(temp,format,t1,t2);
				sprintf(hdr,"%d",1300+value);
				AddStringToBrief(hdr,temp,brief_string);
				break;
			case 2:
				ReadIndexedString(1400+value,format,127);
				ConstructOrderedSentence(temp,format,t1,t2);
				sprintf(hdr,"%d",1400+value);
				AddStringToBrief(hdr,temp,brief_string);
				break;
			case 3:
				ReadIndexedString(1500+value,format,127);
				ConstructOrderedSentence(temp,format,t1,t2);
				sprintf(hdr,"%d",1500+value);
				AddStringToBrief(hdr,temp,brief_string);
				break;
			default:
				AddIndexedStringToBrief(1100,brief_string);
				break;
			}
		}
	else if (strcmp(token,"NUM_AIRCRAFT")==0)
		{
		AddIndexedStringToBrief(rand()%4,brief_string);
		}
	else if (strcmp(token,"TIME_ON_TARGET")==0 || strcmp(token,"TIME_ON_STATION_LABEL")==0 || strcmp(token,"PATROL_TIME")==0)
		{
		AddTimeToBrief(1234567,brief_string);
		}
	else if (strcmp(token,"ACTUAL_TIME_ON_TARGET")==0)
		{
		if (!rand()%3)
			AddIndexedStringToBrief(239,brief_string);
		else
			{
			AddTimeToBrief(123456,brief_string);
			if (!rand()%3)
				{
				AddIndexedStringToBrief(117,brief_string);
				AddNumberToBrief(20,brief_string);
				AddIndexedStringToBrief(240,brief_string);
				AddIndexedStringToBrief(118,brief_string);
				}
			else if (!rand()%3)
				{
				AddIndexedStringToBrief(117,brief_string);
				AddNumberToBrief(20,brief_string);
				AddIndexedStringToBrief(241,brief_string);
				AddIndexedStringToBrief(118,brief_string);
				}
			}
		}
	else if (strcmp(token,"ALTERNATE_STRIP_NAME")==0)
		{
		AddStringToBrief(token,AirbaseName,brief_string);
		}
	else if (strcmp(token,"ENEMY_NAME")==0)
		{
		if (rand()%5)
			AddIndexedStringToBrief(40+1+rand()%7,brief_string);
		else
			AddIndexedStringToBrief(113,brief_string);
		}
	else if (strncmp(token,"GENERAL_LOCATION",16)==0 || strncmp(token,"SPECIFIC_LOCATION",17)==0 || strncmp(token,"NEAREST_LOCATION",16)==0 || strncmp(token,"THE_LOCATION",12)==0)
		{
		AddLocationToBrief(tolower(token[0]), brief_string);
		}

	//
	// Mission evaluation tokens here
	//
	else if (strcmp(token,"PACKAGE_SUCCESS")==0 || strcmp(token,"FLIGHT_SUCCESS")==0)
		{
		value = FindCurrentValue("MISSION_SUCCESS");
		AddIndexedStringToBrief(20+value,brief_string);
//		AddIndexedStringToBrief(20+rand()%5,brief_string);
		}
	else if (strcmp(token,"PILOT_RATING")==0)
		AddIndexedStringToBrief(10+rand()%5,brief_string);
	else if (strcmp(token,"PILOT_NAME")==0)
		{
		_TCHAR	temp[128];
		ReadIndexedString(2301,temp, 127);
		AddStringToBrief(token,temp,brief_string);
		}
	else if (strcmp(token,"PILOT_STATUS")==0)
		AddIndexedStringToBrief(95+rand()%4,brief_string);
	else if (strcmp(token,"AA_KILLS")==0)
		AddNumberToBrief(2,brief_string);
	else if (strcmp(token,"AG_KILLS")==0)
		AddNumberToBrief(1,brief_string);
	else if (strcmp(token,"FRIENDLY_LOSSES")==0)
		AddIndexedStringToBrief(3,brief_string);
	else if (strcmp(token,"LONG_MISSION_SUCCESS")==0)
		{
		_TCHAR		tstring[80],wstring[80];
		value = FindCurrentValue("MISSION_SUCCESS");
		AddIndexedStringToBrief(25+value,brief_string);
		ReadIndexedString(1000+rand()%5, wstring, 80);
		_stprintf(tstring,wstring,1);
		AddStringToBrief(token,tstring,brief_string);
		}
	else if (strcmp(token,"PLANE_STATUS")==0)
		AddIndexedStringToBrief(90+rand()%4,brief_string);
	else if (strcmp(token,"SHOW_THREATS")==0)
		{
		if (rand()%2)
			{
			AddStringToBrief("VEHICLE_NAME","SA-2",brief_string);
			AddIndexedStringToBrief(235,brief_string);
			AddLocationToBrief('s', brief_string);
			AddStringToBrief("","\n",brief_string);
			}
		else
			{
			AddStringToBrief("VEHICLE_NAME","ZSU-23",brief_string);
			AddIndexedStringToBrief(236,brief_string);
			AddLocationToBrief('s', brief_string);
			AddStringToBrief("","\n",brief_string);
			}
		}
	else if (strcmp(token,"THREAT_VEHICLE_NAME")==0)
		{
		AddStringToBrief("VEHICLE_NAME","T-72",brief_string);
		}
	else if (strcmp(token,"WEAPON_LOAD")==0)
		AddNumberToBrief(rand()%3,brief_string);
	else if (strcmp(token,"WEAPON_NAME")==0)
		AddStringToBrief(token,"Aim-9", brief_string);
	else if (strcmp(token,"WEAPON_FIRED")==0)
		AddNumberToBrief(2, brief_string);
	else if (strcmp(token,"WEAPON_HIT")==0)
		AddNumberToBrief(1, brief_string);
	else if (strcmp(token,"WEAPON_MISSED")==0)
		AddNumberToBrief(1, brief_string);
	else if (strcmp(token,"WEAPON_HIT_RATIO")==0)
		AddNumberToBrief(50,brief_string);
	else if (strcmp(token,"SHOW_EVENT")==0)
		{
		_TCHAR	format[128],temp[128],name[40],time[40];

		ReadIndexedString(41,name,127);
		GetTimeString(123456, time);

		AddStringToBrief("","\n",brief_string);
		ReadIndexedString(1700,format,127);
		ConstructOrderedSentence(temp,format,name,"F-16","Viper","1",time);
		AddStringToBrief("1700",temp,brief_string);
		AddStringToBrief("","\n",brief_string);
		ReadIndexedString(1701,format,127);
		ConstructOrderedSentence(temp,format,name,"F-16","Viper","1",time);
		AddStringToBrief("1701",temp,brief_string);
		AddStringToBrief("","\n",brief_string);
		ReadIndexedString(1702,format,127);
		ConstructOrderedSentence(temp,format,"Viper","1",time);
		AddStringToBrief("1702",temp,brief_string);
		AddStringToBrief("","\n",brief_string);
		ReadIndexedString(1703,format,127);
		ConstructOrderedSentence(temp,format,"Viper","1",name,"F-16",time);
		AddStringToBrief("1703",temp,brief_string);
		AddStringToBrief("","\n",brief_string);
		ReadIndexedString(1708,format,127);
		ConstructOrderedSentence(temp,format,"Viper","1",name,"F-16",time);
		AddStringToBrief("1708",temp,brief_string);
		AddStringToBrief("","\n",brief_string);
		ReadIndexedString(1710,format,127);
		ConstructOrderedSentence(temp,format,"Viper","1",time);
		AddStringToBrief("1710",temp,brief_string);
		AddStringToBrief("","\n",brief_string);
		}
	else if (strcmp(token,"WAYPOINT_NUM")==0)
		AddNumberToBrief(1, brief_string);
	else if (strcmp(token,"WAYPOINT_ACTION")==0)
		AddIndexedStringToBrief(350+rand()%20, brief_string);
	else if (strcmp(token,"WAYPOINT_TIME")==0)
		AddTimeToBrief(12345678, brief_string);
	else if (strcmp(token,"WAYPOINT_HEADING")==0)
		AddNumberToBrief(45,brief_string);
	else if (strcmp(token,"WAYPOINT_SPEED")==0)
		AddNumberToBrief(450,brief_string);
	else if (strcmp(token,"WAYPOINT_ALT")==0)
		AddNumberToBrief(10000,brief_string);
	else if (strcmp(token,"WAYPOINT_CLIMB")==0)
		{
//		AddIndexedStringToBrief(1600,brief_string);
		AddIndexedStringToBrief(1650,brief_string);
		}
	else if (strcmp(token,"WAYPOINT_DESC")==0)
		AddIndexedStringToBrief(1650+rand()%20, brief_string);
	else if (strcmp(token,"ENEMY_SQUADRONS")==0)
		{
		AddStringToBrief("SQUADRON_NAME",SquadronName, brief_string);
		AddStringToBrief("SQUADRON_NAME"," (F-16)	-- 100%% ", brief_string);
		AddIndexedStringToBrief(164, brief_string);
		AddStringToBrief("","\n", brief_string);
		}
	else if (strcmp(token,"ENTITY_ELEMENT_NAME")==0)
		AddStringToBrief("VEHICLE_NAME","Mig-29",brief_string);
	else if (strcmp(token,"ENTITY_OPERATIONAL")==0)
		AddNumberToBrief(100,brief_string);
	else if (strcmp(token,"BEST_FEATURES")==0)
		AddStringToBrief("FEATURE_NAME",FeatureName[0],brief_string);
	else if (strcmp(token,"POTENTIAL_TARGETS")==0)
		{
		AddStringToBrief("OBJECTIVE_NAME",BridgeName, brief_string);
		AddStringToBrief("","  100%% ", brief_string);
		AddIndexedStringToBrief(165, brief_string);
		AddStringToBrief("","\n", brief_string);
		}
	}
Ejemplo n.º 30
0
/*
 * print the command-line prompt
 */
VOID PrintPrompt(VOID)
{
	static TCHAR default_pr[] = _T("$P$G");
	TCHAR  szPrompt[256];
	LPTSTR pr;

	if (GetEnvironmentVariable (_T("PROMPT"), szPrompt, 256))
		pr = szPrompt;
	else
		pr = default_pr;

	while (*pr)
	{
		if (*pr != _T('$'))
		{
			ConOutChar (*pr);
		}
		else
		{
			pr++;

			switch (_totupper (*pr))
			{
				case _T('A'):
					ConOutChar (_T('&'));
					break;

				case _T('B'):
					ConOutChar (_T('|'));
					break;

				case _T('C'):
					ConOutChar (_T('('));
					break;

				case _T('D'):
					ConOutPrintf(_T("%s"), GetDateString());
					break;

				case _T('E'):
					ConOutChar (_T('\x1B'));
					break;

				case _T('F'):
					ConOutChar (_T(')'));
					break;

				case _T('G'):
					ConOutChar (_T('>'));
					break;

				case _T('H'):
					ConOutChar (_T('\x08'));
          ConOutChar (_T(' '));
          ConOutChar (_T('\x08'));
					break;

				case _T('L'):
					ConOutChar (_T('<'));
					break;

				case _T('N'):
					{
						TCHAR szPath[MAX_PATH];
						GetCurrentDirectory (MAX_PATH, szPath);
						ConOutChar (szPath[0]);
					}
					break;

				case _T('P'):
					{
						TCHAR szPath[MAX_PATH];
						GetCurrentDirectory (MAX_PATH, szPath);
						ConOutPrintf (_T("%s"), szPath);
					}
					break;

				case _T('Q'):
					ConOutChar (_T('='));
					break;

        case _T('S'):
					ConOutChar (_T(' '));
					break;

				case _T('T'):
					ConOutPrintf(_T("%s"), GetTimeString());
					break;

				case _T('V'):
					switch (osvi.dwPlatformId)
					{
						case VER_PLATFORM_WIN32_WINDOWS:
							if (osvi.dwMajorVersion == 4 &&
								osvi.dwMinorVersion == 1)
								ConOutPrintf (_T("Windows 98"));
							else
								ConOutPrintf (_T("Windows 95"));
							break;


						case VER_PLATFORM_WIN32_NT:
							ConOutPrintf (_T("Windows NT Version %lu.%lu"),
										  osvi.dwMajorVersion, osvi.dwMinorVersion);
							break;
					}
					break;

				case _T('_'):
					ConOutChar (_T('\n'));
					break;

				case '$':
					ConOutChar (_T('$'));
					break;

#ifdef FEATURE_DIRECTORY_STACK
				case '+':
					{
						INT i;
						for (i = 0; i < GetDirectoryStackDepth (); i++)
							ConOutChar (_T('+'));
					}
					break;
#endif
			}
		}
		pr++;
	}
}