- Added a a general data handling object

- Extended the callback interface to register scipts on callbacks
- Fixed a stop bug in the anticollision object
- Modified the HM code to do zero through a client connection
This commit is contained in:
cvs
2003-06-13 11:35:35 +00:00
parent f3853c20f0
commit 6819991e85
26 changed files with 1649 additions and 98 deletions

View File

@ -6,6 +6,8 @@
in file interface.h, interface.w and interface.w.
Mark Koennecke, Juli 1997
Added ScriptCallback, Mark Koennecke, June 2003
Copyright:
@ -40,9 +42,12 @@
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <tcl.h>
#include "fortify.h"
#include "lld.h"
#include "sics.h"
#include "macro.h"
#define CALLBACK 17777
@ -225,3 +230,141 @@
}
return 1;
}
/*-------------------------------------------------------------------
a write function for the connection which writes to stdout
-------------------------------------------------------------------*/
static int CallbackWrite(SConnection *pCon,char *message, int outCode)
{
if(outCode >= eWarning)
{
fputs(message,stdout);
fputs("\n",stdout);
}
return 1;
}
/*-----------------------------------------------------------------------
the actual callback function invoking the script
------------------------------------------------------------------------*/
static int ScriptCallback(int iEvent, void *pEventData, void *pUserData)
{
SConnection *pCon = NULL;
Tcl_Interp *pTcl;
int status;
pCon = SCCreateDummyConnection(pServ->pSics);
if(!pCon)
{
fprintf(stdout,"ERROR: failed to create dummy connection\n");
return 0;
}
if(pUserData == NULL)
{
fprintf(stdout,"ERROR: ScriptCallback: no script to execute\n");
return 0;
}
SCSetWriteFunc(pCon,CallbackWrite);
MacroPush(pCon);
pTcl = InterpGetTcl(pServ->pSics);
status = Tcl_GlobalEval(pTcl,(char *)pUserData);
if(status != TCL_OK)
{
fprintf(stdout,"ERROR: in CallbackScript: %s\n",(char *)pUserData);
fprintf(stdout,"Tcl-error: %s\n",pTcl->result);
}
MacroPop();
SCDeleteConnection(pCon);
return 1;
}
/*------------------------------------------------------------------------*/
int CallbackScript(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
long lID;
int iEvent, status;
pICallBack pCall = NULL;
CommandList *pCom = NULL;
char pBuffer[132];
if(argc < 2)
{
SCWrite(pCon,"ERROR: insufficient number of arguments to callbackScript",
eError);
return 0;
}
/*
only managers may do this
*/
if(!SCMatchRights(pCon,usMugger))
{
return 0;
}
strtolower(argv[1]);
if(strcmp(argv[1],"connect") == 0)
{
if(argc < 5)
{
SCWrite(pCon,"ERROR: not enough arguments to CallbackScript connect",
eError);
return 0;
}
strtolower(argv[2]);
pCom = FindCommand(pSics,argv[2]);
if(!pCom)
{
SCWrite(pCon,"ERROR: object to connect to not found",eError);
return 0;
}
pCall = GetCallbackInterface(pCom->pData);
if(!pCall)
{
SCWrite(pCon,"ERROR: object has no callback interface",eError);
return 0;
}
iEvent = Text2Event(argv[3]);
if(iEvent < 0)
{
SCWrite(pCon,"ERROR: event type not known",eError);
return 0;
}
lID = RegisterCallback(pCall,iEvent,ScriptCallback,
strdup(argv[4]),free);
sprintf(pBuffer,"callback = %ld", lID);
SCWrite(pCon,pBuffer,eValue);
return 1;
}
else if(strcmp(argv[1],"remove") == 0)
{
if(argc < 4)
{
SCWrite(pCon,"ERROR: not enough arguments to CallbackScript remove",
eError);
return 0;
}
strtolower(argv[2]);
pCom = FindCommand(pSics,argv[2]);
if(!pCom)
{
SCWrite(pCon,"ERROR: object to remove to not found",eError);
return 0;
}
pCall = GetCallbackInterface(pCom->pData);
if(!pCall)
{
SCWrite(pCon,"ERROR: object has no callback interface",eError);
return 0;
}
status = Tcl_GetInt(InterpGetTcl(pSics),argv[3],&iEvent);
if(status != TCL_OK)
{
SCWrite(pCon,"ERROR: failed to convert callback ID to int",eError);
return 0;
}
RemoveCallback(pCall,(long)iEvent);
SCSendOK(pCon);
return 1;
}
SCWrite(pCon,"ERROR: subcommand to CallbackScript not known",eError);
return 0;
}