Beispiel #1
0
static void DEFAULT_CC
session_start_sessvc(int xpid, int wmpid, long data)
{
  struct list* sessvc_params;
  char wmpid_str[25];
  char xpid_str[25];
  char exe_path[262];
  int i;

  /* new style waiting for clients */
  g_sprintf(wmpid_str, "%d", wmpid);
  g_sprintf(xpid_str, "%d",  xpid);
  log_message(&(g_cfg->log), LOG_LEVEL_INFO,
              "starting xrdp-sessvc - xpid=%s - wmpid=%s",
              xpid_str, wmpid_str);

  sessvc_params = list_create();
  sessvc_params->auto_free = 1;

  /* building parameters */
  g_snprintf(exe_path, 261, "%s/xrdp-sessvc", XRDP_SBIN_PATH);

  list_add_item(sessvc_params, (long)g_strdup(exe_path));
  list_add_item(sessvc_params, (long)g_strdup(xpid_str));
  list_add_item(sessvc_params, (long)g_strdup(wmpid_str));
  list_add_item(sessvc_params, 0); /* mandatory */

  /* executing sessvc */
  g_execvp(exe_path, ((char**)sessvc_params->items));

  /* should not get here */
  log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,
              "error starting xrdp-sessvc - pid %d - xpid=%s - wmpid=%s",
              g_getpid(), xpid_str, wmpid_str);

  /* logging parameters */
  /* no problem calling strerror for thread safety: other threads
     are blocked */
  log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s",
              errno, g_get_strerror());
  log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "execve parameter list:");
  for (i = 0; i < (sessvc_params->count); i++)
  {
    log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "        argv[%d] = %s", i,
                (char*)list_get_item(sessvc_params, i));
  }
  list_delete(sessvc_params);

  /* keep the old waitpid if some error occurs during execlp */
  g_waitpid(wmpid);
  g_sigterm(xpid);
  g_sigterm(wmpid);
  g_sleep(1000);
  auth_end(data);
  g_exit(0);
}
Beispiel #2
0
int load_add_resource(char *resource_name, int resource_id)
{
   id_type id = (id_type) SafeMalloc(sizeof(id_struct));
   resource_type r = (resource_type) SafeMalloc(sizeof(resource_struct));
   
   id->name = strdup(resource_name);
   id->idnum = resource_id;
   id->type = I_RESOURCE;
   id->ownernum = st.curclass;
   id->source = DBASE;

   r->lhs = id;
   // Have to load in resources from *rsc files
   for (int i = 0; i < sizeof(r->resource) / sizeof(r->resource[i]); i++)
   {
      r->resource[i] = NULL;
   }

   /* Add resource to resource list of current class */
   if (current_class == NULL)
      database_error("Resource appears outside of class in database file");
   current_class->resources = list_add_item(current_class->resources, (void *) r);

   /* OK if parameter already in table; just ignore return value */
   table_insert(st.globalvars, (void *) id, id_hash, id_compare);
   return True;
}
Beispiel #3
0
status_t
send_command(hci_id hid, snet_buffer* snbuf)
{
	bt_usb_dev* bdev = fetch_device(NULL, hid);
	status_t err = B_OK;

	if (bdev == NULL)
		return B_ERROR;

	// TODO: check if device is actually ready for this
	// TODO: mutex

	if (snbuf != NULL) {
		list_add_item(&bdev->nbuffersTx[BT_COMMAND], snbuf);
		bdev->nbuffersPendingTx[BT_COMMAND]++;
	} else {
		err = B_BAD_VALUE;
		TRACE("%s: tx sched provoked", __func__);
	}

	// TODO: check if device is actually ready for this
	// TODO: mutex

	/* sched in All cases even if nbuf is null (hidden way to provoke
	 * re-scheduling)
	 */
	sched_tx_processing(bdev);

	return err;
}
Beispiel #4
0
status_t
socket_spawn_pending(net_socket *_parent, net_socket **_socket)
{
	net_socket_private *parent = (net_socket_private *)_parent;

	MutexLocker locker(parent->lock);

	// We actually accept more pending connections to compensate for those
	// that never complete, and also make sure at least a single connection
	// can always be accepted
	if (parent->child_count > 3 * parent->max_backlog / 2)
		return ENOBUFS;

	net_socket_private *socket;
	status_t status = socket_create(parent->family, parent->type, parent->protocol,
		(net_socket **)&socket);
	if (status < B_OK)
		return status;

	// inherit parent's properties
	socket->send = parent->send;
	socket->receive = parent->receive;
	socket->options = parent->options & ~SO_ACCEPTCONN;
	socket->linger = parent->linger;
	memcpy(&socket->address, &parent->address, parent->address.ss_len);
	memcpy(&socket->peer, &parent->peer, parent->peer.ss_len);

	// add to the parent's list of pending connections
	list_add_item(&parent->pending_children, socket);
	socket->parent = parent;
	parent->child_count++;

	*_socket = socket;
	return B_OK;
}
Beispiel #5
0
status_t
set_sem_owner(sem_id id, team_id newTeamID)
{
	if (sSemsActive == false)
		return B_NO_MORE_SEMS;
	if (id < 0)
		return B_BAD_SEM_ID;
	if (newTeamID < 0)
		return B_BAD_TEAM_ID;

	int32 slot = id % sMaxSems;

	// get the new team
	Team* newTeam = Team::Get(newTeamID);
	if (newTeam == NULL)
		return B_BAD_TEAM_ID;
	BReference<Team> newTeamReference(newTeam, true);

	InterruptsSpinLocker semListLocker(sSemsSpinlock);
	SpinLocker semLocker(sSems[slot].lock);

	if (sSems[slot].id != id) {
		TRACE(("set_sem_owner: invalid sem_id %ld\n", id));
		return B_BAD_SEM_ID;
	}

	list_remove_link(&sSems[slot].u.used.team_link);
	list_add_item(&newTeam->sem_list, &sSems[slot].u.used.team_link);

	sSems[slot].u.used.owner = newTeam->id;
	return B_OK;
}
Beispiel #6
0
status_t
set_port_owner(port_id id, team_id newTeamID)
{
	TRACE(("set_port_owner(id = %ld, team = %ld)\n", id, newTeamID));

	if (id < 0)
		return B_BAD_PORT_ID;

	int32 slot = id % sMaxPorts;

	MutexLocker locker(sPorts[slot].lock);

	if (sPorts[slot].id != id) {
		TRACE(("set_port_owner: invalid port_id %ld\n", id));
		return B_BAD_PORT_ID;
	}

	InterruptsSpinLocker teamLocker(gTeamSpinlock);

	struct team* team = team_get_team_struct_locked(newTeamID);
	if (team == NULL) {
		T(OwnerChange(sPorts[slot], newTeamID, B_BAD_TEAM_ID));
		return B_BAD_TEAM_ID;
	}

	// transfer ownership to other team
	list_remove_link(&sPorts[slot].team_link);
	list_add_item(&team->port_list, &sPorts[slot].team_link);
	sPorts[slot].owner = newTeamID;

	T(OwnerChange(sPorts[slot], newTeamID, B_OK));
	return B_OK;
}
Beispiel #7
0
/*!	Registers an image with the specified team.
*/
static image_id
register_image(Team *team, extended_image_info *info, size_t size, bool locked)
{
	image_id id = atomic_add(&sNextImageID, 1);
	struct image *image;

	image = (struct image*)malloc(sizeof(struct image));
	if (image == NULL)
		return B_NO_MEMORY;

	memcpy(&image->info, info, sizeof(extended_image_info));
	image->team = team->id;

	if (!locked)
		mutex_lock(&sImageMutex);

	image->info.basic_info.id = id;

	// Add the app image to the head of the list. Some code relies on it being
	// the first image to be returned by get_next_image_info().
	if (image->info.basic_info.type == B_APP_IMAGE)
		list_add_link_to_head(&team->image_list, image);
	else
		list_add_item(&team->image_list, image);
	sImageTable->Insert(image);

	// notify listeners
	sNotificationService.Notify(IMAGE_ADDED, image);

	if (!locked)
		mutex_unlock(&sImageMutex);

	TRACE(("register_image(team = %p, image id = %ld, image = %p\n", team, id, image));
	return id;
}
/* Broadcast a message to all active streams */
static bool actl_stream_broadcast_callback(struct stream *str,
                                           struct str_broadcast_data *sbd)
{
    switch (sbd->cmd)
    {
    case STREAM_PLAY:
    case STREAM_PAUSE:
        break;

    case STREAM_STOP:
        if (sbd->data != 0)
        {
            actl_lock();

            list_remove_item(stream_mgr.actl, str);
            list_add_item(stream_mgr.strl, str);

            actl_unlock();
            sbd->data = 0;
        }
        break;

    default:
        return false;
    }

