Ejemplo n.º 1
0
void open_chat_log() {
    char starttime[200], sttime[200];
    struct tm *l_time;
    time_t c_time;

    char chat_log_file[100];
    char srv_log_file[100];

    time(&c_time);
    l_time = localtime(&c_time);

    if (get_rotate_chat_log())
    {
        char logsuffix[7];
        strftime(logsuffix, sizeof(logsuffix), "%Y%m", l_time);
        safe_snprintf (chat_log_file, sizeof (chat_log_file),  "chat_log_%s.txt", logsuffix);
        safe_snprintf (srv_log_file, sizeof (srv_log_file), "srv_log_%s.txt", logsuffix);
    }
    else
    {
        safe_strncpy(chat_log_file, "chat_log.txt", sizeof(chat_log_file));
        safe_strncpy(srv_log_file, "srv_log.txt", sizeof(srv_log_file));
    }

    chat_log = open_file_config (chat_log_file, "a");
    if (log_chat == LOG_SERVER || log_chat == LOG_SERVER_SEPERATE)
        srv_log = open_file_config (srv_log_file, "a");
    if (chat_log == NULL)
    {
        LOG_TO_CONSOLE(c_red3, "Unable to open log file to write. We will NOT be recording anything.");
        log_chat = LOG_NONE;
        return;
    }
    else if ((log_chat == LOG_SERVER || log_chat == LOG_SERVER_SEPERATE) && srv_log == NULL)
    {
        LOG_TO_CONSOLE(c_red3, "Unable to open server log file to write. We will fall back to recording everything in chat_log.txt.");
        log_chat = LOG_CHAT;
        return;
    }
    strftime(sttime, sizeof(sttime), "\n\nLog started at %Y-%m-%d %H:%M:%S localtime", l_time);
    safe_snprintf(starttime, sizeof(starttime), "%s (%s)\n\n", sttime, tzname[l_time->tm_isdst>0]);
    fwrite (starttime, strlen(starttime), 1, chat_log);
}
Ejemplo n.º 2
0
void            ResetLog()
{
    if (g_log)
    {
        char            logfilename[_MAX_PATH];

        safe_snprintf(logfilename, _MAX_PATH, "%s.log", g_Mapname);
        _unlink(logfilename);
    }
}
Ejemplo n.º 3
0
int chilli_module_load(void **ctx, char *name)
{
	struct chilli_module *m;
	char path[512];
	void *lib_handle;
	char *error;
	void *sym;
	int len;

	safe_snprintf(path, sizeof(path), "%s/%s.so",
		      _options.moddir ? _options.moddir : DEFLIBDIR, name);

	lib_handle = dlopen(path, RTLD_NOW | RTLD_LOCAL);

	if (!lib_handle) {
		log_err(errno, "chilli_module_load() %s", dlerror());
		return -1;
	}

	safe_snprintf(path, sizeof(path), "%s_module", name);

	len = strlen(path);
	while (len-- > 0)
		if (path[len] == '-')
			path[len] = '_';

	sym = dlsym(lib_handle, path);
	if ((error = dlerror()) != NULL) {
		dlclose(lib_handle);
		log_err(errno, "%s", error);
		return -1;
	}

	m = (struct chilli_module *)sym;
	m->lib = lib_handle;

	log_dbg("Loaded module %s", name);

	*ctx = m;

	return 0;
}
Ejemplo n.º 4
0
int redis_zset::zrangebyscore_get(const char* cmd, const char* key,
	const char* min, const char* max, std::vector<string>* out,
	const int* offset /* = NULL */, const int* count /* = NULL */)
{
	const char* argv[8];
	size_t lens[8];
	size_t argc = 4;

	argv[0] = cmd;
	lens[0] = strlen(cmd);

	argv[1] = key;
	lens[1] = strlen(key);

	argv[2] = min;
	lens[2] = strlen(min);

	argv[3] = max;
	lens[3] = strlen(max);

	char offset_s[INTLEN], count_s[INTLEN];
	if (offset && count)
	{
		safe_snprintf(offset_s, sizeof(offset_s), "%d", *offset);
		safe_snprintf(count_s, sizeof(count_s), "%d", *count);

		argv[4] = "LIMIT";
		lens[4] = sizeof("LIMIT") - 1;

		argv[5] = offset_s;
		lens[5] = strlen(offset_s);

		argv[6] = count_s;
		lens[6] = strlen(count_s);

		argc += 3;
	}

	hash_slot(key);
	build_request(argc, argv, lens);
	return get_strings(out);
}
Ejemplo n.º 5
0
void createAllHostsMap(void) {
  HostTraffic *el;
  int num_hosts = 0;

  sendString((char*)map_head);
  //sendString(googleMapsKey);
  sendString((char*)map_head2);
  sendString((char*)map_head3);
  sendString((char*)map_head4);
  
  for(el=getFirstHost(myGlobals.actualReportDeviceId);
      el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {
    if(el->geo_ip) {
      char buf[512];
#if 0
      char buf1[256] = { 0 };
      int showSymIp;

      if((el->hostResolvedName[0] != '\0')
	 && strcmp(el->hostResolvedName, el->hostNumIpAddress)
	 && (!subnetPseudoLocalHost(el)))
	showSymIp = 1;
      else
	showSymIp = 0;
#endif

      safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf),
 		    "createMarker(new google.maps.LatLng(%.2f, %.2f), \""
#if 0
		    "%s%s"
#endif
		    "<A HREF=/%s.html>%s</A><br>%s<br>%s\");\n", 
		    el->geo_ip->latitude, el->geo_ip->longitude,
#if 0
		    showSymIp ? escape_string(el->hostResolvedName, buf1, sizeof(buf1)) : "", showSymIp ? "<br>" : "",
#endif
		    el->hostNumIpAddress, el->hostNumIpAddress,
		    el->geo_ip->city ? el->geo_ip->city : "", 
		    el->geo_ip->country_name ? el->geo_ip->country_name : "");
      sendString(buf);
      num_hosts++;
      if(num_hosts > MAX_NUM_MAP_HOSTS) break; /* Too many hosts */
    }
  }

  sendString((char*)map_tail);

  if(num_hosts > MAX_NUM_MAP_HOSTS)
    sendString("<p><center><b><font color=red>WARNING:</font></b>You have more hosts to display than the number typically supported by Google maps. Some hosts have not been rendered.</center></p>");

