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 module_stop (Q5Module* self)
{
  EcListCursor cursor;
  
  self->done = TRUE;
  
  eclist_cursor (self->threads, &cursor);
  
  while (eclist_cnext (&cursor))
  {
    ecthread_join (cursor.value);
  }
  
  while (eclist_cnext (&cursor))
  {
    ecthread_delete((EcThread*)(&cursor.value));
  }
  
  eclist_delete (&(self->threads));
  
  gse_destroy(&(self->entities));

  enet_host_destroy (self->server);

  enet_deinitialize();
   
  eclogger_fmt (LL_DEBUG, properties.name, "server", "stopped");  

  return TRUE;
}
Exemplo n.º 3
0
int gs_frames_next (GameServerFrameCursor* cursor, GameServerFrame* frame)
{
  if (cursor->pos == 0)
  {
    const unsigned char* posbuf = cursor->orig->buffer + cursor->pos;
   
    frame->ch1 = posbuf [0];
    frame->ch2 = posbuf [1];

    eclogger_fmt (LL_TRACE, "GAME_S", "frame", "received %i bytes [%i|%i]", cursor->orig->size, frame->ch1, frame->ch2);  
    
    
    /*
    if (posbuf [2] & C_BUFFER_SIZE_BIG)
    {
      EcBuffer_s buf = { cursor->orig->buffer + 8, cursor->orig->size - 8 };
      
      frame->content = ecbins_read(&buf, NULL);      
    }
    else if (posbuf [2] & C_BUFFER_SIZE_NORMAL)
    {
      EcBuffer_s buf = { cursor->orig->buffer + 6, cursor->orig->size - 6 };      

      frame->content = ecbins_read(&buf, NULL);      
    }
    else
    {
      EcBuffer_s buf = { cursor->orig->buffer + 5, cursor->orig->size - 5 };      
      
      frame->content = ecbins_read(&buf, NULL);      
    }
     */

    {
      EcBuffer_s buf = { cursor->orig->buffer + 2, cursor->orig->size - 2 };      
      
      frame->content = ecbins_read(&buf, NULL);      
    }
    
    cursor->pos = 1;
    
    return TRUE;
  }
  else
  {
    if (frame->content)
    {
      ecudc_destroy(&(frame->content));
    }
    
    return FALSE;
  }
}
Exemplo n.º 4
0
const EcString ecmime_getFromFile (const EcString filename)
{
  const EcString ext = ecfs_extractFileExtension (filename);
  
  if (ext)
  {
    return ecmime_getFromExtension (ext);
  }
  else
  {
    eclogger_fmt (LL_WARN, "ENTC", "mime", "can't extract extension from '%s'", filename);
    return "application/octet-stream";
  }
}
Exemplo n.º 5
0
EcListNode eclist_insert (EcAlloc alloc, EcList self, EcListNode node, void* data)
{
  EcListNode n01;
  EcListNode noden = alloc->fnew (alloc->ptr, sizeof(struct EcListNode_s));
  
  if (noden == NULL)
  {
    eclogger_fmt (LL_FATAL, "ENTC", "eclist ins", "can't create new node");
    return NULL;
  }
  
  /* set the data */
  noden->data = data;

  n01 = node->next;
  /* set forward */
  noden->forw = n01->forw;
  n01->forw = noden;
  /* set next */
  node->next = noden;
  noden->next = n01;
  
  return noden;
}
Exemplo n.º 6
0
void adbl_parseXMLDatabase( AdblManager self, EcXMLStream xmlstream, const char* confpath)
{
  const EcString name = ecxmlstream_nodeAttribute( xmlstream, "name" );
  if(name)
  {
    const EcString dbtype = ecxmlstream_nodeAttribute( xmlstream, "type" );
    if(dbtype)
    {
      ADBLModuleProperties* pp;
      EcMapNode node;
      
      node = ecmap_find(self->modules, dbtype);
      if (node == ecmap_end(self->modules))
      {
        eclogger_fmt (LL_WARN, MODULE, "credentials", "database '%s' not in the list", dbtype);
        return;
      }
      
      pp = ecmap_data (node);
      
      node = ecmap_find(self->credentials, name);      
      if( node == ecmap_end(self->credentials) )
      { 
        int isfile = FALSE;
        EcString fileprefix = NULL;
        EcString filextension = NULL;
        //create new credential
        AdblCredentials* pc = adbl_credentials_new (dbtype);
        pc->pp = pp;
        //add to map
        ecmap_append(self->credentials, name, pc);        
        //parse the other stuff
        ENTC_XMLSTREAM_BEGIN

        if( ecxmlstream_isBegin( xmlstream, "connection" ) )
        {
		        const char* port = ecxmlstream_nodeAttribute( xmlstream, "port" );

          pc->properties.host = ecstr_copy( ecxmlstream_nodeAttribute( xmlstream, "host" ) );
  
          if(port)
            pc->properties.port = atoi(port);

        }
        else if( ecxmlstream_isBegin( xmlstream, "schema" ) )
        {
          pc->properties.schema = ecstr_copy( ecxmlstream_nodeAttribute( xmlstream, "name" ) );
          pc->properties.username = ecstr_copy( ecxmlstream_nodeAttribute( xmlstream, "user" ) );
          pc->properties.password = ecstr_copy( ecxmlstream_nodeAttribute( xmlstream, "password" ) );
        }
        else if( ecxmlstream_isBegin( xmlstream, "file" ) )
        {
          isfile = TRUE;
          fileprefix = ecstr_copy( ecxmlstream_nodeAttribute( xmlstream, "prefix" ) );
          filextension = ecstr_copy( ecxmlstream_nodeAttribute( xmlstream, "filextension" ) );
        }
        ENTC_XMLSTREAM_END( "database" )
        //create the filename
        if( isfile == TRUE )
        {
          EcStream file = ecstream_new();
          
          if( fileprefix )
          {
            ecstream_append( file, fileprefix );
            ecstream_append( file, "_" );
            ecstr_delete (&fileprefix );  
          }

          if( pc->properties.schema )
          {
            ecstream_append( file, pc->properties.schema );
          }

          if( filextension )
          {
            ecstream_append( file, filextension );
            ecstr_delete (&filextension);  
          }
          else
          {
            ecstream_append( file, ".db" );
          }
          
          pc->properties.file = ecfs_mergeToPath(confpath, ecstream_buffer( file ));
          
          /* clean up */
          ecstream_delete(&file);
        }
      }
      else
      {
        eclogger_fmt (LL_WARN, MODULE, "credentials", "parsing the config file: db-source already exists [%s] in current register", name );
      }     
    }
Exemplo n.º 7
0
const EcString ecmime_getFromExtension (const EcString ext)
{
  static EcMapChar mime_types = NULL;
  
  if (mime_types == NULL)
  {
    eclogger_fmt (LL_TRACE, "ENTC", "mime", "create new mime types");

    mime_types = ecmapchar_create (EC_ALLOC);
    
    ecmapchar_append( mime_types, "pdf",      "application/pdf" );
    ecmapchar_append( mime_types, "sig",      "application/pgp-signature" );
    ecmapchar_append( mime_types, "class",    "application/octet-stream" );
    ecmapchar_append( mime_types, "ps",       "application/postscript" );
    ecmapchar_append( mime_types, "torrent",  "application/x-bittorrent" );
    ecmapchar_append( mime_types, "dvi",      "application/x-dvi" );
    ecmapchar_append( mime_types, "gz",       "application/x-gzip" );
    ecmapchar_append( mime_types, "pac",      "application/x-ns-proxy-autoconfig" );
    ecmapchar_append( mime_types, "swf",      "application/x-shockwave-flash" );
    
    ecmapchar_append( mime_types, "tgz",      "application/x-tgz" );
    ecmapchar_append( mime_types, "tar",      "application/x-tar" );
    ecmapchar_append( mime_types, "zip",      "application/zip" );
    ecmapchar_append( mime_types, "mp3",      "audio/mpeg" );
    ecmapchar_append( mime_types, "m3u",      "audio/x-mpegurl" );
    ecmapchar_append( mime_types, "wma",      "audio/x-ms-wma" );
    ecmapchar_append( mime_types, "wax",      "audio/x-ms-wax" );
    ecmapchar_append( mime_types, "ogg",      "application/ogg" );
    ecmapchar_append( mime_types, "wav",      "audio/x-wav" );
    
    ecmapchar_append( mime_types, "gif",      "image/gif" );
    ecmapchar_append( mime_types, "jpg",      "image/jpeg" );
    ecmapchar_append( mime_types, "jpeg",     "image/jpeg" );
    ecmapchar_append( mime_types, "png",      "image/png" );
    ecmapchar_append( mime_types, "xbm",      "image/x-xbitmap" );
    ecmapchar_append( mime_types, "xpm",      "image/x-xpixmap" );
    ecmapchar_append( mime_types, "xwd",      "image/x-xwindowdump" );
    ecmapchar_append( mime_types, "svg",      "image/svg+xml");
    
    ecmapchar_append( mime_types, "css",      "text/css" );
    ecmapchar_append( mime_types, "html",     "text/html" );
    ecmapchar_append( mime_types, "htm",      "text/html" );
    ecmapchar_append( mime_types, "js",       "text/javascript" );
    ecmapchar_append( mime_types, "asc",      "text/plain" );
    ecmapchar_append( mime_types, "c",        "text/plain" );
    ecmapchar_append( mime_types, "txt",      "text/plain" );
    ecmapchar_append( mime_types, "json",     "application/json");
    ecmapchar_append( mime_types, "ico",      "image/x-ico; charset=binary" );
    ecmapchar_append( mime_types, "map",      "application/json");
    
    ecmapchar_append( mime_types, "woff",     "application/font-woff");
    ecmapchar_append( mime_types, "woff2",    "application/font-woff2");
    ecmapchar_append( mime_types, "ttf",      "application/font-ttf");
    ecmapchar_append( mime_types, "eot",      "application/vnd.ms-fontobject");
    ecmapchar_append( mime_types, "otf",      "application/font-otf");
    
    ecmapchar_append( mime_types, "csv",      "text/csv");
    ecmapchar_append( mime_types, "xls",      "application/vnd.ms-excel");
    
    ecmapchar_append( mime_types, "exe",      "application/octet-stream" );
    ecmapchar_append( mime_types, "dll",      "application/x-msdownload" );
  }
  
  {
    EcMapCharNode node = ecmapchar_find( mime_types, ext);
    
    if( node != ecmapchar_end( mime_types ))
    {
      return ecmapchar_data( node );
    }
    else
    {
      eclogger_fmt (LL_WARN, "ENTC", "mime", "can't find mime type from extension '%s'", ext);
      return "application/octet-stream";
    }
  }
}