Exemple #1
0
int Sentry_FindTarget(  )
{
    gedict_t *client;
    float   r;
    float   gotone;
    float   loopc;

    r = 0;
    loopc = 0;
    gotone = 0;
    while ( loopc < 6 && !gotone )
    {
        client = checkclient(  );
        gotone = CheckTarget( client );
        loopc = loopc + 1;
    }
    if ( !gotone )
        return 0;
    self->s.v.enemy = EDICT_TO_PROG( client );
    if ( strneq( PROG_TO_EDICT( self->s.v.enemy )->s.v.classname, "player" ) )
    {
        self->s.v.enemy = PROG_TO_EDICT( self->s.v.enemy )->s.v.enemy;
        if ( strneq( PROG_TO_EDICT( self->s.v.enemy )->s.v.classname, "player" ) )
        {
            self->s.v.enemy = EDICT_TO_PROG( world );
            return 0;
        }
    }
    Sentry_FoundTarget(  );
    return 1;
}
Exemple #2
0
static int testmode()
{
int	fd;
struct	dupinfo di;

	for (;;)
	{
		printf("Ready.\n");
		if ((fd=dup(0)) < 0)
		{
			perror("dup");
			return (1);
		}

		di.fd=fd;
		di.cancelfunc= &testcancel;

		di.cmdfp=stdin;
		di.doclosecmdfp=0;
		if (hashclient(&di) < 0)	break;
		checkclient(&di);
	}
	return (0);
}
int main(int argc, char **argv)
{
    printf("starting\n");
    fflush(stdout);
    short port = 0;
    char opt;
    struct sockaddr_in cl_addr,proxyserver_addr;
    socklen_t sin_size = sizeof(struct sockaddr_in);
    int sockfd,accept_sockfd,on = 1;
    pthread_t Clitid;
    printf("deal arguement\n");
    fflush(stdout);
    while((opt = getopt(argc, argv, "p:")) != EOF)
    {
        switch(opt)
        {
            case 'p':
                port = (short)atoi(optarg);
                break;
            default:
                printf("Usage: %s -p port\n", argv[0]);
                return -1;
        }
    }
    if (port == 0)
    {
        printf("Invalid port number,try again.\n");
        printf("Usage: %s -p port\n", argv[0]);
        return -1;
    }
    printf("create socket\n");
    fflush(stdout);
    sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (sockfd < 0)
    {
        printf("Socket failed .. Abort...\n");
    }

    memset(&proxyserver_addr, 0, sizeof(proxyserver_addr));
    proxyserver_addr.sin_family = AF_INET;
    proxyserver_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    proxyserver_addr.sin_port = htons(port);

    setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on));

    if(bind(sockfd,(struct sockaddr *)&proxyserver_addr,sizeof(proxyserver_addr)) < 0)
    {
        printf("Bind failed...Abort...\n");
        return -1;
    }
    if(listen(sockfd, QUEUE_SIZE) < 0)
    {
        printf("listen failed...Abort...\n");
        return -1;
    }
    printf("enter while\n");
    fflush(stdout);
    while(1)
    {
        printf("wait....\n");
		fflush(stdout);
        accept_sockfd = accept(sockfd, (struct sockaddr *)&cl_addr, &sin_size);
	    printf("accept....a packet.\n");
        fflush(stdout);
        if(accept_sockfd < 0)
        {
            printf("accept failed");
            continue;
        }
        printf("Received a request from %s:%d\n", inet_ntoa(cl_addr.sin_addr), ntohs(cl_addr.sin_port));
        if(checkclient(cl_addr.sin_addr.s_addr) == 1)
        {
            printf("create thread!\n");
            pthread_create(&Clitid, NULL, (void*)dealonereq, (void*)&accept_sockfd);

        }
        else
        {
            close(accept_sockfd);
        }
    }
    return 0;
}
Exemple #4
0
/*
===========
FindTarget

Self is currently not attacking anything, so try to find a target

Returns true if an enemy was sighted

When a player fires a missile, the point of impact becomes a fakeplayer so
that monsters that see the impact will respond as if they had seen the
player.

To avoid spending too much time, only a single client (or fakeclient) is
checked each frame.  This means multi player games will have slightly
slower noticing monsters.
============
*/
float FindTarget()
{
	gedict_t	*client = NULL;

// if the first spawnflag bit is set, the monster will only wake up on
// really seeing the player, not another monster getting angry

// spawnflags & 3 is a big hack, because zombie crucified used the first
// spawn flag prior to the ambush flag, and I forgot about it, so the second
// spawn flag works as well
	if ( sight_entity_time + 0.1 >= g_globalvars.time && !((int)self->s.v.spawnflags & 3) )
	{
		client = sight_entity; // NOTE: may be NULL, so be careful

		if ( !client || client == world )
			return false;

		if ( client->s.v.enemy == self->s.v.enemy )
			return false; // not sure I understand this, both have same enemy?
	}
	else
	{
		client = checkclient();

		if ( !client || client == world )
			return false;	// current check entity isn't in PVS
	}

	if ( client == PROG_TO_EDICT( self->s.v.enemy ) )
		return false;

	if ( (int)client->s.v.flags & FL_NOTARGET )
		return false;

	if ( (int)client->s.v.items & IT_INVISIBILITY )
		return false;

	// in bloodfest mode monsters spot players always.
	if ( !k_bloodfest )
	{
		float		r = range ( client );

		if ( r == RANGE_FAR )
			return false;

		if ( !visible( client ) )
			return false;

		if ( r == RANGE_NEAR )
		{
			if ( client->show_hostile < g_globalvars.time && !infront( client ) )
				return false;
		}
		else if ( r == RANGE_MID )
		{
			if ( /* client->show_hostile < g_globalvars.time || */ !infront( client ) )
				return false;
		}
	}

//
// got one
//
	self->s.v.enemy = EDICT_TO_PROG( client );

	if ( PROG_TO_EDICT( self->s.v.enemy )->ct != ctPlayer || ( (int)PROG_TO_EDICT( self->s.v.enemy )->s.v.flags & FL_NOTARGET ) )
	{
		self->s.v.enemy = PROG_TO_EDICT( self->s.v.enemy )->s.v.enemy;

		if ( PROG_TO_EDICT( self->s.v.enemy )->ct != ctPlayer || ( (int)PROG_TO_EDICT( self->s.v.enemy )->s.v.flags & FL_NOTARGET ) )
		{
			self->s.v.enemy = EDICT_TO_PROG( world );
			return false;
		}
	}

	FoundTarget ();

	return true;
}
Exemple #5
0
// Get the requested index from the stack and verify it being a proper Client
// returns -1 if it is not a valid client (either no client, or already NULL)
// SOFT ERROR
UpnpClient_Handle getclient(lua_State *L, int idx)
{
	return checkclient(L, idx);
}