//  sendString("<p><center><b><font color=red>NOTE:</font></b> ");
//  sendString("make sure you get your key <a href=http://code.google.com/apis/maps/>here</A>"
//	  " for using Google Maps from ntop and register it as \'google_maps.key\' key <A href=/"CONST_EDIT_PREFS"#google_maps.key>here</A>.</center></p>\n"); 
}
Ejemplo n.º 6
0
static int writePid( int fd, pid_t pid )
{
    char achBuf[20];
    int len = safe_snprintf( achBuf, 20, "%d\n", (int)pid );
    if ( ftruncate( fd, 0 ) || (nio_write( fd, achBuf, len ) != len)  )
    {
        nio_close( fd );
        return -1;
    }
    return fd;
}
Ejemplo n.º 7
0
// =====================================================================================
//  hlassume
//      my assume
// =====================================================================================
void            hlassume(bool exp, assume_msgs msgid)
{
    if (!exp)
    {
        char            message[MAX_MESSAGE];
        const MessageTable_t* msg = GetAssume(msgid);

        safe_snprintf(message, MAX_MESSAGE, "%s\nDescription: %s\nHowto Fix: %s\n", msg->title, msg->text, msg->howto);
        Error(message);
    }
}
Ejemplo n.º 8
0
char* formatSeconds(unsigned long sec, char* outStr, int outStrLen) {
  u_int hour = 0, min = 0, days = 0;

  if(sec >= 3600) {
    hour = (u_int)(sec / 3600);

    if(hour > 0) {
      if(hour >= 24) {
	days = (hour / 24);
	hour = hour % 24;
	sec -= days*86400;
      }
      sec -= hour*3600;
    } else
      hour = 0;
  }

  min = (u_int)(sec / 60);
  if(min > 0) sec -= min*60;

  if(days > 0) {
    char yearStr[32];

    if(days > 365) {
      safe_snprintf(__FILE__, __LINE__, yearStr, sizeof(yearStr), "%d years, ", days/365);
      days %= 365;
    } else
      yearStr[0] = '\0';

    safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%s%u day%s %u:%02u:%02lu", 
		  yearStr, days, (days>1)?"s":"", hour, min, sec);
  } else if(hour > 0) {
    safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%u:%02u:%02lu", hour, min, sec);
  } else if(min > 0) {
    safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%u:%02lu", min, sec);
  } else {
    safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%lu sec", sec);
  }

  return(outStr);
}
Ejemplo n.º 9
0
void rtmon_print_ifaces(struct rtmon_t *rtmon, int fd) {
  char line[512];
  int i;

  safe_snprintf(line,512,"\nSystem Interfaces\n");
  safe_write(fd, line, strlen(line));

  for (i=0; i < rtmon->_iface_sz; i++) {

    if (rtmon->_ifaces[i].has_data) {
      unsigned char *u = rtmon->_ifaces[i].hwaddr;

      safe_snprintf(line,512,"%d) %s (%d)",
		    i, rtmon->_ifaces[i].devname, rtmon->_ifaces[i].index);
      safe_write(fd, line, strlen(line));

      if (rtmon->_ifaces[i].address.s_addr) {
	safe_snprintf(line,512," ip=%s", inet_ntoa(rtmon->_ifaces[i].address));
	safe_write(fd, line, strlen(line));
      }

      safe_snprintf(line,512," net=%s", inet_ntoa(rtmon->_ifaces[i].network));
      safe_write(fd, line, strlen(line));

      safe_snprintf(line,512," mask=%s", inet_ntoa(rtmon->_ifaces[i].netmask));
      safe_write(fd, line, strlen(line));

      if (rtmon->_ifaces[i].broadcast.s_addr) {
	safe_snprintf(line,512," bcase=%s", inet_ntoa(rtmon->_ifaces[i].broadcast));
	safe_write(fd, line, strlen(line));
      }

      if (rtmon->_ifaces[i].gateway.s_addr) {
	safe_snprintf(line,512," peer=%s", inet_ntoa(rtmon->_ifaces[i].gateway));
	safe_write(fd, line, strlen(line));
      }

      safe_snprintf(line,512," mac=%2.2X-%2.2X-%2.2X-%2.2X-%2.2X-%2.2x",
		    u[0], u[1], u[2], u[3], u[4], u[5]);
      safe_write(fd, line, strlen(line));

      safe_snprintf(line,512," mtu=%u\n",  rtmon->_ifaces[i].mtu);
      safe_write(fd, line, strlen(line));
    }
  }
}
Ejemplo n.º 10
0
void createHostMap(HostTraffic *host) {
  HostTraffic *el;
  int num_hosts = 0;

  sendString((char*)map_head);
  //sendString(googleMapsKey);
  sendString((char*)map_head2);
  sendString((char*)map_head4);
  
  for(el=getFirstHost(myGlobals.actualReportDeviceId);
      el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {

    if((el->l2Host == host->l2Host) && (el->hostIpAddress.hostFamily == host->hostIpAddress.hostFamily)) {
      if((CM_PointEst(host->sent_to_matrix, el->serialHostIndex) > 0)
	 || (CM_PointEst(host->recv_from_matrix, el->serialHostIndex) > 0)) {
	if(el->geo_ip) {
	  char buf[512];
#if 0
	  char buf1[256] = { 0 };
	  int showSymIp;

	  if((el->hostResolvedName[0] != '\0')
	     && strcmp(el->hostResolvedName, el->hostNumIpAddress)
	     && (!privateIPAddress(el)))
	    showSymIp = 1;
	  else
	    showSymIp = 0;
#endif

	  safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf),
			"createMarker(new google.maps.LatLng(%.2f, %.2f), \""
#if 0
			"%s%s"
#endif
			"<A HREF=/%s.html>%s</A><br>%s<br>%s\");\n", 
			el->geo_ip->latitude, el->geo_ip->longitude,
#if 0
			showSymIp ? escape_string(el->hostResolvedName, buf1, sizeof(buf1)) : "", 
			showSymIp ? "<br>" : "",
#endif
			el->hostNumIpAddress, el->hostNumIpAddress,
			el->geo_ip->city ? el->geo_ip->city : "", 
			el->geo_ip->country_name ? el->geo_ip->country_name : "");
	  sendString(buf);
	  num_hosts++;
	  if(num_hosts > MAX_NUM_MAP_HOSTS) break; /* Too many hosts */
	}
      }
    }
  }

  sendString((char*)map_tail2);
}
Ejemplo n.º 11
0
char *datalinkname(int type)
{
	static char name[TEXTSIZE];
	int i;

	for (i = 0; datalinktypes[i].name; i++)
		if (datalinktypes[i].type == type)
			return datalinktypes[i].name;

	safe_snprintf(name, TEXTSIZE, "#%d", type);
	return name;
}
Ejemplo n.º 12
0
static int chartohex(unsigned char *src, char *dst, int len) {
  char x[3];
  int n;
  
  for (n=0; n < len; n++) {
    safe_snprintf(x, sizeof(x), "%.2x", src[n]);
    dst[n*2+0] = x[0];
    dst[n*2+1] = x[1];
  }
  dst[len*2] = 0;
  return 0;
}
Ejemplo n.º 13
0
static int click_change_buddy_handler(widget_list *w, int mx, int my, Uint32 flags)
{
	char string[255];
	int send_message = 1;

	if(buddy_delete) {
		safe_snprintf(string, sizeof(string), "%c#del_buddy %s", RAW_TEXT, buddy_to_change);
		buddy_delete = 0;
	} else if (buddy_type_input_id != -1) {
		safe_snprintf(string, sizeof(string), "%c#change_buddy %s %i", RAW_TEXT, buddy_to_change, multiselect_get_selected(buddy_change_win, buddy_type_input_id));
	} else {
		send_message = 0;
	}
	if (send_message) {
		my_tcp_send(my_socket, (Uint8*)string, strlen(string+1)+1);
	}
	destroy_window(buddy_change_win);
	buddy_change_win = -1;
	buddy_to_change = NULL;
	return 1;
}
Ejemplo n.º 14
0
// =====================================================================================
bool        GetWadConfig(FILE* wadcfg, wadconfig_t* wadconfig)
{
    char            TokenBuffer[MAX_TOKENBUFFER];
    wadname_t*      current;
    wadname_t*      previous;

    while (!feof(wadcfg))
    {
        Safe_GetToken(wadcfg, TokenBuffer, MAX_TOKENBUFFER);

        if (!strcmp(TokenBuffer, "}"))
            return true; // no more work to do
        
        if (!strcmp(TokenBuffer, ";"))
            continue; // old seperator, no longer used but here for backwards compadibility

        if (!strcmp(TokenBuffer, "{"))  // wtf
        {
            WadCfgParseError("Expected wadpath (Nested blocks illegal)", g_wadcfglinecount, TokenBuffer);
            return false;
        }

        // otherwise assume its a wadpath, make an entry in this configuration
        current = (wadname_t*)malloc(sizeof(wadname_t));
        wadconfig->entries++;
        current->next = NULL;
        current->wadinclude = false;

        if (!strcmp(TokenBuffer, "include"))
        {
            current->wadinclude = true;
            Safe_GetToken(wadcfg, TokenBuffer, MAX_TOKENBUFFER);
        }
        
        strcpy_s(current->wadname, TokenBuffer);
        
        if (!wadconfig->firstentry)
        {
            wadconfig->firstentry = current;
        }
        else
        {
            previous->next = current;
        }

        previous = current;
        previous->next = NULL;
    }

    safe_snprintf(TokenBuffer, MAX_TOKENBUFFER, "Unexptected end of file encountered while parsing configuration '%s'", wadconfig->name);
    WadCfgParseError(TokenBuffer, g_wadcfglinecount, "(eof)");
    return false; 
}
Ejemplo n.º 15
0
void floatingmessages_compare_stat(int actor_id, int value, int new_value, const unsigned char *skillname)
{
        char str[50];
        int diff=new_value-value;

        safe_snprintf(str, sizeof(str), "%s: %c%d", skillname, diff<0?' ':'+', diff);

        if(diff<0)
                add_floating_message(actor_id, str, FLOATINGMESSAGE_SOUTH, 1.0, 0.3, 0.3,1500);
        else
                add_floating_message(actor_id, str, FLOATINGMESSAGE_NORTH, 0.3, 1.0, 0.3,1500);
}
Ejemplo n.º 16
0
int StaticFileCacheData::buildFixedHeaders( int etag )
{
    int size = 6 + 30 + 17 + RFC_1123_TIME_LEN
            + 20 + m_pMimeType->getMIME()->len() + 10 ;
    const char * pCharset;
    if ( m_pCharset && HttpMime::needCharset(m_pMimeType->getMIME()->c_str()) )
    {
        pCharset = m_pCharset->c_str();
        size += m_pCharset->len();
    }
    else
        pCharset = "";
    if ( !m_sHeaders.resizeBuf( size ) )
        return SC_500;
    
    char * pEnd = m_sHeaders.buf() + size;
    char *p = m_sHeaders.buf();
    m_iFileETag = etag;
    
    memcpy( p, "ETag: ", 6 );
    m_pETag = p + 6;
    m_iETagLen = safe_snprintf( m_pETag, pEnd - m_pETag,
            "\"%lx-%lx-%lx\"",
            (unsigned long)m_fileData.getFileSize(),
            m_fileData.getLastMod(),
            (long)m_fileData.getINode());
    p = m_pETag + m_iETagLen;
    memcpy( p, "\r\nLast-Modified: ", 17 );
    p += 17;
    DateTime::getRFCTime( m_fileData.getLastMod(), p );
    p += RFC_1123_TIME_LEN;

    p += safe_snprintf( p, pEnd - p ,
            "\r\nContent-Type: %s%s\r\n",
             m_pMimeType->getMIME()->c_str(), pCharset );
            
    m_sHeaders.setLen( p - m_sHeaders.buf() );
    m_iValidateHeaderLen = 6 + 17 + 2 + m_iETagLen + RFC_1123_TIME_LEN ;
    return 0;
}
Ejemplo n.º 17
0
void rtmon_print_routes(struct rtmon_t *rtmon, int fd) {
  char line[512];
  int i;

  safe_snprintf(line,512,"\nSystem Routes\n");
  safe_write(fd, line, strlen(line));

  for (i=0; i < rtmon->_route_sz; i++) {
    if (rtmon->_routes[i].has_data) {
      safe_snprintf(line,512,"%d) dst=%s", i, inet_ntoa(rtmon->_routes[i].destination));
      safe_write(fd, line, strlen(line));
      safe_snprintf(line,512," mask=%s", inet_ntoa(rtmon->_routes[i].netmask));
      safe_write(fd, line, strlen(line));
      if (rtmon->_routes[i].gateway.s_addr) {
	safe_snprintf(line,512," gw=%s", inet_ntoa(rtmon->_routes[i].gateway));
	safe_write(fd, line, strlen(line));
      }
      safe_snprintf(line,512," dev=%s (%d)\n", idx2name(rtmon, rtmon->_routes[i].if_index), rtmon->_routes[i].if_index);
      safe_write(fd, line, strlen(line));
    }
  }
}
Ejemplo n.º 18
0
const char* DLLCALL inet_addrtop(union xp_sockaddr *addr, char *dest, size_t size)
{
#ifdef _WIN32
	if(getnameinfo(&addr->addr, xp_sockaddr_len(addr), dest, size, NULL, 0, NI_NUMERICHOST))
		safe_snprintf(dest, size, "<Error %u converting address, family=%u>", WSAGetLastError(), addr->addr.sa_family);
	return dest;
#else
	switch(addr->addr.sa_family) {
		case AF_INET:
			return inet_ntop(addr->in.sin_family, &addr->in.sin_addr, dest, size);
		case AF_INET6:
			return inet_ntop(addr->in6.sin6_family, &addr->in6.sin6_addr, dest, size);
		case AF_UNIX:
			strncpy(dest, addr->un.sun_path, size);
			dest[size-1]=0;
			return dest;
		default:
			safe_snprintf(dest, size, "<unknown address family: %u>", addr->addr.sa_family);
			return NULL;
	}
#endif
}
Ejemplo n.º 19
0
void read_local_book (const char *data, int len)
{
	char file_name[200];
	book *b;

	safe_snprintf (file_name, sizeof(file_name), "%.*s", len-3, data+3);
	
	b = get_book (SDL_SwapLE16 (*((Uint16*)(data+1))));
	if (b == NULL)
	{
		b = read_book (file_name, data[0], SDL_SwapLE16 (*((Uint16*)(data+1))));
		if (b == NULL)
		{
			char str[200];
			safe_snprintf (str, sizeof(str), book_open_err_str, file_name);
			LOG_TO_CONSOLE(c_red1, str);
			return;
		}
	}
	
	display_book_window (b); // Otherwise there's no point...
}
Ejemplo n.º 20
0
void add_to_download(const char *filename, const Uint8 *md5)
{
	// lock the mutex
	CHECK_AND_LOCK_MUTEX(download_mutex);
	if(download_queue_size < MAX_UPDATE_QUEUE_SIZE){
		// add the file to the list, and increase the count
		download_queue[download_queue_size]= strdup(filename);
		download_MD5s[download_queue_size]= calloc(1, 16);
		memcpy(download_MD5s[download_queue_size], md5, 16);
		download_queue_size++;
		
		// start a thread if one isn't running
		if(!download_cur_file){
			char	buffer[1024];
			FILE    *fp;

			safe_snprintf(download_temp_file, sizeof(download_temp_file), "tmp/temp%03d.dat", ++temp_counter);
			buffer[sizeof(buffer)-1]= '\0';
			fp = open_file_config(download_temp_file, "wb+");
			if(fp == NULL){
				LOG_ERROR("%s: %s \"%s\": %s\n", reg_error_str, cant_open_file, download_temp_file, strerror(errno));
			} else {
				// build the proper URL to download
				download_cur_file= download_queue[--download_queue_size];
				download_cur_md5= download_MD5s[download_queue_size];
				if(is_this_files_lst){
					safe_snprintf(buffer, sizeof(buffer), "http://%s/updates%d%d%d/%s", update_server, VER_MAJOR, VER_MINOR, VER_RELEASE, download_cur_file);
				} else {
					safe_snprintf(buffer, sizeof(buffer), "http://%s/updates/%s", update_server, download_cur_file);
				}
				buffer[sizeof(buffer)-1]= '\0';
				LOG_DEBUG("@@ %s %s",update_server,buffer);
				http_threaded_get_file(update_server, buffer, fp, download_cur_md5, EVENT_DOWNLOAD_COMPLETE);
			}
		}
	}
	// unlock the mutex
	CHECK_AND_UNLOCK_MUTEX(download_mutex);
}
Ejemplo n.º 21
0
static char *lookup_name(struct msgnames_t *db, int id) {
  static char name[512];
  struct msgnames_t *msgnamesiter;
  for (msgnamesiter=db; msgnamesiter->msg; ++msgnamesiter) {
    if (msgnamesiter->id == id)
      break;
  }
  if (msgnamesiter->msg) {
    return msgnamesiter->msg;
  }
  safe_snprintf(name,sizeof(name),"#%i\n",id);
  return name;
}
Ejemplo n.º 22
0
bool redis_list::ltrim(const char* key, int start, int end)
{
	const char* argv[4];
	size_t lens[4];

	argv[0] = "LTRIM";
	lens[0] = sizeof("LTRIM") - 1;
	argv[1] = key;
	lens[1] = strlen(key);

	char start_s[LONG_LEN], end_s[LONG_LEN];
	safe_snprintf(start_s, sizeof(start_s), "%d", start);
	safe_snprintf(end_s, sizeof(end_s), "%d", end);

	argv[2] = start_s;
	lens[2] = strlen(start_s);
	argv[3] = end_s;
	lens[3] = strlen(end_s);

	build_request(4, argv, lens);
	return check_status();
}
Ejemplo n.º 23
0
//draws a NUM_MIX_SLOTSx1 grid of items+grid
static int draw_production_pipe(window_info *win, int x, int y, int recipe_num){
	int i,ofs,valid;
	Uint8 str[80];
	item *the_list;

	//if recipe_num is negative we draw the current manufacture_list, else a recipe
	if (recipe_num<0) {
		the_list=manufacture_list;
		ofs=MIX_SLOT_OFFSET;
		valid=1;
	} else {
		the_list=recipes_store[recipe_num].items;
		ofs=0;
		valid=recipes_store[recipe_num].status;
	}

	glEnable(GL_TEXTURE_2D);
	//ok, now let's draw the mixed objects
	for(i=ofs;i<NUM_MIX_SLOTS+ofs;i++) {
		glColor3f(1.0f,1.0f,1.0f);
		if(the_list[i].quantity > 0){
			int x_start,y_start;
			int use_large = (mouse_over_pipe_pos == i-ofs) && enlarge_text();
			int y_offset = SLOT_SIZE - ((use_large) ?win->default_font_len_y :win->small_font_len_y);

			//get the x and y
			x_start=x+SLOT_SIZE*(i%NUM_MIX_SLOTS)+1;
			y_start=y;

			draw_item(the_list[i].image_id,x_start,y_start,SLOT_SIZE);
			safe_snprintf((char *)str, sizeof(str), "%i", the_list[i].quantity);

			if (use_large)
				draw_string_shadowed_zoomed(x_start, y_start+y_offset, (unsigned char*)str, 1, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, win->current_scale);
			else
				draw_string_small_shadowed_zoomed(x_start, y_start+y_offset, (unsigned char*)str, 1, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, win->current_scale);

			if (!valid)
				gray_out(x_start,y_start,SLOT_SIZE);
		}
	}
	glDisable(GL_TEXTURE_2D);

	//draw the grid, in red if selected
	if (recipe_num==cur_recipe) glColor3f(1.0f,0.0f,0.0f);
	else glColor3f(0.77f,0.57f,0.39f);
	rendergrid(NUM_MIX_SLOTS,1,x, y, SLOT_SIZE, SLOT_SIZE);

	glEnable(GL_TEXTURE_2D);
	return 1;
}
Ejemplo n.º 24
0
bool hsclient::mod(const char* values[], int num,
	const char* to_values[], int to_num, const char* cond /* = "=" */,
	int nlimit /* = 0 */, int noffset /* = 0 */)
{
	if (tbl_curr_ == NULL)
	{
		error_ = HS_ERR_NOT_OPEN;
		logger_error("tbl not opened yet!");
		return (false);
	}
	else if (values == NULL || values[0] == NULL)
	{
		error_ = HS_ERR_PARAMS;
		logger_error("values null");
		return (false);
	}
	else if (num <= 0 || num > tbl_curr_->nfld_)
	{
		error_ = HS_ERR_PARAMS;
		logger_error("num(%d) invalid, nfld(%d)",
			num, tbl_curr_->nfld_);
		return (false);
	}
	else if (cond == NULL || *cond == 0)
	{
		error_ = HS_ERR_PARAMS;
		logger_error("cond null");
		return (false);
	}
	else if (to_values == NULL || to_values[0] == NULL)
	{
		error_ = HS_ERR_PARAMS;
		logger_error("to_values null");
		return (false);
	}
	else if (to_num <= 0 || to_num > tbl_curr_->nfld_)
	{
		error_ = HS_ERR_PARAMS;
		logger_error("to_num(%d) invalid, nfld(%d)",
			to_num, tbl_curr_->nfld_);
		return (false);
	}

	if (nlimit <= 0)
		nlimit = MAX_INT;
	if (noffset < 0)
		noffset = 0;
	char buf[32];
	safe_snprintf(buf, sizeof(buf), "%d\t%d", nlimit, noffset);
	return (query(cond, values, num, buf, 'U', to_values, to_num));
}
Ejemplo n.º 25
0
void add_floating_message(int actor_id, char * str, int direction, float r, float g, float b, int active_time)
{
        int time;
        static int last_time_added[5]={0};
        static int last_direction_added[5]={0};
        static int last_actor[5]={0};//Make sure that we don't see too many messages from that actor
        floating_message *m=get_free_floatingmessage();

        if(!m) return;

        m->color[0]=r;
        m->color[1]=g;
        m->color[2]=b;

        safe_snprintf(m->message, sizeof(m->message), "%s", str);

        m->direction=direction;
        m->active_time=active_time;

        if(last_actor[4]==actor_id && last_time_added[4]+550>cur_time && last_direction_added[4]==direction)
                time=m->first_time=last_time_added[4]+550;
        else if(last_actor[3]==actor_id && last_time_added[3]+550>cur_time && last_direction_added[3]==direction)
                time=m->first_time=last_time_added[3]+550;
        else if(last_actor[2]==actor_id && last_time_added[2]+550>cur_time && last_direction_added[2]==direction)
                time=m->first_time=last_time_added[2]+550;
        else if(last_actor[1]==actor_id && last_time_added[1]+550>cur_time && last_direction_added[1]==direction)
                time=m->first_time=last_time_added[1]+550;
        else if(last_actor[0]==actor_id && last_time_added[0]+550>cur_time && last_direction_added[0]==direction)
                time=m->first_time=last_time_added[0]+550;
        else
                time=m->first_time=cur_time;

        m->active=1;
        m->actor_id=actor_id;

        last_actor[0]=last_actor[1];
        last_time_added[0]=last_time_added[1];
        last_direction_added[0]=last_direction_added[1];
        last_actor[1]=last_actor[2];
        last_time_added[1]=last_time_added[2];
        last_direction_added[1]=last_direction_added[2];
        last_actor[2]=last_actor[3];
        last_time_added[2]=last_time_added[3];
        last_direction_added[2]=last_direction_added[3];
        last_actor[3]=last_actor[4];
        last_time_added[3]=last_time_added[4];
        last_direction_added[3]=last_direction_added[4];
        last_actor[4]=actor_id;
        last_time_added[4]=time;
        last_direction_added[4]=direction;
}
Ejemplo n.º 26
0
int Awstats::executeUpdate(const char * pName)
{
    const char * pWorking = m_sWorkingDir.c_str();
    char achBuf[8192];
    safe_snprintf( achBuf, 8192, "%s/add-ons/awstats",
            HttpGlobals::s_pServerRoot );
    if ( HttpGlobals::s_psChroot )
        pWorking += HttpGlobals::s_psChroot->len();
    if ( chdir( achBuf ) == -1 )
    {
        LOG_ERR(( "Cannot change to dir [%s]: %s", achBuf, strerror( errno ) ));
        return -1;
    }
    if ( m_iMode == AWS_STATIC )
    {
        safe_snprintf( achBuf, 8192,
            "tools/awstats_buildstaticpages.pl -awstatsprog=wwwroot/cgi-bin/awstats.pl"
            " -dir='%s/html' -update "
            "-configdir='%s/conf' "
            "-config='%s' -lang=en", pWorking, pWorking,
            pName );
    }
    else if ( m_iMode == AWS_DYNAMIC )
    {
        safe_snprintf( achBuf, 8192,
            "wwwroot/cgi-bin/awstats.pl -update -configdir='%s/conf' -config='%s'",
                pWorking, pName );
    }
    else
    {
        LOG_ERR(( "Unknown update method %d", m_iMode ));
        return -1;
    }
    
    setpriority( PRIO_PROCESS, 0, getpriority( PRIO_PROCESS, 0) + 4 );
    int ret = system( achBuf );
    return ret;
}
Ejemplo n.º 27
0
// =====================================================================================
//  Warning
//      For formatted warning messages
//      automatically appends an extra newline to the message
// =====================================================================================
void CDECL      Warning(const char* const warning, ...)
{
    char            message[MAX_WARNING];
    char            message2[MAX_WARNING];

    va_list         argptr;

    va_start(argptr, warning);
    vsnprintf(message, MAX_WARNING, warning, argptr);
    va_end(argptr);

    safe_snprintf(message2, MAX_MESSAGE, "Warning: %s\n", message);
    WriteLog(message2);
}
Ejemplo n.º 28
0
char* formatKBytes(float numKBytes, char *outStr, int outStrLen) {
  if(numKBytes < 0) return(""); /* It shouldn't happen */

  if(numKBytes < 1024) {
    safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%.1f%sKBytes", numKBytes, myGlobals.separator);
  } else {
    float tmpKBytes = numKBytes/1024;

    if(tmpKBytes < 1024) {
      safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%.1f%sMBytes",  tmpKBytes, myGlobals.separator);
    } else {
      float tmpGBytes = tmpKBytes/1024;

      if(tmpGBytes < 1024) {
	safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%.1f%sGBytes", tmpGBytes, myGlobals.separator);
      } else {
	safe_snprintf(__FILE__, __LINE__, outStr, outStrLen, "%.1f%sTBytes", ((float)(tmpGBytes)/1024), myGlobals.separator);
      }
    }
  }

  return(outStr);
}
Ejemplo n.º 29
0
bool redis_list::lrange(const char* key, int start, int end,
	std::vector<string>* result)
{
	const char* argv[4];
	size_t lens[4];

	argv[0] = "LRANGE";
	lens[0] = sizeof("LRANGE") - 1;
	argv[1] = key;
	lens[1] = strlen(key);

	char start_s[LONG_LEN], end_s[LONG_LEN];
	safe_snprintf(start_s, sizeof(start_s), "%d", start);
	safe_snprintf(end_s, sizeof(end_s), "%d", end);

	argv[2] = start_s;
	lens[2] = strlen(start_s);
	argv[3] = end_s;
	lens[3] = strlen(end_s);

	build_request(4, argv, lens);
	return get_strings(result) < 0 ? false : true;
}
Ejemplo n.º 30
0
char* DLLCALL get_msgid(scfg_t* cfg, uint subnum, smbmsg_t* msg, char* msgid, size_t maxlen)
{
	char*	host;

	if(msg->id!=NULL && *msg->id!=0) {
		strncpy(msgid,msg->id,maxlen);
		return(msg->id);
	}

	/* Try *really* hard to get a hostname from the configuration data */
	host=cfg->sys_inetaddr;
	if(!host[0]) {
		host=cfg->sys_id;
		if(!host[0]) {
			host=cfg->sys_name;
			if(!host[0]) {
				host=cfg->sys_op;
			}
		}
	}

	if(subnum>=cfg->total_subs)
		safe_snprintf(msgid,maxlen
			,"<%08lX.%lu@%s>"
			,msg_time(msg)
			,msg_number(msg)
			,host);
	else
		safe_snprintf(msgid,maxlen
			,"<%08lX.%lu.%s@%s>"
			,msg_time(msg)
			,msg_number(msg)
			,cfg->sub[subnum]->code
			,host);

	return(msgid);
}