    str_send_msg(str, sbd->cmd, sbd->data);
    return true;
}
Beispiel #9
0
void APP_CC
list_insert_item(struct list* self, int index, tbus item)
{
  tbus* p;
  int i;

  if (index == self->count)
  {
    list_add_item(self, item);
    return;
  }
  if (index >= 0 && index < self->count)
  {
    self->count++;
    if (self->count > self->alloc_size)
    {
      i = self->alloc_size;
      self->alloc_size += self->grow_by;
      p = (tbus*)g_malloc(sizeof(tbus) * self->alloc_size, 1);
      g_memcpy(p, self->items, sizeof(tbus) * i);
      g_free(self->items);
      self->items = p;
    }
    for (i = (self->count - 2); i >= index; i--)
    {
      self->items[i + 1] = self->items[i];
    }
    self->items[index] = item;
  }
}
Beispiel #10
0
/* returns error */
int APP_CC
xrdp_cache_remove_os_bitmap(struct xrdp_cache *self, int rdpindex)
{
    struct xrdp_os_bitmap_item *bi;
    int index;

    if ((rdpindex < 0) || (rdpindex >= 2000))
    {
        return 1;
    }

    bi = self->os_bitmap_items + rdpindex;

    if (bi->bitmap->tab_stop)
    {
        index = list_index_of(self->xrdp_os_del_list, rdpindex);

        if (index == -1)
        {
            list_add_item(self->xrdp_os_del_list, rdpindex);
        }
    }

    xrdp_bitmap_delete(bi->bitmap);
    g_memset(bi, 0, sizeof(struct xrdp_os_bitmap_item));
    return 0;
}
Beispiel #11
0
int load_add_message(char *message_name, int message_id)
{
   id_type id = (id_type) SafeMalloc(sizeof(id_struct));
   message_handler_type m = (message_handler_type) SafeMalloc(sizeof(message_handler_struct));
   message_header_type h = (message_header_type) SafeMalloc(sizeof(message_header_struct));

   id->name = strdup(message_name);
   id->idnum = message_id;
   id->type = I_MESSAGE;
   id->ownernum = st.curclass;
   id->source = DBASE;

   h->message_id = id;
   h->params = NULL;

   m->header = h;
   m->locals = NULL;
   m->body = NULL;

   /* Add message to message list of current class */
   if (current_class == NULL)
      simple_error("Message appears outside of class in database file");
   else
      current_class->messages = list_add_item(current_class->messages, (void *) m);

   current_message = h;
   st.curmessage = message_id;
   /* OK if message already in table; just ignore return value */
   table_insert(st.globalvars, (void *) id, id_hash, id_compare);
   return True;
}
Beispiel #12
0
void assign_io_interrupt_to_cpu(long vector, int32 newCPU)
{
    ASSERT(sVectors[vector].type == INTERRUPT_TYPE_IRQ);

    int32 oldCPU = sVectors[vector].assigned_cpu->cpu;

    if (newCPU == -1)
        newCPU = assign_cpu();

    if (newCPU == oldCPU)
        return;

    ASSERT(oldCPU != -1);
    cpu_ent* cpu = &gCPU[oldCPU];

    SpinLocker locker(cpu->irqs_lock);
    sVectors[vector].assigned_cpu->cpu = -1;
    list_remove_item(&cpu->irqs, sVectors[vector].assigned_cpu);
    locker.Unlock();

    cpu = &gCPU[newCPU];
    locker.SetTo(cpu->irqs_lock, false);
    sVectors[vector].assigned_cpu->cpu = newCPU;
    arch_int_assign_to_cpu(vector, newCPU);
    list_add_item(&cpu->irqs, sVectors[vector].assigned_cpu);
}
Beispiel #13
0
/* Return False on error, True on success */
int load_add_class(char *class_name, int class_id, int superclass_id, char *superclass_name)
{
   /* Build up a class data structure for the new class. */
   id_type id = (id_type) SafeMalloc(sizeof(id_struct));
   id_type temp_id = (id_type) SafeMalloc(sizeof(id_struct));
   class_type c = (class_type) SafeMalloc(sizeof(class_struct));

   id->name = strdup(class_name);
   id->idnum = class_id;
   id->type = I_CLASS;
   id->source = DBASE;

   c->class_id = id;
   c->properties = c->messages = c->resources = c->classvars = NULL;
   c->is_new = False;  /* Don't generate code for this class */
   /* Store superclass id # in pointer for now.  Id # will be converted to pointer
    * when build_superclasses below is called. */
   c->superclass = (class_type)(intptr_t) superclass_id;

   /* Add to list of classes that have been read in */
   st.classes = list_add_item(st.classes, (void *) c);

   current_class = c;
   st.curclass = class_id;
   current_message = NULL;

   /* Call table_insert instead of add_identifier so that our id # from
    * the database file is preserved. 
    */
   if (table_insert(st.globalvars, (void *) id, id_hash, id_compare) == 0)
      return True;
   else return False;
}
Beispiel #14
0
int
callout_reset(struct callout *c, int ticks, void (*func)(void *), void *arg)
{
    int canceled = callout_stop(c);

    MutexLocker locker(sLock);

    c->c_func = func;
    c->c_arg = arg;

    TRACE("callout_reset %p, func %p, arg %p\n", c, c->c_func, c->c_arg);

    if (ticks >= 0) {
        // reschedule or add this timer
        if (c->due <= 0)
            list_add_item(&sTimers, c);

        c->due = system_time() + ticks_to_usecs(ticks);

        // notify timer about the change if necessary
        if (sTimeout > c->due)
            release_sem(sWaitSem);
    }

    return canceled;
}
Beispiel #15
0
d3d_render_cache *D3DCacheSystemSwap(d3d_render_cache_system *pCacheSystem)
{
	list_type			list = pCacheSystem->renderCacheList;
	d3d_render_cache	*pRenderCache = NULL;

	if (pCacheSystem->curCache->next)
	{
		pCacheSystem->curCache = pCacheSystem->curCache->next;

		return (d3d_render_cache *)pCacheSystem->curCache->data;
	}
	else
	{
		pRenderCache = (d3d_render_cache *)D3DRenderMalloc(sizeof(d3d_render_cache));

		if (pRenderCache)
		{
			D3DCacheInit(pRenderCache, TEMP_CACHE_MAX, TEMP_NUM_STAGES, D3DUSAGE_DYNAMIC |
				D3DUSAGE_WRITEONLY | gD3DDriverProfile.vertexProcessFlag);
			list_add_item(pCacheSystem->renderCacheList, pRenderCache);
			pCacheSystem->curCache = pCacheSystem->curCache->next;
			CACHE_RESET(pRenderCache);
			pCacheSystem->pCurCache = pRenderCache;
			pCacheSystem->numCaches++;

			return pRenderCache;
		}
		else
			return NULL;
	}
}
Beispiel #16
0
/*
 * add_parent_classvars: Add classvars of a class's superclasses to the
 *   class's classvars.  
 *   cv_list is a list used just for holding classvars; we need a separate list
 *   to handle classvars that are overridden with properties in a parent class.
 */
