berkelium plugin no longer has annoying rescaling.

jabber plugin greatly extended. now uses links, automatically connects the next time its started, supports adding contacts, can cope with < a little better. started work towards support for NAT hole punching - can currently connect if the server has a correctly guessed public ip (first detected ipv4 address needs to work), needs more work for other scenarios.
other plugins required a little maintenance.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4398 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2013-06-23 02:33:52 +00:00
parent fa9252cefa
commit 1e423d106f
11 changed files with 2047 additions and 578 deletions

View File

@ -18,8 +18,8 @@
#define avio_alloc_context av_alloc_put_byte
*/
#define ARGNAMES ,sourceid, data, speed, samples, channels, width
BUILTIN(void, S_RawAudio, (int sourceid, void *data, int speed, int samples, int channels, int width));
#define ARGNAMES ,sourceid, data, speed, samples, channels, width, volume
BUILTIN(void, S_RawAudio, (int sourceid, void *data, int speed, int samples, int channels, int width, float volume));
#undef ARGNAMES
/*should probably try threading this*/

View File

@ -412,6 +412,30 @@ static media_encoder_funcs_t encoderfuncs =
AVEnc_End
};
/*
qintptr_t AVEnc_ExecuteCommand(qintptr_t *args)
{
char cmd[256];
Cmd_Argv(0, cmd, sizeof(cmd));
if (!strcmp(cmd, "avcapture"))
{
menuclear
menualias menucallback
menubox 0 0 320 8
menutext 0 0 "GO GO GO!!!" "radio21"
menutext 0 8 "Fall back" "radio22"
menutext 0 8 "Stick together" "radio23"
menutext 0 16 "Get in position" "radio24"
menutext 0 24 "Storm the front" "radio25"
menutext 0 24 "Report in" "radio26"
menutext 0 24 "Cancel"
return true;
}
return false;
}
*/
qboolean AVEnc_Init(void)
{
pCvar_Register("avplug_format", "", 0, "avplug");
@ -430,6 +454,9 @@ qboolean AVEnc_Init(void)
return false;
}
// if (Plug_Export("ExecuteCommand", AVEnc_ExecuteCommand))
// Cmd_AddCommand("avcapture");
return true;
}

View File

@ -54,7 +54,7 @@
<Tool
Name="VCLinkerTool"
AdditionalDependencies="berkelium/berkelium.lib"
OutputFile="C:\Games\Quake\fte\plugins\$(ProjectName)x86.dll"
OutputFile="../../fteplug_berkeliumx86.dll"
LinkIncremental="2"
GenerateManifest="false"
ModuleDefinitionFile="..\plugin.def"

View File

