Exemplo n.º 1
0
int module_start (Q5Module* self)
{
  int i;  
  uint32_t gameEngineSrvNo;
  ENetAddress address;

  if (enet_initialize () != 0)
  {
    eclogger_msg (LL_ERROR, properties.name, "server", "could not initialize enet");
    return FALSE;
  }
  
  enet_address_set_host (&address, self->host);
  address.port = self->port;
  
  self->server = enet_host_create (&address, 32, 2, 0, 0);      
  if (!self->server)
  {
    enet_deinitialize();

    eclogger_msg (LL_ERROR, properties.name, "server", "can't start enet server");
    return FALSE;
  }

  eclogger_fmt (LL_DEBUG, properties.name, "server", "listen '%s' on port '%u'", self->host, self->port);

  self->threads = eclist_new ();
  
  self->done = FALSE;
  
  for (i = 0; i < 1; i++)
  {
    EcThread thread = ecthread_new ();
    
    eclist_append(self->threads, thread);
    
    ecthread_start(thread, module_thread_run, self);
  }

  gameEngineSrvNo = q5core_getModuleId (self->core, "GAME_E");
  
  if (gameEngineSrvNo == 0)
  {
    eclogger_fmt (LL_WARN, properties.name, "server", "no game engine available");
  }
  
  self->entities = gse_create (self->server, gameEngineSrvNo, "Lobo's geiler server");
  
  gse_addRealm (self->entities, "the shire");
  
  ecmessages_add (self->instance->msgid, Q5_DATA_GET, module_callback_get, self);

  return TRUE;
}
Exemplo n.º 2
0
int main (int argc, char *argv[])
{
  EcMessageData d01;
  EcMessagesOutput o1;
  EcThread threads [21];
  int i;

  ecmessages_initialize ();
  
  ecmessages_add (0x01, 0x01, m01, NULL);
  ecmessages_add (0x02, 0x01, m02, NULL);
  
  ecmessages_broadcast (0x01, NULL, NULL);
  
  ecmessages_send (0x02, 0x01, NULL, NULL);
  ecmessages_send (0x01, 0x01, NULL, NULL);
  ecmessages_send (0x01, 0x02, NULL, NULL);
    
  d01.type = 0;
  d01.ref = 0;
  d01.content = ecudc_create (EC_ALLOC, ENTC_UDC_STRING, NULL);
  ecudc_setS (d01.content, "Hello World");

  ecmessages_broadcast (0x01, &d01, NULL);
  
  ecudc_destroy(EC_ALLOC, &(d01.content));
  
  o1 = ecmessages_output_create (c01, NULL, 0, 0);
  ecmessages_broadcast (0x01, NULL, o1);
  ecmessages_output_destroy (&o1);
  
  printf("threading !!!!\n");
  
  for (i = 0; i < 20; i++)
  {
    threads [i] = ecthread_new ();
  }
  
  for (i = 0; i < 20; i++)
  {
    ecthread_start(threads [i], th01, NULL);
  }

  for (i = 0; i < 20; i++)
  {
    ecthread_join(threads [i]);
    ecthread_delete(&(threads [i]));
  }
  
  ecmessages_deinitialize ();
  
  return 0;
}