void add_parent_classvars(list_type cv_list, class_type base, class_type parent)
{
   list_type cv;

   if (parent == NULL)
   {
      list_delete(cv_list);
      return;
   }

   for (cv = parent->classvars; cv != NULL; cv = cv->next)
   {
      classvar_type classvar = (classvar_type) (cv->data);
      /* Parser error recovery may have made a NULL property */
      if (classvar != NULL)
      {
	 // Increment classvar count even for classvars that are overridden by properties.
	 // Only add non-overridden classvars to symbol table, though, so that references
	 // to the name will map to the property, not the classvar.

	 if (list_find_item(cv_list, classvar->id, id_compare) == NULL)
	 {
	    cv_list = list_add_item(cv_list, classvar->id);
	    st.maxclassvars++;
	 }

	 // Insert to table will fail if property with same name is already there
	 table_insert(st.classvars, (void *) classvar->id, id_hash, id_compare);
      }
   }

   add_parent_classvars(cv_list, base, parent->superclass);
}
Beispiel #17
0
int APP_CC
process_preamble_packet(struct xrdp_wm *self)
{
    char* line_end;
    char* t;
    char* q;
    char* r;
    DEBUG(("Preamble %s", self->session->client_info->osirium_preamble_buffer))
    line_end = g_strchr(self->session->client_info->osirium_preamble_buffer, '\n');
    while (line_end != 0)
    {
        q = line_end+1;
        // locate start of name
        while ( isspace(*q) )
        {
            q++;
        }
        DEBUG(("Preamble still needing processing %s", q));
        // locate separator
        t = r = g_strchr(q,'=');
        if ( r == 0 ) break;  // handle broken preamble by assuming at end of pre
        *r = 0; // ensure name terminated

        // strip possible trailing spaces from name
        while ( isspace(*--t) )
        {
            *t = 0; // nulls to terminate name
        };
        // locate start of value
        while ( isspace(*++r) )
        {
          // pre increment
        }

        line_end = g_strchr(r, '\n'); //locate end of value
        if (line_end)   // may be last value in preamble and have no LF at end.
        {
            *line_end = 0; // null terminate value
        }
        DEBUG(("Name '%s' Value '%s'", q, r));
        list_add_item(self->mm->login_names, (long)g_strdup(q));
        list_add_item(self->mm->login_values, (long)g_strdup(r));
    }
    g_free(self->session->client_info->osirium_preamble_buffer);
    self->session->client_info->osirium_preamble_buffer = 0;
    xrdp_wm_set_login_mode(self, 2);
}
Beispiel #18
0
list_type add_statement(list_type l, stmt_type s)
{
   /* Put in statement's line # */
   if (s != NULL)
      s->lineno = get_statement_line(s, lineno);
   
   return list_add_item(l, s);
}
Beispiel #19
0
Item* list_add(List *self, void *val)
{
    Item *item = list_item_new(val);
    if (item) {
        list_add_item(self, item);
    }

    return item;
}
/* Add a stream to the playback pool */
void stream_add_stream(struct stream *str)
{
    actl_lock();

    list_remove_item(stream_mgr.strl, str);
    list_add_item(stream_mgr.strl, str);

    actl_unlock();
}
Beispiel #21
0
/* returns error
   returns 0 if everything is ok
   returns 1 if problem reading file */
