version 1.25 | | version 1.26 |
---|
| | |
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; |
} | | } |
| | |
| | |
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; |
} | | } |
| | |
| | |
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; |
} | | } |
| | |
| | |
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; |
} | | } |
| | |
{ | | { |
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; |
} | | } |
| | |
{ | | { |
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; |
} | | } |
| | |
{ | | { |
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; |
} | | } |
| | |
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); |
} | | } |
| | |
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); |
| | |
| | |
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); |
} | | } |
| | |
| | |
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); |
} | | } |
| | |
| | |
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); |
} | | } |
| | |
| | |
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); |
} | | } |
| | |
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; |
| | |
| | |
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; |
| | |
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; |
| | |
#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; |
| | |
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); |
| | |
| | |
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; |
| | |
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; |
| | |
} | | } |
} | | } |
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; |
} | | } |
| | |
| | |
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; |
} | | } |
| | |
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; |
} | | } |
| | |
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); |
} | | } |
| | |
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; |
| | |
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; |
} | | } |
| | |
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*))); |
| | |
| | |
va_end(args); | | va_end(args); |
| | |
if (!do_script(context,0)) | | if (!do_script(context, 0)) { |
{ | | |
freeContext(context); | | freeContext(context); |
return &rv; | | return &rv; |
} | | } |
| | |
Py_Finalize(); | | Py_Finalize(); |
return 0; | | return 0; |
} | | } |
| | |