@ -18,6 +18,9 @@ public:
int height;
unsigned int *buffer;
bool repainted;
int paintedwidth;
int paintedheight;
};
class MyDelegate : public Berkelium::WindowDelegate
@ -200,8 +203,8 @@ static void *Dec_Create(char *medianame)
decctx *ctx = new decctx();
Berkelium::Context* context = Berkelium::Context::create();
ctx->width = 1024;
ctx->height = 1024;
ctx->paintedwidth = ctx->width = 1024;
ctx->paintedheight = ctx->height = 1024;
ctx->repainted = false;
ctx->buffer = (unsigned int*)malloc(ctx->width * ctx->height * 4);
ctx->wnd = Berkelium::Window::create(context);
@ -226,6 +229,8 @@ static void *Dec_DisplayFrame(void *vctx, qboolean nosound, enum uploadfmt_e *fm
if (!ctx->repainted)
return NULL;
ctx->paintedwidth = ctx->width;
ctx->paintedheight = ctx->height;
ctx->repainted = false;
return ctx->buffer;
}
@ -238,8 +243,16 @@ static void Dec_Destroy(void *vctx)
static void Dec_GetSize (void *vctx, int *width, int *height)
{
decctx *ctx = (decctx*)vctx;
*width = ctx->width;
*height = ctx->height;
if (ctx->repainted)
{
*width = ctx->width;
*height = ctx->height;
}
else
{
*width = ctx->paintedwidth;
*height = ctx->paintedheight;
}
}
static qboolean Dec_SetSize (void *vctx, int width, int height)
{

File diff suppressed because it is too large Load Diff

527
plugins/jabber/xml.c Normal file
View File

@ -0,0 +1,527 @@
#include "../plugin.h"
#include "xml.h"
void XML_Destroy(xmltree_t *t);
char *XML_GetParameter(xmltree_t *t, char *paramname, char *def)
{
xmlparams_t *p;
if (t)
{
for (p = t->params; p; p = p->next)
if (!strcmp(p->name, paramname))
return p->val;
}
return def;
}
void XML_AddParameter(xmltree_t *t, char *paramname, char *value)
{
xmlparams_t *p = malloc(sizeof(xmlparams_t));
Q_strlcpy(p->name, paramname, sizeof(p->name));
Q_strlcpy(p->val, value, sizeof(p->val));
if (t->params) //reverse insert
{
xmlparams_t *prev;
for(prev = t->params; prev->next; prev = prev->next)
;
prev->next = p;
p->next = NULL;
}
else
{
p->next = t->params;
t->params = p;
}
}
void XML_AddParameteri(xmltree_t *t, char *paramname, int value)
{
char svalue[64];
Q_snprintf(svalue, sizeof(svalue), "%i", value);
XML_AddParameter(t, paramname, svalue);
}
xmltree_t *XML_CreateNode(xmltree_t *parent, char *name, char *xmlns, char *body)
{
struct subtree_s *node = malloc(sizeof(*node));
//clear out links
node->params = NULL;
node->child = NULL;
node->sibling = NULL;
//link into parent if we actually have a parent.
if (parent)
{
node->sibling = parent->child;
parent->child = node;
}
Q_strlcpy(node->name, name, sizeof(node->name));
Q_strlcpy(node->xmlns, xmlns, sizeof(node->xmlns));
Q_strlcpy(node->xmlns_dflt, xmlns, sizeof(node->xmlns_dflt));
Q_strlcpy(node->body, body, sizeof(node->xmlns_dflt));
if (*xmlns)
XML_AddParameter(node, "xmlns", xmlns);
return node;
}
const struct
{
char code;
int namelen;
char *name;
} xmlchars[] =
{
{'<', 2, "lt"},
{'>', 2, "gt"},
{'&', 3, "amp"},
{'\'', 4, "apos"},
{'\"', 4, "quot"},
{0, 0, NULL}
};
//converts < to &lt; etc.
//returns the end of d.
char *XML_Markup(char *s, char *d, int dlen)
{
int i;
dlen--;
while(*s)
{
for(i = 0; xmlchars[i].name; i++)
{
if (*s == xmlchars[i].code)
break;
}
if (xmlchars[i].name)
{
if (dlen < xmlchars[i].namelen+2)
break;
*d++ = '&';
memcpy(d, xmlchars[i].name, xmlchars[i].namelen);
d+=xmlchars[i].namelen;
*d++ = ';';
*s++;
}
else
{
if (!dlen)
break;
*d++ = *s++;
}
}
*d = 0;
return d;
}
//inplace. result will always be same length or shorter.
//converts &lt; etc to their original chars
void XML_Unmark(char *s)
{
char *d;
int i;
for (d = s; *s; )
{
if (*s == '&')
{
s++;
for (i = 0; xmlchars[i].name; i++)
{
if (!strncmp(s, xmlchars[i].name, xmlchars[i].namelen) && s[xmlchars[i].namelen] == ';')
break;
}
if (xmlchars[i].name)
{
s += xmlchars[i].namelen+1;
*d++ = xmlchars[i].code;
}
else
{
*d++ = '&';
}
}
else
*d++ = *s++;
}
*d = 0;
}
struct buf_ctx
{
char *buf;
int len;
int maxlen;
};
static void buf_cat(struct buf_ctx *buf, char *data, int datalen)
{
int newlen = buf->len + datalen+1;
if (newlen > buf->maxlen)
{
char *newd;
newlen *= 2;
newd = malloc(newlen);
memcpy(newd, buf->buf, buf->len);
free(buf->buf);
buf->buf = newd;
buf->maxlen = newlen;
}
memcpy(buf->buf + buf->len, data, datalen);
buf->len += datalen;
}
static XML_DumpToBuf(struct buf_ctx *buf, xmltree_t *t, int indent)
{
xmltree_t *c;
xmlparams_t *p;
int i;
for (i = 0; i < indent; i++)
buf_cat(buf, " ", 1);
buf_cat(buf, "<", 1);
buf_cat(buf, t->name, strlen(t->name));
for (p = t->params; p; p = p->next)
{
buf_cat(buf, " ", 1);
buf_cat(buf, p->name, strlen(p->name));
buf_cat(buf, "=\'", 2);
buf_cat(buf, p->val, strlen(p->val));
buf_cat(buf, "\'", 1);
}
if (t->child)
{
buf_cat(buf, ">", 1);
if (indent>=0)
buf_cat(buf, "\n", 1);
for (c = t->child; c; c = c->sibling)
XML_DumpToBuf(buf, c, ((indent<0)?indent:(indent+2)));
for (i = 0; i < indent; i++)
buf_cat(buf, " ", 1);
buf_cat(buf, "</", 2);
buf_cat(buf, t->name, strlen(t->name));
buf_cat(buf, ">", 1);
}
else if (*t->body)
{
buf_cat(buf, ">", 1);
buf_cat(buf, t->body, strlen(t->body));
buf_cat(buf, "</", 2);
buf_cat(buf, t->name, strlen(t->name));
buf_cat(buf, ">", 1);
}
else
{
buf_cat(buf, "/>", 2);
}
if (indent>=0)
buf_cat(buf, "\n", 1);
}
char *XML_GenerateString(xmltree_t *root)
{
struct buf_ctx buf = {NULL, 0, 0};
XML_DumpToBuf(&buf, root, -1);
buf_cat(&buf, "", 1);
return buf.buf;
}
xmltree_t *XML_Parse(char *buffer, int *startpos, int maxpos, qboolean headeronly, char *defaultnamespace)
{
xmlparams_t *p;
xmltree_t *child;
xmltree_t *ret;
int bodypos;
int pos, i;
char *tagend;
char *tagstart;
char *ns;
char token[1024];
pos = *startpos;
while (buffer[pos] >= '\0' && buffer[pos] <= ' ')
{
if (pos >= maxpos)
break;
pos++;
}
if (pos == maxpos)
{
*startpos = pos;
return NULL; //nothing anyway.
}
//expect a <
if (buffer[pos] != '<')
{
Con_Printf("Missing open bracket\n");
return NULL; //should never happen
}
if (buffer[pos+1] == '/')
{
Con_Printf("Unexpected close tag.\n");
return NULL; //err, terminating a parent tag
}
tagend = strchr(buffer+pos, '>');
if (!tagend)
{
Con_Printf("Missing close bracket\n");
return NULL; //should never happen
}
*tagend = '\0';
tagend++;
//assume no nulls in the tag header.
tagstart = buffer+pos+1;
while (*tagstart == ' ' || *tagstart == '\n' || *tagstart == '\r' || *tagstart == '\t')
tagstart++;
for (i = 0; i < sizeof(token)-1 && *tagstart; )
{
if (*tagstart == ' ' || *tagstart == '\n' || *tagstart == '\r' || *tagstart == '\t')
break;
token[i++] = *tagstart++;
}
token[i] = 0;
pos = tagend - buffer;
ret = malloc(sizeof(xmltree_t));
memset(ret, 0, sizeof(*ret));
ns = strchr(token, ':');
if (ns)
{
*ns = 0;
ns++;
memcpy(ret->xmlns, "xmlns:", 6);
Q_strlcpy(ret->xmlns+6, token, sizeof(ret->xmlns)-6);
Q_strlcpy(ret->name, ns, sizeof(ret->name));
}
else
{
Q_strlcpy(ret->xmlns, "xmlns", sizeof(ret->xmlns));
Q_strlcpy(ret->name, token, sizeof(ret->name));
}
while(*tagstart)
{
int nlen;
while(*tagstart <= ' ' && *tagstart)
tagstart++; //skip whitespace (note that we know there is a null terminator before the end of the buffer)
if (!*tagstart)
break;
p = malloc(sizeof(xmlparams_t));
nlen = 0;
while (nlen < sizeof(p->name)-2)
{
if(*tagstart <= ' ')
break;
if (*tagstart == '=')
break;
p->name[nlen++] = *tagstart++;
}
p->name[nlen++] = '\0';
while(*tagstart <= ' ' && *tagstart)
tagstart++; //skip whitespace (note that we know there is a null terminator before the end of the buffer)
if (*tagstart != '=')
continue;
tagstart++;
while(*tagstart <= ' ' && *tagstart)
tagstart++; //skip whitespace (note that we know there is a null terminator before the end of the buffer)
nlen = 0;
if (*tagstart == '\'')
{
tagstart++;
while (*tagstart && nlen < sizeof(p->name)-2)
{
if(*tagstart == '\'')
break;
p->val[nlen++] = *tagstart++;
}
tagstart++;
p->val[nlen++] = '\0';
}
else if (*tagstart == '\"')
{
tagstart++;
while (*tagstart && nlen < sizeof(p->name)-2)
{
if(*tagstart == '\"')
break;
p->val[nlen++] = *tagstart++;
}
tagstart++;
p->val[nlen++] = '\0';
}
else
{
while (*tagstart && nlen < sizeof(p->name)-2)
{
if(*tagstart <= ' ')
break;
p->val[nlen++] = *tagstart++;
}
p->val[nlen++] = '\0';
}
XML_Unmark(p->val);
p->next = ret->params;
ret->params = p;
}
ns = XML_GetParameter(ret, ret->xmlns, "");
Q_strlcpy(ret->xmlns, ns, sizeof(ret->xmlns));
ns = XML_GetParameter(ret, "xmlns", NULL);
Q_strlcpy(ret->xmlns_dflt, ns?ns:defaultnamespace, sizeof(ret->xmlns_dflt));
tagend[-1] = '>';
if (tagend[-2] == '/')
{ //no body
*startpos = pos;
return ret;
}
if (ret->name[0] == '?')
{
//no body either
if (tagend[-2] == '?')
{
*startpos = pos;
return ret;
}
}
if (headeronly)
{
*startpos = pos;
return ret;
}
//does it have a body, or is it child tags?
bodypos = 0;
while(1)
{
if (pos == maxpos)
{ //malformed
Con_Printf("tree is malfored\n");
XML_Destroy(ret);
return NULL;
}
if (buffer[pos] == '<')
{
if (buffer[pos+1] == '/')
{ //the end of this block
//FIXME: check name
tagend = strchr(buffer+pos, '>');
if (!tagend)
{
Con_Printf("No close tag\n");
XML_Destroy(ret);
return NULL; //should never happen
}
tagend++;
pos = tagend - buffer;
break;
}
child = XML_Parse(buffer, &pos, maxpos, false, ret->xmlns_dflt);
if (!child)
{
Con_Printf("Child block is unparsable\n");
XML_Destroy(ret);
return NULL;
}
child->sibling = ret->child;
ret->child = child;
}
else
{
char c = buffer[pos++];
if (bodypos < sizeof(ret->body)-1)
ret->body[bodypos++] = c;
}
}
ret->body[bodypos++] = '\0';
XML_Unmark(ret->body);
*startpos = pos;
return ret;
}
void XML_Destroy(xmltree_t *t)
{
xmlparams_t *p, *np;
if (t->child)
XML_Destroy(t->child);
if (t->sibling)
XML_Destroy(t->sibling);
for (p = t->params; p; p = np)
{
np = p->next;
free(p);
}
free(t);
}
xmltree_t *XML_ChildOfTree(xmltree_t *t, char *name, int childnum)
{
if (t)
{
for (t = t->child; t; t = t->sibling)
{
if (!strcmp(t->name, name))
{
if (childnum-- == 0)
return t;
}
}
}
return NULL;
}
void XML_ConPrintTree(xmltree_t *t, int indent)
{
int start, c, chunk;
struct buf_ctx buf = {NULL, 0, 0};
XML_DumpToBuf(&buf, t, indent);
buf_cat(&buf, "", 1);
for (start = 0; start < buf.len; )
{
chunk = buf.len - start;
if (chunk > 128)
chunk = 128;
c = buf.buf[start+chunk];
buf.buf[start+chunk] = 0;
Con_Print(buf.buf+start);
buf.buf[start+chunk] = c;
start += chunk;
}
free(buf.buf);
}

33
plugins/jabber/xml.h Normal file
View File

@ -0,0 +1,33 @@
typedef struct xmlparams_s
{
char val[256]; //FIXME: make pointer
struct xmlparams_s *next;
char name[64]; //FIXME: make variable sized
} xmlparams_t;
typedef struct subtree_s
{
char name[64]; //FIXME: make pointer to tail of structure
char xmlns[64]; //namespace of the element //FIXME: make pointer to tail of structure
char xmlns_dflt[64]; //default namespace of children //FIXME: make pointer to tail of structure
char body[2048]; //FIXME: make pointer+variablesized
xmlparams_t *params;
struct subtree_s *child;
struct subtree_s *sibling;
} xmltree_t;
char *XML_GetParameter(xmltree_t *t, char *paramname, char *def);
void XML_AddParameter(xmltree_t *t, char *paramname, char *value);
void XML_AddParameteri(xmltree_t *t, char *paramname, int value);
xmltree_t *XML_CreateNode(xmltree_t *parent, char *name, char *xmlns, char *body);
char *XML_Markup(char *s, char *d, int dlen);
void XML_Unmark(char *s);
char *XML_GenerateString(xmltree_t *root);
xmltree_t *XML_Parse(char *buffer, int *startpos, int maxpos, qboolean headeronly, char *defaultnamespace);
void XML_Destroy(xmltree_t *t);
xmltree_t *XML_ChildOfTree(xmltree_t *t, char *name, int childnum);
void XML_ConPrintTree(xmltree_t *t, int indent);

View File

@ -58,6 +58,8 @@ typedef struct
typedef struct
{
searchpathfuncs_t pub;
char desc[MAX_OSPATH];
vfsfile_t *file;
ofs_t filestart;
@ -244,11 +246,6 @@ unsigned int mpq_lookuphash(mpqarchive_t *mpq, const char *filename, int locale)
}
vfsfile_t *MPQ_OpenVFS(void *handle, flocation_t *loc, const char *mode);
void MPQ_GetDisplayPath(void *handle, char *outpath, unsigned int pathsize)
{
mpqarchive_t *mpq = handle;
Q_strlcpy(outpath, mpq->desc, pathsize);
}
void MPQ_ClosePath(void *handle)
{
mpqarchive_t *mpq = handle;
@ -346,13 +343,13 @@ static int mpqwildcmp(const char *wild, const char *string, char **end)
}
return !*wild;
}
int MPQ_EnumerateFiles(void *handle, const char *match, int (QDECL *func)(const char *fname, int fsize, void *parm, void *spath), void *parm)
int MPQ_EnumerateFiles(searchpathfuncs_t *handle, const char *match, int (QDECL *func)(const char *fname, int fsize, void *parm, searchpathfuncs_t *spath), void *parm)
{
int ok = 1;
char *s, *n;
char name[MAX_QPATH];
flocation_t loc;
mpqarchive_t *mpq = handle;
mpqarchive_t *mpq = (mpqarchive_t*)handle;
if (mpq->listfile)
{
s = mpq->listfile;
@ -403,7 +400,17 @@ void MPQ_BuildHash(void *handle, int depth, void (QDECL *AddFileHash)(int depth,
}
}
void *MPQ_OpenNew(vfsfile_t *file, const char *desc)
int MPQ_GeneratePureCRC (void *handle, int seed, int usepure)
{
return 0;
}
qboolean MPQ_PollChanges(void *handle)
{
return false;
}
searchpathfuncs_t *MPQ_OpenArchive(vfsfile_t *file, const char *desc)
{
flocation_t lloc;
mpqarchive_t *mpq;
@ -492,13 +499,20 @@ void *MPQ_OpenNew(vfsfile_t *file, const char *desc)
break;
}
}
return mpq;
mpq->pub.fsver = FSVER;
mpq->pub.ClosePath = MPQ_ClosePath;
mpq->pub.BuildHash = MPQ_BuildHash;
mpq->pub.FindFile = MPQ_FindFile;
mpq->pub.ReadFile = MPQ_ReadFile;
mpq->pub.EnumerateFiles = MPQ_EnumerateFiles;
mpq->pub.GeneratePureCRC = MPQ_GeneratePureCRC;
mpq->pub.OpenVFS = MPQ_OpenVFS;
mpq->pub.PollChanges = MPQ_PollChanges;
return &mpq->pub;
}
int MPQ_GeneratePureCRC (void *handle, int seed, int usepure)
{
return 0;
}
struct blastdata_s
{
@ -815,38 +829,20 @@ vfsfile_t *MPQ_OpenVFS(void *handle, flocation_t *loc, const char *mode)
return &f->funcs;
}
qboolean MPQ_PollChanges(void *handle)
{
return false;
}
searchpathfuncs_t funcs =
{
MPQ_GetDisplayPath,
MPQ_ClosePath,
MPQ_BuildHash,
MPQ_FindFile,
MPQ_ReadFile,
MPQ_EnumerateFiles,
MPQ_OpenNew,
MPQ_GeneratePureCRC,
MPQ_OpenVFS,
MPQ_PollChanges,
};
qintptr_t Plug_Init(qintptr_t *args)
{
mpq_init_cryptography();
//we can't cope with being closed randomly. files cannot be orphaned safely.
//so ask the engine to ensure we don't get closed before everything else is.
pPlug_ExportNative("UnsafeClose", NULL);
if (!pPlug_ExportNative("FS_RegisterArchiveType_mpq", &funcs))
if (!pPlug_ExportNative("FS_RegisterArchiveType_mpq", MPQ_OpenArchive))
{
Con_Printf("avplug: Engine doesn't support media decoder plugins\n");
return false;
}
if (!pPlug_ExportNative("FS_RegisterArchiveType_MPQ", &funcs))
if (!pPlug_ExportNative("FS_RegisterArchiveType_MPQ", MPQ_OpenArchive))
{
Con_Printf("avplug: Engine doesn't support media decoder plugins\n");
return false;

View File

@ -116,6 +116,7 @@ extern "C" {
extern qintptr_t (*plugin_syscall)( qintptr_t arg, ... );
void Q_strlcpy(char *d, const char *s, int n);
void Q_strlcat(char *d, const char *s, int n);
int Q_snprintf(char *buffer, size_t maxlen, const char *format, ...);
int Q_vsnprintf(char *buffer, size_t maxlen, const char *format, va_list vargs);

View File

@ -561,4 +561,13 @@ void Q_strlcpy(char *d, const char *s, int n)
}
*d='\0';
}
void Q_strlcat(char *d, const char *s, int n)
{
if (n)
{
int dlen = strlen(d);
int slen = strlen(s)+1;
memcpy(d+dlen, s, min((n-1)-dlen, slen));
d[n - 1] = 0;
}
}

View File

@ -382,7 +382,7 @@ void X_SendIntialResponse(xclient_t *cl)
setup->maxKeyCode = 255;
vendor = (char *)(setup+1);
strcpy(vendor, FULLENGINENAME " X");
strcpy(vendor, "FTE X");
setup->nbytesVendor = (strlen(vendor)+3)&~3;
pixmapformats = (xPixmapFormat *)(vendor + setup->nbytesVendor);