static int APP_CC
l_file_read_sections(int fd, int max_file_size, struct list *names)
{
    struct stream *s;
    char text[FILE_MAX_LINE_BYTES];
    char c;
    int in_it;
    int in_it_index;
    int len;
    int index;
    int rv;

    rv = 0;
    g_file_seek(fd, 0);
    in_it_index = 0;
    in_it = 0;
    g_memset(text, 0, FILE_MAX_LINE_BYTES);
    list_clear(names);
    make_stream(s);
    init_stream(s, max_file_size);
    len = g_file_read(fd, s->data, max_file_size);

    if (len > 0)
    {
        s->end = s->p + len;

        for (index = 0; index < len; index++)
        {
            in_uint8(s, c);

            if (c == '[')
            {
                in_it = 1;
            }
            else if (c == ']')
            {
                list_add_item(names, (tbus)g_strdup(text));
                in_it = 0;
                in_it_index = 0;
                g_memset(text, 0, FILE_MAX_LINE_BYTES);
            }
            else if (in_it)
            {
                text[in_it_index] = c;
                in_it_index++;
            }
        }
    }
    else if (len < 0)
    {
        rv = 1;
    }

    free_stream(s);
    return rv;
}
Beispiel #22
0
int APP_CC
xrdp_region_add_rect(struct xrdp_region* self, struct xrdp_rect* rect)
{
  struct xrdp_rect* r;

  r = (struct xrdp_rect*)g_malloc(sizeof(struct xrdp_rect), 1);
  *r = *rect;
  list_add_item(self->rects, (long)r);
  return 0;
}
Beispiel #23
0
/*
 * KeyAddTable:  Add the given key table to handle keypresses in the given
 *   game state.
 */
