コード例 #1
0
ファイル: balloonmgr.cpp プロジェクト: ECRS/Asus-RT-N16
void BalloonMgr::post()
{
    if (_pending.empty())
        return;  // No active balloon!?

    // Post balloon tip
    Balloon &balloon = _pending.front();
    NOTIFYICONDATA nid;
    nid.hWnd = balloon.hwnd;
    nid.cbSize = sizeof(nid);
    nid.uID = IDI_APCUPSD;
    nid.uFlags = NIF_INFO;
    astrncpy(nid.szInfo, balloon.text.c_str(), sizeof(nid.szInfo));
    astrncpy(nid.szInfoTitle, balloon.title.c_str(), sizeof(nid.szInfoTitle));
    nid.uTimeout = MAX_TIMEOUT;
    nid.dwInfoFlags = NIIF_INFO;
    Shell_NotifyIcon(NIM_MODIFY, &nid);

    // Set a timeout to clear the balloon
    LARGE_INTEGER timeout;
    if (_pending.size() > 1)  // More balloons pending: use minimum timeout
        timeout.QuadPart = -(MIN_TIMEOUT * 10000);
    else  // No other balloons pending: Use maximum timeout
        timeout.QuadPart = -(MAX_TIMEOUT * 10000);
    SetWaitableTimer(_timer, &timeout, 0, NULL, NULL, false);

    // Remember the time at which we started the timer
    gettimeofday(&_time, NULL);
}
コード例 #2
0
ファイル: fake.c プロジェクト: Ceiu/hyperspace-asss
local Player * CreateFakePlayer(const char *name, Arena *arena, int ship, int freq)
{
	Player *p;

	/* create pid */
	p = pd->NewPlayer(T_FAKE);
	if (!p) return NULL;

	/* set up pdata struct and pretend he's logged in */
	strncpy(p->pkt.name, name, 20);
	astrncpy(p->name, name, 21);
	strncpy(p->pkt.squad, "", 20);
	astrncpy(p->squad, "", 21);
	astrncpy(p->clientname, "<internal fake player>", sizeof(p->clientname));
	p->p_ship = ship;
	p->p_freq = freq;
	p->arena = arena;
	SET_SEND_DAMAGE(p);

	/* enter arena */
	if (net) net->SendToArena(arena, p, (byte*)&p->pkt, 64, NET_RELIABLE);
	if (chatnet) chatnet->SendToArena(arena, p,
			"ENTERING:%s:%d:%d", p->name, ship, freq);
	p->status = S_PLAYING;

	if (lm)
		lm->Log(L_INFO, "<fake> {%s} [%s] fake player created",
				arena->name,
				p->name);

	return p;
}
コード例 #3
0
ファイル: pwcache.c プロジェクト: Ceiu/hyperspace-asss
local void hash_password(const char *name, const char *pwd,
		unsigned char out[HASHLEN], char work[NAMELEN+PWLEN])
{
	struct MD5Context ctx;

	memset(work, 0, NAMELEN+PWLEN);
	astrncpy(work, name, NAMELEN);
	ToLowerStr(work);
	astrncpy(work + NAMELEN, pwd, PWLEN);

	MD5Init(&ctx);
	MD5Update(&ctx, (unsigned char *)work, NAMELEN+PWLEN);
	MD5Final(out, &ctx);
}
コード例 #4
0
ファイル: capman.c プロジェクト: Ceiu/hyperspace-asss
local void RemoveGroup(Player *p, const char *info)
{
	pdata *pdata = PPDATA(p, pdkey);

	if (!p->arena)
		return;

	/* in all cases, set current group to default */
	astrncpy(pdata->group, DEFAULT, MAXGROUPLEN);

	switch (pdata->source)
	{
		case src_default:
			/* player is in the default group already, nothing to do */
			break;

		case src_global:
			cfg->SetStr(staff_conf, AG_GLOBAL, p->name, DEFAULT, info, TRUE);
			break;

		case src_arena:
			cfg->SetStr(staff_conf, p->arena->basename, p->name, DEFAULT, info, TRUE);
			break;

#ifdef CFG_USE_ARENA_STAFF_LIST
		case src_arenalist:
			cfg->SetStr(p->arena->cfg, "Staff", p->name, DEFAULT, info);
			break;
#endif

		case src_temp:
			break;
	}
}
コード例 #5
0
ファイル: log_smod.c プロジェクト: Ceiu/hyperspace-asss
void ReopenLog(void)
{
	const char *ln;
	char fname[256];

	pthread_mutex_lock(&logmtx);

	if (logfile)
		fclose(logfile);

	/* cfghelp: Log:LogFile, global, string, def: asss.log
	 * The name of the log file. */
	ln = cfg->GetStr(GLOBAL, "Log", "SmodLogFile");
	if (!ln) ln = "smod.log";

	/* if it has a /, treat it as an absolute path. otherwise, prepend
	 * 'log/' */
	if (strchr(ln, '/'))
		astrncpy(fname, ln, sizeof(fname));
	else
		snprintf(fname, sizeof(fname), "log/%s", ln);

	logfile = fopen(fname, "a");

	pthread_mutex_unlock(&logmtx);

	LogFile("I <log_smod> opening log file ==================================");
}
コード例 #6
0
ファイル: capman.c プロジェクト: Ceiu/hyperspace-asss
local void SetTempGroup(Player *p, const char *newgroup)
{
	pdata *pdata = PPDATA(p, pdkey);
	if (newgroup)
	{
		astrncpy(pdata->group, newgroup, MAXGROUPLEN);
		pdata->source = src_temp;
	}
}
コード例 #7
0
ファイル: capman.c プロジェクト: Ceiu/hyperspace-asss
local void update_group(Player *p, pdata *pdata, Arena *arena, int log)
{
	const char *g;

	if (!p->flags.authenticated)
	{
		/* if the player hasn't been authenticated against either the
		 * biller or password file, don't assign groups based on name. */
		astrncpy(pdata->group, DEFAULT, MAXGROUPLEN);
		pdata->source = src_default;
		return;
	}

	if (arena && (g = cfg->GetStr(staff_conf, arena->basename, p->name)))
	{
		astrncpy(pdata->group, g, MAXGROUPLEN);
		pdata->source = src_arena;
		if (log)
			lm->LogP(L_DRIVEL, "capman", p, "assigned to group '%s' (arena)", pdata->group);
	}
#ifdef CFG_USE_ARENA_STAFF_LIST
	else if (arena && arena->cfg && (g = cfg->GetStr(arena->cfg, "Staff", p->name)))
	{
		astrncpy(pdata->group, g, MAXGROUPLEN);
		pdata->source = src_arenalist;
		if (log)
			lm->LogP(L_DRIVEL, "capman", p, "assigned to group '%s' (arenaconf)", pdata->group);
	}
#endif
	else if ((g = cfg->GetStr(staff_conf, AG_GLOBAL, p->name)))
	{
		/* only global groups available for now */
		astrncpy(pdata->group, g, MAXGROUPLEN);
		pdata->source = src_global;
		if (log)
			lm->LogP(L_DRIVEL, "capman", p, "assigned to group '%s' (global)", pdata->group);
	}
	else
	{
		astrncpy(pdata->group, DEFAULT, MAXGROUPLEN);
		pdata->source = src_default;
	}
}
コード例 #8
0
ファイル: capman.c プロジェクト: Ceiu/hyperspace-asss
local void paction(Player *p, int action, Arena *arena)
{
	pdata *pdata = PPDATA(p, pdkey);
	if (action == PA_PREENTERARENA)
		update_group(p, pdata, arena, TRUE);
	else if (action == PA_CONNECT)
		update_group(p, pdata, NULL, TRUE);
	else if (action == PA_DISCONNECT || action == PA_LEAVEARENA)
		astrncpy(pdata->group, "none", MAXGROUPLEN);
}
コード例 #9
0
ファイル: capman.c プロジェクト: Ceiu/hyperspace-asss
local void SetPermGroup(Player *p, const char *group, int global, const char *info)
{
	pdata *pdata = PPDATA(p, pdkey);

	/* first set it for the current session */
	astrncpy(pdata->group, group, MAXGROUPLEN);

	/* now set it permanently */
	if (global)
	{
		cfg->SetStr(staff_conf, AG_GLOBAL, p->name, group, info, TRUE);
		pdata->source = src_global;
	}
	else if (p->arena)
	{
		cfg->SetStr(staff_conf, p->arena->basename, p->name, group, info, TRUE);
		pdata->source = src_arena;
	}
}
コード例 #10
0
ファイル: hs_flagtime.c プロジェクト: Ceiu/hyperspace-asss
local void FlagLost(Arena *a, Player *p, int fid, int how)
{
	DEF_AD(a);
	BDEF_PD(p);

	if(how == CLEANUP_DROPPED)
	{
		FlagOwner *owner = amalloc(sizeof(FlagOwner));
		owner->Arena = a;
		astrncpy(owner->Name, p->name, sizeof(p->name));
		owner->Freq = p->pkt.freq;
		owner->FlagID = fid;
		ad->FlagOwners[fid] = owner;

		pdat->DroppedFlags++;
		FlagTeam *team = GetFlagTeam(a, p->pkt.freq);
		team->DroppedFlags++;
	}
}
コード例 #11
0
ファイル: mapnewsdl.c プロジェクト: Ceiu/hyperspace-asss
local void aaction_work(void *clos)
{
	Arena *arena = clos;
	LinkedList *dls = P_ARENA_DATA(arena, dlkey);
	struct MapDownloadData *data = NULL;
	char fname[256];

	/* first add the map itself */
	/* cfghelp: General:Map, arena, string
	 * The name of the level file for this arena. */
	if (mapdata->GetMapFilename(arena, fname, sizeof(fname), NULL))
		data = compress_map(fname, TRUE);

	if (!data)
	{
		/* emergency hardcoded map: */
		byte emergencymap[] =
		{
			0x2a, 0x74, 0x69, 0x6e, 0x79, 0x6d, 0x61, 0x70,
			0x2e, 0x6c, 0x76, 0x6c, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x78, 0x9c, 0x63, 0x60, 0x60, 0x60, 0x04,
			0x00, 0x00, 0x05, 0x00, 0x02
		};

		lm->LogA(L_WARN, "mapnewsdl", arena, "can't load level file, falling back to tinymap.lvl");
		data = amalloc(sizeof(*data));
		data->checksum = 0x5643ef8a;
		data->uncmplen = 4;
		data->cmplen = sizeof(emergencymap);
		data->cmpmap  = amalloc(sizeof(emergencymap));
		memcpy(data->cmpmap, emergencymap, sizeof(emergencymap));
		astrncpy(data->filename, "tinymap.lvl", sizeof(data->filename));
	}

	LLAdd(dls, data);

	/* now look for lvzs */
	mapdata->EnumLVZFiles(arena, one_lvz_file, dls);

	aman->Unhold(arena);
}
コード例 #12
0
ファイル: smartsetup2.c プロジェクト: AllardJ/Tomato
/*
 * This subroutine polls the APC Smart UPS to find out 
 * what capabilities it has.          
 */
