Difference for plugins/cfpython/cfpython.c from version 1.25 to 1.26


version 1.25 version 1.26
Line 210
 
Line 210
     object* op;      object* op;
     op = cf_create_object();      op = cf_create_object();
   
     if (op == NULL)      if (op == NULL) {
     {  
         Py_INCREF(Py_None);          Py_INCREF(Py_None);
         return Py_None;          return Py_None;
     }      }
Line 227
 
Line 226
   
     op = cf_create_object_by_name(obname);      op = cf_create_object_by_name(obname);
   
     if (op == NULL)      if (op == NULL) {
     {  
         Py_INCREF(Py_None);          Py_INCREF(Py_None);
         return Py_None;          return Py_None;
     }      }
Line 283
 
Line 281
   
     if (foundpl!=NULL)      if (foundpl!=NULL)
         return Py_BuildValue("O",Crossfire_Object_wrap(foundpl->ob));          return Py_BuildValue("O",Crossfire_Object_wrap(foundpl->ob));
     else      else {
     {  
         Py_INCREF(Py_None);          Py_INCREF(Py_None);
         return Py_None;          return Py_None;
     }      }
Line 299
 
Line 296
   
     map = cf_map_get_map(mapname);      map = cf_map_get_map(mapname);
   
     if (map == NULL)      if (map == NULL) {
     {  
         Py_INCREF(Py_None);          Py_INCREF(Py_None);
         return Py_None;          return Py_None;
     }      }
Line 457
 
