ConVar Manager Update and more!
Last night and today I worked on finishing the ConVar manager, which I did actually complete! All convars created inside of a plug-in are added to the ConVar manager’s internal database (A Trie) and the plug-in’s convar list. Tomorrow I’ll work on adding a “cvars” option to the Viper menu, which will be accessed with “sm py cvars”. I’ve created a test plug-in to create many ConVars, which successfully created every single one, and was able to retrieve the value from each; each convar was declared as a different type of data (Float, int, string, etc.), and retrieved by each type, so as to test my error checking, also.
There is one problem, though: If you create a convar from the console by using the Python interpreter command I’ve created, “py”, it does not work. The Python convar object is created, so you can call functions on it and the such, but the Source ConVar class instantiated through “new ConVar(name, defaultVal, …)” equates to NULL when accessed. The chain of command is this:
- On the Python side, the user creates a convar object
convar = console.CreateConVar("a_name", "a_value")
- CreateConVar does some simple error checking (Making sure the name isn’t blank, etc) and calls New_ConVarObject, then Init_ConVarObject. I’m going to showoff here and present the code of this:
static PyObject * Console_CreateConVar(PyObject* self, PyObject* args, PyObject *keywds) { char const *pName, *pDefaultValue, *pHelpString = NULL; int flags = FCVAR_PLUGIN; float fMin = NULL, fMax = NULL; static char* kwds[] = {"name", "value", "desc", "flags", "max", "min", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "ss|siff", kwds, &pName, &pDefaultValue, &pHelpString, &flags, &fMin, &fMax)) return NULL; if(pName[0] == '\0') Py_RETURN_NONE; Py_XINCREF((PyObject*) &console_ConVarType); PyObject* ConVarObj = (PyObject*) console_ConVarType->tp_new((_typeobject*)console_ConVarType, args, (PyObject*)NULL); ConVarObj->ob_type->tp_init(ConVarObj, args, (PyObject*)NULL); return ConVarObj; }
- New_ConVarObject just sets the values of the object. Nothing to see here.
- Init_ConVarObject does all the real work for the Python side: error rechecks (Just in case :D), creates the ConVar (Through the ConVar manager), and does some work after the ConVar object is created.
- The ConVar manager does all the real work on the C++ side:
static int console_ConVar_Get(console_ConVarObject *self, PyObject *args, PyObject *keywds) { char const *pName, *pDefaultValue, *pHelpString = NULL; int iFlags = 0; float fMin = NULL, fMax = NULL; static char* kwds[] = {"name", "value", "desc", "flags", "max", "min", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "ss|siff", kwds, &pName, &pDefaultValue, &pHelpString, &iFlags, &fMin, &fMax)) return -1; // Make sure the ConVar has a name. teame06 would be dumb enough to make a ConVar with no name, which is why I add this check in! if(pName[0] == '\0') { PyErr_SetString(PyExc_ValueError, "cannot have a blank ConVar name."); return -1; } CPlugin* pPlugin = g_VPlugins.GetPluginByPath(GetCurrentPath()); if(pPlugin == NULL) { PyErr_SetString(PyExc_StandardError, "error in accessing the plugin."); return -1; } self->info = g_VVars.CreateConVar(pPlugin, pName, pDefaultValue, pHelpString, iFlags, (fMin != NULL), fMin, (fMax != NULL), fMax); if(!self->info || !self->info->pCvar) { PyErr_SetString(PyExc_StandardError, "error in creating ConVar."); return -1; } self->info->handle = self; self->convar = self->info->pCvar; printf("Convar '%s': '%s'\n", self->convar->GetName(), self->convar->GetString()); return 0; }
Anyways, I’m getting way too technical now. Nobody understands me. I’ll go cry in a corner.
The “and more!” is that I added ClientCommand and FakeClientCommand to the Client object. I’ll work on the Client object tomorrow, too; it needs Kick and Ban. Now, off to workout and bed for me!
can you embed ruby now
Comment by sawce — April 20, 2008 @ 10:37 pm
I’ll answer that question with another question: Has Gaben gone on a diet?
Comment by theY4Kman — April 21, 2008 @ 5:11 am
Hey theY4Kman long time no talk. Sorry about this being the only way to contact you but we haven’t talked in ages. You may remember me from a little website you got banned from
called fpsbanana.com. My name there was sh4d0w. You made me some shit for my profile like the uberstyle changer and shit like that. Then you and me(barely) were trying to make the skin installer. If you want to talk again add me at tezza_d@hotmail.com. Cheers. Nice code btw:P
Comment by terminus — April 30, 2008 @ 8:02 am