Example #1
0
/**
 * @brief Send the servers list to the specified client address.
 */
static void Ms_GetServers(struct sockaddr_in *from) {
	mem_buf_t buf;
	byte buffer[0xffff];

	Mem_InitBuffer(&buf, buffer, sizeof(buffer));

	const char *servers = "\xFF\xFF\xFF\xFF" "servers ";
	Mem_WriteBuffer(&buf, servers, strlen(servers));

	uint32_t i = 0;
	GList *s = ms_servers;
	while (s) {
		const ms_server_t *server = (ms_server_t *) s->data;
		if (server->validated) {
			Mem_WriteBuffer(&buf, &server->addr.sin_addr, sizeof(server->addr.sin_addr));
			Mem_WriteBuffer(&buf, &server->addr.sin_port, sizeof(server->addr.sin_port));
			i++;
		}
		s = s->next;
	}

	if ((sendto(ms_sock, buf.data, buf.size, 0, (struct sockaddr *) from, sizeof(*from))) == -1) {
		Com_Warn("%s: %s\n", atos(from), strerror(errno));
	} else {
		Com_Verbose("Sent %d servers to %s\n", i, atos(from));
	}
}
Example #2
0
File: rv2.c Project: NREL/Radiance
void
saveview(				/* save view to rad file */
	char  *s
)
{
	char  view[64];
	char  *fname;
	FILE  *fp;

	if (*atos(view, sizeof(view), s)) {
		if (isint(view)) {
			error(COMMAND, "cannot write view by number");
			return;
		}
		s = sskip(s);
	}
	if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) {
		error(COMMAND, "no previous rad file");
		return;
	}
	if ((fname = getpath(rifname, NULL, 0)) == NULL ||
			(fp = fopen(fname, "a")) == NULL) {
		sprintf(errmsg, "cannot open \"%s\"", rifname);
		error(COMMAND, errmsg);
		return;
	}
	fputs("view= ", fp);
	fputs(view, fp);
	fprintview(&ourview, fp);
	putc('\n', fp);
	fclose(fp);
}
Example #3
0
/**
 * @brief
 */
static void Ms_ParseMessage(struct sockaddr_in *from, char *data) {
	char *cmd = data;
	char *line = data;

	while (*line && *line != '\n') {
		line++;
	}

	*(line++) = '\0';
	cmd += 4;

	if (!g_ascii_strncasecmp(cmd, "ping", 4)) {
		Ms_AddServer(from);
	} else if (!g_ascii_strncasecmp(cmd, "heartbeat", 9) || !g_ascii_strncasecmp(cmd, "print", 5)) {
		Ms_Heartbeat(from);
	} else if (!g_ascii_strncasecmp(cmd, "ack", 3)) {
		Ms_Ack(from);
	} else if (!g_ascii_strncasecmp(cmd, "shutdown", 8)) {
		Ms_RemoveServer(from);
	} else if (!g_ascii_strncasecmp(cmd, "getservers", 10) || !g_ascii_strncasecmp(cmd, "y", 1)) {
		Ms_GetServers(from);
	} else {
		Com_Warn("Unknown command from %s: '%s'", atos(from), cmd);
	}
}
Example #4
0
/**
 * @brief Removes the specified server.
 */
static void Ms_RemoveServer(struct sockaddr_in *from) {
	ms_server_t *server = Ms_GetServer(from);

	if (!server) {
		Com_Warn("Shutdown from unregistered server %s\n", atos(from));
		return;
	}

	Com_Print("Shutdown from %s\n", stos(server));
	Ms_DropServer(server);
}
Example #5
0
/**
 * @brief Acknowledge the server from the specified address.
 */
static void Ms_Ack(struct sockaddr_in *from) {
	ms_server_t *server = Ms_GetServer(from);

	if (server) {
		Com_Verbose("Ack from %s (%d)\n", stos(server), server->queued_pings);

		server->validated = true;
		server->queued_pings = 0;

	} else {
		Com_Warn("Ack from unregistered server %s\n", atos(from));
	}
}
Example #6
0
/**
 * @brief Adds the specified server to the master.
 */