Line 453
 {  {
     if (!PyArg_ParseTuple(args,"",NULL))      if (!PyArg_ParseTuple(args,"",NULL))
         return NULL;          return NULL;
  if (!current_context->who)      if (!current_context->who) {
  {  
  Py_INCREF(Py_None);   Py_INCREF(Py_None);
  return Py_None;   return Py_None;
  }   }
Line 469
 
Line 464
 {  {
     if (!PyArg_ParseTuple(args,"",NULL))      if (!PyArg_ParseTuple(args,"",NULL))
         return NULL;          return NULL;
  if (!current_context->activator)      if (!current_context->activator) {
  {  
  Py_INCREF(Py_None);   Py_INCREF(Py_None);
  return Py_None;   return Py_None;
  }   }
Line 481
 
Line 475
 {  {
     if (!PyArg_ParseTuple(args,"",NULL))      if (!PyArg_ParseTuple(args,"",NULL))
         return NULL;          return NULL;
  if (!current_context->third)      if (!current_context->third) {
  {  
  Py_INCREF(Py_None);   Py_INCREF(Py_None);
  return Py_None;   return Py_None;
  }   }
Line 495
 
Line 488
         return NULL;          return NULL;
   
     if (current_context->message == NULL)      if (current_context->message == NULL)
     {  
         return Py_BuildValue("");          return Py_BuildValue("");
     }  
     else      else
         return Py_BuildValue("s",current_context->message);          return Py_BuildValue("s",current_context->message);
 }  }
Line 522
 
Line 513
         return NULL;          return NULL;
   
  data = PyDict_GetItemString(private_data,current_context->script);   data = PyDict_GetItemString(private_data,current_context->script);
  if (!data)      if (!data) {
  {  
  data = PyDict_New();   data = PyDict_New();
  PyDict_SetItemString(private_data,current_context->script,data);   PyDict_SetItemString(private_data,current_context->script,data);
  Py_DECREF(data);   Py_DECREF(data);
Line 548
 
Line 538
   
  list = PyList_New(0);   list = PyList_New(0);
  arch = cf_archetype_get_first();   arch = cf_archetype_get_first();
  while (arch)      while (arch) {
  {  
  PyList_Append(list,Crossfire_Archetype_wrap(arch));   PyList_Append(list,Crossfire_Archetype_wrap(arch));
  arch = cf_archetype_get_next(arch);   arch = cf_archetype_get_next(arch);
  }   }
Line 563
 
Line 552
   
  list = PyList_New(0);   list = PyList_New(0);
  map = cf_map_get_first();   map = cf_map_get_first();
  while (map)      while (map) {
  {  
  PyList_Append(list,Crossfire_Map_wrap(map));   PyList_Append(list,Crossfire_Map_wrap(map));
  map = cf_map_get_property(map,CFAPI_MAP_PROP_NEXT);   map = cf_map_get_property(map,CFAPI_MAP_PROP_NEXT);
  }   }
Line 578
 
Line 566
   
  list = PyList_New(0);   list = PyList_New(0);
  party = cf_party_get_first();   party = cf_party_get_first();
  while (party)      while (party) {
  {  
  PyList_Append(list,Crossfire_Party_wrap(party));   PyList_Append(list,Crossfire_Party_wrap(party));
  party = cf_party_get_next(party);   party = cf_party_get_next(party);
  }   }
Line 593
 
Line 580
   
  list = PyList_New(0);   list = PyList_New(0);
  reg = cf_region_get_first();   reg = cf_region_get_first();
  while (reg)      while (reg) {
  {  
  PyList_Append(list,Crossfire_Region_wrap(reg));   PyList_Append(list,Crossfire_Region_wrap(reg));
  reg = cf_region_get_next(reg);   reg = cf_region_get_next(reg);
  }   }
Line 611
 
Line 597
     if (!PyArg_ParseTuple(args, "ssd",&cmdname,&scriptname,&cmdspeed))      if (!PyArg_ParseTuple(args, "ssd",&cmdname,&scriptname,&cmdspeed))
         return NULL;          return NULL;
   
     if (cmdspeed < 0)      if (cmdspeed < 0) {
     {  
         set_exception("speed must not be negative");          set_exception("speed must not be negative");
         return NULL;          return NULL;
     }      }
   
     for (i=0;i<NR_CUSTOM_CMD;i++)      for (i = 0; i < NR_CUSTOM_CMD; i++) {
     {          if (CustomCommand[i].name != NULL) {
         if (CustomCommand[i].name != NULL)              if (!strcmp(CustomCommand[i].name, cmdname)) {
         {  
             if (!strcmp(CustomCommand[i].name,cmdname))  
             {  
                 set_exception("command '%s' is already registered", cmdname);                  set_exception("command '%s' is already registered", cmdname);
                 return NULL;                  return NULL;
             }              }
         }          }
     }      }
     for (i=0;i<NR_CUSTOM_CMD;i++)      for (i = 0; i < NR_CUSTOM_CMD; i++) {
     {          if (CustomCommand[i].name == NULL) {
         if (CustomCommand[i].name == NULL)  
         {  
             CustomCommand[i].name = cf_strdup_local(cmdname);              CustomCommand[i].name = cf_strdup_local(cmdname);
             CustomCommand[i].script = cf_strdup_local(scriptname);              CustomCommand[i].script = cf_strdup_local(scriptname);
             CustomCommand[i].speed = cmdspeed;              CustomCommand[i].speed = cmdspeed;
Line 651
 
Line 631
   
 void pushContext(CFPContext* context)  void pushContext(CFPContext* context)
 {  {
     if (current_context == NULL)      if (current_context == NULL) {
     {  
         context_stack = context;          context_stack = context;
         context->down = NULL;          context->down = NULL;
     }      } else {
     else  
     {  
         context->down = current_context;          context->down = current_context;
     }      }
     current_context = context;      current_context = context;
Line 666
 
Line 643
 CFPContext* popContext()  CFPContext* popContext()
 {  {
     CFPContext* oldcontext;      CFPContext* oldcontext;
     if (current_context != NULL)      if (current_context != NULL) {
     {  
         oldcontext = current_context;          oldcontext = current_context;
         current_context = current_context->down;          current_context = current_context->down;
         return oldcontext;          return oldcontext;
Line 695
 
Line 671
 #endif  #endif
   
     scriptfile = fopen(context->script,"r");      scriptfile = fopen(context->script,"r");
     if (scriptfile == NULL)      if (scriptfile == NULL) {
     {  
         if (!silent)          if (!silent)
             printf( "cfpython - The Script file %s can't be opened\n",context->script);              printf( "cfpython - The Script file %s can't be opened\n",context->script);
         return 0;          return 0;
Line 705
 
Line 680
     dict = PyDict_New();      dict = PyDict_New();
     PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins());      PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins());
     ret = PyRun_File(scriptfile, context->script, Py_file_input, dict, dict);      ret = PyRun_File(scriptfile, context->script, Py_file_input, dict, dict);
     if (PyErr_Occurred())      if (PyErr_Occurred()) {
     {  
         PyErr_Print();          PyErr_Print();
     }      }
     Py_XDECREF(ret);      Py_XDECREF(ret);
 #if 0  #if 0
     printf( "cfpython - %d items in heap\n", PyDict_Size(dict));      printf( "cfpython - %d items in heap\n", PyDict_Size(dict));
     list = PyDict_Values(dict);      list = PyDict_Values(dict);
     for (item = PyList_Size(list) - 1; item >= 0; item--)      for (item = PyList_Size(list) - 1; item >= 0; item--) {
     {  
         dict = PyList_GET_ITEM(list,item);          dict = PyList_GET_ITEM(list,item);
         ret = PyObject_Str(dict);          ret = PyObject_Str(dict);
         printf(" ref %s = %d\n",PyString_AsString(ret),dict->ob_refcnt);          printf(" ref %s = %d\n",PyString_AsString(ret),dict->ob_refcnt);
Line 766
 
Line 739
   
     CFPythonError = PyErr_NewException("Crossfire.error",NULL,NULL);      CFPythonError = PyErr_NewException("Crossfire.error",NULL,NULL);
     PyDict_SetItemString(d,"error",CFPythonError);      PyDict_SetItemString(d,"error",CFPythonError);
     for (i=0;i<NR_CUSTOM_CMD;i++)      for (i = 0; i < NR_CUSTOM_CMD; i++) {
     {  
         CustomCommand[i].name   = NULL;          CustomCommand[i].name   = NULL;
         CustomCommand[i].script = NULL;          CustomCommand[i].script = NULL;
         CustomCommand[i].speed  = 0.0;          CustomCommand[i].speed  = 0.0;
Line 787
 
Line 759
     va_start(args, type);      va_start(args, type);
     propname = va_arg(args, char *);      propname = va_arg(args, char *);
   
     if(!strcmp(propname,"command?"))      if (!strcmp(propname, "command?")) {
     {  
         char* cmdname;          char* cmdname;
         cmdname = va_arg(args, char *);          cmdname = va_arg(args, char *);
         va_end(args);          va_end(args);
   
         for (i=0;i<NR_CUSTOM_CMD;i++)          for (i = 0; i < NR_CUSTOM_CMD; i++) {
         {              if (CustomCommand[i].name != NULL) {
             if (CustomCommand[i].name != NULL)                  if (!strcmp(CustomCommand[i].name, cmdname)) {
             {  
                 if (!strcmp(CustomCommand[i].name,cmdname))  
                 {  
                     rtn_cmd.name = CustomCommand[i].name;                      rtn_cmd.name = CustomCommand[i].name;
                     rtn_cmd.time = (float)CustomCommand[i].speed;                      rtn_cmd.time = (float)CustomCommand[i].speed;
                     rtn_cmd.func = runPluginCommand;                      rtn_cmd.func = runPluginCommand;
Line 808
 
Line 776
             }              }
         }          }
         return NULL;          return NULL;
     }      } else if (!strcmp(propname, "Identification")) {
     else if (!strcmp(propname, "Identification"))  
     {  
         va_end(args);          va_end(args);
         return PLUGIN_NAME;          return PLUGIN_NAME;
     }      } else if (!strcmp(propname, "FullName")) {
     else if (!strcmp(propname, "FullName"))  
     {  
         va_end(args);          va_end(args);
         return PLUGIN_VERSION;          return PLUGIN_VERSION;
     }      }
Line 830
 
Line 794
   
  rv = 0;   rv = 0;
   
     if (current_command < -999)      if (current_command < -999) {
     {  
         printf("Illegal call of runPluginCommand, call find_plugin_command first.\n");          printf("Illegal call of runPluginCommand, call find_plugin_command first.\n");
         return 1;          return 1;
     }      }
Line 848
 
Line 811
     snprintf(context->options, sizeof(context->options), "%s", params);      snprintf(context->options, sizeof(context->options), "%s", params);
     context->returnvalue = 1; /* Default is "command successful" */      context->returnvalue = 1; /* Default is "command successful" */
   
     if (!do_script(context,0))      if (!do_script(context, 0)) {
     {  
         freeContext(context);          freeContext(context);
         return rv;          return rv;
     }      }
Line 891
 
Line 853
     registerGlobalEvent(NULL,EVENT_KICK,PLUGIN_NAME,globalEventListener);      registerGlobalEvent(NULL,EVENT_KICK,PLUGIN_NAME,globalEventListener);
   
     scriptfile = fopen(cf_get_maps_directory("python/events/python_init.py"),"r");      scriptfile = fopen(cf_get_maps_directory("python/events/python_init.py"),"r");
     if (scriptfile != NULL)      if (scriptfile != NULL) {
     {  
         PyRun_SimpleFile(scriptfile, cf_get_maps_directory("python/events/python_init.py"));          PyRun_SimpleFile(scriptfile, cf_get_maps_directory("python/events/python_init.py"));
         fclose(scriptfile);          fclose(scriptfile);
     }      }
Line 925
 
Line 886
     rv = context->returnvalue = 0;      rv = context->returnvalue = 0;
     snprintf(context->script, sizeof(context->script), "%s", cf_get_maps_directory("python/events/python_event.py"));      snprintf(context->script, sizeof(context->script), "%s", cf_get_maps_directory("python/events/python_event.py"));
     strcpy(context->options, "");      strcpy(context->options, "");
     switch(context->event_code)      switch(context->event_code) {
     {  
         case EVENT_CRASH:          case EVENT_CRASH:
             printf( "Unimplemented for now\n");              printf( "Unimplemented for now\n");
             break;              break;
Line 1028
 
Line 988
     va_end(args);      va_end(args);
     context->returnvalue = 0;      context->returnvalue = 0;
   
     if (!do_script(context,1))      if (!do_script(context, 1)) {
     {  
         freeContext(context);          freeContext(context);
         return &rv;          return &rv;
     }      }
Line 1061
 
Line 1020
     context->activator   = Crossfire_Object_wrap(va_arg(args, object*));      context->activator   = Crossfire_Object_wrap(va_arg(args, object*));
     context->third       = Crossfire_Object_wrap(va_arg(args, object*));      context->third       = Crossfire_Object_wrap(va_arg(args, object*));
     buf = va_arg(args, char*);      buf = va_arg(args, char*);
     if (buf !=0)      if (buf != NULL)
         snprintf(context->message, sizeof(context->message), "%s", buf);          snprintf(context->message, sizeof(context->message), "%s", buf);
     context->fix         = va_arg(args, int);      context->fix         = va_arg(args, int);
     snprintf(context->script, sizeof(context->script), "%s", cf_get_maps_directory(va_arg(args, char*)));      snprintf(context->script, sizeof(context->script), "%s", cf_get_maps_directory(va_arg(args, char*)));
Line 1070
 
Line 1029
   
     va_end(args);      va_end(args);
   
     if (!do_script(context,0))      if (!do_script(context, 0)) {
     {  
         freeContext(context);          freeContext(context);
         return &rv;          return &rv;
     }      }
Line 1088
 
Line 1046
     Py_Finalize();      Py_Finalize();
     return 0;      return 0;
 }  }
   


Legend:
line(s) removed in v.1.25 
line(s) changed
 line(s) added in v.1.26

File made using version 1.98 of cvs2html by leaf at 2011-07-21 16:59