void KeyAddTable(int game_state, KeyTable table)
{
   KeyTableListEntry *entry;

   entry = (KeyTableListEntry *) SafeMalloc(sizeof (KeyTableListEntry));
   entry->state = game_state;
   entry->table = table;

   key_tables = list_add_item(key_tables, entry);
}
Beispiel #24
0
/* make a "debugging string"; the string has a numerical id, which is an
 * index to the list of all debugging strings encountered in this file */
const_type make_string_constant(char *str)
{
   const_type c = (const_type) SafeMalloc(sizeof(const_struct));

   c->type = C_STRING;
   /* Add string to symbol table, and remember index */
   c->value.numval = st.num_strings++;
   st.strings = list_add_item(st.strings, str);

   return c;
}
Beispiel #25
0
int list_test_and_add_item(struct list_mgt *mgt, struct list_item*item)
{
    struct list_item *sameitem;
    sameitem = list_test_find_samefile_item(mgt, item);
    if (sameitem) {
        //av_log(NULL, AV_LOG_INFO, "list_test_and_add_item found same item\nold:%s[seq=%d]\nnew:%s[seq=%d]", sameitem->file, sameitem->seq, item->file, item->seq);
        return -1;/*found same item,drop it */
    }

    list_add_item(mgt, item);
    return 0;
}
Beispiel #26
0
Bool HandleArticles(char *ptr, long len)
{
   WORD newsgroup;
   WORD num_articles;
   BYTE part, max_part;
   NewsArticle *article;
   list_type list = NULL;
   int i;

   if (len < SIZE_NEWSGROUP_ID + 2 * SIZE_PART + 2)
      return False;

   Extract(&ptr, &newsgroup, SIZE_NEWSGROUP_ID);
   Extract(&ptr, &part, SIZE_PART);
   Extract(&ptr, &max_part, SIZE_PART);
   Extract(&ptr, &num_articles, 2);
   len -= SIZE_NEWSGROUP_ID + 2 * SIZE_PART + 2;

   for (i=0; i < num_articles; i++)
   {
      if (len < 4 + SIZE_TIME)
      {
	 list_destroy(list);
	 return False;
      }
      len -= 4 + SIZE_TIME;

      article = (NewsArticle *) SafeMalloc(sizeof(NewsArticle));
      Extract(&ptr, &article->num, 4);
      Extract(&ptr, &article->time, SIZE_TIME);
      len = ExtractString(&ptr, len, article->poster, MAXUSERNAME);
      if (len == -1)
      {
	 list_destroy(list);
	 return False;
      }

      len = ExtractString(&ptr, len, article->title, MAX_SUBJECT);
      if (len == -1)
      {
	 list_destroy(list);
	 return False;
      }
      list = list_add_item(list, article);     
   }

   if (len != 0)
      return False;

   ReceiveArticles(newsgroup, part, max_part, list);
   return True;
}
Beispiel #27
0
int list_add_rect(struct list* l, int left, int top, int right, int bottom) {
	struct xrdp_rect* r;
	if (left <= right && top <= bottom)
	{
		r = (struct xrdp_rect*) g_malloc(sizeof(struct xrdp_rect), 1);
		r->left = left;
		r->top = top;
		r->right = right;
		r->bottom = bottom;
		list_add_item(l, (tbus) r);
	}
	return 0;
}
/* Callback for various list-moving operations */
static bool strl_enum_callback(struct stream *str, intptr_t data)
{
    actl_lock();

    list_remove_item(stream_mgr.strl, str);

    if (data == 1)
        list_add_item(stream_mgr.actl, str);

    actl_unlock();

    return true;
}
Beispiel #29
0
void D3DParticleEmitterInit(particle_system *pParticleSystem, float posX, float posY, float posZ,
                           float velX, float velY, float velZ, unsigned char b, unsigned char g,
                           unsigned char r, unsigned char a, int energy, int timerBase,
                           float rotX, float rotY, float rotZ, int randomPos, int randomRot,
                           int maxParticles, int emitterFlags)
{
   emitter	*pEmitter = NULL;

   if (pParticleSystem == NULL)
      return;

   pEmitter = (emitter *)SafeMalloc(sizeof(emitter));

   if (pEmitter == NULL)
      return;
   // User can choose how many particles to display.
   pEmitter->maxParticles = (maxParticles * config.particles) / 100;
   if (pEmitter->maxParticles <= 0)
      return;

   // Allocate particle mem and set to 0.
   pEmitter->particles = (particle *)SafeMalloc(pEmitter->maxParticles * sizeof(particle));
   memset(pEmitter->particles, 0, pEmitter->maxParticles * sizeof(particle));

   pEmitter->numParticles = 0;
   pEmitter->numAlive = 0;
   pEmitter->emitterFlags = emitterFlags;
   pEmitter->pos.x = posX;
   pEmitter->pos.y = posY;
   pEmitter->pos.z = posZ;
   pEmitter->rotation.x = rotX;
   pEmitter->rotation.y = rotY;
   pEmitter->rotation.z = rotZ;
   pEmitter->velocity.x = velX;
   pEmitter->velocity.y = velY;
   pEmitter->velocity.z = velZ;
   pEmitter->energy = energy;
   pEmitter->timer = timerBase;
   pEmitter->timerBase = timerBase;
   pEmitter->bgra.b = b;
   pEmitter->bgra.g = g;
   pEmitter->bgra.r = r;
   pEmitter->bgra.a = a;
   pEmitter->randomPos = randomPos;
   pEmitter->randomRot = randomRot;

   if (!pParticleSystem->emitterList)
      pParticleSystem->emitterList = list_create(pEmitter);
   else
      list_add_item(pParticleSystem->emitterList, pEmitter);
}
Beispiel #30
0
/* Return False on error, True on success */
int load_add_class(char *class_name, int class_id, int superclass_id, char *superclass_name)
{
   /* Build up a class data structure for the new class. */
   id_type id = (id_type)SafeMalloc(sizeof(id_struct));
   id_type temp_id = (id_type)SafeMalloc(sizeof(id_struct));
   class_type c = (class_type)SafeMalloc(sizeof(class_struct));

   // Adding new built-in object types will render existing kodbase.txt files
   // incompatible. This isn't a problem as a pre-existing kodbase.txt is only
   // required for reloading a live server, so a new one can be made. Check
   // for built-in class name/ID mismatches here and instruct the user to
   // delete kodbase.txt if this check fails.

   extern id_struct BuiltinIds[];
   if ((strcmp(BuiltinIds[SETTINGS_CLASS].name, class_name) == 0
         && class_id != SETTINGS_CLASS)
      || (strcmp(BuiltinIds[REALTIME_CLASS].name, class_name) == 0
         && class_id != REALTIME_CLASS)
      || (strcmp(BuiltinIds[EVENTENGINE_CLASS].name, class_name) == 0
         && class_id != EVENTENGINE_CLASS))
   {
      database_error("Incompatible kodbase.txt. Delete the file and recompile.");
      return False;
   }

   id->name = strdup(class_name);
   id->idnum = class_id;
   id->type = I_CLASS;
   id->source = DBASE;

   c->class_id = id;
   c->properties = c->messages = c->resources = c->classvars = NULL;
   c->is_new = False;  /* Don't generate code for this class */
   /* Store superclass id # in pointer for now.  Id # will be converted to pointer
    * when build_superclasses below is called. */
   c->superclass = (class_type) superclass_id;

   /* Add to list of classes that have been read in */
   st.classes = list_add_item(st.classes, (void *) c);

   current_class = c;
   st.curclass = class_id;
   current_message = NULL;

   /* Call table_insert instead of add_identifier so that our id # from
    * the database file is preserved. 
    */
   if (table_insert(st.globalvars, (void *) id, id_hash, id_compare) == 0)
      return True;
   else return False;
}