Exemplo n.º 1
0
int getkeypress(int tm, int flags)
{
	int t = gettm(0);
	int keypress;
	if (socket_fd > -1)
		flags |= SINGLE_PL;
	while (1) {
		if (tm <= 0)
			return 0;
		keypress = getkeypress_select(tm, flags);
#if JOYSTICK
		if (!keypress)
			keypress = getautorepeat(flags);
#endif
		if (keypress)
			break;
		if (gettm(t) == t)
			sleep_msec(1);
		tm -= gettm(t)-t;
		t = gettm(0);
#ifdef ALLEGRO
		if (close_button_pressed)
			exit(0);
#endif
	}
	return keypress;
}
Exemplo n.º 2
0
void logp(const char *fmt, ...)
{
#ifndef UTEST
	int pid;
	char buf[512]="";
	va_list ap;
	va_start(ap, fmt);
	vsnprintf(buf, sizeof(buf), fmt, ap);
	pid=(int)getpid();
	if(logfzp)
		fzp_printf(logfzp, "%s: %s[%d] %s", gettm(), prog, pid, buf);
	else
	{
		if(do_syslog)
			syslog(LOG_INFO, "%s", buf);
		if(do_stdout)
		{
			if(json)
			{
				char *cp=NULL;
				if((cp=strrchr(buf, '\n'))) *cp='\0';
				// To help programs parsing the monitor output,
				// log things with simple JSON.
				fprintf(stdout, "{ \"logline\": \"%s\" }\n", buf);
			}
			else
				fprintf(stdout, "%s: %s[%d] %s",
					gettm(), prog, pid, buf);
		}
	}
	va_end(ap);
#endif
}
Exemplo n.º 3
0
int test_autorep_tm(short *tm)
{
	int t = *tm;
	t = gettm(t)-t;
	if (t >= DAS_INITIAL_DELAY) {
		*tm = gettm(0)-t+DAS_DELAY+10000;
		return 1;
	}
	return 0;
}
Exemplo n.º 4
0
Arquivo: log.c Projeto: fenio/burp
void logp(const char *fmt, ...)
{
    int pid;
    char buf[512]="";
    va_list ap;
    va_start(ap, fmt);
    vsnprintf(buf, sizeof(buf), fmt, ap);
    pid=(int)getpid();
    fprintf(logfp?logfp:stdout, "%s: %s[%d] %s", gettm(), prog, pid, buf);
    syslog(LOG_INFO, "%s: %s[%d] %s", gettm(), prog, pid, buf);
    va_end(ap);
}
Exemplo n.º 5
0
void spawn_discard_drops(int pl)
{
	int i = 0;
	if (pl==2) {
		i = 1;
		if (socket_fd > -1) {
			spawn_tm[1] = 0;
			return;
		}
	}
	spawn_tm[i] = gettm(0);
#ifdef ALLEGRO
	kb_reset_drop(pl);
#endif
#ifdef JOYSTICK
	if (!num_joyst)
		return;
	i = !js_pressed(0);
	if (pl==2 && inputdevs_player[i+1] != 2) {
		if (i || inputdevs_player[2] != 2)
			return;
		i = 1;
	}
	if (js_pressed(i))
		js_reset_drop(i);
#endif
}
Exemplo n.º 6
0
static int dropsafe(int i)
{
	int t = spawn_tm[i];
	if (t && gettm(t)-t < DAS_DELAY)
		return 1;
	spawn_tm[i] = 0;
	return 0;
}
Exemplo n.º 7
0
Arquivo: v1.c Projeto: fahlgren/kore
int
v1(struct http_request *http_req)
{
	struct jsonrpc_request	req;
	int			ret;
	
	/* We only allow POST/PUT methods. */
	if (http_req->method != HTTP_METHOD_POST &&
	    http_req->method != HTTP_METHOD_PUT) {
		http_response_header(http_req, "allow", "POST, PUT");
		http_response(http_req, HTTP_STATUS_METHOD_NOT_ALLOWED, NULL, 0);
		return (KORE_RESULT_OK);
	}
	
	/* Read JSON-RPC request. */
	if ((ret = jsonrpc_read_request(http_req, &req)) != 0)
		return jsonrpc_error(&req, ret, NULL);
	
	/* Echo command takes and gives back params. */
	if (strcmp(req.method, "echo") == 0) {
		if (!YAJL_IS_ARRAY(req.params)) {
			jsonrpc_log(&req, LOG_ERR,
			    "Echo only accepts positional params");
			return jsonrpc_error(&req, JSONRPC_INVALID_PARAMS, NULL);
		}
		for (size_t i = 0; i < req.params->u.array.len; i++) {
			yajl_val v = req.params->u.array.values[i];
			if (!YAJL_IS_STRING(v)) {
				jsonrpc_log(&req, -3,
				    "Echo only accepts strings");
				return jsonrpc_error(&req,
				    JSONRPC_INVALID_PARAMS, NULL);
			}
		}
		return jsonrpc_result(&req, write_string_array_params, NULL);
	}
	
	/* Date command displays date and time according to parameters. */
	if (strcmp(req.method, "date") == 0) {
		time_t		time_value;
		struct tm	time_info;
		char		timestamp[33];
		struct tm	*(*gettm)(const time_t *, struct tm *) =
				    localtime_r;
		
		if (YAJL_IS_OBJECT(req.params)) {
			const char	*path[] = {"local", NULL};
			yajl_val	bf;

			bf = yajl_tree_get(req.params, path, yajl_t_false);
			if (bf != NULL)
				gettm = gmtime_r;
		} else if (req.params != NULL) {
			jsonrpc_log(&req, LOG_ERR,
			    "Date only accepts named params");
			return jsonrpc_error(&req, JSONRPC_INVALID_PARAMS, NULL);
		}

		if ((time_value = time(NULL)) == -1)
			return jsonrpc_error(&req, -2,
			    "Failed to get date time");
		
		if (gettm(&time_value, &time_info) == NULL)
			return jsonrpc_error(&req, -3,
			    "Failed to get date time info");
		
		memset(timestamp, 0, sizeof(timestamp));
		if (strftime_l(timestamp, sizeof(timestamp) - 1, "%c",
		    &time_info, LC_GLOBAL_LOCALE) == 0)
			return jsonrpc_error(&req, -4,
			    "Failed to get printable date time");
		
		return jsonrpc_result(&req, write_string, timestamp);
	}
	
	return jsonrpc_error(&req, JSONRPC_METHOD_NOT_FOUND, NULL);
}