static void Ms_AddServer(struct sockaddr_in *from) {

	if (Ms_GetServer(from)) {
		Com_Warn("Duplicate ping from %s\n", atos(from));
		return;
	}

	if (Ms_BlacklistServer(from)) {
		Com_Warn("Server %s has been blacklisted\n", atos(from));
		return;
	}

	ms_server_t *server = Mem_Malloc(sizeof(ms_server_t));

	server->addr = *from;
	server->last_heartbeat = time(NULL);

	ms_servers = g_list_prepend(ms_servers, server);
	Com_Print("Server %s registered\n", stos(server));

	// send an acknowledgment
	sendto(ms_sock, "\xFF\xFF\xFF\xFF" "ack", 7, 0, (struct sockaddr *) from, sizeof(*from));
}
Example #7
0
void main(){
int i=0;
/*printf("%s\n",onesillaba("amico asino    asino"));
printf("%s\n",onesillaba("edivagavano"));
printf("%s\n",onesillaba("edividere"));
printf("%s\n",onesillaba("asino"));
printf("%s\n",onesillaba("evadere"));*/
//printf("%d",len(convtoarray("ciao dani come stai")));
printf("%s",atos(convtoarray("ciao dani come stai")));
/*char *s="amico";
s=silschema2(s);
for(i=0;s[i]!='\0';i++)
   printf("%c\n",s[i]);*/

/*char* s="ciao dani come va";
char **ret=convtoarray(s);
for(i;i<numero(s);i++)
   printf("%s\n", ret[i] );*/

}
Example #8
0
 std::string Utility::atos(KrylovStop::t const & x){
     std::stringstream ss;
     // Converts the Krylov stopping condition to a shorter string 
     switch(x){
     case KrylovStop::NegativeCurvature:
         return atos("NegCurv");
     case KrylovStop::RelativeErrorSmall:
         return atos("RelErrSml");
     case KrylovStop::MaxItersExceeded:
         return atos("IterExcd");
     case KrylovStop::TrustRegionViolated:
         return atos("TrstReg");
     case KrylovStop::Instability:
         return atos("Unstable");
     case KrylovStop::InvalidTrustRegionCenter:
         return atos("InvldCnt");
     default:
         throw;
     }
 }
Example #9
0
/**
 * @brief
 */