int apcsmart_ups_get_capabilities(UPSINFO *ups)
{
   char answer[1000];              /* keep this big to handle big string */
   char caps[1000], *cmds, *p;
   int i;

   write_lock(ups);

   /* Get UPS capabilities string */
   astrncpy(caps, smart_poll(ups->UPS_Cmd[CI_UPS_CAPS], ups), sizeof(caps));
   if (strlen(caps) && (strcmp(caps, "NA") != 0)) {
      ups->UPS_Cap[CI_UPS_CAPS] = TRUE;

      /* skip version */
      for (p = caps; *p && *p != '.'; p++)
         ;

      /* skip alert characters */
      for (; *p && *p != '.'; p++)
         ;

      cmds = p;                    /* point to commands */
      if (!*cmds) {                /* oops, none */
         cmds = NULL;
         ups->UPS_Cap[CI_UPS_CAPS] = FALSE;
      }
   } else {
      cmds = NULL;                 /* No commands string */
   }

   /*
    * Try all the possible UPS capabilities and mark the ones supported.
    * If we can get the eprom caps list, use them to jump over the
    * unsupported caps, if we can't get the cap list try every known
    * capability.
    */
   for (i = 0; i <= CI_MAX_CAPS; i++) {
      if (ups->UPS_Cmd[i] == 0)
         continue;
      if (!cmds || strchr(cmds, ups->UPS_Cmd[i]) != NULL) {
         astrncpy(answer, smart_poll(ups->UPS_Cmd[i], ups), sizeof(answer));
         if (*answer && (strcmp(answer, "NA") != 0)) {
            ups->UPS_Cap[i] = true;
         }
      }
   }

   /*
    * If UPS did not support APC_CMD_UPSMODEL (the default comand for 
    * CI_UPSMODEL), maybe it supports APC_CMD_OLDFWREV which can be used to 
    * construct the model number.
    */
   if (!ups->UPS_Cap[CI_UPSMODEL] && 
       (!cmds || strchr(cmds, APC_CMD_OLDFWREV) != NULL)) {
      astrncpy(answer, smart_poll(APC_CMD_OLDFWREV, ups), sizeof(answer));
      if (*answer && (strcmp(answer, "NA") != 0)) {
         ups->UPS_Cap[CI_UPSMODEL] = true;
         ups->UPS_Cmd[CI_UPSMODEL] = APC_CMD_OLDFWREV;
      }
   }

   /*
    * If UPS does not support APC_CMD_REVNO (the default command for CI_REVNO),
    * maybe it supports APC_CMD_OLDFWREV instead.
    */
   if (!ups->UPS_Cap[CI_REVNO] && 
       (!cmds || strchr(cmds, APC_CMD_OLDFWREV) != NULL)) {
      astrncpy(answer, smart_poll(APC_CMD_OLDFWREV, ups), sizeof(answer));
      if (*answer && (strcmp(answer, "NA") != 0)) {
         ups->UPS_Cap[CI_REVNO] = true;
         ups->UPS_Cmd[CI_REVNO] = APC_CMD_OLDFWREV;
      }
   }

   write_unlock(ups);

   return 1;
}
コード例 #13
0
ファイル: capman.c プロジェクト: Ceiu/hyperspace-asss
local void new_player(Player *p, int isnew)
{
	char *group = ((pdata*)PPDATA(p, pdkey))->group;
	if (isnew)
		astrncpy(group, "none", MAXGROUPLEN);
}
コード例 #14
0
ファイル: smart.c プロジェクト: AllardJ/Tomato
/********************************************************************* 
 *
 *  This subroutine is called to load our shared memory with
 *  information that is changing inside the UPS depending
 *  on the state of the UPS and the mains power.
 */
