/* File: module_pyNetrek_server_tools_setgame.c Version: 0.1 Date: 2007/03/04 19:55:26 EST William U. Clark, Jr. */ /* gcc -pthread -shared -I../include module_pyNetrek_server_util_setgame.c -I/usr/include/python2.4 ../ntserv/libnetrek.a /usr/lib/libpython2.4.so.1.0 -o setgame.so */ #include "Python.h" #include #include #include #include #include #include "defs.h" #include "struct.h" #include "data.h" #include "proto.h" #include "util.h" /* send message to players */ static void _pmessage(char *str, int recip, int group) { struct message *cur; if (++(mctl->mc_current) >= MAXMESSAGE) mctl->mc_current = 0; cur = &messages[mctl->mc_current]; cur->m_no = mctl->mc_current; cur->m_flags = group; cur->m_time = 0; cur->m_from = 255; cur->m_recpt = recip; (void) sprintf(cur->m_data, "%s", str); cur->m_flags |= MVALID; } /* send message to players */ static void say(const char *fmt, ...) { va_list args; char buf[80]; va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); _pmessage(buf, 0, MALL); va_end(args); } static char setgame_doc[] = "This module interfaces netrek setship. It provide one function: setship()."; static PyObject* setgame_pause(PyObject *self, PyObject *args) { status->gameup |= GU_PAUSED; say("setgame->Game paused."); return Py_BuildValue("s", "Game Paused"); } static char setgame_pause_doc[] = "pause()\n\ \n\ Pauses Netrek Server Simulation."; static PyObject* setgame_resume(PyObject *self, PyObject *args) { status->gameup &= ~GU_PAUSED; say("setgame->Game resumed."); return Py_BuildValue("s", "Game Resumed"); } static char setgame_resume_doc[] = "resume()\n\ \n\ Resumes Netrek Server Simulation."; static PyObject* setgame_terminate(PyObject *self, PyObject *args) { status->gameup &= ~GU_GAMEOK; return Py_BuildValue("s", "Game terminated"); } static char setgame_terminate_doc[] = "terminate()\n\ \n\ Terminate the Netrek game."; static PyObject* setgame_waitForTerminate(PyObject *self, PyObject *args) { while (status->gameup & GU_GAMEOK) sleep(1); return Py_BuildValue("s", "Game terminated"); } static char setgame_waitForTerminate_doc[] = "waitForTerminate()\n\ \n\ Wait for the game to terminate."; static PyObject* setgame_setTestCounter(PyObject *self, PyObject *args) { PyObject *n; if(!PyArg_ParseTuple(args, "i", &n)){ return NULL; } context->frame_test_counter = n; return Py_BuildValue("si", "Test counter set:", n); } static char setgame_setTestCounter_doc[] = "setTestCounter(n)\n\ \n\ Set the number of frames to step in test mode."; static PyObject* setgame_setTestMode(PyObject *self, PyObject *args) { PyObject *n; if(!PyArg_ParseTuple(args, "i", &n)){ return NULL; } if(n==0){ context->frame_test_mode = 0; return Py_BuildValue("i", context->frame_test_mode); } else { context->frame_test_mode = 1; return Py_BuildValue("i", context->frame_test_mode); } } static char setgame_setTestMode_doc[] = "setTestMode(n)\n\ \n\ Set test mode on if 1 off if 0"; static PyObject* setgame_showContext(PyObject *self, PyObject *args) { char buff[1024]; sprintf(buff,"daemon: %d\n", context->daemon); sprintf(buff,"%sframe: %d\n", buff, context->frame); sprintf(buff,"%sframe_tourn_start: %d\n", buff, context->frame_tourn_start); sprintf(buff,"%sframe_tourn_end: %d\n", buff, context->frame_tourn_end); sprintf(buff,"%sframe_test_mode: %d\n", buff, context->frame_test_mode); sprintf(buff,"%sframe_test_counter: %d\n", buff, context->frame_test_counter); sprintf(buff,"%squorum[2]: %d %d (%s vs %s)\n", buff, context->quorum[0], context->quorum[1], team_code(context->quorum[0]), team_code(context->quorum[1])); sprintf(buff,"%sblog_pickup_game_full: %d\n", buff, context->blog_pickup_game_full); sprintf(buff,"%sblog_pickup_queue_full: %d", buff, context->blog_pickup_queue_full); return Py_BuildValue("s", buff); } static char setgame_showContext_doc[] = "showContext()\n\ \n\ Show the context structure."; static PyObject* setgame_example(PyObject *self, PyObject *args) { } static char setgame_example_doc[] = "example()\n\ \n\ example."; static PyMethodDef setgame_methods[] = { {"pause", setgame_pause, METH_VARARGS, setgame_pause_doc}, {"resume", setgame_resume, METH_VARARGS, setgame_resume_doc}, {"terminate", setgame_terminate, METH_VARARGS, setgame_terminate_doc}, {"waitForTerminate", setgame_waitForTerminate, METH_VARARGS, setgame_waitForTerminate_doc}, {"setTestCounter", setgame_setTestCounter, METH_VARARGS, setgame_setTestCounter_doc}, {"setTestMode", setgame_setTestMode, METH_VARARGS, setgame_setTestMode_doc}, {"showContext", setgame_showContext, METH_VARARGS, setgame_showContext_doc}, {NULL, NULL} }; PyMODINIT_FUNC initsetgame(void) { ///PyObject *m, *d; Py_InitModule3("setgame", setgame_methods, setgame_doc); //d = PyModule_GetDict(m); openmem(0); //PyDict_SetItemString(d, "pi", verbose); //Py_DECREF(verbose); }