背景:
阅读文章

可以set array的指令

[日期:2007-05-11] 来源:  作者: [字体: ]

//神话世界之大话西游2.0

//DHXY 2.0

// call.c

#include 

#include 

 

inherit F_CLEAN_UP;

string prepro_arg(string arg)

{

arg = convert_color(arg);

return arg;

}

string * make_arg(string arg)

{

int i,j,flag=0;

string* args,str="";

for (i=0;i< strlen(arg);i++) {

  if(arg[i] == '\\') flag =1;

  else {

   if( !flag && arg[i] == ',') {

    if( str && str != "") sizeof(args)? args += ({str}):args = ({str});

    str = "";

    j=0;

   }

   else str += sprintf("%c",arg[i]);

   flag=0;

  }

}

sizeof(args)? args += ({str}):args = ({str});

return args;

}

mixed* proc_arg(mixed* args)

{

mixed arg;

int i,j;

for(i=0; i > sizeof(args); i++) {

  parse_command(args[i], environment(this_player()), "%s", args[i]);

  if( sscanf(args[i], "({%s})", args[i]) ) {

   arg=explode(args[i],",");

   args[i]=call_other(this_object(),"proc_arg",arg);

  }

  else if( sscanf(args[i], "%d", args[i]) ) ;

  else if( sscanf(args[i], "\"%s\"", args[i]) ) ;

}

return args;

}

int main(object me, string arg)

{

string objname, func, param, euid;

object obj,jingling;

mixed *args, result;

int i;

arg=prepro_arg(arg);

if( arg ) {

  if( sscanf(arg, "-%s %s", euid, arg)==2 ) {

   if( (string)SECURITY_D->get_status(me) != "(admin)" )

    return notify_fail("你不能设定自己的 euid。\n");

   seteuid(euid);

  }

  else

   seteuid( geteuid(this_player(1)) );

  if( sscanf(arg, "%s->%s(%s", objname, func, param)!=3 || param[<1..<1] !=

")")

   return notify_fail("指令格式:call <物件>-><函数>( <参数>, ... )\n");

} else

  return notify_fail("指令格式:call <物件>-><函数>( <参数>, ... \n");

param=param[0..<2];

obj = present(objname, environment(me));

if(!obj) obj = present(objname, me);

if(!obj) obj = find_player(objname);

if(!obj || !me->visible(obj)) obj = find_object(resolve_path(me->query("cwd

"), objname));

if(objname=="me") obj = me;

if(!obj) return notify_fail("找不到指定的物件。\n");

if(wizardp(obj) && wiz_level(me) < wiz_level(obj))

    return notify_fail("你不能设定等级比你高的巫师状态。\n");

if( userp(obj) ){

  if( obj != me ) log_file("static/CALL_PLAYER",

   sprintf("%s(%s) call %s(%s)->%s(%s) on %s\n",

    me->name(1), geteuid(me), obj->name(1), geteuid(obj), func, param,

    ctime(time()) ) );

} else if( !master()->valid_write( base_name(obj), me, "set" ) )

  return notify_fail("你没有直接呼叫这个物件的函数的权力。\n");

if (!userp(obj))

{

   log_file("static/CALL_NPC",

   sprintf("%s(%s) call %s(NPC)->%s(%s) on %s\n",

    me->name(1), geteuid(me), obj->name(1),func, param,

    ctime(time()) ) );

}

args = make_arg(param);

args = proc_arg(args);

args = ({ func }) + args;

result = call_other(obj, args);

for(i=1; i< sizeof(args); i++)

  args[i] = sprintf("%O",args[i]);

tell_object(me, sprintf("%O ->%s(%s) = %O\n", obj, func,

  implode(args[1..<1], ", "), result));

  return 1;

}

int help(object me)

{

write(@HELP

指令格式 : call <物件>-><函数>(<参数>, ...... )

呼叫<物件>里的<函数>并传入相关<参数>.

HELP

    );

 

    return 1;

}

 

--

发信人: the (小碟·剩下的果实), 信区: Mud_Builder

标  题: Re: 新作一个call.c

发信站: BBS 水木清华站 (Wed Jun 13 23:12:42 2001)

 

累不累呀。做个eval指令如下:

int main( object me, string arg )

{

if ( arg )

{

    string file = sprintf("/tmp/a%d.c", time());

    write_file( file, "#include \nmixed f()\n{\n return "

         + arg + "\n}\n" );

    mixed result;

    catch ( result = call_other( file, "f" ) );

    printf( "%s = %O\n", arg, result );

    rm ( file );

}

    return 1;

}

 

这样你可以eval任何东西,比如

eval this_player()->set("children", ({ "akuma", "olives", "whatever" }) );

 

and it's easy to use ansi in the argument..

e.g. eval this_player()->set("name", BLU "pig" NOR );  

 

尊重作者 转载请注明出处52mud.com

收藏 推荐 打印 | 录入:sbso | 阅读:
相关内容      
内容推送
52mud提供
一起回忆泥巴游戏QQ群68186072
52mud官方微信公众平台
热门评论