int apcsmart_ups_read_volatile_data(UPSINFO *ups)
{
   time_t now;
   char *answer;

   /*
    * We need it for self-test start time.
    */
   now = time(NULL);

   write_lock(ups);

   UPSlinkCheck(ups);              /* make sure serial port is working */

   ups->poll_time = time(NULL);    /* save time stamp */

   /* UPS_STATUS */
   if (ups->UPS_Cap[CI_STATUS]) {
      char status[10];
      int retries = 5;             /* Number of retries on status read */

    again:
      answer = smart_poll(ups->UPS_Cmd[CI_STATUS], ups);
      Dmsg1(80, "Got CI_STATUS: %s\n", answer);
      strncpy(status, answer, sizeof(status));

      /*
       * The Status command may return "SM" probably because firmware
       * is in a state where it still didn't updated its internal status
       * register. In this case retry to read the register. To be sure
       * not to get stuck here, we retry only 5 times.
       *
       * XXX
       *
       * If this fails, apcupsd may not be able to detect a status
       * change and will have unpredictable behavior. This will be fixed
       * once we will handle correctly the own apcupsd Status word.
       */
      if (status[0] == 'S' && status[1] == 'M' && (retries-- > 0))
         goto again;

      ups->Status &= ~0xFF;        /* clear APC byte */
      ups->Status |= strtoul(status, NULL, 16) & 0xFF;  /* set APC byte */
   }

   /* ONBATT_STATUS_FLAG -- line quality */
   if (ups->UPS_Cap[CI_LQUAL]) {
      answer = smart_poll(ups->UPS_Cmd[CI_LQUAL], ups);
      Dmsg1(80, "Got CI_LQUAL: %s\n", answer);
      astrncpy(ups->linequal, answer, sizeof(ups->linequal));
   }

   /* Reason for last transfer to batteries */
   if (ups->UPS_Cap[CI_WHY_BATT]) {
      answer = smart_poll(ups->UPS_Cmd[CI_WHY_BATT], ups);
      Dmsg1(80, "Got CI_WHY_BATT: %s\n", answer);
      ups->lastxfer = decode_lastxfer(answer);
      /*
       * XXX
       *
       * See if this is a self test rather than power failure
       * But not now !
       * When we will be ready we will copy the code below inside
       * the driver entry point, for performing this check inside the
       * driver.
       */
   }

   /* Results of last self test */
   if (ups->UPS_Cap[CI_ST_STAT]) {
      answer = smart_poll(ups->UPS_Cmd[CI_ST_STAT], ups);
      Dmsg1(80, "Got CI_ST_STAT: %s\n", answer);
      ups->testresult = decode_testresult(answer);
   }

   /* LINE_VOLTAGE */
   if (ups->UPS_Cap[CI_VLINE]) {
      answer = smart_poll(ups->UPS_Cmd[CI_VLINE], ups);
      Dmsg1(80, "Got CI_VLINE: %s\n", answer);
      ups->LineVoltage = atof(answer);
   }

   /* UPS_LINE_MAX */
   if (ups->UPS_Cap[CI_VMAX]) {
      answer = smart_poll(ups->UPS_Cmd[CI_VMAX], ups);
      Dmsg1(80, "Got CI_VMAX: %s\n", answer);
      ups->LineMax = atof(answer);
   }

   /* UPS_LINE_MIN */
   if (ups->UPS_Cap[CI_VMIN]) {
      answer = smart_poll(ups->UPS_Cmd[CI_VMIN], ups);
      Dmsg1(80, "Got CI_VMIN: %s\n", answer);
      ups->LineMin = atof(answer);
   }

   /* OUTPUT_VOLTAGE */
   if (ups->UPS_Cap[CI_VOUT]) {
      answer = smart_poll(ups->UPS_Cmd[CI_VOUT], ups);
      Dmsg1(80, "Got CI_VOUT: %s\n", answer);
      ups->OutputVoltage = atof(answer);
   }

   /* BATT_FULL Battery level percentage */
   if (ups->UPS_Cap[CI_BATTLEV]) {
      answer = smart_poll(ups->UPS_Cmd[CI_BATTLEV], ups);
      Dmsg1(80, "Got CI_BATTLEV: %s\n", answer);
      ups->BattChg = atof(answer);
   }

   /* BATT_VOLTAGE */
   if (ups->UPS_Cap[CI_VBATT]) {
      answer = smart_poll(ups->UPS_Cmd[CI_VBATT], ups);
      Dmsg1(80, "Got CI_VBATT: %s\n", answer);
      ups->BattVoltage = atof(answer);
   }

   /* UPS_LOAD */
   if (ups->UPS_Cap[CI_LOAD]) {
      answer = smart_poll(ups->UPS_Cmd[CI_LOAD], ups);
      Dmsg1(80, "Got CI_LOAD: %s\n", answer);
      ups->UPSLoad = atof(answer);
   }

   /* LINE_FREQ */
   if (ups->UPS_Cap[CI_FREQ]) {
      answer = smart_poll(ups->UPS_Cmd[CI_FREQ], ups);
      Dmsg1(80, "Got CI_FREQ: %s\n", answer);
      ups->LineFreq = atof(answer);
   }

   /* UPS_RUNTIME_LEFT */
   if (ups->UPS_Cap[CI_RUNTIM]) {
      answer = smart_poll(ups->UPS_Cmd[CI_RUNTIM], ups);
      Dmsg1(80, "Got CI_RUNTIM: %s\n", answer);
      ups->TimeLeft = atof(answer);
   }

   /* UPS_TEMP */
   if (ups->UPS_Cap[CI_ITEMP]) {
      answer = smart_poll(ups->UPS_Cmd[CI_ITEMP], ups);
      Dmsg1(80, "Got CI_ITEMP: %s\n", answer);
      ups->UPSTemp = atof(answer);
   }

   /* DIP_SWITCH_SETTINGS */
   if (ups->UPS_Cap[CI_DIPSW]) {
      answer = smart_poll(ups->UPS_Cmd[CI_DIPSW], ups);
      Dmsg1(80, "Got CI_DIPSW: %s\n", answer);
      ups->dipsw = strtoul(answer, NULL, 16);
   }

   /* Register 1 */
   if (ups->UPS_Cap[CI_REG1]) {
      answer = smart_poll(ups->UPS_Cmd[CI_REG1], ups);
      Dmsg1(80, "Got CI_REG1: %s\n", answer);
      ups->reg1 = strtoul(answer, NULL, 16);
   }

   /* Register 2 */
   if (ups->UPS_Cap[CI_REG2]) {
      answer = smart_poll(ups->UPS_Cmd[CI_REG2], ups);
      Dmsg1(80, "Got CI_REG2: %s\n", answer);
      ups->reg2 = strtoul(answer, NULL, 16);
      ups->set_battpresent(!(ups->reg2 & 0x20));
   }

   /* Register 3 */
   if (ups->UPS_Cap[CI_REG3]) {
      answer = smart_poll(ups->UPS_Cmd[CI_REG3], ups);
      Dmsg1(80, "Got CI_REG3: %s\n", answer);
      ups->reg3 = strtoul(answer, NULL, 16);
   }

   /* Humidity percentage */
   if (ups->UPS_Cap[CI_HUMID]) {
      answer = smart_poll(ups->UPS_Cmd[CI_HUMID], ups);
      Dmsg1(80, "Got CI_HUMID: %s\n", answer);
      ups->humidity = atof(answer);
   }

   /* Ambient temperature */
   if (ups->UPS_Cap[CI_ATEMP]) {
      answer = smart_poll(ups->UPS_Cmd[CI_ATEMP], ups);
      Dmsg1(80, "Got CI_ATEMP: %s\n", answer);
      ups->ambtemp = atof(answer);
   }

   /* Hours since self test */
   if (ups->UPS_Cap[CI_ST_TIME]) {
      answer = smart_poll(ups->UPS_Cmd[CI_ST_TIME], ups);
      Dmsg1(80, "Got CI_ST_TIME: %s\n", answer);
      ups->LastSTTime = atof(answer);
   }

   apc_enable(ups);                /* reenable APC serial UPS */

   write_unlock(ups);

   return SUCCESS;
}
コード例 #15
0
ファイル: smart.c プロジェクト: AllardJ/Tomato
/********************************************************************* 
 *
 *  This subroutine is called to load our shared memory with
 *  information that is static inside the UPS.        Hence it
 *  normally would only be called once when starting up the
 *  UPS.
 */
