2016-07-26 07:22:47 +07:00
|
|
|
#include "precompiled.h"
|
2016-07-04 12:07:29 +06:00
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
MRegCmd::MRegCmd(char* cmd_name, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin) : pfnCmd(cmd_handler), status(RG_VALID), plugid(cmd_plugin->index)
|
2016-07-04 12:07:29 +06:00
|
|
|
{
|
2017-01-07 03:20:55 +03:00
|
|
|
name = _strdup(name);
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
bool MRegCmd::call() const
|
2016-07-26 07:22:47 +07:00
|
|
|
{
|
2017-01-07 03:20:55 +03:00
|
|
|
pfnCmd();
|
|
|
|
return status != RG_INVALID;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
void MRegCmd::disable()
|
2016-07-04 12:07:29 +06:00
|
|
|
{
|
2017-01-07 03:20:55 +03:00
|
|
|
pfnCmd = [](){};
|
|
|
|
plugid = 0;
|
|
|
|
status = RG_INVALID;
|
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
char* MRegCmd::getname() const
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
MRegCmdList::MRegCmdList() : m_list()
|
|
|
|
{
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
MRegCmd *MRegCmdList::find(const char *name) const
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2017-01-07 03:20:55 +03:00
|
|
|
for (auto icmd : m_list)
|
2016-07-26 23:31:47 +07:00
|
|
|
{
|
2017-01-07 03:20:55 +03:00
|
|
|
if (!Q_stricmp(icmd->name, name))
|
|
|
|
return icmd;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
return nullptr;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
MRegCmd *MRegCmdList::add(char *addname, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin)
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2017-01-07 03:20:55 +03:00
|
|
|
auto icmd = new MRegCmd(addname, cmd_handler, cmd_plugin);
|
|
|
|
m_list.push_back(icmd);
|
|
|
|
return icmd;
|
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
void MRegCmdList::remove(char* cmd_name)
|
|
|
|
{
|
|
|
|
for (auto it = m_list.begin(), end = m_list.end(); it != end; ++it) {
|
|
|
|
auto icmd = *it;
|
2016-07-04 12:07:29 +06:00
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
if (!Q_stricmp(icmd->name, cmd_name)) {
|
|
|
|
if (g_RehldsFuncs) {
|
|
|
|
g_RehldsFuncs->Cmd_RemoveCmd(cmd_name);
|
|
|
|
m_list.erase(it);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icmd->disable();
|
|
|
|
}
|
|
|
|
}
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable any functions belonging to the given plugin (by index id).
|
2017-01-07 03:20:55 +03:00
|
|
|
void MRegCmdList::remove(int owner_plugin_id)
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2017-01-07 03:20:55 +03:00
|
|
|
for (auto it = m_list.begin(), end = m_list.end(); it != end; ++it) {
|
|
|
|
auto icmd = *it;
|
|
|
|
|
|
|
|
if (icmd->plugid == owner_plugin_id) {
|
|
|
|
if (g_RehldsFuncs) {
|
|
|
|
g_RehldsFuncs->Cmd_RemoveCmd(icmd->name);
|
|
|
|
m_list.erase(it);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icmd->disable();
|
|
|
|
}
|
|
|
|
}
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// List all the registered commands.
|
2016-07-30 02:03:01 +03:00
|
|
|
void MRegCmdList::show() const
|
2016-07-26 07:22:47 +07:00
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
int n = 0, a = 0;
|
2016-07-26 15:18:32 +03:00
|
|
|
char bplug[18 + 1]; // +1 for term null
|
2016-07-04 12:07:29 +06:00
|
|
|
|
|
|
|
META_CONS("Registered plugin commands:");
|
2017-01-07 03:20:55 +03:00
|
|
|
META_CONS(" %*s %-*s %-s", WIDTH_MAX_REG, "", sizeof bplug - 1, "plugin", "command");
|
|
|
|
|
|
|
|
for (auto icmd : m_list)
|
2016-07-26 23:31:47 +07:00
|
|
|
{
|
|
|
|
if (icmd->status == RG_VALID)
|
|
|
|
{
|
2017-01-07 03:20:55 +03:00
|
|
|
auto iplug = g_plugins->find(icmd->plugid);
|
|
|
|
|
|
|
|
Q_strncpy(bplug, iplug ? iplug->desc : "(unknown)", sizeof bplug - 1);
|
|
|
|
bplug[sizeof bplug - 1] = '\0';
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1);
|
2016-07-26 15:18:32 +03:00
|
|
|
bplug[sizeof bplug - 1] = '\0';
|
2016-07-26 07:22:47 +07:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
META_CONS(" [%*d] %-*s %-s", WIDTH_MAX_REG, ++n, sizeof bplug - 1, bplug, icmd->name);
|
|
|
|
|
2016-07-26 23:31:47 +07:00
|
|
|
if (icmd->status == RG_VALID)
|
|
|
|
a++;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2017-01-07 03:20:55 +03:00
|
|
|
META_CONS("%d commands, %d available", n, a);
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// List all the registered commands for the given plugin id.
|
2016-07-30 02:03:01 +03:00
|
|
|
void MRegCmdList::show(int plugin_id) const
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
int n = 0;
|
2016-07-26 07:22:47 +07:00
|
|
|
|
2016-07-04 12:07:29 +06:00
|
|
|
META_CONS("Registered commands:");
|
2017-01-07 03:20:55 +03:00
|
|
|
for (auto icmd : m_list)
|
2016-07-26 23:31:47 +07:00
|
|
|
{
|
2016-07-26 07:22:47 +07:00
|
|
|
if (icmd->plugid != plugin_id)
|
2016-07-04 12:07:29 +06:00
|
|
|
continue;
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2016-07-04 12:07:29 +06:00
|
|
|
META_CONS(" %s", icmd->name);
|
|
|
|
n++;
|
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2016-07-04 12:07:29 +06:00
|
|
|
META_CONS("%d commands", n);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init values. It would probably be more "proper" to use containers and
|
|
|
|
// constructors, rather than arrays and init-functions.
|
2016-07-26 07:22:47 +07:00
|
|
|
void MRegCvar::init(int idx)
|
2016-07-04 12:07:29 +06:00
|
|
|
{
|
|
|
|
index = idx;
|
|
|
|
data = NULL;
|
|
|
|
plugid = 0;
|
|
|
|
status = RG_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the cvar, copying values from given cvar.
|
|
|
|
// meta_errno values:
|
|
|
|
// - ME_ARGUMENT given cvar doesn't match this cvar
|
2016-07-30 02:03:01 +03:00
|
|
|
bool MRegCvar::set(cvar_t *src) const
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
if (Q_stricmp(src->name, data->name))
|
|
|
|
{
|
|
|
|
META_ERROR("Tried to set cvar with mismatched name; src=%s dst=%s", src->name, data->name);
|
2017-01-07 21:03:16 +03:00
|
|
|
return false;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2016-07-04 12:07:29 +06:00
|
|
|
// Would like to free() existing string, but can't tell where it was
|
|
|
|
// allocated...
|
2016-07-26 23:31:47 +07:00
|
|
|
data->string = Q_strdup(src->string);
|
2016-07-04 12:07:29 +06:00
|
|
|
data->flags = src->flags;
|
|
|
|
data->value = src->value;
|
|
|
|
data->next = src->next;
|
2016-07-30 02:03:01 +03:00
|
|
|
return true;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegCvarList::MRegCvarList()
|
2016-07-04 12:07:29 +06:00
|
|
|
: vlist(0), size(REG_CVAR_GROWSIZE), endlist(0)
|
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
vlist = (MRegCvar *)Q_malloc(size * sizeof(MRegCvar));
|
|
|
|
|
2016-07-04 12:07:29 +06:00
|
|
|
// initialize array
|
2016-07-26 23:31:47 +07:00
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
vlist[i].init(i + 1); // 1 - based
|
|
|
|
|
2016-07-26 15:18:32 +03:00
|
|
|
endlist = 0;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the given cvar name to the list and return the instance. This only
|
|
|
|
// writes the "name" to the new cvar; other fields are written with
|
|
|
|
// cvar::set().
|
|
|
|
// meta_errno values:
|
|
|
|
// - ME_NOMEM couldn't alloc or realloc for various parts
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegCvar *MRegCvarList::add(const char *addname)
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegCvar *icvar;
|
|
|
|
if (endlist == size)
|
|
|
|
{
|
2016-07-04 12:07:29 +06:00
|
|
|
// grow array
|
2016-07-26 23:31:47 +07:00
|
|
|
int newsize = size + REG_CVAR_GROWSIZE;
|
|
|
|
|
2016-07-04 12:07:29 +06:00
|
|
|
META_DEBUG(6, ("Growing reg cvar list from %d to %d", size, newsize));
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegCvar *temp = (MRegCvar *) realloc(vlist, newsize * sizeof(MRegCvar));
|
|
|
|
if (!temp)
|
|
|
|
{
|
2016-07-26 15:18:32 +03:00
|
|
|
META_ERROR("Couldn't grow registered cvar list to %d for '%s'; %s", newsize, addname, strerror(errno));
|
2017-01-07 21:03:16 +03:00
|
|
|
return NULL;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 15:18:32 +03:00
|
|
|
vlist = temp;
|
|
|
|
size = newsize;
|
2016-07-04 12:07:29 +06:00
|
|
|
// initialize new (unused) entries
|
2016-07-26 23:31:47 +07:00
|
|
|
for (int i = endlist; i < size; i++)
|
2016-07-26 15:18:32 +03:00
|
|
|
vlist[i].init(i + 1); // 1-based
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
icvar = &vlist[endlist];
|
|
|
|
|
|
|
|
// Malloc space for the cvar and cvar name, for two reasons:
|
2016-07-26 23:31:47 +07:00
|
|
|
// - Can't point to memory loc in plugin (another segv waiting to
|
2016-07-04 12:07:29 +06:00
|
|
|
// happen).
|
2016-07-26 23:31:47 +07:00
|
|
|
// - Can't point to memory in vlist which might get moved later by
|
2016-07-04 12:07:29 +06:00
|
|
|
// realloc (again, segv).
|
2016-07-26 23:31:47 +07:00
|
|
|
icvar->data = (cvar_t *)Q_malloc(sizeof(cvar_t));
|
|
|
|
if (!icvar->data)
|
|
|
|
{
|
|
|
|
META_ERROR("Couldn't malloc cvar for adding reg cvar name '%s': %s", addname, strerror(errno));
|
2017-01-07 21:03:16 +03:00
|
|
|
return NULL;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
|
|
|
icvar->data->name = Q_strdup(addname);
|
|
|
|
if (!icvar->data->name)
|
|
|
|
{
|
|
|
|
META_ERROR("Couldn't Q_strdup for adding reg cvar name '%s': %s", addname, strerror(errno));
|
2017-01-07 21:03:16 +03:00
|
|
|
return NULL;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
endlist++;
|
2016-07-26 23:31:47 +07:00
|
|
|
return icvar;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find a registered cvar with the given name.
|
|
|
|
// meta_errno values:
|
|
|
|
// - ME_NOTFOUND couldn't find a matching cvar
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegCvar *MRegCvarList::find(const char *findname)
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
for (int i = 0; i < endlist; i++)
|
|
|
|
{
|
2016-07-26 15:18:32 +03:00
|
|
|
if (!_stricmp(vlist[i].data->name, findname))
|
2016-07-26 23:31:47 +07:00
|
|
|
return &vlist[i];
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2017-01-07 21:03:16 +03:00
|
|
|
return NULL;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disable any cvars belonging to the given plugin (by index id).
|
2016-07-30 02:03:01 +03:00
|
|
|
void MRegCvarList::disable(int plugin_id) const
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2016-07-04 12:07:29 +06:00
|
|
|
int i;
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegCvar *icvar;
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
2016-07-26 15:18:32 +03:00
|
|
|
icvar = &vlist[i];
|
2016-07-26 23:31:47 +07:00
|
|
|
if (icvar->plugid == plugin_id)
|
|
|
|
{
|
2016-07-04 12:07:29 +06:00
|
|
|
icvar->status = RG_INVALID;
|
|
|
|
icvar->plugid = 0;
|
|
|
|
// Decided not to do this, in order to keep pre-existing values
|
|
|
|
// after a plugin reload.
|
|
|
|
// CVAR_SET_STRING(icvar->data->name, "[metamod: cvar invalid; plugin unloaded]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// List all the registered cvars.
|
2016-07-30 02:03:01 +03:00
|
|
|
void MRegCvarList::show() const
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
|
|
|
int i, n = 0, a = 0;
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegCvar *icvar;
|
|
|
|
MPlugin *iplug;
|
2016-07-26 15:18:32 +03:00
|
|
|
char bplug[13 + 1], bname[20 + 1], bval[15 + 1]; // +1 for term null
|
2016-07-04 12:07:29 +06:00
|
|
|
|
|
|
|
META_CONS("Registered plugin cvars:");
|
2016-07-26 23:31:47 +07:00
|
|
|
META_CONS(" %*s %-*s %-*s %*s %s", WIDTH_MAX_REG, "", sizeof(bplug) - 1, "plugin", sizeof(bname) - 1, "cvar", sizeof(bval) - 1, "float value", "string value");
|
|
|
|
for (i = 0; i < endlist; i++)
|
|
|
|
{
|
2016-07-04 12:07:29 +06:00
|
|
|
icvar = &vlist[i];
|
2016-07-26 23:31:47 +07:00
|
|
|
if (icvar->status == RG_VALID)
|
|
|
|
{
|
2016-07-26 15:18:32 +03:00
|
|
|
iplug = g_plugins->find(icvar->plugid);
|
2016-07-26 23:31:47 +07:00
|
|
|
if (iplug)
|
|
|
|
{
|
|
|
|
Q_strncpy(bplug, iplug->desc, sizeof bplug - 1);
|
2016-07-26 15:18:32 +03:00
|
|
|
bplug[sizeof bplug - 1] = '\0';
|
2016-07-26 07:22:47 +07:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Q_strncpy(bplug, "(unknown)", sizeof bplug - 1);
|
2016-07-26 15:18:32 +03:00
|
|
|
bplug[sizeof bplug - 1] = '\0';
|
2016-07-26 07:22:47 +07:00
|
|
|
}
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1);
|
2016-07-26 15:18:32 +03:00
|
|
|
bplug[sizeof bplug - 1] = '\0';
|
2016-07-26 07:22:47 +07:00
|
|
|
}
|
|
|
|
|
2016-07-26 23:31:47 +07:00
|
|
|
Q_strncpy(bname, icvar->data->name, sizeof bname - 1);
|
2016-07-26 15:18:32 +03:00
|
|
|
bname[sizeof bname - 1] = '\0';
|
2016-07-26 23:31:47 +07:00
|
|
|
Q_snprintf(bval, sizeof(bval), "%f", icvar->data->value);
|
|
|
|
META_CONS(" [%*d] %-*s %-*s %*s %s", WIDTH_MAX_REG, icvar->index, sizeof(bplug) - 1, bplug, sizeof(bname) - 1, bname, sizeof(bval) - 1, bval, icvar->data->string);
|
|
|
|
|
|
|
|
if (icvar->status == RG_VALID)
|
|
|
|
a++;
|
|
|
|
|
2016-07-04 12:07:29 +06:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
META_CONS("%d cvars, %d available (%d allocated)", n, a, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
// List the registered cvars for the given plugin id.
|
2016-07-30 02:03:01 +03:00
|
|
|
void MRegCvarList::show(int plugin_id) const
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
int n = 0;
|
|
|
|
MRegCvar *icvar;
|
2016-07-26 15:18:32 +03:00
|
|
|
char bname[30 + 1], bval[15 + 1]; // +1 for term null
|
|
|
|
|
2016-07-26 23:31:47 +07:00
|
|
|
META_CONS("%-*s %*s %s", sizeof(bname) - 1, "Registered cvars:", sizeof(bval) - 1, "float value", "string value");
|
|
|
|
for (int i = 0; i < endlist; i++)
|
|
|
|
{
|
2016-07-04 12:07:29 +06:00
|
|
|
icvar = &vlist[i];
|
2016-07-26 07:22:47 +07:00
|
|
|
if (icvar->plugid != plugin_id)
|
2016-07-04 12:07:29 +06:00
|
|
|
continue;
|
2016-07-26 23:31:47 +07:00
|
|
|
|
|
|
|
Q_strncpy(bname, icvar->data->name, sizeof bname - 1);
|
2016-07-26 15:18:32 +03:00
|
|
|
bname[sizeof bname - 1] = '\0';
|
2016-07-26 23:31:47 +07:00
|
|
|
Q_snprintf(bval, sizeof(bval), "%f", icvar->data->value);
|
|
|
|
META_CONS(" %-*s %*s %s", sizeof(bname) - 1, bname, sizeof(bval) - 1, bval, icvar->data->string);
|
2016-07-04 12:07:29 +06:00
|
|
|
n++;
|
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2016-07-26 07:22:47 +07:00
|
|
|
META_CONS("%d cvars", n);
|
|
|
|
}
|
2016-07-04 12:07:29 +06:00
|
|
|
|
|
|
|
// Constructor
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegMsgList::MRegMsgList()
|
2016-07-04 12:07:29 +06:00
|
|
|
: size(MAX_REG_MSGS), endlist(0)
|
|
|
|
{
|
|
|
|
// initialize array
|
2016-07-26 23:31:47 +07:00
|
|
|
Q_memset(mlist, 0, sizeof(mlist));
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2016-07-26 15:18:32 +03:00
|
|
|
mlist[i].index = i + 1; // 1-based
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2016-07-26 15:18:32 +03:00
|
|
|
endlist = 0;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the given user msg the list and return the instance.
|
|
|
|
// meta_errno values:
|
|
|
|
// - ME_MAXREACHED reached max number of msgs allowed
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegMsg *MRegMsgList::add(const char *addname, int addmsgid, int addsize)
|
2016-07-26 15:18:32 +03:00
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
if (endlist == size)
|
|
|
|
{
|
2016-07-04 12:07:29 +06:00
|
|
|
// all slots used
|
2016-07-26 23:31:47 +07:00
|
|
|
META_ERROR("Couldn't add registered msg '%s' to list; reached max msgs (%d)", addname, size);
|
2017-01-07 21:03:16 +03:00
|
|
|
return NULL;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegMsg *imsg = &mlist[endlist];
|
2016-07-04 12:07:29 +06:00
|
|
|
endlist++;
|
|
|
|
|
|
|
|
// Copy msg data into empty slot.
|
|
|
|
// Note: 'addname' assumed to be a constant string allocated in the
|
|
|
|
// gamedll.
|
2016-07-26 15:18:32 +03:00
|
|
|
imsg->name = addname;
|
|
|
|
imsg->msgid = addmsgid;
|
|
|
|
imsg->size = addsize;
|
2016-07-04 12:07:29 +06:00
|
|
|
|
2016-07-26 23:31:47 +07:00
|
|
|
return imsg;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find a registered msg with the given name.
|
|
|
|
// meta_errno values:
|
|
|
|
// - ME_NOTFOUND couldn't find a matching cvar
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegMsg *MRegMsgList::find(const char *findname)
|
2016-07-26 07:22:47 +07:00
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
for (int i = 0; i < endlist; i++)
|
|
|
|
{
|
|
|
|
if (!Q_strcmp(mlist[i].name, findname))
|
|
|
|
return &mlist[i];
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2017-01-07 21:03:16 +03:00
|
|
|
return NULL;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find a registered msg with the given msgid.
|
|
|
|
// meta_errno values:
|
|
|
|
// - ME_NOTFOUND couldn't find a matching cvar
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegMsg *MRegMsgList::find(int findmsgid)
|
2016-07-26 07:22:47 +07:00
|
|
|
{
|
2016-07-26 23:31:47 +07:00
|
|
|
for (int i = 0; i < endlist; i++)
|
|
|
|
{
|
2016-07-26 07:22:47 +07:00
|
|
|
if (mlist[i].msgid == findmsgid)
|
2016-07-26 23:31:47 +07:00
|
|
|
return &mlist[i];
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2017-01-07 21:03:16 +03:00
|
|
|
return NULL;
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// List the registered usermsgs for the gamedll.
|
2016-07-26 23:31:47 +07:00
|
|
|
void MRegMsgList::show()
|
2016-07-26 07:22:47 +07:00
|
|
|
{
|
|
|
|
int i, n = 0;
|
2016-07-26 23:31:47 +07:00
|
|
|
MRegMsg *imsg;
|
2016-07-26 15:18:32 +03:00
|
|
|
char bname[25 + 1]; // +1 for term null
|
2016-07-04 12:07:29 +06:00
|
|
|
|
2016-07-26 23:31:47 +07:00
|
|
|
META_CONS("%-*s %5s %5s", sizeof(bname) - 1, "Game registered user msgs:", "msgid", "size");
|
|
|
|
for (i = 0; i < endlist; i++)
|
|
|
|
{
|
2016-07-04 12:07:29 +06:00
|
|
|
imsg = &mlist[i];
|
2016-07-26 23:31:47 +07:00
|
|
|
|
|
|
|
Q_strncpy(bname, imsg->name, sizeof bname - 1);
|
2016-07-26 15:18:32 +03:00
|
|
|
bname[sizeof bname - 1] = '\0';
|
2016-07-26 23:31:47 +07:00
|
|
|
META_CONS(" %-*s %3d %3d", sizeof(bname) - 1, bname, imsg->msgid, imsg->size);
|
2016-07-04 12:07:29 +06:00
|
|
|
n++;
|
|
|
|
}
|
2016-07-26 23:31:47 +07:00
|
|
|
|
2016-07-26 07:22:47 +07:00
|
|
|
META_CONS("%d game user msgs", n);
|
2016-07-04 12:07:29 +06:00
|
|
|
}
|