int32_t main(int32_t argc, char **argv) {

	printf("Quetoo Master Server %s %s %s\n", VERSION, __DATE__, BUILD_HOST);

	memset(&quetoo, 0, sizeof(quetoo));

	quetoo.Debug = Debug;
	quetoo.Verbose = Verbose;

	quetoo.Init = Init;
	quetoo.Shutdown = Shutdown;

	signal(SIGINT, Sys_Signal);
	signal(SIGQUIT, Sys_Signal);
	signal(SIGSEGV, Sys_Signal);
	signal(SIGTERM, Sys_Signal);

	Com_Init(argc, argv);

	int32_t i;
	for (i = 0; i < Com_Argc(); i++) {

		if (!g_strcmp0(Com_Argv(i), "-v") || !g_strcmp0(Com_Argv(i), "-verbose")) {
			verbose = true;
			continue;
		}

		if (!g_strcmp0(Com_Argv(i), "-d") || !g_strcmp0(Com_Argv(i), "-debug")) {
			debug = true;
			continue;
		}
	}

	ms_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

	struct sockaddr_in address;
	memset(&address, 0, sizeof(address));

	address.sin_family = AF_INET;
	address.sin_port = htons(PORT_MASTER);
	address.sin_addr.s_addr = INADDR_ANY;

	if ((bind(ms_sock, (struct sockaddr *) &address, sizeof(address))) == -1) {
		Com_Error(ERROR_FATAL, "Failed to bind port %i\n", PORT_MASTER);
	}

	Com_Print("Listening on %s\n", atos(&address));

	while (true) {
		fd_set set;

		FD_ZERO(&set);
		FD_SET(ms_sock, &set);

		struct timeval delay;
		delay.tv_sec = 1;
		delay.tv_usec = 0;

		if (select(ms_sock + 1, &set, NULL, NULL, &delay) > 0) {

			if (FD_ISSET(ms_sock, &set)) {

				char buffer[0xffff];
				memset(buffer, 0, sizeof(buffer));

				struct sockaddr_in from;
				memset(&from, 0, sizeof(from));

				socklen_t from_len = sizeof(from);

				const ssize_t len = recvfrom(ms_sock, buffer, sizeof(buffer), 0,
				                             (struct sockaddr *) &from, &from_len);

				if (len > 0) {
					if (len > 4) {
						Ms_ParseMessage(&from, buffer);
					} else {
						Com_Warn("Invalid packet from %s\n", atos(&from));
					}
				} else {
					Com_Warn("Socket error: %s\n", strerror(errno));
				}
			}
		}

		Ms_Frame();
	}
}
Example #10
0
static void
runrad(				/* run rad and load variables */
	int	ac,
	char	**av
)
{
	static char	optfile[] = TEMPLATE;
	int	nvn = 0, nvv = 0;
	FILE	*fp;
	register char	*cp;
	char	radcomm[256], buf[128], nam[32];
					/* set rad commmand */
	strcpy(radcomm, "rad -w -v 0        ");	/* look out below! */
	cp = radcomm + 19;
	if (silent) {
		strcpy(cp, "-s ");
		cp += 3;
	}
	while (ac--) {
		strcpy(cp, *av++);
		while (*cp) cp++;
		*cp++ = ' ';
	}
	strcpy(cp, "OPTFILE=");		/* create temporary options file */
	strcpy(cp+8, mktemp(optfile));
	if (system(radcomm))		/* update octree */
		error(USER, "error executing rad command");
					/* replace "-v 0" with "-n -e -s -V" */
	strcpy(radcomm+7, "-n -e -s -V");
	radcomm[18] = ' ';
	if ((fp = popen(radcomm, "r")) == NULL)
		error(SYSTEM, "cannot start rad command");
	buf[0] = '\0';			/* read variables alphabetically */
						/* get exposure */
	if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) {
		expval = atof(cp);
		if ((*cp == '-') | (*cp == '+'))
			expval = pow(2., expval);
		expval *= 0.5;		/* compensate for local shading */
	}
						/* look for eye separation */
	if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL)
		eyedist = atof(cp);
						/* look for materials */
	while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) {
		nscenef += wordstring(scene+nscenef, cp);
		buf[0] = '\0';
	}
						/* look for octree */
	if ((cp = scan4var(buf, sizeof(buf), "OCTREE", fp)) != NULL)
		octree = savqstr(cp);
						/* look for scene files */
	while ((cp = scan4var(buf, sizeof(buf), "scene", fp)) != NULL) {
		nscenef += wordstring(scene+nscenef, cp);
		buf[0] = '\0';
	}
						/* load view names */
	while ((cp = scan4var(buf, sizeof(buf), "view", fp)) != NULL) {
		if (nvn >= MAXVIEW)
			error(INTERNAL, "too many views in rad file");
		vwl[nvn++].nam = *cp == '-' ? (char *)NULL :
				savqstr(atos(nam, sizeof(nam), cp));
		buf[0] = '\0';
	}
						/* load actual views */
	do
		if (isview(buf)) {
			vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW));
			*(vwl[nvv].v) = stdview;
			sscanview(vwl[nvv].v, buf);
			if ((cp = setview(vwl[nvv++].v)) != NULL) {
				fprintf(stderr, "%s: bad view %d - %s\n",
						progname, nvv, cp);
				quit(1);
			}
		}
	while (fgets(buf, sizeof(buf), fp) != NULL);
	if (nvv != nvn)
		error(INTERNAL, "view miscount in runrad");
	pclose(fp);
						/* open options file */
	if ((fp = fopen(optfile, "r")) == NULL)
		error(SYSTEM, "cannot open options file");
						/* get relevant options */
	while (fgets(buf, sizeof(buf), fp) != NULL)
		if (!strncmp(buf, "-av ", 4))
			setcolor(ambval, atof(buf+4),
					atof(sskip2(buf+4,1)),
					atof(sskip2(buf+4,2)));
		else if (backvis && !strncmp(buf, "-bv", 3) &&
				(!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL))
			backvis = 0;
	fclose(fp);
	unlink(optfile);			/* delete options file */
}
Example #11
0
File: reg.cpp Project: nealey/vera
static int notify(processor_t::idp_notify msgid, ...) { // Various messages:
  va_list va;
  va_start(va, msgid);

// A well behaving processor module should call invoke_callbacks()
// in his notify() function. If this function returns 0, then
// the processor module should process the notification itself
// Otherwise the code should be returned to the caller:

  int code = invoke_callbacks(HT_IDP, msgid, va);
  if ( code ) return code;


  switch(msgid)
  {
    case processor_t::init:
      inf.mf = 1;                                 // MSB first
    default:
      break;

    case processor_t::newfile:
      {

        segment_t *sptr = get_first_seg();
        if( sptr != NULL )
        {
          if( sptr->startEA - get_segm_base( sptr ) == 0 )
          {
            inf.beginEA = sptr->startEA + 0xC;
            inf.startIP = 0xC;

            for( int i = 0; i < qnumber(entries); i++ )
            {
              ea_t ea = sptr->startEA + entries[i].off;
              if( isEnabled(ea) )
              {
                doWord( ea, 2 );
// ig: set_op_type - внутренняя функция, ее нельзя использовать
//                set_op_type( ea, offflag(), 0 );
                set_offset( ea, 0, sptr->startEA );
                ea_t ea1 = sptr->startEA + get_word( ea );
                auto_make_proc( ea1 );
                set_name( ea, entries[i].name );
// ig: так получше будет?
                set_cmt( sptr->startEA+get_word(ea), entries[i].cmt, 1 );
              }
            }
          }

          set_segm_class( sptr, "CODE" );
        }

        segment_t s;
        ea_t bottom = toEA( inf.baseaddr, 0 );
        intmem       = s.startEA = freechunk( bottom, 256, 0xF );
        s.endEA      = s.startEA + 256;
        s.sel        = allocate_selector( s.startEA >> 4 );
        s.type       = SEG_IMEM;                    // internal memory
        add_segm_ex( &s, "INTMEM", NULL, ADDSEG_OR_DIE);

        const predefined_t *ptr;
        for( ptr = iregs; ptr->name != NULL; ptr++ )
        {
          ea_t ea = intmem + ptr->addr;
          ea_t oldea = get_name_ea( BADADDR, ptr->name );
          if( oldea != ea )
          {
            if( oldea != BADADDR )    set_name( oldea, NULL );
            do_unknown( ea, DOUNK_EXPAND );
            set_name( ea, ptr->name );
          }
          if( ptr->cmt != NULL )      set_cmt( ea, ptr->cmt, 1 );
        }
      }
      break;

    case processor_t::oldfile:
      sel_t sel;
      if( atos( "INTMEM", &sel) ) intmem = specialSeg(sel);
      break;

    case processor_t::newseg:
      {                 // default DS is equal to CS
        segment_t *sptr = va_arg(va, segment_t *);
        sptr->defsr[rVds-ph.regFirstSreg] = sptr->sel;
      }
  }
  va_end(va);

  return(1);
}
Example #12
0
File: reg.cpp Project: nealey/vera
//----------------------------------------------------------------------
static void setup_data_segment_pointers(void)
{
    sel_t sel;
    if ( atos("INTMEM",&sel) || atos("RAM", &sel) ) intmem = specialSeg(sel);
    if ( atos("SFR",&sel)    || atos("FSR", &sel) ) sfrmem = specialSeg(sel) - 0x80;
}