int apcsmart_ups_read_static_data(UPSINFO *ups)
{
   char *answer;

   /* Everything from here on down is non-volitile, that is
    * we do not expect it to change while the UPS is running
    * unless we explicitly change it.
    */

   /* SENSITIVITY */
   if (ups->UPS_Cap[CI_SENS]) {
      answer = smart_poll(ups->UPS_Cmd[CI_SENS], ups);
      Dmsg1(80, "Got CI_SENS: %s\n", answer);
      astrncpy(ups->sensitivity, answer, sizeof(ups->sensitivity));
   }

   /* WAKEUP_DELAY */
   if (ups->UPS_Cap[CI_DWAKE]) {
      answer = smart_poll(ups->UPS_Cmd[CI_DWAKE], ups);
      Dmsg1(80, "Got CI_DWAKE: %s\n", answer);
      ups->dwake = (int)atof(answer);
   }

   /* SLEEP_DELAY */
   if (ups->UPS_Cap[CI_DSHUTD]) {
      answer = smart_poll(ups->UPS_Cmd[CI_DSHUTD], ups);
      Dmsg1(80, "Got CI_DSHUTD: %s\n", answer);
      ups->dshutd = (int)atof(answer);
   }

   /* LOW_TRANSFER_LEVEL */
   if (ups->UPS_Cap[CI_LTRANS]) {
      answer = smart_poll(ups->UPS_Cmd[CI_LTRANS], ups);
      Dmsg1(80, "Got CI_LTRANS: %s\n", answer);
      ups->lotrans = (int)atof(answer);
   }

   /* HIGH_TRANSFER_LEVEL */
   if (ups->UPS_Cap[CI_HTRANS]) {
      answer = smart_poll(ups->UPS_Cmd[CI_HTRANS], ups);
      Dmsg1(80, "Got CI_HTRANS: %s\n", answer);
      ups->hitrans = (int)atof(answer);
   }

   /* UPS_BATT_CAP_RETURN */
   if (ups->UPS_Cap[CI_RETPCT]) {
      answer = smart_poll(ups->UPS_Cmd[CI_RETPCT], ups);
      Dmsg1(80, "Got CI_RETPCT: %s\n", answer);
      ups->rtnpct = (int)atof(answer);
   }

   /* ALARM_STATUS */
   if (ups->UPS_Cap[CI_DALARM]) {
      answer = smart_poll(ups->UPS_Cmd[CI_DALARM], ups);
      Dmsg1(80, "Got CI_DALARM: %s\n", answer);
      astrncpy(ups->beepstate, answer, sizeof(ups->beepstate));
   }

   /* LOWBATT_SHUTDOWN_LEVEL */
   if (ups->UPS_Cap[CI_DLBATT]) {
      answer = smart_poll(ups->UPS_Cmd[CI_DLBATT], ups);
      Dmsg1(80, "Got CI_DLBATT: %s\n", answer);
      ups->dlowbatt = (int)atof(answer);
   }

   /* UPS_NAME */
   if (ups->upsname[0] == 0 && ups->UPS_Cap[CI_IDEN]) {
      answer = smart_poll(ups->UPS_Cmd[CI_IDEN], ups);
      Dmsg1(80, "Got CI_IDEN: %s\n", answer);
      astrncpy(ups->upsname, answer, sizeof(ups->upsname));
   }

   /* UPS_SELFTEST */
   if (ups->UPS_Cap[CI_STESTI]) {
      answer = smart_poll(ups->UPS_Cmd[CI_STESTI], ups);
      Dmsg1(80, "Got CI_STESTI: %s\n", answer);
      astrncpy(ups->selftest, answer, sizeof(ups->selftest));
   }

   /* UPS_MANUFACTURE_DATE */
   if (ups->UPS_Cap[CI_MANDAT]) {
      answer = smart_poll(ups->UPS_Cmd[CI_MANDAT], ups);
      Dmsg1(80, "Got CI_MANDAT: %s\n", answer);
      astrncpy(ups->birth, answer, sizeof(ups->birth));
   }

   /* UPS_SERIAL_NUMBER */
   if (ups->UPS_Cap[CI_SERNO]) {
      answer = smart_poll(ups->UPS_Cmd[CI_SERNO], ups);
      Dmsg1(80, "Got CI_SERNO: %s\n", answer);
      astrncpy(ups->serial, answer, sizeof(ups->serial));
   }

   /* UPS_BATTERY_REPLACE */
   if (ups->UPS_Cap[CI_BATTDAT]) {
      answer = smart_poll(ups->UPS_Cmd[CI_BATTDAT], ups);
      Dmsg1(80, "Got CI_BATTDAT: %s\n", answer);
      astrncpy(ups->battdat, answer, sizeof(ups->battdat));
   }

   /* Nominal output voltage when on batteries */
   if (ups->UPS_Cap[CI_NOMOUTV]) {
      answer = smart_poll(ups->UPS_Cmd[CI_NOMOUTV], ups);
      Dmsg1(80, "Got CI_NOMOUTV: %s\n", answer);
      ups->NomOutputVoltage = (int)atof(answer);
   }

   /* Nominal battery voltage */
   if (ups->UPS_Cap[CI_NOMBATTV]) {
      answer = smart_poll(ups->UPS_Cmd[CI_NOMBATTV], ups);
      Dmsg1(80, "Got CI_NOMBATTV: %s\n", answer);
      ups->nombattv = atof(answer);
   }

   /* Firmware revision */
   if (ups->UPS_Cap[CI_REVNO]) {
      answer = smart_poll(ups->UPS_Cmd[CI_REVNO], ups);
      Dmsg1(80, "Got CI_REVNO: %s\n", answer);
      astrncpy(ups->firmrev, answer, sizeof(ups->firmrev));
   }

   /* Number of external batteries installed */
   if (ups->UPS_Cap[CI_EXTBATTS]) {
      answer = smart_poll(ups->UPS_Cmd[CI_EXTBATTS], ups);
      Dmsg1(80, "Got CI_EXTBATTS: %s\n", answer);
      ups->extbatts = (int)atof(answer);
   }

   /* Number of bad batteries installed */
   if (ups->UPS_Cap[CI_BADBATTS]) {
      answer = smart_poll(ups->UPS_Cmd[CI_BADBATTS], ups);
      Dmsg1(80, "Got CI_BADBATTS: %s\n", answer);
      ups->badbatts = (int)atof(answer);
   }

   /* UPS model */
   if (ups->UPS_Cap[CI_UPSMODEL]) {
      answer = smart_poll(ups->UPS_Cmd[CI_UPSMODEL], ups);
      if (ups->UPS_Cmd[CI_UPSMODEL] == APC_CMD_OLDFWREV) {
         /* Derive UPS model from old fw rev */
         astrncpy(ups->upsmodel, get_model_from_oldfwrev(answer), 
                  sizeof(ups->upsmodel));
      } else {
         astrncpy(ups->upsmodel, answer, sizeof(ups->upsmodel));
      }
      Dmsg1(80, "Got CI_UPSMODEL: %s\n", ups->upsmodel);
   }

   /* EPROM Capabilities */
   if (ups->UPS_Cap[CI_EPROM]) {
      answer = smart_poll(ups->UPS_Cmd[CI_EPROM], ups);
      Dmsg1(80, "Got CI_EPROM: %s\n", answer);
      astrncpy(ups->eprom, answer, sizeof(ups->eprom));
   }

   return SUCCESS;
}
コード例 #16
0
ファイル: drv_powernet.c プロジェクト: AllardJ/Tomato
int powernet_snmp_ups_read_static_data(UPSINFO *ups)
{
   struct snmp_ups_internal_data *Sid = 
      (struct snmp_ups_internal_data *)ups->driver_internal_data;
   struct snmp_session *s = &Sid->session;
   powernet_mib_t *data = (powernet_mib_t *)Sid->MIB;

   if (powernet_check_comm_lost(ups) == 0)
      return 0;

   data->upsBasicIdent = NULL;
   powernet_mib_mgr_get_upsBasicIdent(s, &(data->upsBasicIdent));
   if (data->upsBasicIdent) {
      SNMP_STRING(upsBasicIdent, Model, upsmodel);
      SNMP_STRING(upsBasicIdent, Name, upsname);
      free(data->upsBasicIdent);
   }

   data->upsAdvIdent = NULL;
   powernet_mib_mgr_get_upsAdvIdent(s, &(data->upsAdvIdent));
   if (data->upsAdvIdent) {
      SNMP_STRING(upsAdvIdent, FirmwareRevision, firmrev);
      SNMP_STRING(upsAdvIdent, DateOfManufacture, birth);
      SNMP_STRING(upsAdvIdent, SerialNumber, serial);
      free(data->upsAdvIdent);
   }

   data->upsBasicBattery = NULL;
   powernet_mib_mgr_get_upsBasicBattery(s, &(data->upsBasicBattery));
   if (data->upsBasicBattery) {
      SNMP_STRING(upsBasicBattery, LastReplaceDate, battdat);
      free(data->upsBasicBattery);
   }

   data->upsAdvBattery = NULL;
   powernet_mib_mgr_get_upsAdvBattery(s, &(data->upsAdvBattery));
   if (data->upsAdvBattery) {
      ups->extbatts = data->upsAdvBattery->__upsAdvBatteryNumOfBattPacks;
      ups->badbatts = data->upsAdvBattery->__upsAdvBatteryNumOfBadBattPacks;
      free(data->upsAdvBattery);
   }

   data->upsAdvConfig = NULL;
   powernet_mib_mgr_get_upsAdvConfig(s, &(data->upsAdvConfig));
   if (data->upsAdvConfig) {
      ups->NomOutputVoltage = data->upsAdvConfig->__upsAdvConfigRatedOutputVoltage;
      ups->hitrans = data->upsAdvConfig->__upsAdvConfigHighTransferVolt;
      ups->lotrans = data->upsAdvConfig->__upsAdvConfigLowTransferVolt;
      switch (data->upsAdvConfig->__upsAdvConfigAlarm) {
      case 1:
         if (data->upsAdvConfig->__upsAdvConfigAlarmTimer / 100 < 30)
            astrncpy(ups->beepstate, "0 Seconds", sizeof(ups->beepstate));
         else
            astrncpy(ups->beepstate, "Timed", sizeof(ups->beepstate));
         break;
      case 2:
         astrncpy(ups->beepstate, "LowBatt", sizeof(ups->beepstate));
         break;
      case 3:
         astrncpy(ups->beepstate, "NoAlarm", sizeof(ups->beepstate));
         break;
      default:
         astrncpy(ups->beepstate, "Timed", sizeof(ups->beepstate));
         break;
      }

      ups->rtnpct = data->upsAdvConfig->__upsAdvConfigMinReturnCapacity;

      switch (data->upsAdvConfig->__upsAdvConfigSensitivity) {
      case 1:
         astrncpy(ups->sensitivity, "Auto", sizeof(ups->sensitivity));
         break;
      case 2:
         astrncpy(ups->sensitivity, "Low", sizeof(ups->sensitivity));
         break;
      case 3:
         astrncpy(ups->sensitivity, "Medium", sizeof(ups->sensitivity));
         break;
      case 4:
         astrncpy(ups->sensitivity, "High", sizeof(ups->sensitivity));
         break;
      default:
         astrncpy(ups->sensitivity, "Unknown", sizeof(ups->sensitivity));
         break;
      }

      /* Data in Timeticks (1/100th sec). */
      ups->dlowbatt = data->upsAdvConfig->__upsAdvConfigLowBatteryRunTime / 6000;
      ups->dwake = data->upsAdvConfig->__upsAdvConfigReturnDelay / 100;
      ups->dshutd = data->upsAdvConfig->__upsAdvConfigShutoffDelay / 100;
      free(data->upsAdvConfig);
   }

   data->upsAdvTest = NULL;
   powernet_mib_mgr_get_upsAdvTest(s, &(data->upsAdvTest));
   if (data->upsAdvTest) {
      switch (data->upsAdvTest->__upsAdvTestDiagnosticSchedule) {
      case 1:
         astrncpy(ups->selftest, "unknown", sizeof(ups->selftest));
         break;
      case 2:
         astrncpy(ups->selftest, "biweekly", sizeof(ups->selftest));
         break;
      case 3:
         astrncpy(ups->selftest, "weekly", sizeof(ups->selftest));
         break;
      case 4:
         astrncpy(ups->selftest, "atTurnOn", sizeof(ups->selftest));
         break;
      case 5:
         astrncpy(ups->selftest, "never", sizeof(ups->selftest));
         break;
      default:
         astrncpy(ups->selftest, "unknown", sizeof(ups->selftest));
         break;
      }

      switch (data->upsAdvTest->__upsAdvTestDiagnosticsResults) {
      case 1:  /* Passed */
         ups->testresult = TEST_PASSED;
         break;
      case 2:  /* Failed */
      case 3:  /* Invalid test */
         ups->testresult = TEST_FAILED;
         break;
      case 4:  /* Test in progress */
         ups->testresult = TEST_INPROGRESS;
         break;
      default:
         ups->testresult = TEST_UNKNOWN;
         break;
      }

      free(data->upsAdvTest);
   }

   return 1;
}
コード例 #17
0
ファイル: bw_nolimit.c プロジェクト: Ceiu/hyperspace-asss
local void GetInfo(BWLimit *bw, char *buf, int buflen)
{
	astrncpy(buf, "(no limit)", buflen);
}
コード例 #18
0
ファイル: mapnewsdl.c プロジェクト: Ceiu/hyperspace-asss
local struct MapDownloadData * compress_map(const char *fname, int docomp)
{
	byte *cmap;
	uLong csize;
	const char *mapname;
	struct MapDownloadData *data;
	MMapData *mmd;

	data = amalloc(sizeof(*data));

	/* get basename */
	mapname = strrchr(fname, '/');
	if (!mapname)
		mapname = fname;
	else
		mapname++;
	astrncpy(data->filename, mapname, 20);

	mmd = MapFile(fname, FALSE);
	if (!mmd)
		goto fail1;

	/* calculate crc on mmap'd map */
	data->checksum = crc32(crc32(0, Z_NULL, 0), mmd->data, mmd->len);
	data->uncmplen = mmd->len;

	/* allocate space for compressed version */
	if (docomp)
		csize = (uLong)(1.0011 * mmd->len + 35);
	else
		csize = mmd->len + 17;

	cmap = malloc(csize);
	if (!cmap)
	{
		lm->Log(L_ERROR, "<mapnewsdl> malloc failed in compress_map for %s", fname);
		goto fail2;
	}

	/* set up packet header */
	cmap[0] = S2C_MAPDATA;
	strncpy((char*)(cmap+1), mapname, 16);

	if (docomp)
	{
		/* compress the stuff! */
		compress(cmap+17, &csize, mmd->data, mmd->len);
		csize += 17;

		/* shrink the allocated memory */
		data->cmpmap = realloc(cmap, csize);
		if (data->cmpmap == NULL)
		{
			lm->Log(L_ERROR, "<mapnewsdl> realloc failed in compress_map for %s", fname);
			goto fail3;
		}
	}
	else
	{
		/* just copy */
		memcpy(cmap+17, mmd->data, mmd->len);
		data->cmpmap = cmap;
	}

	data->cmplen = csize;

	if (csize > 256*1024)
		lm->Log(L_WARN, "<mapnewsdl> compressed map/lvz is bigger than 256k: %s", fname);

	UnmapFile(mmd);

	return data;

fail3:
	free(cmap);
fail2:
	UnmapFile(mmd);
fail1:
	afree(data);
	return NULL;
}
コード例 #19
0
ファイル: mark.c プロジェクト: Ceiu/hyperspace-asss
local void Cmark(const char *tc, const char *params, Player *p, const Target *target)
{
	kothmark *md;

	md = (kothmark*)PPDATA(p, markey);

	if (*params || (target->type == T_PLAYER))
	{
		marklistednode *node;
		const char *name;
		Player *pp;

		if (*params)
		{
			pp = 0;
			name = params;
		}
		else
		{
			pp = target->u.p;
			name = pp->name;
		}

#ifdef MARK_SELF_MESSAGE
		if (strcasecmp(p->name, name) == 0) {
			chat->SendMessage(p,MARK_SELF_MESSAGE);
			return;
		}
#endif
		if (strlen(name) >= MARK_NAME_LENGTH_MAX) {
			chat->SendMessage(p,"Mark names must be under %i characters",MARK_NAME_LENGTH_MAX);
			return;
		}
		if (md->listCount >= MARK_MAX_LISTED) {
			chat->SendMessage(p,"You may not mark more than %i players",MARK_MAX_LISTED);
			return;
		}
		if (markExists(md,name)) {
#ifdef ACK_MARK_COMMANDS
			chat->SendMessage(p,"You have already marked %s", name);
#endif
			return;
		}

		node = amalloc(sizeof(marklistednode));

		RETURN_IF(!node)

		astrncpy(node->name, name, MARK_NAME_LENGTH_MAX);

		LLAdd(&md->listed,node);
		++md->listCount;

#ifdef ACK_MARK_COMMANDS
		chat->SendMessage(p,"Marked %s",name);
#endif

		if (!pp) {
			pp = pd->FindPlayer(name);
			RETURN_IF(!pp)
		}